Matlab gives no result when I use the ODE (Ordinary Differential Equations)

1 回表示 (過去 30 日間)
Samer Atawneh
Samer Atawneh 2020 年 1 月 18 日
コメント済み: Star Strider 2020 年 1 月 19 日
When trying to find the symbolic solution in the following code, I got a warning and empty sym!
syms y(t) y0 Dy0
A=1;
B=2;
Dy = diff(y,t);
D2y = diff(y,t,2);
ode = diff(y,t,2)-A*(y)^2-B^2*y==0;
cond1 = y(0) == 1;
cond2 = Dy(1) == 0;
conds = [cond1 cond2];
ySol(t) = dsolve(ode,conds);
ySol = simplify(ySol, 'Steps',20)
disp(ySol(t))
Warning: Explicit solution could not be found.
> In dsolve (line 201)
In symbolic_Fun (line 11)
ySol(t) =
[ empty sym ]
[ empty sym ]
What was my mistake?
Please advise.

採用された回答

Star Strider
Star Strider 2020 年 1 月 18 日
The differential equation is nonlinear (the ‘y^2’ term) and very few nonlinear differential equations have analytic solutions. You need to integrate it numerically.
Try this:
syms y(t) y0 Dy0 T Y
A=1;
B=2;
Dy = diff(y,t);
D2y = diff(y,t,2);
ode = diff(y,t,2)-A*(y)^2-B^2*y==0;
cond1 = y(0) == 1;
cond2 = Dy(1) == 0;
conds = [cond1 cond2];
[VF,Subs] = odeToVectorField(ode)
odefcn = matlabFunction(VF, 'Vars',{T,Y})
initconds = [1, 0]; % Use The ÑSubs’ Output To Determine These Positions In The Vector
tspan = [0 1];
[t,y] = ode45(odefcn, tspan, initconds);
figure
plot(t, y)
grid
legend(string(Subs))
It goes to +Inf at about t=1.9.
  8 件のコメント
Samer Atawneh
Samer Atawneh 2020 年 1 月 19 日
Dear Strider,
Thank you very much. Appreciated.
Star Strider
Star Strider 2020 年 1 月 19 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by