Question: The formula f'(x) = f(x + h) f(x h) - 2h can be used to find an approximate derivative of a mathematical function f(x) if

 The formula f'(x) = f(x + h) f(x h) - 2h

The formula f'(x) = f(x + h) f(x h) - 2h can be used to find an approximate derivative of a mathematical function f(x) if h is small. (This is a finite- difference formula, which you will see later as well. There is more than one way to set these approximations up.) Write a function diff( f,x, h=1e-5 ) that returns the approximation of the derivative of a mathematical function represented by a Python function f( x). For instance, the result of diff( math.sin, 0.25*math.pi ) should be 0.7071 (with some numerical error). The result of diff( math.sin, 0.375*math.pi, h=1e-3 ) should be 0.3827 (with some numerical error). (This assignment is based on Langtangen, Exercise 3.24a.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!