<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>CppAD Speed: Gradient of Ode Solution</title>
<meta name="description" id="description" content="CppAD Speed: Gradient of Ode Solution"/>
<meta name="keywords" id="keywords" content=" link_ode cppad speed ode "/>
<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='_cppad_ode.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="cppad_mat_mul.cpp.xml" target="_top">Prev</a>
</td><td><a href="cppad_poly.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_cppad</option>
<option>cppad_ode.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_cppad-&gt;</option>
<option>cppad_det_minor.cpp</option>
<option>cppad_det_lu.cpp</option>
<option>cppad_mat_mul.cpp</option>
<option>cppad_ode.cpp</option>
<option>cppad_poly.cpp</option>
<option>cppad_sparse_hessian.cpp</option>
<option>cppad_sparse_jacobian.cpp</option>
</select>
</td>
<td>cppad_ode.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>CppAD Speed: Gradient of Ode Solution</big></big></b></center>
<br/>
<b><big><a name="Specifications" id="Specifications">Specifications</a></big></b>
<br/>
See <a href="link_ode.xml" target="_top"><span style='white-space: nowrap'>link_ode</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/cppad.hpp&gt;
# include &lt;cppad/speed/ode_evaluate.hpp&gt;
# include &lt;cppad/speed/uniform_01.hpp&gt;
# include &lt;cassert&gt;

// Note that CppAD uses global_memory at the main program level
extern bool
	global_onetape, global_atomic, global_optimize, global_boolsparsity;

bool link_ode(
	size_t                     size       ,
	size_t                     repeat     ,
	CppAD::vector&lt;double&gt;      &amp;x         ,
	CppAD::vector&lt;double&gt;      &amp;jacobian
)
{
	// speed test global option values
	if( global_atomic || global_boolsparsity )
		return false;

	// --------------------------------------------------------------------
	// setup
	assert( x.size() == size );
	assert( jacobian.size() == size * size );

	typedef CppAD::<a href="ad.xml" target="_top">AD</a>&lt;double&gt;       ADScalar;
	typedef CppAD::vector&lt;ADScalar&gt; ADVector;

	size_t j;
	size_t p = 0;              // use ode to calculate function values
	size_t n = size;           // number of independent variables
	size_t m = n;              // number of dependent variables
	ADVector  X(n), Y(m);      // independent and dependent variables
	CppAD::<a href="funconstruct.xml" target="_top">ADFun</a>&lt;double&gt;  f;   // AD function

	// -------------------------------------------------------------
	if( ! global_onetape ) while(repeat--)
	{ 	// choose next x value
		uniform_01(n, x);
		for(j = 0; j &lt; n; j++)
			X[j] = x[j];

		// declare the independent variable vector
		<a href="independent.xml" target="_top">Independent</a>(X);

		// evaluate function
		CppAD::ode_evaluate(X, p, Y);

		// create function object f : X -&gt; Y
		f.Dependent(X, Y);

		if( global_optimize )
			f.optimize();

		jacobian = f.<a href="jacobian.xml" target="_top">Jacobian</a>(x);
	}
	else
	{ 	// an x value
		uniform_01(n, x);
		for(j = 0; j &lt; n; j++)
			X[j] = x[j];

		// declare the independent variable vector
		<a href="independent.xml" target="_top">Independent</a>(X);

		// evaluate function
		CppAD::ode_evaluate(X, p, Y);

		// create function object f : X -&gt; Y
		f.Dependent(X, Y);

		if( global_optimize )
			f.optimize();
		while(repeat--)
		{	// get next argument value
			uniform_01(n, x);

			// evaluate jacobian
			jacobian = f.<a href="jacobian.xml" target="_top">Jacobian</a>(x);
		}
	}
	return true;
}
</pre></font></code>


<hr/>Input File: speed/cppad/ode.cpp

</body>
</html>
