# Why is DSolve returning imaginary results?

When using DSolve, I expected $$y(x) = a + b x$$ as the only result because $$y(x)$$ is real

 DSolve[{y''[x](1 + (y'[x])^2) == 0}, y[x], x]


However, it is returning three results, which include two imaginary ones

$$\{\{y(x)\to c_1-i x\},\{y(x)\to i x+c_1\},\{y(x)\to c_2 x+c_1\}\}$$

Why is it returning those imaginary results?

Note: I understand how it gets them.

• Because they are valid solutions and there's no convenient option in DSolve to hint that y[x] must be real. Related: mathematica.stackexchange.com/questions/225116/… and mathematica.stackexchange.com/questions/10253/… Jul 2, 2020 at 16:08
• @flinty: Shouldn't it do it the other way around by convention?
– Moo
Jul 2, 2020 at 16:14
• In many areas of mathematics complex numbers are considered the general case and the real numbers are a special case (that often lead to complications). Jul 2, 2020 at 19:04
• Most people want the solution rather than a subset. Your desired result is very simply obtained using Select[sol, FreeQ[#, Complex] &] Jul 2, 2020 at 19:29

Why is it returning those imaginary results?

The ode is

$$y^{\prime\prime}(1+\left( y^{\prime}\right) ^{2})=0$$

This gives 2 equations

\begin{align*} y^{\prime\prime} & =0\\ (1+\left( y^{\prime}\right) ^{2}) & =0 \end{align*}

The first has the solution $$y=c_{1}+c_{2}x$$ and the second is $$\left( y^{\prime}\right) ^{2}=-1$$ or $$y^{\prime}=\pm i$$. For $$y^{\prime}=i$$, by integrating this the result is $$y=i\int dx=ix+c_{1}$$ and for $$y^{\prime}=-i$$, by integrating this the result is $$y=-i\int dx=-ix+c_{1}$$

Hence the solutions are

\begin{align*} y_{1}\left( x\right) & =c_{1}+c_{2}x\\ y_{2}\left( x\right) & =ix+c_{1}\\ y_{3}\left( x\right) & =-ix+c_{1} \end{align*}

This is why Mathematica gave the complex solutions.

Why isn't the assumption that the results for DEQs are real?

First, there are no assumptions in the post.

Second, DSolve returns solutions to ODE's. You could always filter out solutions you do not want afterwords. The solver does not know if $$y(x)$$ is real or not until it solves the ODE. It just finds solutions that satisfies the ODE. What do you want the solver to do when asked to solve $$y'=i$$?

 DSolve[y'[x] == I, y[x], x, Assumptions -> Element[y[x], Reals]]


As mentioned in other places, DSolve seems to ignore such assumptions. Notice also that the constant of integration could be complex or not, depending on initial conditions. So DSolve can't really be sure if solution is real or not with no initial conditions as well.

The bottom line, if you want real solutions, filter them out yourself afterwords using other Mathematica commands by post processing the DSolve results.

• Thanks: As I stated in the question, I understand how it got them, I just don't understand why it displays them. Why isn't the assumption that the results for DEQs are real? Then maybe have an option for displaying imaginary (whatever those might mean to any application).
– Moo
Jul 2, 2020 at 16:19
• @Moo I tried to answer this in the above. Jul 2, 2020 at 16:29
• As a curiosity, does Maple return the same?
– Moo
Jul 2, 2020 at 16:38