24 using namespace gtsam;
28 assert(
x.size() == 2);
40 Vector actual = numericalGradient<Vector2>(
f,
x);
52 Matrix actual = numericalHessian<Vector2>(
f,
x);
59 assert(
x.size() == 2);
65 TEST(testNumericalDerivative, numericalHessian2) {
85 double x1 = 1,
x2 = 5;
88 Matrix actual11 = numericalHessian211<double, double>(
f3,
x1,
x2);
92 Matrix actual12 = numericalHessian212<double, double>(
f3,
x1,
x2);
96 Matrix actual22 = numericalHessian222<double, double>(
f3,
x1,
x2);
107 double f4(
double x,
double y,
double z) {
114 double x = 1,
y = 2,
z = 3;
116 Matrix actual11 = numericalHessian311<double, double, double>(
f4,
x,
y,
z);
120 Matrix actual12 = numericalHessian312<double, double, double>(
f4,
x,
y,
z);
124 Matrix actual13 = numericalHessian313<double, double, double>(
f4,
x,
y,
z);
128 Matrix actual22 = numericalHessian322<double, double, double>(
f4,
x,
y,
z);
132 Matrix actual23 = numericalHessian323<double, double, double>(
f4,
x,
y,
z);
136 Matrix actual33 = numericalHessian333<double, double, double>(
f4,
x,
y,
z);
141 Vector6
f6(
const double x1,
const double x2,
const double x3,
const double x4,
142 const double x5,
const double x6) {
149 const double x5,
const double x6) {
157 TEST(testNumericalDerivative, numeriDerivative61) {
158 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
162 double, double, double,
double>(
f6,
x1,
x2,
x3,
x4,
x5, x6);
166 Matrix expected61Dynamic = Matrix::Zero(6, 1);
167 expected61Dynamic(0, 0) =
cos(
x1);
177 TEST(testNumericalDerivative, numeriDerivative62) {
178 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
186 Matrix expected62Dynamic = Matrix::Zero(6, 1);
187 expected62Dynamic(1, 0) = -
sin(
x2);
189 double, double, double, double, 1>(
f6,
x1,
x2,
x3,
x4,
x5, x6);
196 TEST(testNumericalDerivative, numeriDerivative63) {
197 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
199 Matrix expected63 = (
Matrix(6, 1) << 0, 0, 2 *
x3, 0, 0, 0).finished();
205 Matrix expected63Dynamic = Matrix::Zero(6, 1);
206 expected63Dynamic(2, 0) = 2 *
x3;
207 Matrix61 actual63Dynamic =
216 TEST(testNumericalDerivative, numeriDerivative64) {
217 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
219 Matrix expected64 = (
Matrix(6, 1) << 0, 0, 0, 3 *
x4 *
x4, 0, 0).finished();
225 Matrix expected64Dynamic = Matrix::Zero(6, 1);
226 expected64Dynamic(3, 0) = 3 *
x4 *
x4;
227 Matrix61 actual64Dynamic =
236 TEST(testNumericalDerivative, numeriDerivative65) {
237 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
245 Matrix expected65Dynamic = Matrix::Zero(6, 1);
246 expected65Dynamic(4, 0) = 0.5 /
sqrt(
x5);
247 Matrix61 actual65Dynamic =
256 TEST(testNumericalDerivative, numeriDerivative66) {
257 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
265 Matrix expected66Dynamic = Matrix::Zero(6, 1);
266 expected66Dynamic(5, 0) =
cos(x6) +
sin(x6);
267 Matrix61 actual66Dynamic =