polykin.math.derivatives¤
derivative_centered ¤
derivative_centered(
f: Callable[[float], float],
x: float,
*,
epsf: float | None = None,
h: float = 0.0
) -> tuple[float, float]
Calculate the numerical derivative of a scalar function using the centered finite-difference scheme.
References
- J. Martins and A. Ning. Engineering Design Optimization. Cambridge University Press, 2021.
- boost/math/differentiation/finite_difference.hpp.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
Function to be differentiated.
TYPE:
|
x
|
Differentiation point.
TYPE:
|
epsf
|
Machine precision of the function values. If
TYPE:
|
h
|
Finite-difference step. If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, float]
|
Tuple with derivative and mean function value, \((f'(x), f(x))\). |
Examples:
Evaluate the numerical derivative of f(x)=x**3 at x=1.
>>> from polykin.math import derivative_centered
>>> def f(x): return x**3
>>> derivative_centered(f, 1.0)
(3.0000000003141882, 1.0000000009152836)
Source code in src/polykin/math/derivatives/ndiff.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |