Solve second-order ODE using gamma functions I would like to solve the ODE
$$\left(x-k_1\right)\frac{dY}{dx} + \frac{1}{a}x^2\frac{d^2 Y}{d x^2}-Y+k_2=0$$
with boundary conditions $Y\left(k_3\right)=0$ and $\frac{d Y}{d x}\left(\infty\right)=1-b$ (meaning if $x \to \infty$, the derivative approaches $1-b$). Not sure if it helps, but we also have $0\leq b \leq 1$, $a \geq 0$, and $k_2 + k_3 \leq k_1$. $x$ and $Y$ should also both be $\geq 0$.
I came across this equation years ago and remember that the solution involved gamma functions in some form, but otherwise I'm not sure where to start (or even what term to Google).
Would anyone know how to find the solution here?
 A: $$\left(x-k_1\right)\frac{d Y}{d x} + \frac{1}{a}x^2\frac{d^2 Y}{dx^2}-Y+k_2=0$$
Simplification with change of function :
$$Y(x)=y(x)+k_2\quad\implies\quad \left(x-k_1\right)\frac{d y}{d x} + \frac{1}{a}x^2\frac{d^2 y}{dx^2}-y=0$$
Obviously a simple particular solution is linear on the form $ y_p=\alpha x+\beta$
$\alpha\left(x-k_1\right) -(\alpha x+\beta)=0\quad\implies\quad \beta=-\alpha k_1\quad\implies\quad Y_p=\alpha (x-k_1)$
$\alpha$ is an arbitrary constant.
Knowing a particular solution allows to reduce the order of the ODE with change of function :
$$y(x)=\alpha(x-k_1)Z(x)\quad\implies\quad 
\left(\frac{2}{a}x^2+x-k_1\right)\frac{d Z}{d x}  + \frac{1}{a}x^2\frac{d^2 Z}{dx^2}=0$$
$$z(x)=\frac{d Z}{d x}\quad\implies\quad 
\left(\frac{2}{a}x^2+x-k_1\right)z  + \frac{1}{a}x^2\frac{d z}{dx}=0\quad\text{(See the note at end)}$$
The ODE is separable :
$$ \frac{d z}{z}= \left(-2-\frac{a}{x}+\frac{a k_1}{x^2}\right)dx $$
$$z(x)=c_2\exp\left(\int \left(-2-\frac{a}{x}+\frac{a k_1}{x^2}\right)dx \right)$$
$c_2$ is an arbitrary constant.
$$z(x)=c_2\exp\left(-2x-a\ln|x| -\frac{ak_1}{x}\right)$$
$$Z(x)=c_2\int \exp\left(-2x-a\ln|x| -\frac{ak_1}{x}\right)dx +constant$$
$$y(x)=C_2(x-k_1)\int \exp\left(-2x-a\ln|x| -\frac{ak_1}{x}\right)dx+C_1(x-k_1)$$
$$\boxed{Y(x)=C_1(x-k_1)+k_2+C_2(x-k_1)\int \exp\left(-2x-a\ln|x| -\frac{ak_1}{x}\right)dx}$$
$C_1$ and $C_2$ are arbitrary constants.
In the general case the integral cannot be expressed in a finite number of available standard functions. One have to proceed with numerical calculus which implies to specify the numerical values of $k_1$ and $a$.
In the particular case $k_1=0$ the integral is reduced to incomplete gamma function.
NOTE : There is a mistake in this equation as rightly pointed out by Eli Bartlett in comments. Although the calculus is not correct up to the end this doesn't change my conclusion : No explicite analytic solution,  finally one have to proceed with numerical calculus.
I don't delete the wrong part of the calculus in interest of showing the method or reduction of order and the way up to the integral form of solution.
A: You can solve this equation assuming it is a function of $x$ and $t$, but you will find that when constraining to the boundary conditions it is a function of $x$ only, so I'll treat it like an ODE.
For your question I will use the following trick: given a particular solution $u(x)$ to the homogeneous equation
\begin{align}
u''+f_1(x)u'+f_0(x)u=0,
\end{align}
the ODE
\begin{align}
y''+f_1(x)y'+f_0(x)y=f(x)
\end{align}
is exact under the integrating factor $e^{F_1}u$, where $F_1(x)=\smallint f_1(x)\mathrm dx$. Note that there is a term of the form $xy'-y$, so you should try to find a linear particular solution to your equation. We find that $Y_0=x-k_1$ works. So for your ODE
\begin{align}
Y''+a\frac{x-k_1}{x^2}Y'-\frac{a}{x^2}y+\frac{ak_1}{x^2}=0,
\end{align}
multiply by $(x-k_1)x^ae^{ak_1/x}$ to arrive at
\begin{align}
\left((x-k_1)x^ae^{ak_1/x}Y'-x^ae^{ak_1/x}Y\right)'+ak_1\frac{x-k_1}{x^2}e^{ak_1/x}=0.
\end{align}
Integrating and rearranging we arrive at
\begin{align}
Y'-\frac{1}{x-k_1}Y+\frac{k_1}{x-k_1}=\frac{c_1}{(x-k_1)x^ae^{ak_1/x}}.
\end{align}
This ODE is exact under the integrating factor $1/(x-k_1)$, multiplying, integrating, and rearranging we arrive at
\begin{align}
Y(x)=k_1+(x-k_1)\left(c_2+c_1\mathcal I(x)\right);\quad\left[\mathcal I(x)=\int\frac{\mathrm dx}{(x-k_1)^2x^ae^{ak_1/x}}\right].
\end{align}
We see that we recover the particular solution $Y_0=k_1+c(x-k_1)$ here as well. Now to fit the solution to the constraints. Evaluating $Y(x)$ at $k_3$ and letting $x\rightarrow\infty$ in $Y'(x)$ we get the equations
\begin{align}
\mathcal I(k_3)c_1+c_2&=\frac{k_1}{k_1-k_3},\\
\mathcal I(\infty)c_1+c_2&=1-b;\quad\left[\mathcal I(\infty)=\lim_{x\rightarrow\infty}\mathcal I(x)\right].
\end{align}
Which have the solutions
\begin{align}
c_1&=\frac{1}{\mathcal I(k_3)-\mathcal I(\infty)}\left(\frac{k_1}{k_1-k_3}+b-1\right),\\
c_2&=\frac{1}{\mathcal I(k_3)-\mathcal I(\infty)}\left(\frac{k_1}{k_1-k_3}\mathcal I(\infty)+(1-b)\mathcal I(k_3)\right).
\end{align}
So our solution is
\begin{align}
Y(x)=k_1+\frac{x-k_1}{\mathcal I(k_3)-\mathcal I(\infty)}\left((1-b)(\mathcal I(k_3)-\mathcal I(x))+\frac{k_1}{k_1-k_3}(\mathcal I(x)-\mathcal I(\infty))\right);\\\\\left[\mathcal I(x)=\int\frac{\mathrm dx}{(x-k_1)^2x^ae^{ak_1/x}}\right].
\end{align}
What I've been ignoring is the singularity in $\mathcal I(x)$. If the domain of $x$ includes $k_1$, the integral is divergent. This is why I ask if there are more constraints on your $k$'s! If we restrict our $x$ domain to $[k_3,\infty)$ (as your boundary conditions imply), then we require that $k_3>k_1$ for $x>k_1$.
