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.
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!