numericalderivative.GMSWExponentialProblem

class numericalderivative.GMSWExponentialProblem(x=1.0, interval=[0.001, 12.0])

Create an exponential derivative benchmark problem

See eq. 4 page 312 in (Gill, Murray, Saunders & Wright, 1983)

The function is:

\[f(x) = \left(\exp(x) - 1\right)^2 + \left(\frac{1}{\sqrt{1 + x^2}} - 1\right)^2\]

for any \(x\). The test point is \(x = 1\). For this point, the value of the function is zero. Hence, the absolute error of the function evaluation cannot be computed from a given relative error for this test point. The optimal finite difference step for the forward finite difference formula of the first derivative is approximately \(10^{-3}\).

Parameters:
alphafloat, > 0

The parameter

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]. The interval should not contain x = 0 because the first derivative is zero at this point. This may create an infinite relative error.

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

References

  • Gill, P. E., Murray, W., Saunders, M. A., & Wright, M. H. (1983). Computing forward-difference intervals for numerical optimization. SIAM Journal on Scientific and Statistical Computing, 4(2), 310-321.

__init__(x=1.0, interval=[0.001, 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__([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