Question: ****PLEASE USE PYTHON TO ANSWER QUESTION****** 2 Function of Interest Create a user-defined function named f(x) tha returns the value 1 + 2 tanh(2x). You
****PLEASE USE PYTHON TO ANSWER QUESTION******


2 Function of Interest Create a user-defined function named f(x) tha returns the value 1 + 2 tanh(2x). You will find the tanh function as a part of either the math or numpy modules. Calculate the analytic derivative of this function and create another user-defined function named fprime (x) that returns the appropriate value. 3 Derivative Methods 3.1 Forward and Backward Differences The forward difference algorithm is defined as df d.cl f(x+h)-f(x) Ah Intro to Scientific Computing Exercise 06 Numerical Derivatives of a Built-In Function Create a user-defined function called fd(x,h) that takes in 2 arguments, the value of r and the step-size h, and returns the appropriate result. The backward difference algorithm is defined as df f(x) - f(x - h) da lidh Create a user-defined function called bd(x,h) that takes in 2 arguments, the value of r and the step-size h, and returns the appropriate result. 3.2 Central and Extended Difference A central difference algorithm is given by df f(x+h/2) - f(x - h/2) Dcdf(r,h) = (3) do lodh Create a user-defined function called cd(x,h) that takes in 2 arguments, the value of r and the step-size h, and returns the appropriate result. The extended difference algorithm is a combination of two central differences, one with full step h and one with half-step h/2 df 4Dcd (x, h/2) - Ded(x, h) de led Create a user-defined function called ed(x,h) that takes in 2 arguments, the value of x and the step-size h, and returns the appropriate result. It should call your user-defined function for the central difference twice. (4) 4 Testing the Results 4.1 Absolute Error Create a user-defined function to calculate the absolute error of a value with the exact value of the analytic derivative. Call the function abserr(x,y). It should take in two arguments, the value of x that you are testing and the value of the calculated derivative y. 4.2 Determining the right value of h For x = 0.5, vary h from 0.1 down to 10-12 for each method. Based on your calculations, determine a good value of h to use for each method. Check again for x = -1.0. Does the same value of h work for both values of x? 4.3 Testing To assess each method, compare the exact value of the derivative for x = -1.0, -0.5, 0.0, 0.5, 0.75, 1.0, and 1.5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
