本文整理汇总了C++中CppAD::Poly方法的典型用法代码示例。如果您正苦于以下问题:C++ CppAD::Poly方法的具体用法?C++ CppAD::Poly怎么用?C++ CppAD::Poly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CppAD
的用法示例。
在下文中一共展示了CppAD::Poly方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: complex_poly
bool complex_poly(void)
{ bool ok = true;
size_t deg = 4;
using CppAD::AD;
using CppAD::Poly;
typedef std::complex<double> Complex;
// polynomial coefficients
CPPAD_TESTVECTOR( Complex ) a (deg + 1); // coefficients for p(z)
CPPAD_TESTVECTOR(AD<Complex>) A (deg + 1);
size_t i;
for(i = 0; i <= deg; i++)
A[i] = a[i] = Complex(double(i), double(i));
// independent variable vector
CPPAD_TESTVECTOR(AD<Complex>) Z(1);
Complex z = Complex(1., 2.);
Z[0] = z;
Independent(Z);
// dependent variable vector and indices
CPPAD_TESTVECTOR(AD<Complex>) P(1);
// dependent variable values
P[0] = Poly(0, A, Z[0]);
// create f: Z -> P and vectors used for derivative calculations
CppAD::ADFun<Complex> f(Z, P);
CPPAD_TESTVECTOR(Complex) v( f.Domain() );
CPPAD_TESTVECTOR(Complex) w( f.Range() );
// check first derivative w.r.t z
v[0] = 1.;
w = f.Forward(1, v);
Complex p = Poly(1, a, z);
ok &= ( w[0] == p );
// second derivative w.r.t z is 2 times its second order Taylor coeff
v[0] = 0.;
w = f.Forward(2, v);
p = Poly(2, a, z);
ok &= ( 2. * w[0] == p );
return ok;
}