ySol(t) = 
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: