Question

Osts 10 Problem 3 Numerically integrate the 2nd order linear differential equation on the interval y(t) = 2e - 2e-41 and com
only using matlab
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Screen Shot:

function dy = ode_fun (t,Y) x driver_file. m ode_fun.m X { from: y + 5y + 4y = 0, y(0) = 0, y(0) = 6 let: y = x meaning twclc, clear, close all X 2 driver_file.m ode_fun. m x from: y + 5y + 4y = 0, y(0) = 0, y (0) = 6 let: y = x meaning two ls

Sample Output:
num ее 0-0— 0 eeeeeeeeeeeeeeeeeeeeeeeee y(t) 00 ecoco ооооооооо 4 5 6 оооооооооооо 1 2 3 7 odyctum dych grue dydt 0 1 2 3 4 5 6 7 8 9 10

Program Code to Copy:

function dY = ode_fun(t,Y)
%%
%{
from: y'' + 5y + 4y = 0, y(0) = 0, y'(0) = 6
let: y' = x
meaning two 1st order ode's are formed as:
x' = -5x - 4y, x(0) = y'(0) = 6
y' = x, y(0) = 0
%}
%
%% % extract x and y in the same order initial conditions were set
x = Y(1); y = Y(2);
%
%% compute the derivatives
dx = -5*x - 4*y; % for x'
dy = x; % for y'
%
dY = [dx;dy];

end

______________________________________________

% driver_file.m

clc,clear,close all
%%
%{
from: y'' + 5y + 4y = 0, y(0) = 0, y'(0) = 6
let: y' = x
meaning two 1st order ode's are formed as:
x' = -5x - 4y, x(0) = y'(0) = 6
y' = x, y(0) = 0
%}
%% set the initial conditions and time interval
x0 = 6; y0 = 0;
Y0 = [x0;y0]; % initial conditions
tspan = [0 10]; % time interval
%% solve numerically
[t,Y] = ode45(@ode_fun,tspan,Y0); % using ode45
%% extract the numerical solution
y_num = Y(:,2); % 2nd colum contains the solution y
dydt_num = Y(:,1); % 1st column contains the solution dydt
%% compute the true y and dydt solutions
y_true = 2.*exp(-t) - 2.*exp(-4*t);
dydt_true = -2.*exp(-t) + 8.*exp(-4*t);
%% graph the results
figure,plot(t,y_num,'o b',t,y_true,'- r'),xlabel('t'),ylabel('y(t)')
legend('y_n_u_m','y_t_r_u_e'),grid on
%
figure,plot(t,dydt_num,'o b',t,dydt_true,'- r'),xlabel('t'),ylabel('dydt')
legend('dydt_n_u_m','dydt_t_r_u_e'),grid on

%%


------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Add a comment
Know the answer?
Add Answer to:
only using matlab Osts 10 Problem 3 Numerically integrate the 2nd order linear differential equation on...
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