numericalderivative.SinProblem¶
- class numericalderivative.SinProblem(x=1.0, interval=[-3.141592653589793, 3.141592653589793])¶
Create a sine derivative benchmark problem
The function is:
\[f(x) = \sin(x)\]for any \(x\). The test point is \(x = 1\).
This function can be difficult to differentiate at the points \(x = \pm \pi\) because the second derivative is zero at these points.
Since \(sin(0)=\sin(\pm \pi) = 0\), computing the absolute error depending on the function value is not possible for \(x = 0\) and \(x = \pm \pi\).
See problem #5 in (Dumontet & Vignes, 1977) page 23. See (Stepleman & Wirnarsky, 1979) page 1263.
- 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
Return the fifth derivative of the function of the problem
Return the first derivative of the function of the problem
Return the fourth derivative of the function of the problem
Return the function of the problem
Return the interval of the problem
get_name()Return the name of the problem
Return the second derivative of the function of the problem
Return the third derivative of the function of the problem
get_x()Return the input point of the problem
- __init__(x=1.0, interval=[-3.141592653589793, 3.141592653589793])¶
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
Return the fifth derivative of the function of the problem
Return the first derivative of the function of the problem
Return the fourth derivative of the function of the problem
Return the function of the problem
Return the interval of the problem
get_name()Return the name of the problem
Return the second derivative of the function of the problem
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