<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Not Complex Differentiable: Example and Test</title>
<meta name="description" id="description" content="Not Complex Differentiable: Example and Test"/>
<meta name="keywords" id="keywords" content=" complex polynomial imag() real() example not differentiable 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='_not_complex_ad.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="complexpoly.cpp.xml" target="_top">Prev</a>
</td><td><a href="adfun.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>not_complex_ad.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>ComplexPoly.cpp</option>
<option>not_complex_ad.cpp</option>
</select>
</td>
<td>not_complex_ad.cpp</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Not Complex Differentiable</option>
<option>See Also</option>
<option>Poly</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>Not Complex Differentiable: Example and Test</big></big></b></center>
<br/>
<b><big><a name="Not Complex Differentiable" id="Not Complex Differentiable">Not Complex Differentiable</a></big></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is complex, the functions 

<code><font color="blue"><span style='white-space: nowrap'>real(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
,

<code><font color="blue"><span style='white-space: nowrap'>imag(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
,

<code><font color="blue"><span style='white-space: nowrap'>conj(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
, and

<code><font color="blue"><span style='white-space: nowrap'>abs(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>

are examples of functions that are not complex differentiable.

<br/>
<br/>
<b><big><a name="See Also" id="See Also">See Also</a></big></b>

<br/>
<a href="complexpoly.cpp.xml" target="_top"><span style='white-space: nowrap'>ComplexPoly.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 not_complex_ad(void)
{	bool ok    = true;
	size_t deg = 4;

	using CppAD::AD;
	using CppAD::Poly;
	typedef std::complex&lt;double&gt;       Complex; 
	typedef std::complex&lt; <a href="ad.xml" target="_top">AD</a>&lt;double&gt; &gt; ComplexAD; 

	// The imaginary part in the following assignment will use
	// the CppAD::<a href="ad.xml" target="_top">AD</a>&lt;double&gt; default constructor. Make sure it is zero.
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; ad_zero = <a href="ad.xml" target="_top">AD</a>&lt;double&gt;(0);
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; ad_two  = <a href="ad.xml" target="_top">AD</a>&lt;double&gt;(2);
	ComplexAD  cad_two = ad_two;
	ok                &amp;= cad_two == ComplexAD(ad_two, ad_zero); 

	// polynomial coefficients
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; Complex &gt;   a   (deg + 1); // coefficients for p(z)
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; ComplexAD &gt; A   (deg + 1); 
	size_t i;
	for(i = 0; i &lt;= deg; i++)
	{	a[i] = Complex(i, i);
		A[i] = ComplexAD( <a href="ad.xml" target="_top">AD</a>&lt;double&gt;(i) , <a href="ad.xml" target="_top">AD</a>&lt;double&gt;(i) );
	}

	// declare independent variables and start taping
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; <a href="ad.xml" target="_top">AD</a>&lt;double&gt; &gt; Z_real(1);
	double z_real = 1.;
 	Z_real[0]     = z_real;
	<a href="independent.xml" target="_top">Independent</a>(Z_real);

	// complex calculations
	double z_imag = 2.;
	ComplexAD Z = ComplexAD( Z_real[0], <a href="ad.xml" target="_top">AD</a>&lt;double&gt;(z_imag) );
	ComplexAD P = Poly(0, A, Z);

	// range space vector
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; <a href="ad.xml" target="_top">AD</a>&lt;double&gt; &gt; P_real(1);
	P_real[0] = P.real();   // real() is not complex differentiable

	// create f: Z_real -&gt; P_real  and stop taping
	CppAD::<a href="funconstruct.xml" target="_top">ADFun</a>&lt;double&gt; f(Z_real, P_real);

	// check first derivative w.r.t z
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt;double&gt; v( f.Domain() );
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt;double&gt; w( f.Range() );
	v[0]      = 1.;
	w         = f.<a href="forward.xml" target="_top">Forward</a>(1, v);
	Complex z = Complex(z_real, z_imag);
	Complex p = Poly(1, a, z);
	ok &amp;= ( w[0]  == p.real() );

	// 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.real() );

	return ok;
}

</pre>

</font></code>


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

</body>
</html>

