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

This is the code i have. If it is right, i need help with the first plot. How do

ID: 3597673 • Letter: T

Question

This is the code i have. If it is right, i need help with the first plot. How do you plot R(t) and F(t) on the same axis?

clear;

1323

Ra=@(R,F) 2*R-1.2*R*F;

Fo=@(F,R)-F+.9*R*F

R0=2;

F0=3;

dR=0.1;

dF=0.1;

tsteps=8;

R(1)=R0;

F(1)=F0;

R=R0:dR:R0+tsteps*dR;

F=F0:dF:F0+tsteps*dF;

for i=1:tsteps

h2=dR/2;

h2f=dF/2;

Rtemp=R(i)+h2;

Ftemp=F(i)+h2f;

kR1=Ra(R(i),F(i));

kf1=Fo(F(i),R(i));

kR2= Ra(Rtemp,R(i)+h2*kR1);

kf2=Fo(Ftemp,F(i)+h2f*kf1);

kR3=Ra(Rtemp, R(i)+h2*kR2);

kf3=Fo(Ftemp, F(i)+h2f*kf2);

kR4=Ra(R(i+1),R(i)+dR*kR3);

kf4=Fo(F(i+1),F(i)+dF*kf3)

F(i+1)=R(i)+dR/6*(kR1+2*kR2+2*kR3+kR4);

R(i+1)=F(i)+dF/6*(kf1+2*kf2+2*kf3*kf4);

end

plot(R,F,'r-o')

xlabel('Rabbits')

ylabel('Foxes')

1) In class, we wrote code for the RK-4 method for solving the initial value problem dy dt = f(t,u) y(to)= yo. Modify this code to implement the RK-4 method to solve the predator-prey system dR = 2R-1.2RF dt dF =-F + 0.9 RF dt R(0) = 2 F(0) 3 Display your results in two separate pictures: (a) showing both R(t) and F(t) on the same set of axes and (b) displaying R on the horizontal axis and F on the vertical axis.

Explanation / Answer

Ra=@(R,F) 2*R-1.2*R*F;

Fo=@(F,R)-F+.9*R*F

R0=2;

F0=3;

dR=0.1;

dF=0.1;

tsteps=8;

R(1)=R0;

F(1)=F0;

R=R0:dR:R0+tsteps*dR;

F=F0:dF:F0+tsteps*dF;

for i=1:tsteps

h2=dR/2;

h2f=dF/2;

Rtemp=R(i)+h2;

Ftemp=F(i)+h2f;

kR1=Ra(R(i),F(i));

kf1=Fo(F(i),R(i));

kR2= Ra(Rtemp,R(i)+h2*kR1);

kf2=Fo(Ftemp,F(i)+h2f*kf1);

kR3=Ra(Rtemp, R(i)+h2*kR2);

kf3=Fo(Ftemp, F(i)+h2f*kf2);

kR4=Ra(R(i+1),R(i)+dR*kR3);

kf4=Fo(F(i+1),F(i)+dF*kf3)

F(i+1)=R(i)+dR/6*(kR1+2*kR2+2*kR3+kR4);

R(i+1)=F(i)+dF/6*(kf1+2*kf2+2*kf3*kf4);

end

plot(R,F,'r-o')

xlabel('Rabbits')

ylabel('Foxes')

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote