Lab02 Assignment

Euler’s Method

Euler’s Method is based on using a tangent line approximation to the solution of the initial value problem. The tangent line through the current point on a stream line is used to approximate the next point on the solution curve.  Thus we get the recursive formula:

Given the initial value problem y'=f(x,y), y((Subscript[x, 0]))=(Subscript[y, 0]) then

(Subscript[x, n+1])=(Subscript[x, n])+h and y((Subscript[x, n+1]))≈(Subscript[y, n+1])=(Subscript[y, n])+h f((Subscript[x, n]),(Subscript[y, n]))

where h=(b-a)/n, a=(Subscript[x, 0]) is the left-hand endpoint and b is the right-hand endpoint of the interval you wish an approximation over.  n is the number of subintervals you wish to use.  As a reminder, Euler’s Method as posted in the notebook “Lab01” is given below.

basicEuler[funct_,initX_, initY_,finalX_,numsteps_]:=Module[{f=funct,beginPoint =initX,w0=initY, endPoint = finalX,n=numsteps},
x=beginPoint;
w=w0;
h=(endPoint-beginPoint)/n;  (*The is the step size. *)
xList={x};  (*Initialize our list of t-values *)
wList ={w}; (*Initialize our list of w-vaules: the approximations to the solution *)

(* Here we loop from 1 to n performing Euler's method and appending the results to the lists *)
For[j=1,j<n+1,j++,
m1=h*f[x,w];
x=x+h;
w=w+m1;
xList=Append[xList,x];
wList=Append[wList,w];
];
Return[{xList,wList}]
]

Modified Euler’s Method

Modified Euler’s Method is based on using a linear approximation to the solution of the initial value problem. The linear approximation through the current point on a stream line is used to approximate the next point on the solution curve where the slope used is an average of the slopes at both ends of the subinterval in question.

Given the initial value problem y'=f(x,y), y((Subscript[x, 0]))=(Subscript[y, 0]) then

The first slope is (Subscript[m, 1])=f((Subscript[x, n]),(Subscript[y, n])), the second slope is the slope through the point given by Euler’s Method, namely (Subscript[m, 2])=f((Subscript[x, n])+h,(Subscript[y, n])+h f((Subscript[x, n]),(Subscript[y, n])))=f((Subscript[x, n])+h,(Subscript[y, n])+h (Subscript[m, 1])).  Then we take an average of these two slopes to get the slope of the linear approximation.  This gives us

(Subscript[x, n+1])=(Subscript[x, n])+h and y((Subscript[x, n+1]))≈(Subscript[y, n+1])=(Subscript[y, n])+h ((Subscript[m, 1])+(Subscript[m, 2]))/2

or

(Subscript[x, n+1])=(Subscript[x, n])+h and y((Subscript[x, n+1]))≈(Subscript[y, n+1])=(Subscript[y, n])+h (f((Subscript[x, n]),(Subscript[y, n]))+f((Subscript[x, n])+h,(Subscript[y, n])+h f((Subscript[x, n]),(Subscript[y, n]))))/2

where h=(b-a)/n, a=(Subscript[x, 0]) and b is the right-hand endpoint of the interval you wish an approximation over.  n is the number of subintervals you wish to use.

Assignment

Use Mathematica to complete the following problems.  Your notebook should include written comments using appropriate styles, graphs that are clearly labeled and work that is well organized.

Problem

Consider the differential equation

({{({{(dy/dx)=(e^x) cos(y).}})}})

Find all of the equilibria...note that there are a LOT of them.  Please give a formula for all equilibria.

Generate a direction field which shows where at least 3 perhaps 4 of these equilibria are located. Use -4≤x≤6 and something appropriate for y.

Use Euler’s Method to estimate the solutions with the following step sizes: h=1, 0.5, 0.25, 0.125 over the interval 0≤ x≤4. Choose your initial condition to be near, but just above the largest negative equilibrium (y(0)=-(3/2) would be a good one to use).

Create plots using Grid to illustrate the 4 cases generated by the various h.  Make sure that your horizontal axis ends at x=6.

Explain your results as h changes.

Overlay a plot using Euler’s Method when h=0.125 with the direction field.

Use Modified Euler’s Method to estimate the solutions with the following step sizes: h=1, 0.5, 0.25, 0.125 over the interval 0≤ x≤4. Choose your initial condition so that it is the same as what you used above.

Create plots using Grid to illustrate the 4 cases generated by the various h.  Make sure that your horizontal axis ends at x=6.

Explain your results as h changes.

Overlay a plot using Modified Euler’s Method when h=0.125 with the direction field.

Finally, use DSolve or NDSolve to find a solution for this differential equation using your same initial guess as above.  Plot this and compare to Euler’s Method and Modified Euler’s Method when h=0.125.