Math 260 Lab #2 Numerical methods

Save your work regularly--you never know when Mathematica may crash.  

Email your completed file to tleise@amherst.edu by next Monday 4pm.

Exercise 1.  Using whatever method you like, find the exact solution to the differential equation (dx/dt)= -x  with initial condition x(0)=1.  What is the exact value of x(1)?

Exercise 2.  Use the Euler method with step size Δt=1 to estimate x(1) numerically (in one step).

Exercise 3.  Use the Euler method with step size Δt=1/10 to estimate x(1) numerically (in 10 steps).   You may use the code shown below (ask me if you don't fully understand the code).

f[x_]:=-x; (* defines the function f(x) *)

Clear[xEuler]
xEuler[0]=1; (* initial condition *)
deltat=1/10; (* step size *)
For[k=1,k≤10,k++, (* iterates over k from 1 to 10 *)
xEuler[k]=xEuler[k-1]+f[xEuler[k-1]]deltat (* Euler method formula *)
]
N[xEuler[10]]

Exercise 4.  Plot the Euler method approximation on the same graph as the exact solution. Use the plotting code below. You need to fill in what the exact solution is (in place of ExactSolution).

Show[ListPlot[Table[{k/10,xEuler[k]},{k,1,10}],PlotStyle->{Blue,PointSize[0.02]}], (* generates and plots a list of points *)
Plot[ExactSolution,{t,0,1},PlotStyle->{Black,Thickness[.005]}],PlotRange->{{0,1},{1,0}},AxesOrigin->{0,0}]

Exercise 5.  Use the Euler method with step size Δt = 1/100 to estimate x (1) numerically in 100 steps.

Exercise 6.  Plot the Euler method approximation for Δt = 1/100 on the same graph as the exact solution.

Exercise 7.  What is the error at t = 1 for Δt = 1, for Δt = 1/10, and for Δt = 1/100 (exact value minus Euler method approximation) ?

Exercise 8.  Use the improved Euler method with step size Δt = 1, 1/10 and then 1/100 to estimate x (1) numerically. Do this by updating my code for the Euler method with the improved Euler method formula.

Exercise 9.  Repeat Exercise 7 for the improved Euler method errors. How rapidly do the errors decrease compared to the Euler method?

Exercise 10.  Use the Runge-Kutta method with step size Δt=(10^(-n)) to estimate x(1) numerically (in (10^n) steps), for n=0,1,and 2.

Exercise 11.  Repeat Exercise 7 for the Runge - Kutta method errors. How rapidly do the errors decrease compared to the previous methods?