8
MATLAB Stochastic Simulations Wednesday, 9/13/2002

MATLAB Stochastic Simulations

  • Upload
    rossa

  • View
    50

  • Download
    0

Embed Size (px)

DESCRIPTION

MATLAB Stochastic Simulations. Wednesday, 9/13/2002. Diffusion. nPart = 400; %number of particles sizeRandomStep = .02; %temperature related parameter rMax = 10; %initial particles x = rand(nPart,1)-0.5; y = rand(nPart,1)-0.5; h = plot(x,y,'.'); %plot particles as dots hold on - PowerPoint PPT Presentation

Citation preview

Page 1: MATLAB Stochastic Simulations

MATLAB Stochastic Simulations

Wednesday, 9/13/2002

Page 2: MATLAB Stochastic Simulations

Diffusion

Page 3: MATLAB Stochastic Simulations

DiffusionSimulation

nPart = 400; %number of particlessizeRandomStep = .02; %temperature related parameterrMax = 10;

%initial particlesx = rand(nPart,1)-0.5;y = rand(nPart,1)-0.5;

h = plot(x,y,'.'); %plot particles as dotshold onaxis([-20 20 -20 20])axis squaregrid offset(h,'EraseMode','xor','MarkerSize',18)

% draw the circle the diffusion will finally reach totheta = linspace( 0, pi*2, 50 );plot(rMax*cos(theta),rMax*sin(theta),'r-');

nStep = 0;while ( max(sqrt(x.^2+y.^2)) < rMax ) drawnow x = x + sizeRandomStep * randn(nPart,1); y = y + sizeRandomStep * randn(nPart,1); nStep = nStep + 1; set(h,'XData',x,'YData',y)EndnStep % display how many steps cost to reach to the circle

Page 4: MATLAB Stochastic Simulations

Erase Mode for Animation

This tells the MATLAB graphics system not to redraw theentire plot when the coordinates of one point are changed,but to restore the background color in the vicinity of thepoint using an “exclusive or” operation.

set(h,'EraseMode','xor','MarkerSize',18)

Page 5: MATLAB Stochastic Simulations

Brownian Motion in a Closed Box

Page 6: MATLAB Stochastic Simulations

Boundary Treatment

Reflection for the random movement with tendency to go outside.

Page 7: MATLAB Stochastic Simulations

Pressure

Momentum change for particle hit on the boundary surface with random movement of distance s and hit angle is

mass⋅s⋅sinθtimestep

mass = 1 unit masstimestep = 1 unit time

Page 8: MATLAB Stochastic Simulations

Extension of particles from one room to two rooms