help with finding a numerical answer using Ode45

2 ビュー (過去 30 日間)
Cody Havlin
Cody Havlin 2015 年 4 月 3 日
コメント済み: Star Strider 2015 年 4 月 3 日
I have the equation
m*D2y +dc*Dy + sk*y = A*sin (omega t)
and I need to have numerical values to use. I'm trying to use ode45 ,but I keep hitting the error
Error using odearguments (line 93) @(T,Y)[Y(2);-150/1000*Y(1)-150/1000*Y+8*PI*SIN(5*T)/1000] returns a vector of length 3, but the length of initial conditions vector is 2. The vector returned by @(T,Y)[Y(2);-150/1000*Y(1)-150/1000*Y+8*PI*SIN(5*T)/1000] and the initial conditions vector must have the same number of elements.
I feel like i am missing something simple but i haven't figured it out yet. Can anyone show me the process of getting numerical answers, not just a symbolic answer.
My code is:
f = @(t, y) [y(2); -150/1000*y(1) - 150/1000*y + 8*pi*sin(5*t)/1000];
[xa, ya] = ode45(f, [0 50], [ 0 0 ]);
plot(xa, ya)

採用された回答

Star Strider
Star Strider 2015 年 4 月 3 日
I took me a few minutes to re-derive the two first-order equations (tired), but this works:
f = @(t, y) [y(2); (-150/1000*y(2) - 150/1000*y(1) + 8*pi*sin(5*t)/1000)];
[xa, ya] = ode45(f, [0 50], [0 0]);
  2 件のコメント
Cody Havlin
Cody Havlin 2015 年 4 月 3 日
I've been working on a project that involves this all day. Thank you!
Star Strider
Star Strider 2015 年 4 月 3 日
My pleasure!
The key is that y=y(1), y(2)=dy(1) and the second equation is dy(2).

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

その他の回答 (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