本文整理汇总了C++中NumericalDifferentiation::set_numerical_differentiation_method方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericalDifferentiation::set_numerical_differentiation_method方法的具体用法?C++ NumericalDifferentiation::set_numerical_differentiation_method怎么用?C++ NumericalDifferentiation::set_numerical_differentiation_method使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumericalDifferentiation
的用法示例。
在下文中一共展示了NumericalDifferentiation::set_numerical_differentiation_method方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_calculate_Jacobian
void NumericalDifferentiationTest::test_calculate_Jacobian(void)
{
message += "test_calculate_Jacobian\n";
NumericalDifferentiation nd;
Vector<double> x;
Matrix<double> J;
Matrix<double> J_true;
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::ForwardDifferences);
x.set(2, 0.0);
J = nd.calculate_central_differences_Jacobian(*this, &NumericalDifferentiationTest::f3, x);
J_true.set_identity(2);
assert_true(J == J_true, LOG);
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::CentralDifferences);
x.set(2, 0.0);
J = nd.calculate_central_differences_Jacobian(*this, &NumericalDifferentiationTest::f3, x);
J_true.set_identity(2);
assert_true(J == J_true, LOG);
}
示例2: test_calculate_Hessian
void NumericalDifferentiationTest::test_calculate_Hessian(void)
{
message += "test_calculate_Hessian\n";
NumericalDifferentiation nd;
Vector<double> x;
Matrix<double> H;
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::ForwardDifferences);
x.set(2, 0.0);
H = nd.calculate_Hessian(*this, &NumericalDifferentiationTest::f2, x);
assert_true(H.get_rows_number() == 2, LOG);
assert_true(H.get_columns_number() == 2, LOG);
assert_true(H == 0.0, LOG);
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::CentralDifferences);
x.set(2, 0.0);
H = nd.calculate_Hessian(*this, &NumericalDifferentiationTest::f2, x);
assert_true(H.get_rows_number() == 2, LOG);
assert_true(H.get_columns_number() == 2, LOG);
assert_true(H == 0.0, LOG);
}
示例3: test_calculate_second_derivative
void NumericalDifferentiationTest::test_calculate_second_derivative(void)
{
message += "test_calculate_second_derivative\n";
NumericalDifferentiation nd;
double x;
double d2;
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::ForwardDifferences);
x = 0.0;
d2 = nd.calculate_second_derivative(*this, &NumericalDifferentiationTest::f1, x);
assert_true(fabs(d2) <= 1.0e-6, LOG);
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::CentralDifferences);
x = 0.0;
d2 = nd.calculate_second_derivative(*this, &NumericalDifferentiationTest::f1, x);
assert_true(fabs(d2) <= 1.0e-6, LOG);
}
示例4: test_calculate_gradient
void NumericalDifferentiationTest::test_calculate_gradient(void)
{
message += "test_calculate_gradient\n";
NumericalDifferentiation nd;
Vector<double> x;
Vector<double> g;
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::ForwardDifferences);
x.set(2, 0.0);
g = nd.calculate_gradient(*this, &NumericalDifferentiationTest::f2, x);
assert_true(g.size() == 2, LOG);
assert_true(g == 1.0, LOG);
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::CentralDifferences);
x.set(2, 0.0);
g = nd.calculate_gradient(*this, &NumericalDifferentiationTest::f2, x);
assert_true(g.size() == 2, LOG);
assert_true(g == 1.0, LOG);
}
示例5: test_calculate_derivative
void NumericalDifferentiationTest::test_calculate_derivative(void)
{
message += "test_calculate_derivative\n";
NumericalDifferentiation nd;
// double x;
double d;
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::ForwardDifferences);
// x = 0.0;
d = nd.calculate_derivative(*this, &NumericalDifferentiationTest::f1, 0.0);
assert_true(d == 1.0, LOG);
// Test
nd.set_numerical_differentiation_method(NumericalDifferentiation::CentralDifferences);
// x = 0.0;
d = nd.calculate_derivative(*this, &NumericalDifferentiationTest::f1, 0.0);
assert_true(d == 1.0, LOG);
}