Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer this in octave asap thank you Write a program named random_walkers

ID: 3813359 • Letter: P

Question

Please answer this in octave asap

thank you

Write a program named random_walkers_FerrisID.m (using your Ferris ID) that calculates and plots the path of two random walkers. The starting x, y point will be (0, 0) for both walkers. Each "walker" will then randomly move one unit from their previous position in one of four directions; +x, +y, -x, or -y. This is repeated over and over for a set number of moves. A plot is generated using arrays of the walkers' x and y positions. Include the following with this program: Include at least 5 comments stating the program name, the author name, and describing what different sections of the program do Clear all variables at the beginning Clear the screen (console) before displaying anything or asking questions Display a title line for the program Ask the user to enter the total number of moves for the random walker to take Use a for-end loop and the number of moves to calculate the positions of the two walkers Randomly assign movement directions for the two walkers each time through the loop Use switch-case structures to calculate the new position of each walker based on their previous position and their randomly generated direction Determine the total number of units each walker moved Determine the absolute value of the distance from the ending position to the starting position for each walker Determine the straight line distance that the two walkers ended up from each other Use one or more print f statements to display the total number of units moved by each walker, the number of units each walker ended up being away from the starting position, and the straight line distance between the two walkers when in their final positions (display the distances from the start and straight line distance with 2-decimal places) Plot the path of the walkers using a solid, blue and red lines lines. Set the axes of the plot to be equal and include a title and axes labels. On the same plot, use black + and o markers to mark the final locations of the walkers and a green * to mark the location of the start point. Test the script with 1000 moves Save your plot using the command print ('walkers.png')

Explanation / Answer

function random_walk_2d_simulation ( step_num, walk_num, filename )

time = 0 : step_num;
d21_ave = zeros(step_num+1,1);
d2_max = zeros(step_num+1,1);

for walk = 1 : walk_num

x = zeros(step_num+1,1);
y = zeros(step_num+1,1);
  
for step = 2 : step_num + 1

destination = [ x(step-1) + 1.0, y(step-1); ...
x(step-1) - 1.0, y(step-1); ...
x(step-1), y(step-1) + 1.0; ...
x(step-1), y(step-1) - 1.0 ];

k = ceil ( 4.0 * rand );

x(step) = destination(k,1);
y(step) = destination(k,2);
d2 = x(step)^2 + y(step)^2;
d21_ave(step) = d21_ave(step) + d2;
d2_max(step) = max ( d2_max(step), d2 );

end

end

d21_ave(:,1) = d21_ave(:,1) / walk_num;
clf
plot ( time, d21_ave, time, d2_max, 'LineWidth', 2 );

xlabel ( 'Time' )
ylabel ( 'Distance squared' )
title_string = sprintf ( ...
' %d walks, %d steps', walk_num, step_num );
title ( title_string );

print ( '-dpng', filename );
fprintf ( 1, ' ' );
fprintf ( 1, 'file saved in "%s" ', filename );

return
end