布朗运动

% Script file:EXAMP04030.m

% This Programe in MATLAB modela Brown's motion.

% Clear variables in workspace.

clear

%Clear the current figure window.

clf

% Clear command window.   

clc

% Define the number of moving points n=100.

n=100;

% Define the velocity of the points s=0.005.

s=0.005;

% Define the values of x-positions of the points.

x=rand(n,1)-0.5;

% Define the values of y-positions of points.

y=rand(n,1)-0.5;

% Plot all the points.

h=plot(x,y,'o');

% Determine the range of axes.

axis([-1 1 -1 1]);

% Set axes as square.

axis square;

% Do not show the background grid.

grid off

% Set some properties of the points.

set(h,'EraseMode','Xor',MarkerSize',5,'MarkerFaceColor','r','MarkerEdgeColor','r');

% Let these points move arbitrarily.

for i=linspace(1,10,5000)

% Complete pending drawing events.

drawnow

% Redefine the positions (x,y) of the points.

x=x+s*randn(n,1);

y=y+s*randn(n,1);

%Take the newly defiend values to x and y.

set(h,'XData',x,'YData',y);

end


图片发自简书App
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容