Question: 3. Write a Python function that evaluates the numerical derivative of an arbitrary function. Use the centered differences formula: dxdf(x)=2f(x+)f(x) where is a small number.

 3. Write a Python function that evaluates the numerical derivative of

3. Write a Python function that evaluates the numerical derivative of an arbitrary function. Use the centered differences formula: dxdf(x)=2f(x+)f(x) where is a small number. Try to determine a good value for . You can provide this information as a comment in your code. The general structure should be: 1 def differentiate ( myfun, x): 2 \# your code goes here 3 4 \# derivative of sin(x) at x=1 5 \# derivative of x3 at x=2 Your program should generate the output: Numerical derivative of sin(x) at x=1 is 0.540302 Exact derivative of sin(x) at x=1 is 0.540302 Numerical derivative of x3 at x=2 is 12.000000 Exact derivative of x3 at x=2 is 12.000000 4. Write a Python function that numerically evaluates the second derivative of an arbitrary (mathematical) function. Use the same test problems as above. When you write the code, use the differentiate function developed above. Your program should generate the output: Numerical double derivative of sin(x) at x=1 is 0.841466 Exact double derivative of sin(x) at x=1 is 0.841471 Numerical double derivative of x3 at x=2 is 12.001511 Exact double derivative of x3 at x=2 is 12.000000 How does the choice of affect the accuracy of the

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!