ySol(t) = 
Not the right result for dsolve
Show older comments
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?
Answers (1)
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)=t⋅u(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)
You can refer to the MATLAB documentation for more details about the dsolve function by following the below link:
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!