MIT18 330S12 hw2 PDF
MIT18 330S12 hw2 PDF
1. (1 pt) Let α and β be real numbers. If a quantity f (h) is O(hα ) as h → 0, show that
hβ f (h) = O(hα+β ).
Draw a picture to explain the “midpoint” interpretation. How accurate is the method, i.e., what is the
order of accuracy? Justify your answer.
x
3. (3 pts) Consider the function f (x) = 1+x 4 over the interval [−1, 2]. To integrate this function numeri-
cally, write a script to implement the first-order rectangle rule and the second-order trapezoidal rule.
(Now is a good time to learn about vector operations and the “sum” command in Matlab, if you do not
already know them.)
• How do you write the quadrature formulas to deal with the fact that the interval is [−1, 2] instead
of [0, 1]? In particular, how you relate h to N , and what is your choice of grid points xj ?
R2
• What is the value of −1 f (x) dx, to 10 decimal places?
• Do a log-log plot of the absolute value of the truncation error of each method as a function of h.
(Choose an adequate range of h that spans several orders of magnitude.) Explain how you can
spot the order of convergence of each method from your plot.
4. (1 pt) Repeat the convergence plots as in question 3, but with the function g(x) = (x + 1)3 (x − 2)2
on [−1, 2]. What order of accuracy do you now observe for each method? (Bonus, 1pt: explain your
observation.)
x
5. (3 pts) Consider the same function f (x) = 1+x 4 on [−1, 2]. To differentiate this function numerically,
write a script to implement the first-order forward difference and the second-order centered difference.
We are interested in computing the derivative not just at one point, but at every point of a fine grid with
spacing h (except at the two endpoints). For simplicity, you may want to use the same grid convention
as in the previous questions.
(You are free to use any method when asked about numerical values, including analytical/symbolic,
but please mention how you obtained your answer.)
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.