Not the right result for dsolve

조회 수: 3 (최근 30일)
Adan Garcia
Adan Garcia 2019년 4월 18일
답변: Anay 2025년 6월 2일
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?

답변 (1개)

Anay
Anay 2025년 6월 2일
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:

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by