<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>ODE Inverse Problem Definitions: Source Code</title>
<meta name="description" id="description" content="ODE Inverse Problem Definitions: Source Code"/>
<meta name="keywords" id="keywords" content=" ode inverse example "/>
<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='_ipopt_nlp_ode_problem.hpp_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="ipopt_nlp_ode_problem.xml" target="_top">Prev</a>
</td><td><a href="ipopt_nlp_ode_simple.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>Appendix</option>
<option>deprecated</option>
<option>cppad_ipopt_nlp</option>
<option>ipopt_nlp_ode</option>
<option>ipopt_nlp_ode_problem</option>
<option>ipopt_nlp_ode_problem.hpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>cppad_ipopt_nlp-&gt;</option>
<option>ipopt_nlp_get_started.cpp</option>
<option>ipopt_nlp_ode</option>
<option>ipopt_ode_speed.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>ipopt_nlp_ode-&gt;</option>
<option>ipopt_nlp_ode_problem</option>
<option>ipopt_nlp_ode_simple</option>
<option>ipopt_nlp_ode_fast</option>
<option>ipopt_nlp_ode_run.hpp</option>
<option>ipopt_nlp_ode_check.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>ipopt_nlp_ode_problem-&gt;</option>
<option>ipopt_nlp_ode_problem.hpp</option>
</select>
</td>
<td>ipopt_nlp_ode_problem.hpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>ODE Inverse Problem Definitions: Source Code</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
# include &quot;../src/cppad_ipopt_nlp.hpp&quot;

namespace {
	//------------------------------------------------------------------
	typedef Ipopt::Number Number;
	Number a0 = 1.;  // simulation value for a[0]
	Number a1 = 2.;  // simulation value for a[1]
	Number a2 = 1.;  // simulatioln value for a[2]

	// function used to simulate data
	Number y_one(Number t)
	{	Number y_1 =  a0*a1 * (exp(-a2*t) - exp(-a1*t)) / (a1 - a2);
		return y_1;
	}

	// time points were we have data (no data at first point)
	double s[] = { 0.0,        0.5,        1.0,        1.5,        2.0 }; 
	// Simulated data for case with no noise (first point is not used)
	double z[] = { 0.0,  y_one(0.5), y_one(1.0), y_one(1.5), y_one(2.0) };
	// Number of measurement values
	size_t Nz  = sizeof(z) / sizeof(z[0]) - 1;
	// Number of components in the function y(t, a)
	size_t Ny  = 2;
	// Number of components in the vectro a
	size_t Na  = 3;

	// Initial Condition function, F(a) = y(t, a) at t = 0
	// (for this particular example)
	template &lt;class Vector&gt;
	Vector eval_F(const Vector &amp;a)
	{	Vector F(Ny);
		// y_0 (t) = a[0]*exp(-a[1] * t)
		F[0] = a[0];
		// y_1 (t) = 
		// a[0]*a[1]*(exp(-a[2] * t) - exp(-a[1] * t))/(a[1] - a[2])
		F[1] = 0.; 
		return F;
	}
	// G(y, a) =  \partial_t y(t, a); i.e. the differential equation
	// (for this particular example)
	template &lt;class Vector&gt;
	Vector eval_G(const Vector &amp;y , const Vector &amp;a)
	{	Vector G(Ny);
		// y_0 (t) = a[0]*exp(-a[1] * t)
		G[0] = -a[1] * y[0];  
		// y_1 (t) = 
		// a[0]*a[1]*(exp(-a[2] * t) - exp(-a[1] * t))/(a[1] - a[2])
		G[1] = +a[1] * y[0] - a[2] * y[1]; 
		return G;
	} 
	// H(i, y, a) = contribution to objective at i-th data point
	// (for this particular example)
	template &lt;class Scalar, class Vector&gt;
	Scalar eval_H(size_t i, const Vector &amp;y, const Vector &amp;a)
	{	// This particular H is for a case where y_1 (t) is measured
		Scalar diff = z[i] - y[1];
	 	return diff * diff;
	}
	// function used to count the number of calls to eval_r
	size_t count_eval_r(void)
	{	static size_t count = 0;
		++count;
		return count;
	}
}
</pre>

</font></code>


<hr/>Input File: cppad_ipopt/example/ode_problem.hpp

</body>
</html>
