Hi community, i request assistance in getting the code for this particular question.
I tried watching yotube and looking around matlab answer but i still don't understand the approach in solving it.
Please advice, thanks.

 채택된 답변

Per Hyldahl
Per Hyldahl 2020년 2월 19일

0 개 추천

Hi,
You need to treat your 2nd order differential equation as a system of two 1st order equations and arrange them in a vector, like:
f = [y; y']
such that
f' = [y'; y'']
Then you can obtain the solution using the following code
clc; clear; close all
[t,y] = ode45(@deriv, [0, 25], [0, 0]);
plot(t, y(:,1), t, y(:,2))
legend('y(t)', 'y''(t)')
function f_prime = deriv(t,f)
f_prime = zeros(2,1);
f_prime(1) = f(2);
f_prime(2) = 3*cos(t) -1.5*sin(t) - 3*f(2) - 3.25*f(1);
end
I myself also had problems to wrap my head around this approach when i learned it :)
// Per

댓글 수: 5

David Lee
David Lee 2020년 2월 19일
I know [0,0] is from the initial condition
But may I know how you derived the number [0, 25]
Per Hyldahl
Per Hyldahl 2020년 2월 19일
The array [0, 25] is the time vector and I just chose som arbitrary number; hence starting at t= 0s and endning at t=25s
David Lee
David Lee 2020년 2월 19일
Then how does the function at the 2nd part of the script contribute to the plot when its made after the plot of the graph?
Per Hyldahl
Per Hyldahl 2020년 2월 20일
Hi,
The sub-routine 'deriv' is a function which evaluates the differential equation, and is given to the ode45 as an input argument.
As Hiro-San suggested in a different answer, you should read the documentation of the ODE-solver suite; e.g. for ODE45: https://www.mathworks.com/help/matlab/ref/ode45.html.
Especially, the section regarding input arguments.
/ Per
David Lee
David Lee 2020년 2월 22일
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Hiro Yoshino
Hiro Yoshino 2020년 2월 19일

0 개 추천

You can walk through this:
I guess this is what you work on - read, understand and apply to your homework.

카테고리

태그

질문:

2020년 2월 19일

댓글:

2020년 2월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by