Let f(x) be a given function that can be evaluated at points $x_0 \pm jh, j = 0,1,2,....$ for any fixed value of $h$, $0<h<<1$.
a.) Find a second order formula approximating the third derivative $f^{(3)}(x_0)$. Give the formula, as well as an expression for the truncation error
b.) Use your formula to find approximations to $f^{(3)}(0)$ for the function $f(x) = e^x$ employing values $h = 10^{-1}, 10^{-2},..,10^{-9}$, with the default MATLAB arithmetic. Verify that for the larger values of $h$ your formula is indeed second order accurate. Which value of h gives the closest approximation to $e^0 = 1$?
So I completed part a.) and got the approximation as the following: $$f^{(3)}(x_0)= \frac{3*[f(x_0+h)-f(x_0-h)]}{h^3}-\frac{6f'(x_0)}{h^2}-\frac{f^{(5)}(\xi)}{20}h^2$$ where our truncated error is the last term and is order two.
Using matlab, I generated the approximated values of $f^{(3)}(0)$ using the following code:
h= [10^-9 10^-8 10^-7 10^-6 10^-5 10^-4 10^-3 10^-2 10^-1];
f = @(x) e^x;
f3 =(3*(exp(h)-exp(-h)))./h.^3 - 6*exp(0)./h.^2;
However, I am confused on how to show it is second order accurate. Do I plot the error and observe it follows a degree two polynomial? I.e., set up some symbolic function with h for my approximation, and then plot $1 - f^{(3)}(x_0)$? I have very little experience with matlab, any help is appreciated. Thanks.
If you assume that the error is of the form $E(h) \approx C h^{\alpha}$ and $C$ does not depend on $h$, you can estimate the convergence order from the measured error for two values of $h$, say $h_1, h_2$.
$$ \frac{E(h_1)}{E(h_2)}\approx \frac{C h_1^{\alpha}}{C h_2^{\alpha}} \Rightarrow \alpha \approx \frac{\log(E(h_1)/E(h_2))}{\log(h_1/h_2)}. $$