Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python we mentioned a way of approximating the derivative of a function fat a point x, by the slope of a straight ine through fx
python we mentioned a way of approximating the derivative of a function fat a point x, by the slope of a straight ine through fx - d) and fx+d). More precisely, the formula is (fx+d) fx - d)/(2 d As the distance dtends to zero, we expect this approximation to grow closer to the real derivative f(x). However, this fails to take into account the floating point round-off error in the calculation of fx + d) and fix d), which may become larger relative to the size of 2 d To measure this effect, we can compare the approximation with the true derivative, for cases where the latter is known. For example, if fx) ex(which is available in python as math.exp), we know that the derivative is fx) fx. (a) Write a function that computes the approximation of f(x), with a parameter for the distance d. As python allows you to pass functions as arguments, you can write a (simple) function that does this calculation for any function fand point X. (b) Write another function that calculates the error as the absolute difference between the approximate and true derivative, for given values of x and d, using the exponential function as f. Generate a series of diminishing values for d, from, say, 0.1 down to 10-15. You can do this with list comprehension and the range function: ds [10* ori in range(1,16)] Calculate and plot the error for each d-value in this range. What can you observe
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