<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Sum of the Elements of the Square of a Matrix: Example and Test</title>
<meta name="description" id="description" content="Sum of the Elements of the Square of a Matrix: Example and Test"/>
<meta name="keywords" id="keywords" content=" mat_sum_sq 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='_mat_sum_sq.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="mat_sum_sq.xml" target="_top">Prev</a>
</td><td><a href="mat_sum_sq.hpp.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_utility</option>
<option>mat_sum_sq</option>
<option>mat_sum_sq.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(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_down2(this)'>
<option>speed_utility-&gt;</option>
<option>det_by_lu</option>
<option>det_of_minor</option>
<option>det_by_minor</option>
<option>det_33</option>
<option>det_grad_33</option>
<option>mat_sum_sq</option>
<option>ode_evaluate</option>
<option>sparse_jac_fun</option>
<option>sparse_hes_fun</option>
<option>uniform_01</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>mat_sum_sq-&gt;</option>
<option>mat_sum_sq.cpp</option>
<option>mat_sum_sq.hpp</option>
</select>
</td>
<td>mat_sum_sq.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>Sum of the Elements of the Square of a Matrix: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
# include &lt;vector&gt;
# include &lt;cstddef&gt;
# include &lt;cppad/vector.hpp&gt;
# include &lt;cppad/speed/mat_sum_sq.hpp&gt;

bool mat_sum_sq()
{	bool   ok = true;
	double x_00, x_01, x_10, x_11, check;

	// dimension of the matrices x, y, and the result z
	size_t n = 2;
	CppAD::vector&lt;double&gt; x(n * n), y(n * n), z(1);

	// x = [ 1 2 ; 3 4 ]
	x[0] = x_00 = 1.;
	x[1] = x_01 = 2.;
	x[2] = x_10 = 3.;
	x[3] = x_11 = 4.;

	// compute y = x * x and z = sum of elements in y
	CppAD::mat_sum_sq(n, x, y, z);

	// check y_00
	check = x_00 * x_00 + x_01 * x_10;
	ok   &amp;= (check == y[0]); 

	// check y_01
	check = x_00 * x_01 + x_01 * x_11;
	ok   &amp;= (check == y[1]); 

	// check y_10
	check = x_10 * x_00 + x_11 * x_10;
	ok   &amp;= (check == y[2]); 

	// check y_11
	check = x_10 * x_01 + x_11 * x_11;
	ok   &amp;= (check == y[3]); 
	
	// check z
	check = y[0] + y[1] + y[2] + y[3];
	ok   &amp;= (check == z[0]); 
	
	return ok;
}
</pre>

</font></code>


<hr/>Input File: speed/example/mat_sum_sq.cpp

</body>
</html>
