How do you use ode45( ) when the equation is not in dy/dt form?

2 ビュー (過去 30 日間)
ssmith
ssmith 2021 年 11 月 19 日
コメント済み: Star Strider 2021 年 11 月 23 日
I have an equation that I need to approximate the solution for using ode45( ) with initial values y(0) = 1 and y'(0) = 0 on interval of 0 < t < 150 and then plot x(t)
So far I have this for the equation y" + 4y = sin(1.9t)
syms y(t)
eqn = diff(y,2) + 4*y == sin(1.9*t)
V = odeToVectorField(eqn)
I know if the equation was in the form of dy/dt = sin(1.9t) - 4y then it would be
k = @(t,y) sin(1.9*t)-4*y;
[t,y] = oder45(k,[0,150])
plot(t,y)
But I do not know know how to write it for the form that my equation is in at this moment

回答 (2 件)

Paul
Paul 2021 年 11 月 19 日
Check out this link ....
  2 件のコメント
ssmith
ssmith 2021 年 11 月 19 日
@Paul Do you have an example that shows how to apply initial conditions?
Paul
Paul 2021 年 11 月 19 日
It's shown on the the doc page at that link. Or check
doc ode45
to see how to specifcy the initial conditions

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


Star Strider
Star Strider 2021 年 11 月 19 日
Since the equation as written involves the second derivative, it is also necessary to define the first derivative as a separate element of the resulting system of first-order differential equatiions.
The odeToVectorField function does this (I added the second ‘substitutions’ output to illustrate what the function actually does) —
syms y(t)
eqn = diff(y,2) + 4*y == sin(1.9*t)
eqn(t) = 
[V,S] = odeToVectorField(eqn)
V = 
S = 
This is actually
The function presented to ode45 would then be coded using the matlabFunction function.
Explore that process!
.
  10 件のコメント
ssmith
ssmith 2021 年 11 月 23 日
@Star Strider ok, thank you!
Star Strider
Star Strider 2021 年 11 月 23 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by