%----------------- MATLABソース -----------------%
function main()
N = 128*16;
cx = 0.1; cy = 0.1;
sx = 0; sy = 0;
x(1) = 0; y(1) = 0;
for i=2:N
[dx dy] = randwalk;
sx = sx + cx * dx;
sy = sy + cx * dy;
x(i) = sx;
y(i) = sy;
end
minx = min(x); maxx = max(x);
miny = min(y); maxy = max(y);
for i=1:N-1
plot(x(1:i),y(1:i),'k',x(i),y(i),'o',x(1),y(1),'or');
axis equal;
axis([minx maxx miny maxy]);
pause(0.01)
F(i) = getframe;
end
movie2avi(F,'randomwalk.avi');
end
function [dx dy] = randwalk
w=0;
while w==0
w=rand(1)-0.5;
w = sign(w);
end
dx = 0; dy = 0;
if ceil(2*rand(1)) == 1
dx = w;
else
dy = w;
end
end
%----------------- MATLABソース -----------------%
実行の結果
0 件のコメント:
コメントを投稿