Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 39da2e642be5eb48375f19991c31eb2c > files > 666

cppad-doc-20100101.4-1.fc14.noarch.rpm

<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='pmathml.xsl'?>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>AD Parameter and Variable Functions: Example and Test</title>
<meta name="description" id="description" content="AD Parameter and Variable Functions: Example and Test"/>
<meta name="keywords" id="keywords" content=" Parameter example Variable 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='_parvar.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="parvar.xml" target="_top">Prev</a>
</td><td><a href="equalopseq.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>BoolValued</option>
<option>ParVar</option>
<option>ParVar.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(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_down2(this)'>
<option>BoolValued-&gt;</option>
<option>Compare</option>
<option>NearEqualExt</option>
<option>BoolFun</option>
<option>ParVar</option>
<option>EqualOpSeq</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>ParVar-&gt;</option>
<option>ParVar.cpp</option>
</select>
</td>
<td>ParVar.cpp</td>
<td>Headings</td>
</tr></table><br/>


<center><b><big><big>AD Parameter and Variable Functions: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

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

bool ParVar(void)
{	bool ok = true;

	using CppAD::AD;
	using CppAD::VecAD;
	using CppAD::Parameter;
	using CppAD::Variable;

	// declare independent variables and start tape recording
	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]     = 0.;
	ok &amp;= Parameter(x[0]);     // x[0] is a paraemter here
	CppAD::<a href="independent.xml" target="_top">Independent</a>(x);
	ok &amp;= Variable(x[0]);      // now x[0] is a variable 

	// dependent variable 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] = 2.;
	ok  &amp;= Parameter(y[0]);    // y[0] does not depend on x[0]
	y[1] = abs(x[0]);
	ok  &amp;= Variable(y[1]);     // y[1] does depends on x[0] 

	// VecAD objects
	VecAD&lt;double&gt; z(2);
	z[0] = 0.;
	z[1] = 1.;
	ok  &amp;= Parameter(z);      // z does not depend on x[0]
	z[x[0]] = 2.;
	ok  &amp;= Variable(z);       // z depends on x[0]
	

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

	// check that now all <a href="ad.xml" target="_top">AD</a>&lt;double&gt; objects are parameters
	ok &amp;= Parameter(x[0]); ok &amp;= ! Variable(x[0]);
	ok &amp;= Parameter(y[0]); ok &amp;= ! Variable(y[0]);
	ok &amp;= Parameter(y[1]); ok &amp;= ! Variable(y[1]);

	// check that the VecAD&lt;double&gt; object is a parameter
	ok &amp;= Parameter(z);

	return ok;
}
</pre>
</font></code>


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

</body>
</html>