Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

MATH 2131 Homework 5: Animations Page 1 Instructions. Create a file called HW_5.m that contains the code that creates the animation described below. This animation will use the drawnow function....

1 answer below »
MATH 2131 Homework 5: Animations Page 1
Instructions. Create a file called HW_5.m that contains the code that creates the animation
described below. This animation will use the drawnow function.
Background
Recall the animation we created in class with the file CatAndMouse.m. In that animation a
cat chased a mouse. In a loop we recalculated the new position of the cat each time step,
using the fact that the cat always goes directly towards the mouse.
In this animation there will be 6 cats equally spaced around the unit circle chasing each
other. Specifically, each cat will chase the cat that is immediately clockwise to it. See Figure
1 below.
Figure 1: Each cat chases the cat immediately clockwise to it.
MATH 2131 Homework 5: Animations Page 2
Hints
The code for this animation is very similar to that of CatAndMouseDrawnow.m. It would be
a good idea to start with that code and modify it according to the following hints.
Hint 1. Instead of using a while loop, just use a for loop and run the animation for 250
time steps. Make the time increment, dt, equal to 0.01 seconds.
Hint 2. Instead of positionsMouse and positionsCat you will need variables called positionsCat1,
positionsCat2, etc. An even better idea is to use a single 3-dimensional matrix called po-
sitionsCats. This matrix will have 2 rows, 250 columns, and 6 pages.
Hint 3. In CatAndMouseDrawnow.m, the mouse had its own velocity function, whereas the
cat’s velocity involved always heading straight toward the mouse. In this animation there are
6 cats heading straight for another cat. Therefore you should delete all the code involving
the mouse.
Hint 4. Inside the for loop, it is recommended that you use the following structure:
1. First create variables that contain the previous positions of each cat.
2. Next calculate the direction vectors for each cat.
3. Then calculate the vectors that represent the actual change in position of each cat.
This is where you have to take into account your time step. Don’t forget to make the
direction vectors from the previous step unit vectors by dividing by their norms.
4. Now calculate the 6 cu
ent positions of the cats.
5. Finally, update the positions matrices with the new cu
ent positions.
6. When graphing the data, use the scatter function with a dot size of 50. Make each
cat a different color of your choice.
Answered 4 days After Mar 28, 2021

Solution

Rahul answered on Apr 01 2021
140 Votes
crc = @(r,p,a) [r*cosd(a + p); r*sind(a + p)];
t = linspace(250, 1, 250); % Time
init_pos = 0;
init_pos1 = 60;
init_pos2 = 120;
init_pos3 = 180;
init_pos4 = 240;
init_pos5 = 300; % Initial Position (°)
adius = 1;
locus =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here