Power Series Worksheet: Problem 2

Here is the differential equation from #2 on the Power Series worksheet:

(((d^2)y)/(dt^2))+t(dy/dt)+y=1

The power series solution is:

y(t)=(Subscript[a, 0])+(Subscript[a, 1])t+((1-(Subscript[a, 0]))/2)(t^2)-((Subscript[a, 1])/3)(t^3)+(((Subscript[a, 0])-1)/8)(t^4)+(1/15)(t^5)+⋯

If we impose the initial conditions y(0)=0 and y'(0)=1, then (Subscript[a, 0])=0 and (Subscript[a, 1])=1, so the power series becomes:

y(t)=t+(1/2)(t^2)-(1/3)(t^3)-(1/8)(t^4)+(1/15)(t^5)+⋯

The numerators of the coefficients are 1, 1, -1, -1, 1, 1, -1, -1,.... We can produce this sequence with (((-1))^(⌊((n-1)/2)⌋)), where ⌊k⌋ denotes the floor of k, that is, the largest integer less than or equal to k. For example:

Table[(-1)^Floor[(n-1)/2],{n,1,12}]

The denominators of the coefficients are double factorials. A double factorial is n!!=n(n-2)(n-4)⋯, where the last term in the product is either 2 (if n is even) or 1 (if n is odd). Double factorial is implemented in Mathematica as Factorial2. For example:

Table[Factorial2[n],{n,1,10}]

Thus, we can define the following function to return the first m terms of this power series solution:

series[t_,m_]:=Sum[(-1)^Floor[(n-1)/2]/Factorial2[n]t^n,{n,1,m}]

For example, for m=8:

series[t,8]

We can plot this power series:

Plot[series[t,8],{t,-5,5},PlotRange->{-5,5}]

Now we will find the exact solution to the differential equation:

sol=DSolve[{y''[t]+t*y'[t]+y[t]==1,y[0]==0,y'[0]==1},y[t],t]

Store this solution as a function:

yexact[t_]=y[t]/.sol[[1]]

Now we can plot the exact solution and the power series solution together. We will create a slider that controls the number of terms of the power series to plot:

Manipulate[Plot[{yexact[t],series[t,m]},{t,-5,5},PlotRange->{-5,5},AxesLabel->Automatic],{m,1,40}]