# IVP and complex solutions

f(x,y)=-(-3*y+2*y^2)
p5sol2=desolve(diff(y,x)==f(x,y),y,ics=[0,0.5])


Returns the following:

-1/3*log(2*y(x) - 3) + 1/3*log(y(x)) == x - 26714619/25510582*I - 27229598/58926009


I get the following result from Mathematica:

y[x] -> (1.5 E^(3 x))/(2. + E^(3 x))


Why is sage returning a complex solution? I am assuming it has to do with the logs and absolute values when integrating. Any help will be appreciated. Thanks!!!

edit retag close merge delete

Sort by » oldest newest most voted

I tried more exactly (instead of that 0.5):

sage: x = var('x')
sage: y = function('y')(x)
sage: p5sol2 = desolve( diff(y,x) == 3*y - 2*y^2, y, ics=[0, 1/2], show_method=True )
sage: p5sol2
[-1/3*log(2*y(x) - 3) + 1/3*log(y(x)) == -1/3*I*pi + x - 2/3*log(2),
'separable']


The offered implicit solution can now be rewritten, we multiply with $3$, we apply $\exp$ on both sides, then we can isolate $y$. Explicitly, after multiplying with $3$... $$-\log(2y-3) + \log y = -i\pi + 3x -2\log 2\ .$$

sage: p5sol2 = desolve( diff(y,x) == 3*y - 2*y^2, y, ics=[0, 1/2] )
sage: 3 * p5sol2
-log(2*y(x) - 3) + log(y(x)) == -I*pi + 3*x - 2*log(2)


The rôle of $i$ is now simple to figure out, we apply $\exp$ and $e^{-i\pi}$ becomes real. Explicitly: $$\frac y{2y-3} = -\frac 14 e^{3x}\ .$$ Equivalently: $$\frac {2y-3}y = -4 e^{-3x}\ .$$ The LHS is $2-\frac 3y$, and we can easily extract $y$ from here, $$y = \frac 32\cdot\frac 1{1+2e^{-3x}}\ .$$ (The Mathematica solution, and the following one coincide with the above, after amplification with $e^{3x}$.) Let us do this with code:

sage: solve( exp(-log(2*y(x) - 3) + log(y(x))) == exp(-I*pi + 3*x - 2*log(2)), y(x) )
[y(x) == 3/2*e^(3*x)/(e^(3*x) + 2)]

more

You can get the "Mathematica solution" with the following one-liner :

sage: (desolve(diff(y(x),x)==3*y-2*y^2,y,ics=[0,1/2])*3).exp().maxima_methods().exponentialize().solve(y(x))
[y(x) == 3/2*e^(3*x)/(e^(3*x) + 2)]


which is $\displaystyle y\left(x\right) = \frac{3 \, e^{\left(3 \, x\right)}}{2 \, {\left(e^{\left(3 \, x\right)} + 2\right)}}$

( 2018-01-20 02:18:32 -0500 )edit

Emmanuel Charpentier: Your idea works great. Thanks!!!!!!!

x=var('x');y=function('y')(x)
a=(desolve(diff(y(x),x)==3*y-2*y^2,y,ics=[0,1/2])*3).exp().maxima_methods().exponentialize().solve(y(x))
a=solve(a,y(x))[0].rhs()
plot(a,(x,0,10),ymin=0,ymax=2)

( 2018-01-20 17:30:14 -0500 )edit

dan_fulea:

Thanks!!! I appreciate your response but I was hoping that Sage would give me the solution without having to do the extra step of raising both sides of the implicit solution to E^(##) and then solving for y(x).

Emmanuel Charpentier: Your idea works great. Thanks!!!!!!!

more