Problem 3, on P.S. #3, 2002. Numerical check of perturbation
solution, problem not solved here.
Finds a numerical solution to:
y'' + y ![]()
with y'(0)=0 and y(0)=1.
The period in the numerical solution is then compared to the prediction made from the perturbation expansion. The math for the
perturbation expansion is not shown here.
In[1]:=
![]()
The following line was changed to text. You may want to change the Format>Style to "Input" to execute the statement, and confirm that Mathematica cannot find an analytical solution:
DSolve[{y''[t]+y[t]+eps*y[t]^3==0,y[0]==1,y'[0]==0},y[t],t]
So we resort to a numerical solution for a specified value of eps:
In[2]:=
![nonosc[eps_] := NDSolve[{y ''[t] + y[t] + eps * y[t]^3 == 0, y[0] == 1, y '[0] == 0}, {y}, {t, 0, 10}]](HTMLFiles/index_3.gif)
In[3]:=
![]()
Out[3]=
![]()
Plot the analytical solution for eps=0 in black and the numerical
solution for eps=0.5 in red:
In[4]:=
![Plot[{Cos[t], y[t] /. tryit}, {t, 0, 10}, PlotStyle -> {RGBColor[0, 0, 0], RGBColor[1, 0, 0]}]](HTMLFiles/index_6.gif)
![[Graphics:HTMLFiles/index_7.gif]](HTMLFiles/index_7.gif)
Out[4]=
![]()
Here we make a more convenient interface to access the interpolating function that contains the numerical solution. Notice the replacement rule is inside a nested list, which is accessed by the [[1,1]]:
In[5]:=
![]()
Let's give it a try:
In[6]:=
![]()
Out[6]=
![]()
Let's find t where y(t)=0 in the numerical solution:
In[7]:=
![]()
Out[7]=
![]()
Now make a module to find the first t where y(t)=0 for a
specified value of ϵ.
In[8]:=
![FirstZero[eps_] := Module[{t, tryit, yfun, rt}, tryit = nonosc[eps] ; yfun[t_] = y[t] /. tryit[[1, 1]] ; rt = FindRoot[yfun[t] == 0, {t, 1, 2}] ; t /. rt[[1]] ]](HTMLFiles/index_14.gif)
Try it:
In[9]:=
![]()
Out[9]=
![]()
In[10]:=
![]()
Out[10]=
![]()
Make a table of ratio of the period of oscillation to that with ϵ=0.
In[11]:=
![]()
Out[11]=

In[12]:=
![]()
In[13]:=
![]()
Out[13]=

Compare the numerical result, which we assume to be exact, (green) with the perturbation result (red).
In[14]:=
![Plot[{FirstZero[x] * 2/Pi, PertResult1[x]}, {x, -.5, .5}, PlotStyle -> {RGBColor[0, 1, 0], RGBColor[1, 0, 0]}]](HTMLFiles/index_24.gif)
![[Graphics:HTMLFiles/index_25.gif]](HTMLFiles/index_25.gif)
Out[14]=
![]()
Now compare with the perturbation result out to
:
In[15]:=
![]()
In[16]:=
![Plot[{FirstZero[x] * 2/Pi, PertResult2[x]}, {x, -.5, .5}, PlotStyle -> {RGBColor[0, 1, 0], RGBColor[1, 0, 0]}]](HTMLFiles/index_29.gif)
![[Graphics:HTMLFiles/index_30.gif]](HTMLFiles/index_30.gif)
Out[16]=
![]()
Converted by Mathematica (March 3, 2003)