VIRTUAL ROBOT DISPLACEMENT And Random assignment
2 次查看(过去 30 天)
显示 更早的评论
HI i try to simulate this problem but i can 't get the good results can you help me please ....I want to simulate the random displacement of a virtual robot in a matrix M 100 x 100. The robot begins its journey to the coordinate (50,50). The robot moves randomly: it has a 30% chance to go to the right, a 35% chance to go down, a 15% chance to go to the left, and a 20% chance to go to the right. go up. If the robot manages to reach a box on the edge of the matrix, then the "experiment" is complete.
1. Write the line of code to create the matrix M, filled with 0, in which the robot moves.
2. Each box
of M visited by the robot will be incremented (its value will be increased by 1). The robot begins its journey to the coordinate box (50; 50): Write the line of code to initialize the matrix M with the correct value. We will also initialize two variables: i will be the line number where the robot is located, and j will be the column number where the robot is located.
3. Write the lines of code to test if the experiment is finished, and the end of the screen if this is the case. As a reminder, the experiment ends if the robot is on a box at the edge of the matrix M, that is to say a box whose column or row number is 1 or 100.
4. Write the lines of code allowing the robot to make a random move according to the laws of probability stated at the beginning of the exercise. Be careful, when the robot moves, the box of the matrix M o u moves the robot, as well as the variable i or j, must be updated.
6. Write the line of code, to add to the n of your algorithm, allowing to obtain the number of displacements realized the robot before reaching the edge of the matrix.
7. Write a program that achieves a million times the robot's moving experience in the matrix, and averages the number of trips needed to reach the edge of the matrix.
M=zeros(100,100);
[rows, columns] = size(M);
i=1;
j=1;
R(i,j)=M(50,50);
dp=0;
for k=1:rows
for l=1:columns
M(k,l)=M(k,l)+1
R(i,j)=M(k,l);
dp=dp+1;
end
end
while i==1 & j==1 & i==100 & j==100
disp('experiment is finish')
end
direction=rand()
if direction==0.3
l=l+1;
elseif direction==0.35
k=k+1;
elseif direction==0.15
l=l-1;
else
k=k-1
end
disp('dp is the number of displacement')
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Coordinate Transformations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!