Regular Power Series Solution

Solution of
y''+cos(x) y=0
for y(x) with y(0)=1 and y'(0)=0.
An exact solution can be found in this case, and can
be compared with the series solution.

Off[General::spell1]

Let's find a solution valid out to (x^10).  The first step in finding a series solution is to find an expansion for Cos[x]:

n=10;

cosser=Cos[x]+O[x]^(n+1)

y[x_]=Sum[a[k] x^k, {k,0,n,2}]+O[x]^(n+1)

deqn=y''[x]+cosser*y[x]==0

Here are the unknowns in the expansion of y(x) that we must solve for:

coeffs=Table[a[k],{k,2,n,2}]

Here are the algebraic equations for those coefficients:

eqns=LogicalExpand[deqn]

We actually don't need the TableForm for the math, it is just nice to look at:

TableForm[ReplaceAll[eqns,And->List]]

solset=Solve[eqns,coeffs]

ys[x_]=y[x]/.solset[[1]]

yss[x_]=Normal[ys[x]]

So here is the series solution that satisfies the specified initial conditions:

yss1[x_]=yss[x]/.a[0]->1

Now find exact solution:

Clear[y]

exact=DSolve[{y''[x]+Cos[x] y[x]==0,y'[0]==0,y[0]==1},y[x],x]

ey[x_]=y[x]/.exact[[1]]

Plot approximate (red) and exact (green) solutions:

Plot[{ey[x],yss1[x]},{x,0,10},PlotRange->{-10,10},PlotStyle->{RGBColor[0,1,0], RGBColor[1,0,0]}]