- This problem provides an alternative interpretation of finite difference approximations.
Derive approximations for u0(x) by (i) fitting each of the sets of data below to the highest order polynomial you are able to consider, and then (ii) taking the exact derivative of that polynomial and evaluating that result at x.
- {u(x),u(x + h)}
- {u(x h),u(x)}
- {u(x h),u(x),u(x + h)}
Show that your results correspond exactly to D+u(x), Du(x) and D0u(x), respectively. Discuss how this alternative derivation of these finite difference formulas informs your understanding of their respective truncation errors.
- This problem provides an introduction to the m code that we will use for other problems in this class.
- Use the method of undetermined coefficients to set up the 5 5 Vandermonde system that would determine a fourth-order accurate finite difference approximation to u00(x) based on 5 equally spaced points,
u00(x) = c2u(x 2h) + c1u(x h) + c0u(x) + c1u(x + h) + c2u(x + 2h) + O(h4).
- Compute the coefficients using the Matlab code m available from the CatCourses website, and check that they satisfy the system you determined in part (a).
- Test this finite difference formula to approximate u00(1) for u(x) = sin(2x) with values of h from the array hvals = logspace(-1, -4, 13). Make a table of the error vs. h for several values of h and compare against the predicted error from the leading term of the expression printed by fdstencil. You may want to look at the m-file m for guidance on how to make such a table.
Also produce a log-log plot of the absolute value of the error vs. h. Be sure to label axes, include a legend, and any other items needed to make this plot clear and understandable.
You should observe the predicted accuracy for larger values of h. For smaller values, numerical cancellation in computing the linear combination of u values impacts the accuracy observed.
Reviews
There are no reviews yet.