numericalderivative.PolynomialProblem

class numericalderivative.PolynomialProblem(alpha=2, x=1.0, interval=[-12.0, 12.0])

Create a polynomial derivative benchmark problem

The function is:

\[f(x) = x^\alpha\]

for any \(x > 0\) where \(\alpha \in \mathbb{R}\) is a nonzero parameter. The test point is \(x = 1\).

This test can be difficult depending on the value of \(\alpha\). For example, if \(\alpha = 2\), then the third derivative is zero. This produces an infinite exact step for the first derivative central finite difference formula. For example, the DumontetVignes algorithm does not perform correctly for this problem because it is based on the hypothesis that the third derivative is zero.

The central finite difference for the first derivative is exact for this problem for any value of the differentiation step.

Parameters:
xfloat

The point where the derivative should be computed for a single test.

intervallist of 2 floats

The lower and upper bounds of the benchmark problem. This can be useful for benchmarking on several points. We must have interval[0] <= interval[1].

Methods

get_fifth_derivative()

Return the fifth derivative of the function of the problem

get_first_derivative()

Return the first derivative of the function of the problem

get_fourth_derivative()

Return the fourth derivative of the function of the problem

get_function()

Return the function of the problem

get_interval()

Return the interval of the problem

get_name()

Return the name of the problem

get_second_derivative()

Return the second derivative of the function of the problem

get_third_derivative()

Return the third derivative of the function of the problem

get_x()

Return the input point of the problem

__init__(alpha=2, x=1.0, interval=[-12.0, 12.0])

Create a benchmark problem for numerical derivatives of a function

This provides the function and the exact first derivative. This makes it possible to check the approximation of the first derivative using a finite difference formula. This class also provides the second, third, fourth and fifth derivative. This makes it possible to compute the optimal step for various finite difference formula.

Parameters:
functionfunction

The function

first_derivativefunction

The first derivative of the function

second_derivativefunction

The second derivative of the function

third_derivativefunction

The third derivative of the function

fourth_derivativefunction

The fourth derivative of the function

fifth_derivativefunction

The fifth derivative of the function

xfloat

The point where the derivative should be computed for a single test.

intervallist of 2 floats

The lower and upper bounds of the benchmark problem. This can be useful for benchmarking on several points. We must have interval[0] <= interval[1].

References

  • Dumontet, J., & Vignes, J. (1977). Détermination du pas optimal dans le calcul des dérivées sur ordinateur. RAIRO. Analyse numérique, 11 (1), 13-25.

  • Adaptive numerical differentiation. R. S. Stepleman and N. D. Winarsky. Journal: Math. Comp. 33 (1979), 1257-1264

Examples

The next example creates a benchmark problem.

>>> import numericalderivative as nd
>>> problem = nd.ExponentialProblem()
>>> x = problem.get_x()
>>> function = problem.get_function()
>>> first_derivative = problem.get_first_derivative()

Print a problem.

>>> problem = nd.ExponentialProblem()
>>> print(problem)

The next example creates a benchmark experiment.

>>> import numericalderivative as nd
>>> benchmark = nd.BuildBenchmark()
>>> number_of_problems = len(benchmark)
>>> for i in range(number_of_problems):
>>>     problem = benchmark[i]
>>>     name = problem.get_name()
>>>     print(f"Problem #{i}: {name}")

Methods

__init__([alpha, x, interval])

Create a benchmark problem for numerical derivatives of a function

get_fifth_derivative()

Return the fifth derivative of the function of the problem

get_first_derivative()

Return the first derivative of the function of the problem

get_fourth_derivative()

Return the fourth derivative of the function of the problem

get_function()

Return the function of the problem

get_interval()

Return the interval of the problem

get_name()

Return the name of the problem

get_second_derivative()

Return the second derivative of the function of the problem

get_third_derivative()

Return the third derivative of the function of the problem

get_x()

Return the input point of the problem

get_fifth_derivative()

Return the fifth derivative of the function of the problem

Returns:
fifth_derivativefunction

The fifth derivative of the function

get_first_derivative()

Return the first derivative of the function of the problem

Returns:
first_derivativefunction

The first derivative of the function

get_fourth_derivative()

Return the fourth derivative of the function of the problem

Returns:
fourth_derivativefunction

The fourth derivative of the function

get_function()

Return the function of the problem

Returns:
functionfunction

The function

get_interval()

Return the interval of the problem

Returns:
intervallist of 2 floats

The interval

get_name()

Return the name of the problem

Returns:
namestr

The name

get_second_derivative()

Return the second derivative of the function of the problem

Returns:
second_derivativefunction

The second derivative of the function

get_third_derivative()

Return the third derivative of the function of the problem

Returns:
third_derivativefunction

The third derivative of the function

get_x()

Return the input point of the problem

Returns:
xfloat

The input point