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

조회 수: 1 (최근 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
Samer Atawneh
Samer Atawneh 2020년 1월 19일
Dear Strider,
Thank you very much. Appreciated.

댓글을 달려면 로그인하십시오.

추가 답변 (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