Wednesday, July 4, 2012

Random Walk/Brownian Motion


random_walk
%******************* Random walk/Brownian Motion**********************
%************************** By Mahesha MG ****************************
clc;
figure('color','white');

n=input('Number of steps: ');
x=randi(100,n,1);
y=randi(100,n,1);
sum=0;
for i=2:n
    x1=[x(i-1);x(i)];
    y1=[y(i-1);y(i)];
    sum=sum+sqrt((x(i-1)-x(i))^2+(y(i-1)-y(i))^2);
    plot(x1,y1,'bo',x1,y1,'--r');
    hold all
    xlim([0 100]);
    ylim([0 100]);
    title('Random Walk/Brownian Motion');
    xlabel('Mahesha MG 2012 maheshamg@gmail.com');
    getframe;
    pause(0.2)
end

'Mean free path'
sum/n
Mean free path = 54.5453



No comments:

Post a Comment