<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='pmathml.xsl'?>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>AD Copy Constructor: Example and Test</title>
<meta name="description" id="description" content="AD Copy Constructor: Example and Test"/>
<meta name="keywords" id="keywords" content=" copy Ad object 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='_copyad.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="ad_copy.xml" target="_top">Prev</a>
</td><td><a href="copybase.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>ad_copy</option>
<option>CopyAD.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>multi_thread</option>
<option>library</option>
<option>cppad_ipopt_nlp</option>
<option>Example</option>
<option>preprocessor</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>AD-&gt;</option>
<option>Default</option>
<option>ad_copy</option>
<option>Convert</option>
<option>ADValued</option>
<option>BoolValued</option>
<option>VecAD</option>
<option>base_require</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>ad_copy-&gt;</option>
<option>CopyAD.cpp</option>
<option>CopyBase.cpp</option>
<option>Eq.cpp</option>
</select>
</td>
<td>CopyAD.cpp</td>
<td>Headings</td>
</tr></table><br/>
<center><b><big><big>AD Copy Constructor: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

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

bool CopyAD(void)
{	bool ok = true;   // initialize test result flag
	using CppAD::AD;  // so can use AD in place of CppAD::AD

	// domain space vector
	size_t n = 1;
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; <a href="ad.xml" target="_top">AD</a>&lt;double&gt; &gt; x(n);
	x[0]     = 2.;

	// declare independent variables and start tape recording
	CppAD::<a href="independent.xml" target="_top">Independent</a>(x);

	// create an <a href="ad.xml" target="_top">AD</a>&lt;double&gt; that does not depend on x
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; b = 3.;   

	// use copy constructor 
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; u(x[0]);    
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; v = b;

	// check which are parameters
	ok &amp;= Variable(u);
	ok &amp;= Parameter(v);

	// range space vector
	size_t m = 2;
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; <a href="ad.xml" target="_top">AD</a>&lt;double&gt; &gt; y(m);
	y[0]  = u;
	y[1]  = v;

	// create f: x -&gt; y and vectors used for derivative calculations
	CppAD::<a href="funconstruct.xml" target="_top">ADFun</a>&lt;double&gt; f(x, y);
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt;double&gt; dx(n);
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt;double&gt; dy(m);
 
 	// check parameters flags
 	ok &amp;= ! f.Parameter(0);
 	ok &amp;=   f.Parameter(1);

	// check function values
	ok &amp;= ( y[0] == 2. );
	ok &amp;= ( y[1] == 3. );

	// forward computation of partials w.r.t. x[0]
	dx[0] = 1.;
	dy    = f.<a href="forward.xml" target="_top">Forward</a>(1, dx);
	ok   &amp;= ( dy[0] == 1. );   // du / dx
	ok   &amp;= ( dy[1] == 0. );   // dv / dx

	return ok;
}

</pre>

</font></code>


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

</body>
</html>

