# Why Mathematica solves that equation with the solution in complex numbers?

In order to solve the following Euler Differential Equation I write in the notebook:

Assuming[{y∈\[DoubleStruckCapitalR], n>0,x>0},DSolve[x^2 y''[x]+x  y'[x]- n y[x]==0,y[x],x]]


And I get as an output:

{{y[x]->Subscript[[ConstantC], 1] Cosh[Sqrt[n] Log[x]]+I Subscript[[ConstantC], 2] Sinh[Sqrt[n] Log[x]]}}

On the other hand when Mathematica solves the above equation with a specific value for n, for example $$n=4$$ , it returns the desired solution...

How can I fix this problem, please?

• First, you may see that \[DoubleStruckCapitalR] is colored with blue, which means that this has no built-in meaning and doesn't represent the set of real numbers. You should use Reals or type with EscrealsEsc. – SneezeFor16Min Jul 2 '20 at 7:21
• @SneezeFor16Min,Thanks but if I write Reals, it does not work either.... – dmtri Jul 2 '20 at 7:27
• You could specify initial conditions y[1] == y1 and y'[1] == yP1. – Natas Jul 2 '20 at 7:29

First of all, DSolve does not really take assumptions. (What I mean, DSolve seems to ignore assumptions)

Euler ODE can have 3 different solutions depending on roots $$r_1,r_2$$ of the characteristic equation. For one repeated root, solution is $$y=c_1 x^r+ c_2 x^r \ln x$$, and for 2 real and distinct roots, solution is $$y=c_1 x^{r_1}+ c_2 x^{r_2}$$ and for two complex conjugate roots, solution is $$y=c_1 x^{\alpha+i\beta} + c_2 x^{\alpha-i\beta}$$

For your case, the roots are $$r_1 = -\sqrt{n},r_2 = \sqrt{n}$$. Hence for $$n>0$$ then we are in the second case (2 real distinct roots).

The characteristic equation for Euler ode is found by substituting $$y=A x^r$$ into the ode and then solving for $$r$$

You can obtain, for n>0 the solution you want this way

Clear["Global*"];
ode = x^2 y''[x] + x y'[x] - n y[x] == 0
sol = DSolve[ode, y[x], x]


sol = TrigToExp[sol]


sol = Collect[sol, { x^-Sqrt[n], x^Sqrt[n]}]


We are free to rename constants as we want. Hence

sol = sol /. {C[1]/2 - (I C[2])/2 -> C[3],    C[1]/2 + (I C[2])/2 -> C[4]}


Verify

 ode /. y -> Function[{x}, x^-Sqrt[n] C[3] + x^Sqrt[n] C[4]] // Simplify

(* True *)


Update

what is the characteristic equation?

Clear["Global*"];
ode = x^2 y''[x] + x y'[x] - n y[x] == 0;
charEquation = ode /. y -> Function[{x}, A*x^r]


Since $$A$$ and $$x^r$$ are non zero, we can divide by them and the above simplifies to

Solve[-  n  +  r + (-1 + r) r == 0, r]


which gives the solutions

And since $$n>0$$ then we have two real distinct roots.

• Could you clarify what you mean by saying that DSolve does not really takes assumptions? DSolve has an option Assumptions. – Natas Jul 2 '20 at 7:30
• @Natas I mean, from experience, I found that assumptions most of the time are ignored by DSolve. Just because you pass assumptions to it, does not mean it will use them. – Nasser Jul 2 '20 at 7:33
• OK, I agree. Assumptions cause many problems and are poorly implemented. – Natas Jul 2 '20 at 7:38
• Here we have no constant coefficients, so what is the characteristic equation? – dmtri Jul 2 '20 at 10:14
• @dmtri i've updated the answer with the char equation. – Nasser Jul 2 '20 at 10:50