# Looking for closed form solutions to linear ordinary differential equations with time dependent coefficients.

Let $a \in {\mathbb C}$ and $b\in {\mathbb C}$ and let $n\ge 1$ be an integer.

Consider a following family of Ordinary Differential Equations (ODEs). We have:

$$\frac{d^2 y(x)}{d x^2} - \frac{n^2}{4} (a-b)^4 \frac{P_n^{(2n-2)}(x)}{(x+a)^2(x+b)^{2n+2}} \cdot y(x)=0$$ where $P_n^{(2n-2)}(x)$ are a polynomials of order $2n-2$ in $x$ which read: \begin{eqnarray} P_n^{(2n-2)}(x) = \left\{ \begin{array}{rr} 1 & \mbox{if $\quad n=1$}\\ (a+b+2 x)^2 & \mbox{if $\quad n=2$}\\ (a^2+ a b+b^2+3(a+b)x+3 x^2)^2 & \mbox{if $\quad n=3$}\\ (a+b+2 x)^2(a^2+b^2+2(a+b)x+2 x^2)^2 & \mbox{if $\quad n=4$}\\ \vdots \end{array} \right. \end{eqnarray} as a matter of fact we have: $$P_n^{(2n-2)}(x) =\frac{((x+a)^n - (x+b)^n)^2}{(a-b)^2}$$ for $n=1,2,\cdots$. Now by using the algorithm described in my answer to How do I find a change of variables that reduces a linear 2nd order ODE to the Gaussian hypergeometric differential equation? I have found the fundamental solutions to those ODEs. They read: \begin{eqnarray} y(x) = C_1 \cdot \sqrt{\frac{(x+b)^{n+1}}{(x+a)^{n-1}}}W_{\frac{1}{2}, {\mathfrak A}_n}[\left( \frac{x+a}{x+b}\right)^n] + C_2 \cdot \sqrt{\frac{(x+b)^{n+1}}{(x+a)^{n-1}}}M_{\frac{1}{2}, {\mathfrak A}_n}[\left( \frac{x+a}{x+b}\right)^n] \end{eqnarray} Here the constants read ${\mathfrak A}_n = \sqrt{1+n^2}/(2 n)$ for $n=1,2,\cdots$ and $W$ and $M$ are the Whittaker functions https://en.wikipedia.org/wiki/Whittaker_function . Now the following Mathematica code "proves" the result:

In[322]:= a =.; b =.; x =.;
Table[FullSimplify[(D[#, {x, 2}] -
n^2/4 ( (a - b)^2 ((x + a)^n - (x + b)^n)^2)/((a + x)^2 (b +
x)^(2 n + 2)) #) & /@ {Sqrt[(b + x)^(n + 1)]/
Sqrt[((a + x)^(n - 1))]
WhittakerW[1/2, Sqrt[1 + n^2]/(2 n), ((x + a)/(x + b))^n],
Sqrt[(b + x)^(n + 1)]/ Sqrt[((a + x)^(n - 1))]
WhittakerM[1/2, Sqrt[1 + n^2]/(2 n), ((x + a)/(x + b))^n]}], {n,
1, 6}]

Out[323]= {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}


Now I would love to know what other linear second order ODEs of the form above can be mapped onto hypergeometric functions by a suitable substitution.

By applying the same algorithm to the Bessel functions we get the following answer: $$\frac{d^2 y(x)}{d x^2} -n^2(A b-a B)^2 \frac{\left(-B^{2 n}(A x+a)^{2n}+A^{2 n}(B x+b)^{2 n}\right)}{B^{2 n}(A x+a)^2(B x+b)^{2n+2}}\cdot y(x)=0$$ is solved by \begin{eqnarray} &&y(x)=\\ &&C_1\cdot \sqrt{(A x+a)(B x+b)} J_{\frac{\sqrt{1+(A/B)^{2 n}4 n^2}}{2 n}}\left[(\frac{A x+a}{B x+b})^n\right]+\\ && C_2\cdot \sqrt{(A x+a)(B x+b)} J_{-\frac{\sqrt{1+(A/B)^{2 n}4 n^2}}{2 n}}\left[(\frac{A x+a}{B x+b})^n\right] \end{eqnarray}

The result is checked by the following piece of code:

In[115]:= Table[
FullSimplify[(D[#, {x, 2}] - (
n^2 (A b - a B)^2 (-B^(2 n) (A x + a)^(2 n) +
A^(2 n) (B x + b)^(2 n)))/(
B^(2 n) (a + A x)^2 (b + B x)^(2 n + 2)) #) & /@ {Sqrt[(a +
A x) (b + B x)]
BesselJ[Sqrt[1 + (A/B)^(2 n) 4 n^2]/(
2 n), ((A x + a)/(B x + b))^n],
Sqrt[(a + A x) (b + B x)]
BesselJ[-(Sqrt[1 + (A/B)^(2 n) 4 n^2]/(2 n)), ((A x + a)/(
B x + b))^n]}], {n, 1, 6}]

Out[115]= {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}


Let $a,b,A,B \in {\mathbb N}$ subject to $(a-b)^2 + (A-B)^2 > 0$. Now let $a_1,a_2,b_1 \in {\mathbb R}$ and define: \begin{eqnarray} P_0 &:=& a^2 (a_1-a_2-1) (a_1-a_2+1)+2 a b (2 a_1 a_2-a_1 b_1-a_2 b_1+b_1)+b^2 (b_1-2) b_1 \\ P_1 &:=& 2 (A (a (a_1-a_2-1) (a_1-a_2+1)+b (2 a_1 a_2-a_1 b_1-a_2 b_1+b_1))+B (a (2 a_1 a_2-a_1 b_1-a_2 b_1+b_1)+b (b_1-2) b_1)) \\ P_2 &:=& A^2 (a_1-a_2-1) (a_1-a_2+1)+2 A B (2 a_1 a_2-a_1 b_1-a_2 b_1+b_1)+B^2 (b_1-2) b_1 \end{eqnarray}

Then the fundamental solutions to the following ODE: \begin{eqnarray} \frac{d^2 y(x)}{d x^2} - (a B-A b)^2\frac{\left(P_0 + P_1 x + P_2 x^2\right)}{4 (a+A x)^2 (b+B x)^2 (a-b+ (A-B)x)^2} \cdot y(x) = 0 \end{eqnarray} have the following form: \begin{eqnarray} &&y_1(x) := (a+A x)^{b_1/2} (b+B x)^{\frac{1}{2} (-a_1-a_2+1)} (a+x (A-B)-b)^{\frac{1}{2} (a_1+a_2-b_1+1)} \, _2F_1\left(a_1,a_2;b_1;\frac{a+A x}{b+B x}\right)\\ &&\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!y_2(x) := (a+A x)^{1-\frac{b_1}{2}} (b+B x)^{\frac{1}{2} (-a_1-a_2-1)+b_1} (a+x (A-B)-b)^{\frac{1}{2} (a_1+a_2-b_1+1)} \, _2F_1\left(a_1-b_1+1,a_2-b_1+1;2-b_1;\frac{a+A x}{b+B x}\right) \end{eqnarray}

The following Mathematica code verifies the result:

In[1109]:= A =.; B =.; a =.; b =.; Clear[y1]; Clear[y2]; Clear[v]; x =.;
{A, B, a, b} = RandomInteger[{0, 20}, 4];
v[x_] := (-A b + a B)^2/(
4 (a + A x)^2 (a - b + A x - B x)^2 (b +
B x)^2) (a^2 (-1 + a1 - a2) (1 + a1 - a2) + b^2 (-2 + b1) b1 +
2 a b (2 a1 a2 + b1 - a1 b1 - a2 b1) +
2 (A (a (-1 + a1 - a2) (1 + a1 - a2) +
b (2 a1 a2 + b1 - a1 b1 - a2 b1)) +
B (b (-2 + b1) b1 +
a (2 a1 a2 + b1 - a1 b1 - a2 b1))) x + (A^2 (-1 + a1 -
a2) (1 + a1 - a2) + B^2 (-2 + b1) b1 +
2 A B (2 a1 a2 + b1 - a1 b1 - a2 b1)) x^2);
y1[x_] := (a + A x)^(b1/2) (a - b + (A - B) x)^(
1/2 (1 + a1 + a2 - b1)) (b + B x)^(1/2 (1 - a1 - a2))
Hypergeometric2F1[a1, a2, b1, (A x + a)^1/(B x + b)^1];
y2[x_] := (a + A x)^(1 - b1/2) (a - b + (A - B) x)^(
1/2 (1 + a1 + a2 - b1)) (b + B x)^(1/2 (-1 - a1 - a2) + b1)
Hypergeometric2F1[1 + a1 - b1, 1 + a2 - b1,
2 - b1, (A x + a)^1/(B x + b)^1];
FullSimplify[(D[#, {x, 2}] - v[x] #) & /@ {y1[x], y2[x]}]

Out[1114]= {0, 0}


Update 0: The result above can be used to solve the following inverse problem. Let $A=B=1$. Now let $a,b \in {\mathbb N}$ and let $P_0,P_1,P_2 \in {\mathbb N}$ subject to $P_0^2 + P_1^2 + P_2^2 > 0$. Then there always exist certain $a_1,a_2,b_1 \in {\mathbb R}$ such that the functions $y_{1,2}(x)$ above are fundamental solutions to the following ODE: \begin{eqnarray} \frac{d^2 y(x)}{d x^2} - \frac{(P_0+P_1 x+P_2 x^2)}{(x+a)^2(x+b)^2} \cdot y(x)=0 \end{eqnarray} Indeed if we set $A=B=1$ and then if we set $a,b \in {\mathbb N}$ in the top three equations defining $P_0,P_1,P_2$ above we can always solve those equations for $a_1,a_2,b_1$. Here is the Mathematica code that accomplishes that:

In[1473]:= {A, B} = {1, 1}; Clear[y1]; Clear[y2];
y1[x_] := (a + A x)^(b1/2) (a - b + (A - B) x)^(
1/2 (1 + a1 + a2 - b1)) (b + B x)^(1/2 (1 - a1 - a2))
Hypergeometric2F1[a1, a2, b1, (A x + a)^1/(B x + b)^1];
y2[x_] := (a + A x)^(1 - b1/2) (a - b + (A - B) x)^(
1/2 (1 + a1 + a2 - b1)) (b + B x)^(1/2 (-1 - a1 - a2) + b1)
Hypergeometric2F1[1 + a1 - b1, 1 + a2 - b1,
2 - b1, (A x + a)^1/(B x + b)^1];
{a, b} = RandomInteger[{0, 10}, 2];
{P0, P1, P2} = RandomInteger[{0, 10}, 3];
a1 =.; a2 =.; b1 =.;
subst = FullSimplify[
Solve[{a^2 (-1 + a1 - a2) (1 + a1 - a2) + b^2 (-2 + b1) b1 +
2 a b (2 a1 a2 + b1 - a1 b1 - a2 b1),
2 (A (a (-1 + a1 - a2) (1 + a1 - a2) +
b (2 a1 a2 + b1 - a1 b1 - a2 b1)) +
B (b (-2 + b1) b1 +
a (2 a1 a2 + b1 - a1 b1 - a2 b1))) , (A^2 (-1 + a1 -
a2) (1 + a1 - a2) + B^2 (-2 + b1) b1 +
2 A B (2 a1 a2 + b1 - a1 b1 - a2 b1))} == 4 {P0, P1, P2}, {a1,
a2, b1}]];
subst = Sort[{a1, a2, b1} /. subst, #1[[3]] < #2[[3]] &];
MatrixForm[subst]
aa = FullSimplify[(D[#, {x, 2}] - (
P0 + P1 x + P2 x^2)/((x + a)^2 (x + b)^2) #) & /@ {y1[x],
y2[x]}]
FullSimplify[aa /. Diagonal[Thread[{a1, a2, b1} -> #] & /@ subst[[1]]]]

Out[1483]= {0, 0}


In this particular example we had $\{a,b\}=\{9,7\}$,$\{P_0,P_1,P_2\}=\{ 0,4,9\}$ and \begin{eqnarray} \left(\begin{array}{r}a_1\\a_2\\b_1\end{array}\right)=\left( \begin{array}{r}\frac{1}{2} \left(1+\sqrt{37}+3 \sqrt{46}-\sqrt{694}\right)\\\frac{1}{2} \left(1-\sqrt{1145+12 \sqrt{7981}-4 \sqrt{37 \left(277+3 \sqrt{7981}\right)}}\right)\\1-\sqrt{694}\end{array}\right) \end{eqnarray}

Update 1: Now let us go back to Update 0 and let us take some particular examples where we can indeed give closed form solutions .

(A) If we set $P_2=P_1=0$ and $P_0 \neq 0$ then we get the following: \begin{eqnarray} a_1 &=& 1\\ a_2 &=& 1+\frac{\sqrt{(a-b)^2+4 P_0}}{a-b}\\ b_1 &=& a_2 \end{eqnarray} Therefore the solutions to $$\frac{d^2 y(x)}{d x^2} - \frac{P_0}{(x+a)^2(x+b)^2} y(x)=0$$ are \begin{eqnarray} y_1(x) &=& {(a+x)^{\frac{1}{2}+\frac{\sqrt{(a-b)^2+4 \text{P0}}}{2 (a-b)}} (b+x)^{\frac{1}{2}-\frac{\sqrt{(a-b)^2+4 \text{P0}}}{2 (a-b)}}}\\ y_2(x) &=& {(a+x)^{\frac{1}{2}-\frac{\sqrt{(a-b)^2+4 \text{P0}}}{2 (a-b)}} (b+x)^{\frac{1}{2}+\frac{\sqrt{(a-b)^2+4 \text{P0}}}{2 (a-b)}}} \end{eqnarray} Note that : \begin{eqnarray} \lim_{b\rightarrow a} y_{1,2}(x) = (x+a) \exp\left( \pm \frac{\sqrt{P_0}}{x+a}\right) \end{eqnarray} as it should be.

(B) Likewise let use take $P_2=P_0=0$ and $P_1 \neq 0$. Then we are getting the following solution: \begin{eqnarray} a_2 &=& 1-\frac{\sqrt{\sqrt{16 a b P_1^2-4 P_1 (a+b) (a-b)^2+(a-b)^4}-2 P_1 (a+b)+(a-b)^2}}{\sqrt{2} (a-b)}\\ a_1 &=& 1-\frac{P_1}{(1-a_2) (b-a)}\\ b_1 &=& -1+a_1+a_2 \end{eqnarray} Therefore the solutions to $$\frac{d^2 y(x)}{d x^2} - \frac{P_1 x}{(x+a)^2(x+b)^2} y(x)=0$$ are \begin{eqnarray} y_1(x) &=& (a+x)^{b_1/2} (b+x)^{\frac{1}{2} (-a_1-a_2+1)} \, _2F_1\left(a_1,a_2;b_1;\frac{a+x}{b+x}\right)\\ y_2(x) &=& (a+x)^{1-\frac{b_1}{2}} (b+x)^{\frac{1}{2} (-a_1-a_2-1)+b_1} \, _2F_1\left(a_1-b_1+1,a_2-b_1+1;2-b_1;\frac{a+x}{b+x}\right) \end{eqnarray}

Note that: \begin{eqnarray} \lim_{b\rightarrow a_+} a_2 &=& 1+ \omega\\ a_1 &=& 1-\frac{4 a \omega}{\theta} \\ b_1 &=& \omega + 1 - \frac{4 a \omega}{\theta} \end{eqnarray} where $\omega := \frac{\imath}{2} \sqrt{\frac{P_1}{a}}$ and $\theta:=b-a$. Therefore we have: \begin{eqnarray} &&\theta^{1+\omega}\cdot y_1(x) =\\ && (x+a)^{\frac{\omega+1}{2}-\frac{2 a \omega}{\theta}} \cdot (x+a +\theta)^{\frac{1}{2}(-1-\omega+\frac{4 a}{\omega})} \cdot \theta^{1+\omega} F_{2,1}\left[ \begin{array}{rr} 1+\omega & 1- \frac{4 a \omega}{\theta}\\ & \omega+1-\frac{4 a \omega}{\theta} \end{array}; \frac{x+a}{x+a+\theta} \right]=\\ &&\left(1+\frac{\theta}{x+a}\right)^{\frac{2 a \omega}{\theta}} \cdot \theta^{1+\omega} F_{2,1}\left[ \begin{array}{rr} 1+\omega & 1- \frac{4 a \omega}{\theta}\\ & \omega+1-\frac{4 a \omega}{\theta} \end{array}; \frac{x+a}{x+a+\theta} \right] \underbrace{=}_{\theta \rightarrow 0}\\ &&e^{\frac{2 a \omega}{x+a}}\cdot (x+a) (-4 a \omega)^\omega U(\omega,0;-\frac{4a \omega}{x+a}) \end{eqnarray} See Compute a limit that involves a hypergeometric function. for explanations.

In case of the second function $(a_1,a_2,b_1) \rightarrow (a_1-b_1+1,a_2-b_1+1,2-b_1)$ which is equivalent to $\omega \rightarrow -\omega$ and therefore : \begin{eqnarray} \lim_{b\rightarrow a} y_{1,2}(x) = (x+a) \cdot \exp\left(\pm \frac{2 a \omega}{x+a}\right) \cdot U(\pm\omega,0;\mp\frac{4 a \omega}{x+a}) \end{eqnarray} where $U$ is the confluent hypergeometric function.

(C) Now let us assume that $P_0=P_1=0$ and $P_2\neq 0$. Define $Q:=\sqrt{1+4 P_2}$. Then we have: \begin{eqnarray} &&a_2^4 (a-b)^2+\\ &&-2 a_2^3 (Q+1) (a-b)^2+\\ &&a_2^2 \left(a^2 (4 P_2+3 Q+2)-2 a b (6 P_2+3 Q+2)+b^2 (4 P_2+3 Q+2)\right)+\\ &&-a_2 \left(a^2 (4 P_2+Q+1)-2 a b (2 P_2 (Q+3)+Q+1)+b^2 (4 P_2+Q+1)\right)+\\ &&-2 a b P_2 (Q+1)=0\\ &&\hline\\ a_1&=& \frac{b (a_2 Q+a_2-4 P_2-Q-1)-a (a_2-1) (Q+1)}{(a-b) (-2 a_2+Q+1)}\\ b_1&=&a_1+a_2-Q \end{eqnarray}

Therefore the solutions to $$\frac{d^2 y(x)}{d x^2} - \frac{P_2 x^2}{(x+a)^2(x+b)^2} y(x)=0$$ are \begin{eqnarray} y_1(x) &=& (a+x)^{b_1/2} (b+x)^{\frac{1}{2} (-a_1-a_2+1)} \, _2F_1\left(a_1,a_2;b_1;\frac{a+x}{b+x}\right)\\ y_2(x) &=& (a+x)^{1-\frac{b_1}{2}} (b+x)^{\frac{1}{2} (-a_1-a_2-1)+b_1} \, _2F_1\left(a_1-b_1+1,a_2-b_1+1;2-b_1;\frac{a+x}{b+x}\right) \end{eqnarray}

Now the calculation of the limit of $b$ going to $a$ is very similar to the case before so we only present the result. We have: \begin{eqnarray} \lim_{b\rightarrow a} y_{1,2}(x) = \left(x+a \right)^{\frac{1-Q}{2}}\cdot \exp\left(\mp \frac{a\sqrt{Q^2-1}}{2(x+a)} \right) \cdot U\left(\frac{1}{2}(1+Q\mp\sqrt{Q^2-1}),1+Q;\pm \frac{a\sqrt{Q^2-1}}{x+a} \right) \end{eqnarray} where $Q:=\sqrt{1+4 P_2}$.

(D) Now let us assume that $P_0$,$P_1$ and $P_2$ are arbitrary subject to $P_1 > 2 a P_2$. Then we have: \begin{eqnarray} &&a_2^4 (a-b)^2+\\ &&-2 a_2^3 (Q+1) (a-b)^2+\\ &&a_2^2 \left(a^2 (4 P_2+3 Q+2)+2 a (P_1-b (6 P_2+3 Q+2))+b^2 (4 P_2+3 Q+2)+2 b P_1-4 P_0\right)+\\ &&a_2 \left(a^2 (-(4 P_2+Q+1))+2 a (b (2 P_2 (Q+3)+Q+1)-P_1 (Q+1))-b^2 (4 P_2+Q+1)-2 b P_1 (Q+1)+4 P_0 (Q+1)\right)+\\ &&a (Q+1) (P_1-2 b P_2)+P_1 (b Q+b+P_1)-2 P_0 (2 P_2+Q+1)=0\\ &&\hline\\ &&a_1=\frac{-a (a_2-1) (Q+1)+b (a_2 Q+a_2-4 P_2-Q-1)+2 P_1}{(a-b) (-2 a_2+Q+1)}\\ &&b_1=a_1+a_2-Q \end{eqnarray}

Therefore the solutions to $$\frac{d^2 y(x)}{d x^2} - \frac{P_0+P_1 x+P_2 x^2}{(x+a)^2(x+b)^2} y(x)=0$$ are \begin{eqnarray} y_1(x) &=& (a+x)^{b_1/2} (b+x)^{\frac{1}{2} (-a_1-a_2+1)} \, _2F_1\left(a_1,a_2;b_1;\frac{a+x}{b+x}\right)\\ y_2(x) &=& (a+x)^{1-\frac{b_1}{2}} (b+x)^{\frac{1}{2} (-a_1-a_2-1)+b_1} \, _2F_1\left(a_1-b_1+1,a_2-b_1+1;2-b_1;\frac{a+x}{b+x}\right) \end{eqnarray} In the limit $b$ going to $a$ we have the following result: \begin{eqnarray} \lim_{b\rightarrow a} y_{1,2}(x) = \left(x+a\right)^{\frac{1-Q}{2}}\cdot \exp\left(\pm \frac{R}{x+a}\right)\cdot U\left(\frac{1}{2}(1+Q\pm\frac{-P_1+2 a P_2}{R}),1+Q;\mp \frac{2 R}{x+a} \right) \end{eqnarray} where $Q:=\sqrt{1+4 P_2}$ and $R:=\sqrt{P_0-P_1 a+P_2 a^2}$.

Again by applying the same algorithm to the Gaussian hypergeometric differential equation, i.e. by rescaling the ODE in question by $$x \rightarrow f(x)$$,$$d/dx \rightarrow 1/f^{'}(x) d/dx$$ with $$f(x):=A x^n$$ and then by eliminating the term proportional to the first derivative we found the following result.

Let $$a$$,$$b$$,$$c$$,$$A$$ and $$n$$ be real numbers. Then the following ODE: $$\begin{eqnarray} \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!y^{''}(x) + \left(\frac{-A^2 x^{2 n} \left(a^2 n^2-2 a b n^2+b^2 n^2-1\right)+2 A x^n \left(n^2 (a (c-2 b)+(b-1) c+1)-1\right)-(c-1)^2 n^2+1}{4 x^2 \left(1-A x^n\right)^2}\right) y(x)=0 \end{eqnarray}$$ is solved by $$y(x) = C_1 y_1(x) + C_2 y_2(x)$$ where : $$\begin{eqnarray} y_1(x)&=&x^{\frac{1}{2} ((c-1) n+1)} \left(1-A x^n\right)^{\frac{1}{2} (a+b-c+1)} \, _2F_1\left(a,b;c;A x^n\right)\\ y_2(x)&=&x^{\frac{1}{2} (1-(c-1) n)} \left(1-A x^n\right)^{\frac{1}{2} (a+b-c+1)} \, _2F_1\left(a-c+1,b-c+1;2-c;A x^n\right) \end{eqnarray}$$

The following Mathematica code neatly verifies the result:

In[759]:= Clear[y1]; Clear[y2]; A =.; n =.; a =.; b =.; c =.;
y1[x_] = x^(1/2 ((1 + (-1 + c) n) )) (1 - A x^n)^(
1/2 ((1 + a + b - c))) Hypergeometric2F1[a, b, c, A x^n];
y2[x_] = x^(1/2 ((1 - (-1 + c) n) )) (1 - A x^n)^(
1/2 ((1 + a + b - c)))
Hypergeometric2F1[a + 1 - c, b + 1 - c, 2 - c, A x^n];
FullSimplify[((
1 - (-1 + c)^2 n^2 +
2 A (-1 + (1 + (-1 + b) c + a (-2 b + c)) n^2) x^n -
A^2 (-1 + a^2 n^2 - 2 a b n^2 + b^2 n^2) x^(2 n))/(
4 x^2 (1 - A x^n)^2)) # + D[#, {x, 2}]] & /@ {y1[x], y2[x]}

Out[762]= {0, 0}


Let $$A$$,$$B$$,$$C$$, $$D$$ and $$n$$ be integers. Let $$P_0$$,$$P_1$$ and $$P_2$$ be another integers. Now let $$a$$,$$b$$ and $$c$$ be complex numbers such that such that: $$\begin{eqnarray} P_0&=&B^2 \left(a^2-2 a b+b^2-1\right)+2 B D (2 a b-a c-b c+c)+(c-2) c D^2\\ P_1&=&2 \left(A \left(B \left(a^2-2 a b+b^2-1\right)+D (2 a b-a c-b c+c)\right)+C (a B (2 b-c)+c (-b B+B+(c-2) D))\right)\\ P_2&=&A^2 \left(a^2-2 a b+b^2-1\right)+2 A C (2 a b-a c-b c+c)+(c-2) c C^2 \end{eqnarray}$$

Consider the following ODE: $$\begin{eqnarray} y^{''}(x) + \frac{n}{x} y^{'}(x) + \left( \frac{n(n-2)}{4 x^2} - (B C - A D)^2 \frac{P_0 + P_1 x+P_2 x^2}{4(B+A x)^2(B-D+(A-C)x)^2(D+C x)^2}\right)y(x)=0 \end{eqnarray}$$ then $$\begin{eqnarray} &&y(x)= x^{-n/2} (A x+B)^{c/2} (C x+D)^{\frac{1}{2} (-a-b+1)} (A x+B-C x-D)^{\frac{1}{2} (a+b-c+1)} \cdot \\ &&\left( C_2 \left(\frac{A x+B}{C x+D}\right)^{1-c} \, _2F_1\left(a-c+1,b-c+1;2-c;\frac{B+A x}{D+C x}\right)+C_1 \, _2F_1\left(a,b;c;\frac{B+A x}{D+C x}\right)\right) \end{eqnarray}$$

In[13]:= A =.; B =.; CC =.; DD =.; a =.; b =.; c =.; Clear[m]; n =.; \
x =.;
{A, B, CC, DD} = RandomSample[Range[1, 10], 4];
{P0, P1, P2} = RandomSample[Range[1, 10], 3];
subst = Solve[{(-1 + a^2 - 2 a b + b^2) B^2 +
2 B (2 a b + c - a c - b c) DD + (-2 + c) c DD^2,
2 (A ((-1 + a^2 - 2 a b + b^2) B + (2 a b + c - a c - b c) DD) +
CC (a B (2 b - c) + c (B - b B + (-2 + c) DD))),
A^2 (-1 + a^2 - 2 a b + b^2) +
2 A (2 a b + c - a c - b c) CC + (-2 + c) c CC^2} == {P0, P1,
P2}, {a, b, c}];
{a, b, c} = {a, b, c} /. subst[[1]];
m[x_] = x^(-n/2) (CC x + DD)^(1/2 (1 - a - b)) (B + A x)^(
c/2) (B - DD + A x - CC x)^(1/2 (1 + a + b - c));
eX = (D[#, {x, 2}] +
n/x D[#,
x] + (((-2 + n) n)/(
4 x^2) - ((B CC - A DD)^2 (P0 + P1 x + P2 x^2))/(
4 (B + A x)^2 (B - DD + A x - CC x)^2 (DD +
CC x)^2)) #) & /@ {m[
x] (C[1] Hypergeometric2F1[a, b, c, (A x + B)/(CC x + DD)] +
C[2] ((A x + B)/(CC x + DD))^(1 - c)
Hypergeometric2F1[a + 1 - c, b + 1 - c, 2 - c, (A x + B)/(
CC x + DD)])};

{n, x} = RandomReal[{1, 10}, 2, WorkingPrecision -> 50];
Simplify[eX]

Out[21]= {(0.*10^-48 + 0.*10^-49 I) C[
1] + (0.*10^-48 + 0.*10^-48 I) C[2]}