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

2 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by