% 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