numericalderivative.ThirdDerivativeCentral¶
- class numericalderivative.ThirdDerivativeCentral(function, x, args=None)¶
Compute the third derivative using central finite difference formula
Methods
compute(step)Estimate the 3d derivative f'''(x) using finite differences.
compute_error(step[, ...])Compute the total error for central finite difference for f'''
compute_step([fifth_derivative_value, ...])Compute the optimal step for the central finite difference for f'''.
Return the function
get_x()Return the input point
- __init__(function, x, args=None)¶
Compute the third derivative using central finite difference formula
- Parameters:
- functionfunction
The function to differentiate.
- xfloat
The point where the derivative is to be evaluated.
- argslist
A list of optional arguments that the function takes as inputs. By default, there is no extra argument and calling sequence of the function must be y = function(x). If there are extra arguments, then the calling sequence of the function must be y = function(x, arg1, arg2, ...) where arg1, arg2, ..., are the items in the args list.
- Returns:
- None.
Methods
__init__(function, x[, args])Compute the third derivative using central finite difference formula
compute(step)Estimate the 3d derivative f'''(x) using finite differences.
compute_error(step[, ...])Compute the total error for central finite difference for f'''
compute_step([fifth_derivative_value, ...])Compute the optimal step for the central finite difference for f'''.
Return the function
get_x()Return the input point
- compute(step)¶
Estimate the 3d derivative f'''(x) using finite differences.
This is based on the central finite difference formula (see (Betts, 2010) table 1.7 page 47 and (Dumontet & Vignes, 1977) eq. 27 page 19):
\[\begin{split}f^{(3)}(x) = &\frac{- f(x - 2h) + 2 f(x - h) - 2 f(x + h) + f(x + 2h)}{2h^3} \\ &- \frac{h^2}{4} f^{(5)}(x) + O(h^3)\end{split}\]where \(h > 0\) is the step.
- Parameters:
- stepfloat
The step used for the finite difference formula.
- Returns:
- third_derivativefloat
The approximate f'''(x).
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.
Betts, J. T. (2010). Practical methods for optimal control and estimation using nonlinear programming. Society for Industrial and Applied Mathematics.
- static compute_error(step, fifth_derivative_value=1.0, absolute_precision=1e-16)¶
Compute the total error for central finite difference for f'''
The total error is the sum of the rounding error in the finite difference formula and the truncation error in the Taylor expansion:
\[e(h) = \frac{3 \epsilon_f}{h^3} + \frac{h^2}{4} \left|f^{(5)}(x)\right|\]where \(\epsilon_f > 0\) is the absolute precision of the function evaluation.
- Parameters:
- stepfloat
The differentiation step h.
- fifth_derivative_valuefloat
The value of the fifth derivative at point x. If this value is unknown, we suggest to use the value 1 as an initial guess.
- absolute_precisionfloat, optional
The absolute error of the function f at the point x. This is equal to abs(relative_precision * f(x)) where relative_precision is the relative accuracy and f(x) is the function value of f at point x.
- Returns:
- absolute_errorfloat
The optimal absolute error.
- static compute_step(fifth_derivative_value=1.0, absolute_precision=1e-16)¶
Compute the optimal step for the central finite difference for f'''.
This step minimizes the total error of the second derivative central finite difference (see compute()). The optimal step is:
\[h^\star = \left(\frac{18 \epsilon_f}{|f^{(5)}(x)|} \right)^{1/5}\]The total absolute error corresponding to the optimal step is:
\[e(h^\star) = \frac{5}{12} 2^{2/5} 3^{4/5} \epsilon_f^{2/5} \left|f^{(5)}(x)\right|^{3/5}\]- Parameters:
- fifth_derivative_valuefloat
The fourth derivative f^(4) at point x. If this value is unknown, we suggest to use the value 1 as an initial guess.
- absolute_precisionfloat, optional
The absolute error of the function f at the point x. This is equal to abs(relative_precision * f(x)) where relative_precision is the relative accuracy and f(x) is the function value of f at point x.
- Returns:
- optimal_stepfloat
The finite difference step.
- absolute_errorfloat
The absolute error.
- get_function()¶
Return the function
- Returns:
- functionfunction
The function
- get_x()¶
Return the input point
- Returns:
- xlist
The point