在Matlab中模拟随机游走

问题描述

你好,这就是我所做的

enter image description here

我已经完成了指向F点的操作

我所缺少的,我不知道怎么做是最后一点(G)

因为这样的东西必须出现

最后一点,您能帮我吗?

enter image description here

我的代码:

clc;clear;close all;
x=zeros; %store all x
y=zeros; %store all y
cx=0; %current x
cy=0; %current y
for i=1:20
x1 = rand(1); %generate random value
x2 = rand(1); %generate random value
s = 100*log(x1); %step size
angle = 2*pi*x2;
dx = s*cos(angle); %step size along x
cx = cx+dx; %new x position
dy = s*sin(angle); %step size along y
cy = cy+dy; %new y position
x = [x cx]; %add to array
y = [y cy]; %add to array


end

plot(x,y); %plot

title('Random Walk');
xlabel('X')
ylabel('Y')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)