# Series solutions to a Differential Equation

I am trying to determine the general solution to the equation $y''+f(x)y=0$, where $f(x):R \rightarrow R$. Naturally, I'm trying to use series to find the solution. This is what I have:

Assume $y$ can be written in the form:

$y=\sum_{n=0}^\infty a_n (x-x_0)^n$

Then,

$y'=\sum_{n=1}^\infty na_n (x-x_0)^{n-1}$

and

$y''=\sum_{n=2}^\infty n(n-1)a_n (x-x_0)^{n-2}=\sum_{n=0}^\infty (n+2)(n+1)a_{n+2} (x-x_0)^n$.

Thus, the differnetial equation becomes

$\sum_{n=0}^\infty (n+2)(n+1)a_{n+2} (x-x_0)^n+f(x)\sum_{n=0}^\infty a_n (x-x_0)^n=0$

or

$\sum_{n=0}^\infty \big[ (n+2)(n+1)a_{n+2} +f(x) a_n\big] (x-x_0)^n=0$

This can only be true for all $x$ if

$(n+2)(n+1)a_{n+2} +f(x) a_n=0$

Rearranging,

$a_{n+2}=\frac{-1}{(n+2)(n+1)}f(x)a_n$.

The recurrence relations are then

$a_n=a_{2k}=\frac{(-1)^k}{(2k)!}f(x)^ka_0$ and $a_n=a_{2k+1}=\frac{(-1)^k}{(2k+1)!}f(x)^ka_1$

Finally,

$y=a_0 \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!}f(x)^n (x-x_0)^{2n}+a_1 \sum_{n=0}^\infty \frac{(-1)^n}{(2n+1)!}f(x)^n (x-x_0)^{2n+1}$

which can be rewritten as

$y=a_0 \cos(\sqrt {f(x)} (x-x_0)+a_1 \frac{(x-x_0) \sin(\sqrt{f(x)}(x-x_0)}{\sqrt{f(x)}(x-x_0)}$

This all seems fine to me. However, when I choose a function for $f(x)$, and I check to see if the left hand side of the differential equation actually does equal zero, I find it does not. Where am I going wrong?

Your $a_n$ depends on $x$, therefore your Ansatz is not a power series. In other words, if you do your ansatz you would have to derive $a_n$ as well. But then you would obtain a system of differential equations for $a_n$ which might be even harder to solve.
You also need to expand $f(x)$ into a power series $$f(x)=\sum_nc_n(-x_0)^n$$ and then apply the Cauchy product to the second term, $$f(x)y(x)=\sum_n\sum_{m=0}^n c_ma_{n-m}(x-x_0)^n$$ so that the coefficient relations are $$a_{n+2}=-\frac1{(n+1)(n+2)}\sum_{m=0}^n c_ma_{n-m}$$