Question
Let f(x) = sin(x) cos(x). (a) Construct MATLAB functions to approximate the derivative of f(x) using the following three formulae: D1 [f(x)] = (f(x +
Let f(x) = sin(x) cos(x).
(a) Construct MATLAB functions to approximate the derivative of f(x) using the following three formulae:
D1 [f(x)] = (f(x + h) f(x)) / h ,
D2 [f(x)] = (f(x + h) f(x h)) / 2h ,
D3 [f(x)] = (f(x + 2h) + 4f(x + h) 3f(x)) / 2h .
Each of your MATLAB functions should accept x and h as arguments and produce an approximate derivative as output. Also construct a separate MATLAB function to evaluate the exact derivative f'(x).
(b) Using your MATLAB functions, calculate the relative errors for the approximate derivatives at the points x = 0 and x = 0.6. Use values of h given by h = 10^-d where d = 1, 2, . . ., 10. For each value of x, create a table of results with the headings h, D1error, D2error, and D3error.
(c) Provide an explanation of the various behaviors that you observe. Hint, look at the values of h where each approximation yields the most accurate result.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started