polykin.math.derivatives¤
jacobian_forward ¤
jacobian_forward(
f: Callable[[FloatVector], FloatVector],
x: FloatVector,
*,
fx: FloatVector | None = None,
sclx: FloatVector | None = None,
epsf: float | None = None
) -> FloatMatrix
Calculate the numerical Jacobian of a vector function \(\mathbf{f}(\mathbf{x})\) using the forward finite-difference scheme.
The step size \(h_j\) is optimally determined according to the machine precision of the function values. Typically, the Jacobian is accurate to about half the number of reliable digits returned by the function.
If the function value at \(\mathbf{x}\) is provided, \(N\) function evaluations are required to compute the Jacobian, where \(N\) is the dimension of \(\mathbf{x}\).
References
- J.E. Dennis Jr., R.B. Schnabel, "Numerical Methods for Unconstrained Optimization and Nonlinear Equations", SIAM, 1996, p. 314.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
Function to be differentiated.
TYPE:
|
x
|
Differentiation point.
TYPE:
|
fx
|
Function values at
TYPE:
|
sclx
|
Scaling factors for
TYPE:
|
epsf
|
Machine precision of the function values. If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FloatMatrix
|
Jacobian matrix. |
Examples:
Evaluate the numerical jacobian of f(x) = x1**2 * x2**3 at (2, -2).
>>> from polykin.math import jacobian_forward
>>> import numpy as np
>>> def f(x): return x[0]**2 * x[1]**3
>>> jacobian_forward(f, np.array([2.0, -2.0]))
array([[-32.00000024, 47.99999928]])
Source code in src/polykin/math/derivatives/ndiff.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |