Question: 1. Consider the function f(x) = x + sin(x). (a) Write a function, MyForwardDifference, that takes in a function f, a point (or points)
1. Consider the function f(x) = x + sin(x). (a) Write a function, MyForwardDifference, that takes in a function f, a point (or points) x, and a step size h that represents the spacing between the x points. The function should return an approximated derivative of f using forward differences at each x point. Hint: See Example 1 for an example of generating points with h space between them. Using your function, approximate the derivative Dh f' using step sizes h=2 for n = 1,2,3,..., 15 on the interval [1, 2]. Compare the results of your function to the true derivatives f'(x) = 3x + cos(x) by computing the error Print your results in and the error ratio En = max | f'(x) - Dh(x)| X a table that has as columns: n, the error En (x), En (x) where = 1. En-1(x) E (x) Eo (x)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
