<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>exp_eps: Verify Second Order Reverse Sweep</title>
<meta name="description" id="description" content="exp_eps: Verify Second Order Reverse Sweep"/>
<meta name="keywords" id="keywords" content=" reverse exp_eps "/>
<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='_exp_eps_rev2.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="exp_eps_rev2.xml" target="_top">Prev</a>
</td><td><a href="exp_eps_cppad.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>Introduction</option>
<option>exp_eps</option>
<option>exp_eps_rev2</option>
<option>exp_eps_rev2.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>Introduction-&gt;</option>
<option>get_started.cpp</option>
<option>exp_2</option>
<option>exp_eps</option>
<option>exp_apx_main.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>exp_eps-&gt;</option>
<option>exp_eps.hpp</option>
<option>exp_eps.cpp</option>
<option>exp_eps_for0</option>
<option>exp_eps_for1</option>
<option>exp_eps_rev1</option>
<option>exp_eps_for2</option>
<option>exp_eps_rev2</option>
<option>exp_eps_cppad</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>exp_eps_rev2-&gt;</option>
<option>exp_eps_rev2.cpp</option>
</select>
</td>
<td>exp_eps_rev2.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>exp_eps: Verify Second Order Reverse Sweep</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cstddef&gt;                     // define size_t
# include &lt;cmath&gt;                       // for fabs function
extern bool exp_eps_for0(double *v0);   // computes zero order forward sweep
extern bool exp_eps_for1(double *v1);   // computes first order forward sweep
bool exp_eps_rev2(void)
{	bool ok = true;

	// set the value of v0[j], v1[j] for j = 1 , ... , 7
	double v0[8], v1[8];
	ok &amp;= exp_eps_for0(v0);
	ok &amp;= exp_eps_for1(v1);

	// initial all partial derivatives as zero
	double f_v0[8], f_v1[8];
	size_t j;
	for(j = 0; j &lt; 8; j++)
	{	f_v0[j] = 0.;
		f_v1[j] = 0.;
	}

	// set partial derivative for f_7
	f_v1[7] = 1.;
	ok &amp;= std::fabs( f_v1[7] - 1.  ) &lt;= 1e-10; // partial f_7 w.r.t. v_7^1

	// f_6 = f_7( v_1^0 , ... , v_6^1 , v_4^0 + v_6^0, v_4^1 , v_6^1 )
	f_v0[4] += f_v0[7];
	f_v0[6] += f_v0[7];
	f_v1[4] += f_v1[7];
	f_v1[6] += f_v1[7];
	ok &amp;= std::fabs( f_v0[4] - 0.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_4^0
	ok &amp;= std::fabs( f_v0[6] - 0.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_6^0
	ok &amp;= std::fabs( f_v1[4] - 1.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_4^1
	ok &amp;= std::fabs( f_v1[6] - 1.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_6^1

	// f_5 = f_6( v_1^0 , ... , v_5^1 , v_5^0 / 2 , v_5^1 / 2 )
	f_v0[5] += f_v0[6] / 2.;
	f_v1[5] += f_v1[6] / 2.;
	ok &amp;= std::fabs( f_v0[5] - 0.  ) &lt;= 1e-10; // partial f_5 w.r.t. v_5^0
	ok &amp;= std::fabs( f_v1[5] - 0.5 ) &lt;= 1e-10; // partial f_5 w.r.t. v_5^1

	// f_4 = f_5( v_1^0 , ... , v_4^1 , v_3^0 * v_1^0 , 
	//            v_3^1 * v_1^0 + v_3^0 * v_1^1 )
	f_v0[1] += f_v0[5] * v0[3] + f_v1[5] * v1[3];
	f_v0[3] += f_v0[5] * v0[1] + f_v1[5] * v1[1];
	f_v1[1] += f_v1[5] * v0[3];
	f_v1[3] += f_v1[5] * v0[1];
	ok &amp;= std::fabs( f_v0[1] - 0.5  ) &lt;= 1e-10; // partial f_4 w.r.t. v_1^0
	ok &amp;= std::fabs( f_v0[3] - 0.5  ) &lt;= 1e-10; // partial f_4 w.r.t. v_3^0
	ok &amp;= std::fabs( f_v1[1] - 0.25 ) &lt;= 1e-10; // partial f_4 w.r.t. v_1^1
	ok &amp;= std::fabs( f_v1[3] - 0.25 ) &lt;= 1e-10; // partial f_4 w.r.t. v_3^1

	// f_3 = f_4(  v_1^0 , ... , v_3^1 , 1 + v_3^0 , v_3^1 )
	f_v0[3] += f_v0[4];
	f_v1[3] += f_v1[4];
	ok &amp;= std::fabs( f_v0[3] - 0.5 ) &lt;= 1e-10;  // partial f_3 w.r.t. v_3^0
	ok &amp;= std::fabs( f_v1[3] - 1.25) &lt;= 1e-10;  // partial f_3 w.r.t. v_3^1

	// f_2 = f_3( v_1^0 , ... , v_2^1 , v_2^0 , v_2^1 )
	f_v0[2] += f_v0[3];
	f_v1[2] += f_v1[3];
	ok &amp;= std::fabs( f_v0[2] - 0.5 ) &lt;= 1e-10;  // partial f_2 w.r.t. v_2^0
	ok &amp;= std::fabs( f_v1[2] - 1.25) &lt;= 1e-10;  // partial f_2 w.r.t. v_2^1

	// f_1 = f_2 ( v_1^0 , v_2^0 , v_1^0 , v_2^0 )
	f_v0[1] += f_v0[2];
	f_v1[1] += f_v1[2];
	ok &amp;= std::fabs( f_v0[1] - 1.  ) &lt;= 1e-10;  // partial f_1 w.r.t. v_1^0
	ok &amp;= std::fabs( f_v1[1] - 1.5 ) &lt;= 1e-10;  // partial f_1 w.r.t. v_1^1

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


<hr/>Input File: introduction/exp_apx/exp_eps_rev2.cpp

</body>
</html>
