Question

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

Only Part B please.

B .)By reading the matrix Y and the vector t, find (approximately) the last three values of t in the interval 0 ≤ t ≤ 45 at which y reaches a local maximum. Note that, because the M-file LAB04ex1.m is a function file, all the variables are local and thus not available in the Command Window. To read the matrix Y and the vector t, you need to modify the M-file by adding the line [t, Y(:,1), Y(:,2)]. Do not include the whole output in your lab write-up. Include only the values necessary to answer the question, i.e. just the rows of [t, y, v] with local y-maxima and the adjacent rows. To quickly locate the desired rows, recall that the local maxima of a differentiable function appear where its derivative changes sign from positive to negative. (Note: Due to numerical approximations and the fact that the numerical solution is not necessarily computed at the exact t-values where the maxima occur, you should not expect v(= y 0 ) to be exactly 0 at local maxima, but only close to 0)

Instructions: Just like for all the other lab reports, unless otherwise specified, include in your lab report all M-files, fi

0 0
Add a comment Improve this question Transcribed image text
Answer #1


8&Matlab code for solving ode clear all close all #Answering question b. Initial conditions for ode yO=(1.6;1.2]; {minimum an Plot for y(y and v(t) vs. t solution FLA A yt),v=y 1 VA HA 5 10 15 20 25 30 35 40 45 Phase potrait plot V=y -2.5 -2 -1.5 -1

%%Matlab code for solving ode
clear all
close all
%Answering question b.
%Initial conditions for ode
y0=[1.6;1.2];
      
        %minimum and maximum x
        tspan=[0 45];
        %Solution of ODEs using ode45 matlab function
        sol1= ode45(@(t,y) odefcn1(t,y), tspan, y0);
        %Equally splitting x into small intervals
        t1 = linspace(tspan(1),tspan(end),501);
        %yy is the corresponding x y v and z
        yy1 = deval(sol1,t1);
        figure(1)
        hold on
        plot(t1,yy1(1,:),'linewidth',2)
        plot(t1,yy1(2,:),'linewidth',2)
        ylim([-2.9 2.9])
        title('Plot for y(t) and v(t) vs. t solution')
        xlabel('t')
        ylabel('y(t),v=y''')
        legend('y(t)','v(t)')
        box on
        grid on
        figure(2)
        plot(yy1(1,:),yy1(2,:),'linewidth',2)
        xlabel('y')
        ylabel('v=y''')
        title('Phase potrait plot')
        grid on; box on;
        ylim([-2.9 2.9]); xlim([-2.9 2.9])
%Function for evaluating the ODE
function dydt = odefcn1(t,y)

    eq1= y(2);
    eq2= -4.*sin(t)-4.*y(2)-3.*y(1);
  

    %Evaluate the ODE for our present problem
    dydt = [eq1;eq2];
  
end
%----------------------------End of Code-----------------------------%

Add a comment
Know the answer?
Add Answer to:
t0 = 0; tf = 20; y0 = [10;60]; a = .8; b = .01; c...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Instructions: For your lab write-up follow the instructions of LAB 1 1. (a) Modify the function e...

    Instructions: For your lab write-up follow the instructions of LAB 1 1. (a) Modify the function exvith2eqs to solve the IVP (4) for o St S40 using the MATLAB routine ode45. Call the new function LAB04exl 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();Y(2) Plot y(t) and e(t) in the same window (do not use subplot), and...

  •    MATLAB SCRIPT PLEASE Matlab MATH 210 in 2020 Homework Assignment 8- Due 3/25, 11:59PM Each...

       MATLAB SCRIPT PLEASE Matlab MATH 210 in 2020 Homework Assignment 8- Due 3/25, 11:59PM Each plot should have its own figure associated with it. In all questions, give the figure a title, and label the acis. Save your matlab script as drill 10.m Do not use the fplot command. 1. Plot the function f(x) = (x + 5)2 for -5 <<<10. Include a plot title, and label both aris. 2. Use the subplot command to make two plots of...

  • please help me with this MATLAB CODE and explain to me what each line does and...

    please help me with this MATLAB CODE and explain to me what each line does and what is used for? leave your comments as words, not as pictures. ..................................................................................................................................................................... clear all; close all; % For a script file, you better start with clear all and close all                        % However, for a fucntion, you better NOT to start                        % with them %% End of cell mode example %% Plot function t = 0:0.1:5; x1 = sin(2*5*t); x2 = cos(3*7*t);...

  • help me with this. Im done with task 1 and on the way to do task...

    help me with this. Im done with task 1 and on the way to do task 2. but I don't know how to do it. I attach 2 file function of rksys and ode45 ( the first is rksys and second is ode 45) . thank for your help Consider the spring-mass damper that can be used to model many dynamic systems -- ----- ------- m Applying Newton's Second Law to a free-body diagram of the mass m yields the...

  • 2. The energy of the mass-spring system is given by the sum of the kinetic energy and the potenti...

    using matlab help to answer #2 please show steps in creating code 2. The energy of the mass-spring system is given by the sum of the kinetic energy and the potential energy. In the absence of damping, the energy is conserved (a) Add commands to LAB05ex1 to compute and plot the quantity E-m k2 as a function of time. What do you observe? (pay close attention to the y-axis scale and, if necessary, use ylim to get a better graph)....

  • Problem 1 MATLAB A Taylor series is a series expansion of a function f()about a given point a. For one-dimensional real...

    Problem 1 MATLAB A Taylor series is a series expansion of a function f()about a given point a. For one-dimensional real-valued functions, the general formula for a Taylor series is given as ia) (a) (z- a) (z- a)2 + £(a (r- a) + + -a + f(x)(a) (1) A special case of the Taylor series (known as the Maclaurin series) exists when a- 0. The Maclaurin series expansions for four commonly used functions in science and engineering are: sin(x) (-1)"...

  • Use the attached Matlab code as a basis to solve the following ordinary differential equation usi...

    Question 1 QUESTION 2 Use the attached Matlab code as a basis to solve the following ordinary differential equation using Euler's method, with timestep of 0.1, from t-0to t-100. d)0) -0 - sin (5vt cos(у Plot y versus t from t=0 to t=100. How many local maxima are on this interval(do not include end points). Be careful to count them all! Answer should be an integer 1 w% Matlab code for the solution of Module 2 3 dt-9.1; %dt is...

  • I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear...

    I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear all; format long; f=@(t,y)y*(1-y); y(1)=0.01; %%%% Exact solution [t1 y1]=ode45(f,[0 9],y(1)); figure; plot(t1,y1,'*'); hold on % Eular therom M=[32 64 128]; T=9; fprintf(' M Max error \n' ); for n=1:length(M) k=T/M(n); t=0:k:T; for h=1:length(t)-1 y(h+1)=y(h)+k*f(t(h),y(h)); end plot(t,y); hold on %%%...

  • Exercises: u used to the instructor b the end of next lab. 20 102 Plot the f(t)-sinc(20r) cos(300...

    Exercises: u used to the instructor b the end of next lab. 20 102 Plot the f(t)-sinc(20r) cos(300t)sinc (10t) cos(100t) Use the fast Fourier transform to find the magnitude and phase spectrum of the signal and plot over an appropriate range. Use appropriate values for the time interval and the sampling interval. Note that in Matlab sinc(x)-, so we need to divide the argument by n to make it match the given function. Le, sinc(20t/pi) Hint: Use the parameters from...

  • Need help with this Matlab program %% Exercise 1 % NOTE: Please suppress output--i.e., use a...

    Need help with this Matlab program %% Exercise 1 % NOTE: Please suppress output--i.e., use a semicolon ';' at the end of any % commands for which the output is not necessary to answer the question. % Delete these notes before turning in. % Define input variable theta as discretized row vector (i.e., array). theta = ??; % Define radius. r = ??; % Define x and y in terms of theta and r. x = ??; y = ??;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT