<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Complex Polynomial: Example and Test</title>
<meta name="description" id="description" content="Complex Polynomial: Example and Test"/>
<meta name="keywords" id="keywords" content=" complex polynomial example test "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_complex_poly.cpp_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="base_complex.hpp.xml" target="_top">Prev</a>
</td><td><a href="not_complex_ad.cpp.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>AD</option>
<option>base_require</option>
<option>base_example</option>
<option>base_complex.hpp</option>
<option>complex_poly.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>base_require-&gt;</option>
<option>base_member</option>
<option>base_cond_exp</option>
<option>base_identical</option>
<option>base_ordered</option>
<option>base_std_math</option>
<option>base_example</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>base_example-&gt;</option>
<option>base_alloc.hpp</option>
<option>base_require.cpp</option>
<option>base_adolc.hpp</option>
<option>base_float.hpp</option>
<option>base_double.hpp</option>
<option>base_complex.hpp</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>base_complex.hpp-&gt;</option>
<option>complex_poly.cpp</option>
<option>not_complex_ad.cpp</option>
</select>
</td>
<td>complex_poly.cpp</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>See Also</option>
<option>Poly</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>Complex Polynomial: Example and Test</big></big></b></center>
<br/>
<b><big><a name="See Also" id="See Also">See Also</a></big></b>

<br/>
<a href="not_complex_ad.cpp.xml" target="_top"><span style='white-space: nowrap'>not_complex_ad.cpp</span></a>


<br/>
<br/>
<b><big><a name="Poly" id="Poly">Poly</a></big></b>
<br/>
Select this link to view specifications for <a href="poly.xml" target="_top"><span style='white-space: nowrap'>Poly</span></a>
:

<code><font color="blue">
<pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;
# include &lt;complex&gt;

bool complex_poly(void)
{	bool ok    = true;
	size_t deg = 4;

	using CppAD::AD;
	using CppAD::Poly;
	typedef std::complex&lt;double&gt; Complex; 

	// polynomial coefficients
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>( Complex )     a   (deg + 1); // coefficients for p(z)
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(AD&lt;Complex&gt;) A   (deg + 1); 
	size_t i;
	for(i = 0; i &lt;= deg; i++)
		A[i] = a[i] = Complex(i, i);

	// independent variable vector
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(AD&lt;Complex&gt;) Z(1);
	Complex z = Complex(1., 2.);
 	Z[0]      = z;
	<a href="independent.xml" target="_top">Independent</a>(Z);

	// dependent variable vector and indices
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(AD&lt;Complex&gt;) P(1);

	// dependent variable values
	P[0] = Poly(0, A, Z[0]);

	// create f: Z -&gt; P and vectors used for derivative calculations
	CppAD::<a href="funconstruct.xml" target="_top">ADFun</a>&lt;Complex&gt; f(Z, P);
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(Complex) v( f.Domain() );
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(Complex) w( f.Range() );

	// check first derivative w.r.t z
	v[0]      = 1.;
	w         = f.<a href="forward.xml" target="_top">Forward</a>(1, v);
	Complex p = Poly(1, a, z);
	ok &amp;= ( w[0]  == p );

	// second derivative w.r.t z is 2 times its second order Taylor coeff
	v[0] = 0.;
	w    = f.<a href="forward.xml" target="_top">Forward</a>(2, v);
	p    = Poly(2, a, z);
	ok &amp;= ( 2. * w[0]  == p );

	return ok;
}

</pre>

</font></code>


<hr/>Input File: example/complex_poly.cpp

</body>
</html>
