Skip to content

Commit 58a9fb6

Browse files
committed
Changed index order in Hessian, first index now corresponds to x, not last
1 parent e592fb6 commit 58a9fb6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

spatialmath/base/numeric.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ def numhess(J, x, dx=1e-8):
7575
:rtype: ndarray(m,n,n)
7676
7777
Computes a numerical approximation to the Hessian for ``J(x)`` where
78-
:math:`f: \mathbb{R}^n \mapsto \mathbb{R}^{m \times n}`
78+
:math:`f: \mathbb{R}^n \mapsto \mathbb{R}^{m \times n}`.
79+
80+
The result is a 3D array where
81+
82+
.. math::
83+
84+
H_{i,j,k} = \frac{\partial J_{j,k}}{\partial x_i}
7985
8086
Uses first-order difference :math:`H[:,:,i] = (J(x + dx) - J(x)) / dx`.
8187
"""
@@ -90,7 +96,7 @@ def numhess(J, x, dx=1e-8):
9096

9197
Hcol.append(Hi)
9298

93-
return np.stack(Hcol, axis=2)
99+
return np.stack(Hcol, axis=0)
94100

95101
def array2str(X, valuesep=", ", rowsep=" | ", fmt="{:.3g}",
96102
brackets=("[ ", " ]"), suppress_small=True):

0 commit comments

Comments
 (0)