Not the right result for dsolve

10 visualizaciones (últimos 30 días)
Adan Garcia
Adan Garcia el 18 de Abr. de 2019
Respondida: Anay el 2 de Jun. de 2025
Any kind of guidance would be much appreciated. I need to show that the exact solution of this ODE is y(t) = t tan(lnt).
syms y(t)
ode = diff(y,t) == 1+(y/t)+(y/t)^2;
cond = y(1) == 0;
ySol(t) = dsolve(ode,cond)
However, I keep getting
ySol(t) =
- t*1i - (2*t)/(t^2i*1i + 1i)
What am I doing wrong? Or am I missing something?

Respuestas (1)

Anay
Anay el 2 de Jun. de 2025
Hi Adan,
When solving the ODE using dsolve, MATLAB may return a complex solution due to ambiguity from inverse functions (e.g. arctan) and arbitrary constants during symbolic integration.
You can consider substituting y(t)=tu(t)” which will reduce the ode to a separable form, du/dt = (1 + u^2)/t. This change allows “dsolve” to solve the ODE without any ambiguity and gets the correct solution. You can use the below code for reference:
syms u(t)
% Let y = t*u
y = t*u;
dy = diff(y,t);
% dy = u + t*diff(u)
ode = dy == 1 + u + u^2;
ode_sub = ode;
% Solve
uSol(t) = dsolve(ode_sub, u(1) == 0); % since y = t*u and y(1) = 0 -> u(1) = 0
ySol(t) = t*uSol(t)
ySol(t) = 
You can refer to the MATLAB documentation for more details about the dsolve function by following the below link:

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by