Assignment 4

Name:
Student Number:

1

1. Numerical Integration of a Continuous Function 
a) Plot the following function between x=0 and x=100,
	f(x)=	2 + cos( 2 (Sqrt[x])) 	(1)

Include axes labels.

b) Find the exact value of the integral
                    (∫_0^2) 2+cos(2(Sqrt[x])) dx
by using the (∫_lower^upper)exprdvar command from the palletes.

c)  Examine and compare the convergence properties of the rectangle and trapezoid rule applied to the same integral:
   -   Write expressions for aproximation of the integral by using  the two rules

-  Calculate the error for each of the  two rules (the rectangle and trapezoid rules) as functions of number of elements n as
	
	Error[n]=(Subscript[log, 10])|((Numerical solution-Exact solution)/(Exact solution))|.		(2)

Save your results in lists by using command Table[{n,Error[n]}, {n,10,200}].

Plot the error for the two rules on one figure using ListPlot. Include a legend in your plot.  To do this you will need to "load" the library required to make legends.  Search the online help for PlotLegend as a starting point to figure out how to do this.

d) Discuss the results of your analysis done in b). Which method is the most accurate?

2

Numerical Integration of a Discrete Function 

The atmospheric static pressure P at height h above the Earth surfaceis generally given by,
	
	P(h)=P((Subscript[h, max]))+(∫_h^(Subscript[h, max]))ρ(z) g(z) dz     (3)
	
where z is the vertical axis. Assume (Subscript[h, max])=80 000m (in the ionosphere) and (Subscript[P, 0])=1.1 Pa. 1Pa = 1N/(m^2). Both gravitaional acceleration and air density change with the height z. 

The file Atm_Density _Gravity.dat contains the values of the atmospheric density (3rd column) and gravity (2nd column) as functions of height (1st column).  

a) Import and plot ρ(z).  (Use Mathematica’s online help on the functions Import, Directory, SetDirectory and FileNames.)

b) Calculate and plot the pressure from the surface z=0m to the upper level of the atmosphere z=80000m using i) the rectangle rule and ii) the trapezoid rule.

3.

Numerical solution of ODE

a)

Solve the following ODE using the midpoint scheme from t=0 to 3, using a stepsize of Δt=0.01.  Plot an interpolated form of your numerical solution.

y'(t)=0.4y+(e^(-t)), y(0)=1

b)

Repeat part (a), except implement the 4th Order Runge-Kutta scheme.  Compare the result to part (a).

4.

Numerical solution of system of ODEs

a) Use the fourth-order Runge-Kutta scheme to solve the following set of coupled ODE's:

(dx/dt)= -10 ( x - y)
	(dy/dt)= -x z + 28 x - y
	(dz/dt)= x y - 8 (z/3)

with

x(0)=-8, y(0)=8, z(0)=27

from t=0 to t=100 using a timestep Δt=0.1.  Interpolate your solutions for x(t) and y(t) to plot your results.

Remove["Global`*"]

b) Using DSolve, find the exact solutions for x(t) and y(t).

c) Plot the difference between your numerical solution and the exact solution for y(t).

d) Repeat the necessary steps frorm part a) in order to plot the difference between your numerical solution and the exact solution for y(t) when the timestep is decreased by a factor of 10 to Δt=0.01.  Comment on the outcome.
e) Plot parametric plot of x[t] and y[t]. Describe the trajectory of the solution.
(see also http://www.evolutionnews.org/2011/12/the_butterfly_e054321.html)