THIS IS A MATLAB PROBLEM Suppose you are walking randomly in two dimensions. At
ID: 3829513 • Letter: T
Question
THIS IS A MATLAB PROBLEM
Suppose you are walking randomly in two dimensions. At each time step, you may randomly change your position along the x-axis to the right (plus one) and left (minus one), or nor moving. Similarly, you can randomly change your position on y-axis the same as on the x-axis. (up or down or not moving).
a). program an iterative loop to stimulate the two-dimensional moving start at origion(x=0,y=0). cout how many steps N are needed to cross the boundary of a circle centered at origin with radius of 15, r = 15.
b). plot the trace of the moving to the boundary in one color and overlay the circle boundary in another color.
Explanation / Answer
r = [-1,0,1] ;
x=0 ;
y=0 ;
n=0 ;
c=0 ;
rv=15;
a = linspace(0,2*pi,360);
x1 = 15 * cos(a) ;
y1 = 15 * sin(a) ;
plot(x1,y1,'r');
axis('equal');
while c==0
posx = randi(length(r));
movx = r(posx);
x= x+movx;
posy = randi(length(r));
movy = r(posy);
y= y+movy;
co = [0,0;x,y];
d = sqrt((x-0)^2+(y-0)^2);
n = n+2;
plot(x,y,'b');
if (d >= rv)
c=1;
end
end
fprintf(' Number Of steps taken is %d ',n);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.