quiz10_solution - x = position%pos vec x;col 1 x col 2 y...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [lastposition] = brownian(steps) %BROWNIAN - A function that simulates Brownian motion of a particle. %input - number of steps in simulation, must be an integer. %output - a plot of the particles motion in the x-y plane. %call - call from the command window, e.g. brownian(10000) position = [0 0]; %initial position at origin
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x = position; %pos vec x;col 1 x; col 2 y for k = 1:steps; %for loop theta = 2*pi*rand; %0 < random direction <2*pi position = x(end,:)+[cos(theta) sin(theta)]; %polar to cart; new pos x = [x;position]; %add new pos to vector x end plot(x(:,1),x(:,2), '-k' ); lastposition = [x(end,1),x(end,2)]; end...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online