Test methods for numerical differentation. Make a function table(f, x, hlist, dfdx=None) for writing out a nicely formatted table of the errors in the numerical derivative of a function f(x) at point...


Test methods for numerical differentation. Make a function table(f, x, hlist, dfdx=None) for writing out a nicely formatted table of the errors in the numerical derivative of a function f(x) at point x using the two formulas (7.1) and 7.7 and their implementations in classes Derivative (from Chapter 7.3.2), and Central (from Exercise 7.14). The first column in the table shows a list of h values (hlist), while the two next columns contain the corresponding errors arising from the two numerical approximations of the first derivative. The dfdx argument may hold a Python function that returns the exact derivative. Write out an additional column with the exact derivative if dfdx is given (i.e., not None). Call table for each of the functions x 2 , sin6 (πx), and tanh(10x), and the x values 0 and 0.25. Can you see from the errors in the tables which of the three approximations that seems to have the overall best performance in these examples? Plot the three functions on [−1, 1] and try to understand the behavior of the various approximations from the plots. Name of program file: Derivative_comparisons.py Exercise 7.14


Implement a class for numerical differentation. A widely used formula for numerical differentiation of a function f(x) takes the form


This formula usually gives more accurate derivatives than (7.1) because it applies a centered, rather than a one-sided, difference. The goal of this exercise is to use the formula (7.7) to automatically differentiate a mathematical function f(x) implemented as a Python function f(x). More precisely, the following code should work:


Implement class Central and test that the code above works. Include an optional argument h to the constructor in class Central so that one can specify the value of h in the approximation (7.7). Apply class Central to produce a table of the derivatives and the associated approximation errors for f(x) = ln x, x = 10, and h = 0.5, 0.1, 103
, 104
, 107
, 109
, 1011. Collect class Central and the two applications of the class in the same file, but organize the file as a module so that class Central can be imported in other files. Name of program file: Central.py

Nov 17, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here