I solved this ode by hand and got much simpler solution than Mathematica's. Both are correct. But I could not find a way to simplify Mathematica's solution to the simpler one. Could someone find a way?



BesselJ[-n,Sqrt[E^(2*x)]]*C[1]*Gamma[1-n] + BesselJ[n, Sqrt[E^(2*x)]]*C[2]*Gamma[1+n]

The above can be made simpler as given below. First the solution is verified to be correct


A simpler solution to this Bessel ODE is

 mysol =  C[1] BesselJ[n, Exp[x]] + C[2] BesselY[n, Exp[x]] 

How to simplify/Reduce Mathematica first solution above to the simpler one? I tried many things (Simplify, Reduce, FunctionExpand, etc...) but nothing worked so far. But it is clear these are both equivalent solutions.

I do not understand why Mathematica has Gamma function in there, as the ode is a straight Bessel ODE (after applying known change of variables trick). It could be because it Mathematica choose to two BesselJ for both basis solutions instead of BesselJ for one and BesselY for the second which is the more common way for the solution of Bessel ode's.

V 13.3 on windows 10

ps. I can post my solution step by step if needed.

  • $\begingroup$ @MariuszIwaniuk Yes, correct, that is the change of variables I did solving it by hand. The question though is how to transform/simplify/convert the solution given by Mathematica to the simpler one generated when using this transformation as given in my question. btw, we need to transform the solution back from $t$ to $x$ after this change of variable, since original ode is in $x$. But this is easy step and done at the end. $\endgroup$
    – Nasser
    Jul 9, 2023 at 13:10
  • $\begingroup$ I think one might need to apply some relation between $J_n,Y_n$ to do this. I still do not know why Gamma shows up in Mathematica's solution. Clearly Mathematica used different method to solve this from using this transformation, but I do not know what that would be. $\endgroup$
    – Nasser
    Jul 9, 2023 at 13:20
  • 1
    $\begingroup$ In ode there is n as a constant, then C[1]*Gamma[1-n] is a constant too and redefine C[1]->c1/Gamma[1-n] and so on. You can get rid of Gamma[1-n] with e.g. Assuming[x \[Element] Reals && n \[Element] PositiveIntegers, FullSimplify@DSolveValue[y''[x] + Exp[2 x] y[x] == n^2 y[x], y[x], x]]. It doesn't work for n real altough it could, nevertheless it does't harm much. The system knows this ode, e.g. Entity["MathematicalFunction", "BesselJ"]["DifferentialEquations"][[20, 2, 1, 1]] // Quiet $\endgroup$
    – Artes
    Jul 9, 2023 at 14:50
  • 2
    $\begingroup$ The solution given by Mathematica (V13.3) is incorrect for integer n, since then BesselJ[n,x] and BesselJ[-n,x] are linearly dependent. In this case, for non-negative integer n, the gamma function becomes infinite (so I guess the answer is meaningless, rather than wrong?) $\endgroup$
    – mikado
    Jul 9, 2023 at 16:00

1 Answer 1


I think I found why Mathematica gave the solution it did. It seems to have used the wrong change of variables. Instead of $x=\ln(t)$ it used $x=e^t$. Here is the proof:

ClearAll[y, x, n, u, t]
ode = y''[x] + (Exp[2*x] - n^2)*y[x] == 0

Mathematica graphics

correct change of variable

odeV1 = DSolveChangeVariables[Inactive[DSolve][ode, y, x], u, t, t == Exp[x]]
solV1 = Activate[odeV1]

Mathematica graphics

Change back to $x$

 solV1[[1, 1, 2, 2]] /. t -> Exp[x]

Mathematica graphics

incorrect change of variable

odeV2 = DSolveChangeVariables[Inactive[DSolve][ode, y, x], u, t, t == Log[x]]
solV2 = Activate[odeV2]

Mathematica graphics

Change back to $x$


Mathematica graphics

Which is the exact solution given by Mathematica

Direct use of DSolve

 DSolve[ode, y, x]

Mathematica graphics

Hand solution

\begin{align*} \left({\mathrm e}^{2 x}-n^{2}\right) y+y^{\prime \prime} = 0\tag{1} \end{align*} Any general second order linear ode of the form \begin{equation} ay^{\prime\prime}+by^{\prime}+(ce^{rx}+m)y=0\tag{1} \end{equation} can be transformed to Bessel ode using the transformation \begin{align*} x & =\ln\left( t\right) \\ e^{x} & =t \end{align*} Where $a,b,c,m$ are not functions of $x$ and where $b$ and $m$ are allowed to be be zero. Using this transformation gives \begin{align} \frac{dy}{dx} & =\frac{dy}{dt}\frac{dt}{dx}\nonumber\\ & =\frac{dy}{dt}e^{x}\nonumber\\ & =t\frac{dy}{dt}\tag{2} \end{align} And \begin{align} \frac{d^{2}y}{dx^{2}} & =\frac{d}{dx}\left( \frac{dy}{dx}\right) \nonumber\\ & =\frac{d}{dx}\left( t\frac{dy}{dt}\right) \nonumber\\ & =\frac{d}{dt}\frac{dt}{dx}\left( t\frac{dy}{dt}\right) \nonumber\\ & =\frac{dt}{dx}\frac{d}{dt}\left( t\frac{dy}{dt}\right) \nonumber\\ & =t\frac{d}{dt}\left( t\frac{dy}{dt}\right) \nonumber\\ & =t\left( \frac{dy}{dt}+t\frac{d^{2}y}{dt^{2}}\right) \tag{3} \end{align} Substituting (2,3) into (1) gives \begin{align} at\left( \frac{dy}{dt}+t\frac{d^{2}y}{dt^{2}}\right) +bt\frac{dy} {dt}+(ce^{rx}+m)y & =0\nonumber\\ \left( aty^{\prime}+at^{2}y^{\prime\prime}\right) +bty^{\prime}+(ct^{r}+m)y & =0\nonumber\\ at^{2}y^{\prime\prime}+\left( b+a\right) ty^{\prime}+(ct^{r}+m)y & =0\nonumber\\ t^{2}y^{\prime\prime}+\frac{b+a}{a}ty^{\prime}+\left( \frac{c}{a}t^{r} +\frac{m}{a}\right) y & =0\tag{4} \end{align} Which is Bessel ODE. Comparing the above to the general known Bowman (1954) form of Bessel ode which is \begin{equation} t^{2}y^{\prime\prime}+\left( 1-2\alpha\right) ty^{\prime}+\left( \beta ^{2}\gamma^{2}t^{2\gamma}-\left( n^{2}\gamma^{2}-\alpha^{2}\right) \right) y=0\tag{C} \end{equation} And now comparing equations (4) and (C) shows that \begin{align} \left( 1-2\alpha\right) & =\frac{b+a}{a}\tag{5}\\ \beta^{2}\gamma^{2} & =\frac{c}{a}\tag{6}\\ 2\gamma & =r\tag{7}\\ \left( n^{2}\gamma^{2}-\alpha^{2}\right) & =-\frac{m}{a}\tag{8} \end{align} (5) gives $\alpha=\frac{1}{2}-\frac{b+a}{2a}$. (7) gives $\gamma=\frac{r}{2}$. (8) now becomes $\left( n^{2}\left( \frac{r}{2}\right) ^{2}-\left( \frac{1}{2}-\frac{b+a}{2a}\right) ^{2}\right) =-\frac{m}{a}$ or $n^{2} =\frac{-\frac{m}{a}+\left( \frac{1}{2}-\frac{b+a}{2a}\right) ^{2}}{\left( \frac{r}{2}\right) ^{2}}$. Hence $n=\frac{2}{r}\sqrt{-\frac{m}{a}+\left( \frac{1}{2}-\frac{b+a}{2a}\right) ^{2}}\ $by taking the positive root. And finally (6) gives $\beta^{2}=\frac{c}{a\gamma^{2}}$ or $\beta=\sqrt{\frac {c}{a}}\frac{1}{\gamma}=\sqrt{\frac{c}{a}}\frac{2}{r}$ (also taking the positive root). Hence \begin{align*} \alpha & =\frac{1}{2}-\frac{b+a}{2a}\\ n & =\frac{2}{r}\sqrt{-\frac{m}{a}+\left( \frac{1}{2}-\frac{b+a}{2a}\right) ^{2}}\\ \beta & =\sqrt{\frac{c}{a}}\frac{2}{r}\\ \gamma & =\frac{r}{2} \end{align*} But the solution to (C) which is general form of Bessel ode is known and given by $$ y\left( t\right) =t^{\alpha}\left( c_{1}J_{n}\left( \beta t^{\gamma }\right) +c_{2}Y_{n}\left( \beta t^{\gamma}\right) \right) $$ Substituting the above values found into this solution gives $$ y\left( t\right) =t^{\frac{1}{2}-\frac{b+a}{2a}}\left( c_{1}J_{\frac{2} {r}\sqrt{-\frac{m}{a}+\left( \frac{1}{2}-\frac{b+a}{2a}\right) ^{2}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r}t^{\frac{r}{2}}\right) +c_{2}Y_{\frac{2}{r} \sqrt{-\frac{m}{a}+\left( \frac{1}{2}-\frac{b+a}{2a}\right) ^{2}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r}t^{\frac{r}{2}}\right) \right) $$ Since $e^{x}=t$ then the above becomes \begin{align} y\left( x\right) & =e^{x\left( \frac{1}{2}-\frac{b+a}{2a}\right) }\left( c_{1}J_{\frac{2}{r}\sqrt{-\frac{m}{a}+\left( \frac{1}{2}-\frac {b+a}{2a}\right) ^{2}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r}e^{x\frac{r}{2} }\right) +c_{2}Y_{\frac{2}{r}\sqrt{-\frac{m}{a}+\left( \frac{1}{2} -\frac{b+a}{2a}\right) ^{2}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r} e^{x\frac{r}{2}}\right) \right) \nonumber\\ & =e^{x\left( \frac{-b}{2a}\right) }\left( c_{1}J_{\frac{2}{r}\sqrt {-\frac{m}{a}+\left( \frac{-b}{2a}\right) ^{2}}}\left( \sqrt{\frac{c}{a} }\frac{2}{r}e^{x\frac{r}{2}}\right) +c_{2}Y_{\frac{2}{r}\sqrt{-\frac{m} {a}+\left( \frac{-b}{2a}\right) ^{2}}}\left( \sqrt{\frac{c}{a}}\frac{2} {r}e^{x\frac{r}{2}}\right) \right) \nonumber\\ & =e^{x\left( \frac{-b}{2a}\right) }\left( c_{1}J_{\frac{2}{r}\sqrt {-\frac{m}{a}+\frac{b^{2}}{4a^{2}}}}\left( \sqrt{\frac{c}{a}}\frac{2} {r}e^{x\frac{r}{2}}\right) +c_{2}Y_{\frac{2}{r}\sqrt{-\frac{m}{a}+\frac {b^{2}}{4a^{2}}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r}e^{x\frac{r}{2}}\right) \right) \nonumber\\ & =e^{x\left( \frac{-b}{2a}\right) }\left( c_{1}J_{\frac{2}{r}\sqrt {-\frac{4ma+b^{2}}{4a^{2}}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r}e^{x\frac {r}{2}}\right) +c_{2}Y_{\frac{2}{r}\sqrt{-\frac{4ma+b^{2}}{4a^{2}}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r}e^{x\frac{r}{2}}\right) \right) \nonumber\\ & =e^{x\left( \frac{-b}{2a}\right) }\left( c_{1}J_{\frac{1}{ra} \sqrt{-4ma+b^{2}}}\left( \sqrt{\frac{c}{a}}\frac{2}{r}e^{x\frac{r}{2} }\right) +c_{2}Y_{\frac{1}{ra}\sqrt{-4ma+b^{2}}}\left( \sqrt{\frac{c}{a} }\frac{2}{r}e^{x\frac{r}{2}}\right) \right) \tag{9} \end{align} Equation (9) above is the solution to $ay^{\prime\prime}+by^{\prime} +(ce^{rx}+m)y=0$. Therefore we just need now to compare this form to the ode given and use (9) to obtain the final solution.

Comparing form (1) to the ode we are solving shows that \begin{align*} a &= 1\\ b &= 0\\ c &= 1\\ r &= 2\\ m &= -n^{2} \end{align*} Substituting these in (9) gives the solution as \begin{align*} y&=c_{1} \operatorname{BesselJ}\left(n , {\mathrm e}^{x}\right)+c_{2} \operatorname{BesselY}\left(n , {\mathrm e}^{x}\right) \end{align*}

At least now I know how Mathematica obtained the solution it did.


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.