Not the right result for dsolve

10 vues (au cours des 30 derniers jours)
Adan Garcia
Adan Garcia le 18 Avr 2019
Réponse apportée : Anay le 2 Juin 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?

Réponses (1)

Anay
Anay le 2 Juin 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:

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by