Question: Modify the script ex with 2eqs to solve the IVP (L4.4) for 0 t 35 using the MATLAB routine ode45. Call the new script LAB04ex1.
Modify the script ex with 2eqs to solve the IVP (L4.4) for 0 t 35 using the MATLAB routine ode45. Call the new script LAB04ex1. Let [t,Y] (note the upper case Y) be the output of ode45 and y and v the unknown functions. Use the following commands to define the ODE:
function dYdt= f(t,Y) y=Y(1); v=Y(2); dYdt = [v; 2*cos(t)-6*v-4*y]; end Plot y(t) and v(t) in the same window (do not use subplot), and the phase plot showing v vs y in a separate window. Add a legend to the first plot. (Note: to display v(t) = y 0 (t), use v(t)=y(t)). Add a grid. Use the command ylim([-1.5,1.5]) to adjust the y-limits for both plots. Adjust the x-limits in the phase plot so as to reproduce the pictures in Figure L4g. Include the M-file in your report.
For what (approximate) value(s) of t does y reach a local maximum in the window 0 t 35? Check by reading the matrix Y and the vector t. To read the matrix Y and the vector t in a single array, you need to modify the M-file by adding the line [t Y] Do not include the whole output in your lab write-up. Include only the values necessary to answer the question. (c) What seems to be the long term behavior of y? (d) Modify the initial conditions to y(0) = 5, v(0) = 7 and run the file LAB04ex1.m with the modified initial conditions. Based on the new graphs, determine whether the long term behavior of the solution changes. Explain. Include the pictures with the modified initial conditions to support your answer.
ex with 2 eqs script:
t0 = 0; tf = 20; y0 = [10;60]; a = .8; b = .01; c = .6; d = .1; [t,y] = ode45(@f,[t0,tf],y0,[],a,b,c,d); u1 = y(:,1); u2 = y(:,2); % y in output has 2 columns corresponding to u1 and u2 figure(1); subplot(2,1,1); plot(t,u1,'b-+'); ylabel('u1'); subplot(2,1,2); plot(t,u2,'ro-'); ylabel('u2'); figure(2) plot(u1,u2); axis square; xlabel('u_1'); ylabel('u_2'); % plot the phase plot %---------------------------------------------------------------------- function dydt = f(t,y,a,b,c,d) u1 = y(1); u2 = y(2); dydt = [ a*u1-b*u1*u2 ; -c*u2+d*u1*u2 ]; end Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
