本文整理汇总了C++中CppAD::abs方法的典型用法代码示例。如果您正苦于以下问题:C++ CppAD::abs方法的具体用法?C++ CppAD::abs怎么用?C++ CppAD::abs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CppAD
的用法示例。
在下文中一共展示了CppAD::abs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VecUnary
bool VecUnary(void)
{
using namespace CppAD;
using CppAD::abs;
using CppAD::sin;
using CppAD::atan;
using CppAD::cos;
using CppAD::exp;
using CppAD::log;
using CppAD::sqrt;
bool ok = true;
size_t n = 8;
size_t i;
CPPAD_TEST_VECTOR< AD<double> > X(n);
VecAD<double> Y(n);
CPPAD_TEST_VECTOR< AD<double> > Z(n);
for(i = 0; i < n; i++)
X[i] = int(i); // some compilers require the int here
Independent(X);
AD<double> j;
j = 0.;
Y[j] = X[0];
Z[0] = -Y[j];
j = 1.;
Y[j] = X[1];
Z[1] = sin( Y[j] );
j = 2.;
Y[j] = X[2];
Z[2] = abs( Y[j] );
j = 3.;
Y[j] = X[3];
Z[3] = atan( Y[j] );
j = 4.;
Y[j] = X[4];
Z[4] = cos( Y[j] );
j = 5.;
Y[j] = X[5];
Z[5] = exp( Y[j] );
j = 6.;
Y[j] = X[6];
Z[6] = log( Y[j] );
j = 7.;
Y[j] = X[7];
Z[7] = sqrt( Y[j] );
ADFun<double> f(X, Z);
CPPAD_TEST_VECTOR<double> x(n);
CPPAD_TEST_VECTOR<double> z(n);
for(i = 0; i < n; i++)
x[i] = 2. / double(i + 1);
x[7] = abs( x[7] );
z = f.Forward(0, x);
ok &= NearEqual(z[0], - x[0], 1e-10, 1e-10);
ok &= NearEqual(z[1], sin( x[1] ), 1e-10, 1e-10);
ok &= NearEqual(z[2], abs( x[2] ), 1e-10, 1e-10);
ok &= NearEqual(z[3], atan(x[3] ), 1e-10, 1e-10);
ok &= NearEqual(z[4], cos( x[4] ), 1e-10, 1e-10);
ok &= NearEqual(z[5], exp( x[5] ), 1e-10, 1e-10);
ok &= NearEqual(z[6], log( x[6] ), 1e-10, 1e-10);
ok &= NearEqual(z[7], sqrt(x[7] ), 1e-10, 1e-10);
return ok;
}