2
$\begingroup$

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.

$\endgroup$
4
  • 3
    $\begingroup$ 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/… $\endgroup$
    – flinty
    Commented Jul 2, 2020 at 16:08
  • $\begingroup$ @flinty: Shouldn't it do it the other way around by convention? $\endgroup$
    – Moo
    Commented Jul 2, 2020 at 16:14
  • 1
    $\begingroup$ 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). $\endgroup$
    – Natas
    Commented Jul 2, 2020 at 19:04
  • 1
    $\begingroup$ Most people want the solution rather than a subset. Your desired result is very simply obtained using Select[sol, FreeQ[#, Complex] &] $\endgroup$
    – Bob Hanlon
    Commented Jul 2, 2020 at 19:29

1 Answer 1

6
$\begingroup$

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.

Answer comment

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]]

enter image description here

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.

$\endgroup$
3
  • $\begingroup$ 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). $\endgroup$
    – Moo
    Commented Jul 2, 2020 at 16:19
  • 1
    $\begingroup$ @Moo I tried to answer this in the above. $\endgroup$
    – Nasser
    Commented Jul 2, 2020 at 16:29
  • $\begingroup$ As a curiosity, does Maple return the same? $\endgroup$
    – Moo
    Commented Jul 2, 2020 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.