Question

MATLAB HELP 3. (a) In one window, graph four different solutions to y 00 + 10y 0 + y = sin t by using different initial conditions. (Be sure that all four graphs are clearly visible in the window.) (b) Describe the apparent behavior of the solutions as t → ∞.

4. (a) Graph solutions to y 00 + a y = sin 3t, y(0) = 1, y 0 (0) = 1 for each of the values a = 9.5, 9.25, 9.125, and 9. (b) Which equation (if any) shows resonance? (Hint: You may need to change the range for x to see the full behavior of each solution.)

(a) In one window, graph four different solutions to y + 10y + y = sin t by using different initial conditions. (Be sure th

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


Matlab code for solving ode clear all close all Answering question 3 %1st Initial conditions for ode y0 1 01 minimum and maxitspan 0 &Solution of ODES using ode45 matlab function sol- ode45 (@ (t,y) odefcn (t,y), tspan, y0); Equally splitting time t1tl linspace(tspan1),tspan (end),1001) x is the corresponding value for x(1) and x(2) yy1 deval (sol, tl); for initial conditiPlot for y(t) vs. t for question 3. yO) -1 : dv(OVdt 0 v0-0: d( OVdt=1 0.5 0.5 50 10 45 1.5 35 30 25 20 15 10 time Plot for yPlot for yt vs. t for a-9.25 150 100 50 time vs. t for a 9.12 Plot for y 15 10 5 10 15 150 100 20 50 time 5Plot for y(t vs. t for a-9.00 25 20 15 5 -5 10 15 20 150 100 50 time Published with MATLAB R2018a 6

%%Matlab code for solving ode
clear all
close all
%Answering question 3
%1st Initial conditions for ode
y0=[1;0];

        %minimum and maximum time span
        tspan=[0 50];
        %Solution of ODEs using ode45 matlab function
        sol= ode45(@(t,y) odefcn(t,y), tspan, y0);
        %Equally splitting time
        t1 = linspace(tspan(1),tspan(end),1001);
        %x is the corresponding value for x(1) and x(2)
        yy1 = deval(sol,t1);
      
        %plotting y1(t) vs t for initial condition
        %y(0)=1; dy(0)/dt=0;
        figure(1)
        hold on
        plot(t1,yy1(1,:),'Linewidth',2)
        title('Plot for x(t) vs. t')
        xlabel('time')
        ylabel('y(t)')
        box on
      
      
%2nd Initial conditions for ode
y0=[0;1];

        %minimum and maximum time span
        tspan=[0 50];
        %Solution of ODEs using ode45 matlab function
        sol= ode45(@(t,y) odefcn(t,y), tspan, y0);
        %Equally splitting time
        t1 = linspace(tspan(1),tspan(end),1001);
        %x is the corresponding value for x(1) and x(2)
        yy1 = deval(sol,t1);
      
        %plotting y1(t) vs t for initial condition
        %y(0)=0; dy(0)/dt=1;
     
        plot(t1,yy1(1,:),'Linewidth',2)
        title('Plot for x(t) vs. t')
        xlabel('time')
        ylabel('y(t)')
        box on
      
%3rd Initial conditions for ode
y0=[0.5;0.5];

        %minimum and maximum time span
        tspan=[0 50];
        %Solution of ODEs using ode45 matlab function
        sol= ode45(@(t,y) odefcn(t,y), tspan, y0);
        %Equally splitting time
        t1 = linspace(tspan(1),tspan(end),1001);
        %x is the corresponding value for x(1) and x(2)
        yy1 = deval(sol,t1);
      
        %plotting y1(t) vs t for initial condition
        %y(0)=0.5; dy(0)/dt=0.5;
     
        plot(t1,yy1(1,:),'Linewidth',2)
        title('Plot for y(t) vs. t for question 3.')
        xlabel('time')
        ylabel('y(t)')
        box on
%4th Initial conditions for ode
y0=[-1;-1];

        %minimum and maximum time span
        tspan=[0 50];
        %Solution of ODEs using ode45 matlab function
        sol= ode45(@(t,y) odefcn(t,y), tspan, y0);
        %Equally splitting time
        t1 = linspace(tspan(1),tspan(end),1001);
        %x is the corresponding value for x(1) and x(2)
        yy1 = deval(sol,t1);
      
        %plotting y1(t) vs t for initial condition
        %y(0)=0.5; dy(0)/dt=0.5;
     
        plot(t1,yy1(1,:),'Linewidth',2)
        title('Plot for y(t) vs. t for question 3.')
        xlabel('time')
        ylabel('y(t)')
        box on      
        legend('y(0)=1; dy(0)/dt=0','y(0)=0; dy(0)/dt=1',...
            'y(0)=0.5; dy(0)/dt=0.5','y(0)=-1; dy(0)/dt=-1')
        fprintf('For Question 3.\n')
        fprintf('At t tends to infinity it will be oscillating with as sin(t).\n')

      
%Answering question 4.
%1st Initial conditions for ode
y0=[1;1];
a=[9.5 9.25 9.125 9];

for ii=1:length(a)
        %minimum and maximum time span
        tspan=[0 150];
        %Solution of ODEs using ode45 matlab function
        sol= ode45(@(t,y) odefunc(t,y,a(ii)), tspan, y0);
        %Equally splitting time
        t1 = linspace(tspan(1),tspan(end),1001);
        %x is the corresponding value for x(1) and x(2)
        yy1 = deval(sol,t1);
      
        %plotting y1(t) vs t for initial condition
        %y(0)=1; dy(0)/dt=0;
        figure(ii+1)
     
        plot(t1,yy1(1,:),'Linewidth',2)
        title(sprintf('Plot for y(t) vs. t for a=%2.2f',a(ii)))
        xlabel('time')
        ylabel('y(t)')
        box on
end

fprintf('\tFor question 4. a=9 shows resonance.\n')
%-----------------------------------------------------------------%

%Function for evaluating the ODE for question 3.
function dydt = odefcn(t,y)

    eq1 = y(2);
    eq2 = -y(1)-10*y(2)+sin(t);
  
    %Evaluate the ODE for our present problem
    dydt = [eq1;eq2];
end
%-----------------------------------------------------------------%

%-----------------------------------------------------------------%

%Function for evaluating the ODE for question 4.
function dydt = odefunc(t,y,a)

    eq1 = y(2);
    eq2 = -a*y(1)+sin(3*t);
  
    %Evaluate the ODE for our present problem
    dydt = [eq1;eq2];
end
%-----------------------------------------------------------------%

Add a comment
Know the answer?
Add Answer to:
MATLAB HELP 3. (a) In one window, graph four different solutions to y 00 + 10y 0 + y = sin t by using different initial...
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
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