<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Gradient of Determinant Using Expansion by Minors: Example and Test</title>
<meta name="description" id="description" content="Gradient of Determinant Using Expansion by Minors: Example and Test"/>
<meta name="keywords" id="keywords" content=" gradient minors expansion example 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='_jac_minor_det.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="interface2c.cpp.xml" target="_top">Prev</a>
</td><td><a href="jac_lu_det.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>Example</option>
<option>General</option>
<option>jac_minor_det.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>Example-&gt;</option>
<option>General</option>
<option>ExampleUtility</option>
<option>ListAllExamples</option>
<option>testvector</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>General-&gt;</option>
<option>ad_fun.cpp</option>
<option>ad_in_c.cpp</option>
<option>conj_grad.cpp</option>
<option>cppad_eigen.hpp</option>
<option>hes_minor_det.cpp</option>
<option>hes_lu_det.cpp</option>
<option>interface2c.cpp</option>
<option>jac_minor_det.cpp</option>
<option>jac_lu_det.cpp</option>
<option>mul_level</option>
<option>ode_stiff.cpp</option>
<option>mul_level_ode.cpp</option>
<option>mul_level_adolc_ode.cpp</option>
<option>ode_taylor.cpp</option>
<option>stack_machine.cpp</option>
</select>
</td>
<td>jac_minor_det.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>Gradient of Determinant Using Expansion by Minors: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;
# include &lt;cppad/speed/det_by_minor.hpp&gt;
# include &lt;complex&gt;


typedef std::complex&lt;double&gt;     Complex;
typedef CppAD::<a href="ad.xml" target="_top">AD</a>&lt;Complex&gt;       ADComplex;
typedef <a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(ADComplex)   ADVector;

// ----------------------------------------------------------------------------

bool JacMinorDet(void)
{	bool ok = true;

	using namespace CppAD;

	size_t n = 2;

	// object for computing determinant
	det_by_minor&lt;ADComplex&gt; Det(n);

	// independent and dependent variable vectors
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(ADComplex)  X(n * n);
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(ADComplex)  D(1);

	// value of the independent variable
	size_t i;
	for(i = 0; i &lt; n * n; i++)
		X[i] = Complex(int(i), -int(i));

	// set the independent variables
	<a href="independent.xml" target="_top">Independent</a>(X);

	// comupute the determinant
	D[0] = Det(X); 

	// create the function object
	<a href="funconstruct.xml" target="_top">ADFun</a>&lt;Complex&gt; f(X, D);

	// argument value
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(Complex)     x( n * n );
	for(i = 0; i &lt; n * n; i++)
		x[i] = Complex(2 * i, i);

	// first derivative of the determinant
	<a href="testvector.xml" target="_top">CPPAD_TESTVECTOR</a>(Complex) J( n * n );
	J = f.<a href="jacobian.xml" target="_top">Jacobian</a>(x);

	/*
	f(x)     = x[0] * x[3] - x[1] * x[2]
	f'(x)    = ( x[3], -x[2], -x[1], x[0] )
	*/
	Complex Jtrue[] = { x[3], -x[2], -x[1], x[0] };
	for(i = 0; i &lt; n * n; i++)
		ok &amp;= Jtrue[i] == J[i];

	return ok;

}

</pre>

</font></code>


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

</body>
</html>
