Question: Typically, reducing the step size h will result in a more accurate derivative approxi- mation. Our di erence methods, however, have large round o errors
Typically, reducing the step size h will result in a more accurate derivative approxi- mation. Our di erence methods, however, have large round o errors when h is too small.
Let's investigate with a test problem (a problem where we know the exact value of the derivative). Approximate f '(pi/3) for f(x) = x cos(x) using a centered diference. In Matlab, create an array called h. Start with h(1)=0.05. In a while loop, decrease the step size by a factor of 2 each time until h(i) is smaller than 10^-13. Build another array error in the same loop containing the exact errors for each approximation. Create a log-log plot of the results with the command
loglog(h,error)
Your plot should show an h which minimizes the error. This is called an optimal h. From your plot, estimate the optimal h.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
