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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Star Strider
Star Strider el 18 de En. de 2020
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 comentarios
Samer Atawneh
Samer Atawneh el 19 de En. de 2020
Dear Strider,
Thank you very much. Appreciated.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by