mirror of
https://github.com/gonum/gonum.git
synced 2025-10-12 18:40:09 +08:00
spatial/r3: add Jacobian
This commit is contained in:

committed by
GitHub

parent
177c87adcd
commit
0bc95eb1d3
@@ -302,3 +302,24 @@ func TestMatHessian(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatJacobian(t *testing.T) {
|
||||
const (
|
||||
tol = 1e-5
|
||||
h = 8e-4
|
||||
)
|
||||
step := Vec{X: h, Y: h, Z: h}
|
||||
rnd := rand.New(rand.NewSource(1))
|
||||
for _, test := range vectorFields {
|
||||
for i := 0; i < 1; i++ {
|
||||
p := randomVec(rnd)
|
||||
got := NewMat(nil)
|
||||
got.Jacobian(p, step, test.field)
|
||||
want := test.jacobian(p)
|
||||
if !mat.EqualApprox(got, want, tol) {
|
||||
t.Errorf("matrices not equal within tol\ngot: %v\nwant: %v",
|
||||
mat.Formatted(got), mat.Formatted(want))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user