フィルターのクリア

Solving 3rd order ODE

1 回表示 (過去 30 日間)
Kevin Tran
Kevin Tran 2020 年 5 月 10 日
コメント済み: Star Strider 2020 年 5 月 11 日
Hi guys, I need to solve this 3rd order ODE:
?⃛+2??̈+3??̇+4??=2, t≥0, ?̈(0)=?̇(0)=?(0)=0
This is my script:
[t,y] = ode45(@diffeq3,[0 50],[0;-1;1]);
plot(t,y)
function dy = diffeq3(t,y)
if t >= 0
dy(3) = 0
dy(2) = 0
dy(1) = 0
end
dy = zeros(3,1);
dy(1) = y(2);
dy(2) = y(3);
dy(3) = 2 - 2*y(3) - 3*y(2) - 4*y(1);
end
Did I do it right?
I got two questions, I got three curves which on is which?
And did I define t≥0, ?̈(0)=?̇(0)=?(0)=0 correct? With:
if t >= 0
dy(3) = 0
dy(2) = 0
dy(1) = 0
Thanks in advance for the help!

採用された回答

Star Strider
Star Strider 2020 年 5 月 10 日
There appears to be a factor of ‘y(1)’ missing in the last 3 terms of the ‘dy(3)’ equation. (I gave your differential equation as posted to the odeToVectorField function to be certain.)
Also, the if block is not necessary. It does nothing, and produces slower code.
  6 件のコメント
Kevin Tran
Kevin Tran 2020 年 5 月 11 日
Yeah just different ways of writing the script, thanks for all the help by the way!
Star Strider
Star Strider 2020 年 5 月 11 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by