Trouble using the ode45 input

1 件のコメント

Stephen23
Stephen23 2023 年 11 月 6 日
You need to parameterize the function call:
See Star Strider's answer for an example of this.

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

回答 (2 件)

Sam Chak
Sam Chak 2023 年 11 月 6 日

0 投票

From the ODE, the analytical solution is a sine wave. If the parameters are some fixed values, then you can place them inside the function f.
[t, y] = ode45(@f, [0 15], [-0.9 0]);
plot(t, y), grid on, xlabel('t'), legend('y(t)', 'v(t)')
function dy = f(t, y)
dy = zeros(2, 1);
m = 4;
k = 21;
omega = sqrt(k/m);
dy(1) = y(2);
dy(2) = -(omega^2)*y(1);
end
Star Strider
Star Strider 2023 年 11 月 6 日

0 投票

The call to ‘f’ in the ode45 call (and the correct ode45 call) should be:
[t,Y] = ode45(@(t,y)f(t,y,omega0), [0, 15], [y0,v0]);
My MATLAB release (R2023b) can still not run images of code, only actual code. (Perhaps that will be an upgrade in a future release?!)
.

カテゴリ

製品

リリース

R2023b

タグ

質問済み:

2023 年 11 月 6 日

コメント済み:

2023 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by