From 8ea4654de40c6d59d42389c37a35b7315e4c8297 Mon Sep 17 00:00:00 2001 From: Hamlet Tanyavong <34531738+HamletTanyavong@users.noreply.github.com> Date: Mon, 13 Nov 2023 02:15:17 -0600 Subject: [PATCH] Add test for Jacobian calculations --- .../AutoDiff/AutoDiffExtensionsTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Mathematics.NET.Tests/AutoDiff/AutoDiffExtensionsTests.cs b/tests/Mathematics.NET.Tests/AutoDiff/AutoDiffExtensionsTests.cs index 39d054e0..2735bc3f 100644 --- a/tests/Mathematics.NET.Tests/AutoDiff/AutoDiffExtensionsTests.cs +++ b/tests/Mathematics.NET.Tests/AutoDiff/AutoDiffExtensionsTests.cs @@ -92,6 +92,21 @@ public void Gradient_ScalarFunction_ReturnsGradient(double x, double y, double z Assert.AreApproximatelyEqual(expected, actual, 1e-15); } + [TestMethod] + [TestCategory("Vector Calculus")] + public void Jacobian_R3VectorFunction_ReturnsJacobian() + { + var u = _tape.CreateVariableVector(1.23, 0.66, 2.34); + Matrix3x3 expected = new( + 0.775330615737715, -0.5778557672605755, 0.3080621020764366, + 0.2431083191631576, 0.2431083191631576, 0.2431083191631576, + 1.450186648348945, 2.197252497498402, -0.6197378839098056); + + var actual = _tape.Jacobian(FX, FY, FZ, u); + + Assert.ElementsAreApproximatelyEqual(expected, actual, 1e-15); + } + // // Helpers //