Question 1 R robots are located at the center of a square room of length L. Each
ID: 3628203 • Letter: Q
Question
Question 1
R robots are located at the center of a square room of length L. Each robot moves randomly in a series of discrete steps, in one of four directions, namely, North, East, South or West. At each step, the step size is a random number in the range [0,S] and there is an equal probability of one of the four directions being chosen. Each wall of the room is of one of the following two types: Reflecting or Absorbing.
The inputs are: the number of robots R, the length of the room L, in meters, the number of steps N, the maximum size of each step S, in cm, the type of each wall, reflecting or absorbing.
Using MATLAB, for a given input, draw a plot, with appropriate title and labels, of the position of the robots from the origin (the center of the room), as a function of time. For the same input, draw plots, with appropriate titles and labels, of the average position and standard deviation of the position of the robots, respectively, as a function of time. Does the absorbing or reflecting nature of the walls have an effect on the measures.
This is what I did so far:
% random walk
x=[];
y=[];
x(1)=0;
y(1)=0;
for i=1:3000
J=rand;
if J<0.25
x(i+1)=x(i)+1;
y(i+1)=y(i);
elseif (J>0.25)&(J<0.5)
x(i+1)=x(i)-1;
y(i+1)=y(i);
elseif (J>0.5)&(J<0.75)
x(i+1)=x(i);
y(i+1)=y(i)+1;
else
x(i+1)=x(i);
y(i+1)=y(i)-1;
end
end
plot(x,y)
Please help. Thank you.
Explanation / Answer
Think modularized functions. You're going to want to also use loop structures. Start with pseudo code and work up from there. For example: getInputs for R, S, and N boolean absorbingWallType[4] = askIfAbsorbingWallTypes( N, S, E, W ) // Initialize robot positions at the center of the room. robotPositons = matrix of 2 by R to store x,y for R robots. for( robot : 1 to R ) robotPositions[ robot ] = [ S/2, S/2 ] endfor for( step : 1 to N ) for( robot : 1 to R ) stepSize = S * randomFrom0.0to1.0 direction = chooseDirectionRandomly robotPosition[R] = adjustRobotPosition( robotPosition[R], by S, in the +X,-X,+Y,or -Y) if( robotPosition[R].x < 0 ) // Hit east wall. if( absorbingWallType[W] ) // Absorb the motion. robotPosition[R].x = 0 else // Reflect the motion. robotPosition[R].x = -1 * robotPosition[R].x endif // absorbing wall endif // west wall if( robotPosition[R].y < 0 ) // do similar above for south wall. endif // south wall. // check East Wall (x > S) // check North Wall (y > S) // output robot position for this step of this robot. endfor // robot endfor // step Hope this helps.Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.