# General Solution of ODE with Arbitrary Constant Coefficient

The general solution of $${x^2}y'' + 3xy' + \lambda y = 0$$ is (from Example 4 here) $$y(x) = \begin{cases} {c_1}{x^{ - 1}}\cos \left( {\ln \left( x \right)\sqrt {\lambda - 1} } \right) + {c_2}{x^{ - 1}}\sin \left( {\ln \left( x \right)\sqrt {\lambda - 1} } \right) &\mbox{for } \lambda > 1 \\ {c_1}{x^{ - 1}} + {c_2}{x^{ - 1}}\ln \left( x \right) &\mbox{for } \lambda = 1\\ {c_1}{x^{ - 1 - \sqrt {1 - \lambda } }} + {c_2}{x^{ - 1 + \sqrt {1 - \lambda } }} &\mbox{for } \lambda < 1 \end{cases}$$

Why does Mathematica give only the third case instead of the whole solution? Is it a bug?

FullSimplify[DSolve[x^2*y''[x] + 3*x*y'[x] + \[Lambda]*y[x] == 0, y[x], x], Assumptions -> \[Lambda] \[Element] Reals]

Mathematica gave generic solution to Euler ode.

Using assumptions and little bit of known manipulation, you can obtain the solutions given on that web page

For $$\lambda>1$$

Clear["Global*"];
ode = x^2*y''[x] + 3*x*y'[x] + lam*y[x] == 0;
sol = y[x] /. First@DSolve[ode, y[x], x, Assumptions -> lam > 1]


The only trick is to convert the above to trig, using Euler relations. There might be easier way to do this, but I could not find it now. We need to implement the following transformation

\begin{align*} c_1 x^{\alpha + i \beta}+ c_1 x^{\alpha - i \beta}&= x^\alpha (c_1 x^{i \beta}+c_2 x^{ -i \beta})\\ &=x^\alpha(c_1 e^{\ln x^{i \beta}}+c_2 e^{\ln x^{-i \beta}}\\ &=x^\alpha(c_1 e^{i \beta \ln x}+c_2 e^{-i \beta \ln x}\\ &=x^\alpha(c_1 \cos(\beta \ln x)+ c_2 \sin(\beta \ln x)\\ \end{align*}

The last step above is just Euler's relation.

The above is done using:

ClearAll[a, b];
exponent = sol[[1]] /. Times[Power[x, a_], any_] :> Expand[a];
{a, b} = exponent /. a_ - I b_ :> {Simplify@a, Simplify@b};
sol = x^a (C[1]*Cos[b*Log[x]] + C[2] Sin[b*Log[x]])


For the other two cases, no need to help Mathematica, it gives the solutions as is, when using assumptions

$$\lambda =1$$

  sol = y[x] /. First@DSolve[ode /. lam -> 1, y[x], x]


$$\lambda < 1$$

  sol = y[x] /. First@DSolve[ode, y[x], x, Assumptions -> lam < 1]


What do you mean by "generic solution to Euler ode" in the first line?

I mean the following. This is what Mathematica basically did

$$x^{2}y^{\prime\prime}+3xy^{\prime}+\lambda y=0$$

Let $$y=Cx^{r}$$. Substituting into the ODE this gives \begin{align*} x^{2}Cr\left( r-1\right) x^{r-2}+3xCrx^{r-1}+\lambda Ax^{r} & =0\\ Cr\left( r-1\right) x^{r}+3Crx^{r}+\lambda Cx^{r} & =0 \end{align*}

Simplifying, since $$C x^{r}\neq0$$ gives

\begin{align*} r\left( r-1\right) +3r+\lambda & =0\\ r^{2}-r+3r+\lambda & =0\\ r^{2}+2r+\lambda & =0 \end{align*}

Using the Quadratic formula, $$r=\frac{-b}{2a}\pm\frac{1}{2a}\sqrt{b^{2} -4ac}=\frac{-2}{2}\pm\frac{1}{2}\sqrt{4-4\lambda}=-1\pm\sqrt{1-\lambda}$$. Therefore

\begin{align*} r_{1} & =-1+\sqrt{1-\lambda}\\ r_{2} & =-1-\sqrt{1-\lambda} \end{align*}

Hence the general solution is the sum of the two basis solutions given by

\begin{align*} y & =C_{1}x^{r_{1}}+C_{2}x^{r_{2}}\\ & =C_{1}x^{-1+\sqrt{1-\lambda}}+C_{2}x^{-1-\sqrt{1-\lambda}} \end{align*}

It is a generic solution, since it does not know anything about $$\lambda$$ it could not simplify this any more.

DSolve[x^2*y''[x] + 3*x*y'[x] + \[Lambda]*y[x] == 0, y[x], x] //
Simplify // Expand


• What do you mean by "generic solution to Euler ode" in the first line? Mathematica just assumes that $\lambda < 1$? How can we find out what assumption it made if we didn't have the analytical solution? Jul 11, 2020 at 15:10
• @Leponzo I've tried to answer your comment in the answer above. Jul 11, 2020 at 15:36
• So the answer given by Mathematica is not a bug. It actually works for all $\lambda \in \mathbb{R}$, not just the third case ($\lambda < 1$). For example, $\lambda = 2$ gives $y(x) = {c_1}{x^{ - 1 - i }} + {c_2}{x^{ - 1 + i }}$, which does satisfy the ODE with $\lambda = 2$. (However, the cases may be needed for other ODEs where the answer returned by Mathematica may not represent the general solution.) Jul 11, 2020 at 17:34

Here's a way to generate any solution, by picking a different basis and taking the limit as the parameter approaches a given value of $$\lambda$$:

ode = x^2*y''[x] + 3*x*y'[x] + λ*y[x] == 0;
y2 = DSolveValue[{ode, y[1] == 0, y'[1] == 1}, y[x], x];
y1 = DSolveValue[{ode, y[1] == 1, y'[1] == -1}, y[x], x];
ClearAll[solg];
solg[λ0_?NumericQ] :=
Assuming[x > 0,
Limit[C[1] y1 + C[2] y2, λ -> λ0] // Re //
ComplexExpand // Simplify]


Examples:

solg[1]
ode /. {λ -> 1,
y -> Function[x, Evaluate[solg[1]]]} // Simplify
(*
(C[1] + C[2] Log[x])/x
True
*)

solg[2]
ode /. {λ -> 2,
y -> Function[x, Evaluate[solg[2]]]} // Simplify
(*
(C[1] Cos[Log[x]] + C[2] Sin[Log[x]])/x
True
*)

solg[0]
ode /. {λ -> 0,
y -> Function[x, Evaluate[solg[0]]]} // Simplify
(*
((1 + x^2) C[1] + (-1 + x^2) C[2])/(2 x^2)
True
*)
`