Question: Using Matlab. I have almost everything figured out I need help with section %% Recording time it takes for each competitor to complete the races
Using Matlab. I have almost everything figured out I need help with section
%% Recording time it takes for each competitor to complete the races
What I want to do in this section is to save the last value of ind_rab_t and ind_tort_t into vectors rab_best_t and tort_best_t respectively.
%% Each animal's fastest and slowest run
For this, my goal is if the current ind_rab_t(end) and ind_tort_t(end) is less than the previous one in the while statement, then it will save the lesser vector.
Please don't rewrite anything prior to that unless you have to...
Here's the problem:
Here's a link if the image doesn't show: https://puu.sh/uGJkE/a8e3a8d258.png
Here's what I have:
clc clear
run_count=0;
win_tort=0; win_rab=0; tie=0;
t_tort_100=0; t_rab_100=0;
%% 100 Trials of race while run_count
%% Tortoise
ind = 1; distance_tort(ind) = 0; ind_tort_t(ind) = 0; t_tort = 0; ind = 2;
while distance_tort(ind-1)20 && action_type_tort80 % if 20% slip ind_tort_t(ind)=ind_tort_t(ind-1)+1; t_tort = t_tort + 1; distance_tort(ind) = distance_tort(ind-1) + (S*1); ind = ind + 1; end end end
%% Rabbit
ind = 1; distance_rab(ind) = 0; ind_rab_t(ind) = 0; t_rab = 0; ind = 2;
while distance_rab(ind-1)20 && action_type_rab30 && action_type_rab70 && action_type_rab80 % if 20% small slip ind_rab_t(ind)=ind_rab_t(ind-1)+1; t_rab = t_rab + 1; distance_rab(ind) = distance_rab(ind-1) + (SS*1); ind = ind + 1; end end end
%% Recording the number of races won by each animal if ind_tort_t(end) fprintf('Tortoise has won!') win_tort=win_tort+1; elseif ind_tort_t(end)>ind_rab_t(end) fprintf('Rabbit has won!') win_rab=win_rab+1; else fprintf('It''s a tie!') tie=tie+1; end
%% Recording time it takes for each competitor to complete the races t_tort_100(ind)=ind_tort_t(end); t_rab_100(ind)=ind_rab_t(end);
%% Each animal's fastest and slowest run if ind_tort_t(end) tort_best_t=ind_tort_t; else tort_best_t=ind_tort_t; end
if ind_rab_t(end) rab_best_t=ind_rab_t; else rab_best_t=ind_rab_t; end run_count=run_count+1
end
The racetrack is 4.2 miles long. The first contender to travel that distance wins. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground. The competitors can move in a variety of actions, which move them forward or backward at a certain velocity. After doing one action for a specific time, they immediately do another one. Each action has a certain frequency of occurrence (assumed to be independent of previous actions. The action type, velocity, time to complete, and frequency for each competitor is shown in the following table. Animal Action Type Frequency Time to complete Velocity 20Ro Tortoise Fast Plod 2 minutes Forward at 2 mph Slow plod 4 minutes Forward at mph minute Backward at 1 mph Seep 20Ro Hare 45 minutes No movement 10% Forward at 10 mph Small hops 40% 5 minutes Forward at 3 mph Big Slip 10% minute Backward at 8 mph Backward at 3 mph Small slip Model a series of races using MATLAB and do the following: 1. Perform 100 trials of the race. 2. Record the number of races won by each animal. Present this result in your report. 3. Record how long it takes for each competitor to complete each race. Create a histogram. for each. 4. Keep track of the race progress (time and position) for each animal's fastest and slowest run. Make a plot of position vs. time that features four lines: one for each competitor's fastest and slowest nunsStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
