Codebase list cppad / upstream/2015.00.00.7 doc / sacado_poly.cpp.xml
upstream/2015.00.00.7

Tree @upstream/2015.00.00.7 (Download .tar.gz)

sacado_poly.cpp.xml @upstream/2015.00.00.7raw · history · blame

<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Sacado Speed: Second Derivative of a Polynomial</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="Sacado Speed: Second Derivative of a Polynomial"/>
<meta name="keywords" id="keywords" content=" sacado speed: second derivative of a polynomial link_poly speed specifications implementation "/>
<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='_sacado_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="sacado_ode.cpp.xml" target="_top">Prev</a>
</td><td><a href="sacado_sparse_hessian.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>speed</option>
<option>speed_sacado</option>
<option>sacado_poly.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>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>speed-&gt;</option>
<option>speed_main</option>
<option>speed_utility</option>
<option>speed_double</option>
<option>speed_adolc</option>
<option>speed_cppad</option>
<option>speed_fadbad</option>
<option>speed_sacado</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>speed_sacado-&gt;</option>
<option>sacado_det_minor.cpp</option>
<option>sacado_det_lu.cpp</option>
<option>sacado_mat_mul.cpp</option>
<option>sacado_ode.cpp</option>
<option>sacado_poly.cpp</option>
<option>sacado_sparse_hessian.cpp</option>
<option>sacado_sparse_jacobian.cpp</option>
</select>
</td>
<td>sacado_poly.cpp</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Specifications</option>
<option>Implementation</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>Sacado Speed: Second Derivative of a Polynomial</big></big></b></center>
<br/>
<b><big><a name="Specifications" id="Specifications">Specifications</a></big></b>
<br/>
See <a href="link_poly.xml" target="_top"><span style='white-space: nowrap'>link_poly</span></a>
.

<br/>
<br/>
<b><big><a name="Implementation" id="Implementation">Implementation</a></big></b>



<code><font color='blue'><pre style='display:inline'> 
# include &lt;cppad/vector.hpp&gt;
# include &lt;cppad/poly.hpp&gt;
# include &lt;cppad/speed/uniform_01.hpp&gt;
# include &lt;Sacado.hpp&gt;

// list of possible options
extern bool global_memory, global_onetape, global_atomic, global_optimize;

bool link_poly(
	size_t                     size     , 
	size_t                     repeat   , 
	CppAD::vector&lt;double&gt;     &amp;a        ,  // coefficients of polynomial
	CppAD::vector&lt;double&gt;     &amp;z        ,  // polynomial argument value
	CppAD::vector&lt;double&gt;     &amp;ddp      )  // second derivative w.r.t z  
{
	if( global_atomic )
		return false;
	if( global_memory || global_onetape || global_optimize )
		return false;
	// -----------------------------------------------------
	// setup
	typedef Sacado::Tay::Taylor&lt;double&gt;  ADScalar;
	CppAD::vector&lt;ADScalar&gt;              A(size);

	size_t i;               // temporary index     
	ADScalar   Z;           // domain space AD value
	ADScalar   P;           // range space AD value 
	unsigned int order = 2; // order of Taylor coefficients
	Z.resize(order+1, false);
	P.resize(order+1, false);

	// choose the polynomial coefficients
	CppAD::uniform_01(size, a);

	// AD copy of the polynomial coefficients
	for(i = 0; i &lt; size; i++)
		A[i] = a[i];

	// ------------------------------------------------------
	while(repeat--)
	{	// get the next argument value
		CppAD::uniform_01(1, z);

		// independent variable value
		Z.fastAccessCoeff(0)   = z[0]; // argument value
		Z.fastAccessCoeff(1)   = 1.;   // first order coefficient
		Z.fastAccessCoeff(2)   = 0.;   // second order coefficient

		// AD computation of the dependent variable
		P = CppAD::Poly(0, A, Z);

		// second derivative is twice second order Taylor coefficient
		ddp[0] = 2. * P.fastAccessCoeff(2);
	}
	// ------------------------------------------------------
	return true;
}
</pre></font></code>


<hr/>Input File: speed/sacado/poly.cpp

</body>
</html>