Take Home Midterm 2 Spring 2015

Eli Goldwyn
Name:
Math 309 - Spring 2015
Take Home Midterm 2
Date:
Instructrions:
You have until Monday, April 13 at 5 p.m. to work on this test. It is expected that
your results will be neatly written up. Neatness and thoroughness of explanations count all matlab code, command line input, and output must be neatly labeled. My input to run
the Matlab code must clearly be written in your exam. You may not consult with anyone
except me about the exam. You may not ask a classmate how far along they are on the
exam, or how hard/easy they thought a problem was. You may use your notes and the
text by Sauer for reference. You may not use any other references such as textbooks or the
internet.
If there is any indication that these policies have not been followed, the case will be
sent to the Academic Honor Council. By signing below you acknowledge that you have
read and will abide by these instructions.
Signature:
Take Home Midterm 2
Spring 2015
Eli Goldwyn
Math 309 - Spring 2015
Take Home Midterm 2
1. Given the points (xi , yi ) for i = 0, ..., n the Newton form of the interpolating polynomial is
p(x) = a0 + a1 (x − x0 ) + ... + an (x − x0 )(x − x1 )...(x − xn−1 ).
(a) Write an m-file that takes arrays (vectors) of data x and y and returns an array, a, containing the
coefficients of the Newton form of the interpolating polynomial.
(b) Write an m-file to efficiently evaluate the interpolating polynomial at a point z using nested multiplication. Your routine will take as input the arrays x and a and the scalar z, and it will return
p(z).
2. There are many different formulas to approximate the first derivative of a function. Two are listed below:
f (x + h) − f (x)
h
−f
(x
+
2h)
+
4f
(x + h) − 3f (x)
f 0 (x) ≈
2h
(a) The expression for the error of the order for the top equation was derived in class and is in the text.
Derive an expression for the error for the bottom equation and determine its order of accuracy.
f 0 (x) ≈
(b) Apply the difference formulas to f (x) = e−x at x = 0 to approximate f 0 (0). Make a table (for
each formula) that includes h, the approximation of the derivative, and the absolute error of the
approximation. Do this for each value of h (use values h = 1, 5.0 × 10−1 , 10−1 , 5.0 × 10−2 , 10−2 ,
5.0 × 10−3 , 10−3 , 10−4 )
(c) Plot the absolute errors vs. h on a log-log graph.
(d) Explain how the table of errors and the graph of the errors demonstrate the order of convergence.
3. Consider the integral
Z
1
2
xe−x dx.
−2
(a) Analytically calculate this integral.
(b) Implement the composite Trapezoid rule algorithm and compute an approximation to the above
integral using n = 8, 16, 32, 64 and report the approximation along with the absolute error for each
n in a table.
(c) Implement the composite Simpson’s rule algorithm and compute an approximation to the above
integral using n = 8, 16, 32, 64 and report the approximation along with the absolute error for each
n in a table.
(d) Plot the absolute errors vs. h = (b − a)/n on a log-log graph and explain how the order of accuracy
of this method is demonstrated by table and the plot.
4. Successive Over-Relaxation, SOR(ω) Consider the linear system

5
−4


1

0
0
−4
6
−4
1
0
1
−4
6
−4
1
0
1
−4
6
−4
   
0
   
0
   
   
1  x = b
   
−4    
5
Page 2 of 3
Eli Goldwyn
Math 309 - Spring 2015
Take Home Midterm 2
(a) Write a program for solving the linear system A~x = ~b using SOR(ω). Your program should take
as input A, ~b, ω, and a stopping criterion T OL. The output should be an approximate solution
to the linear system along with the number of iterations required to meet the error tolerance
||~x(k+1) − ~x∗ ||∞ < T OL .
(b) For ~b = [10, −15, 16, −15, 10]T the solution to the system is ~x∗ = [1, −1, 1, −1, 1]T . Using your
SOR(ω) program from part (b) with the initial guess ~x(0) = [0, 0, 0, 0, 0]T , solve the linear system
for this ~b using various values of ω using T OL = 1×10−10 . Plot the number of iterations required for
SOR(ω) to converge versus ω and use this to approximate the optimal ω for this system. Compare
the number of iterations it takes to solve the system using the optimal ω with the number it takes
for ω = 1 (i.e., the Gauss-Seidel case).
5. Consider Romberg integration where the first column is found using the composite trapezoid rule. Perform Richardson Extrapolation to show that the second column is composite Simpsons Rule (okay just
to show that R32 is composite Simpson’s Rule).
6. Determine the degree of precision of the approximation:
Z
1
f (x)dx ≈
−1
1
(3f (−2/3) + 2f (0) + 3f (2/3))
4
Page 3 of 3