<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Sum Elements of a Matrix Times Itself</title>
<meta name="description" id="description" content="Sum Elements of a Matrix Times Itself"/>
<meta name="keywords" id="keywords" content=" mat_sum_sq matrix multiply speed 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_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="det_grad_33.hpp.xml" target="_top">Prev</a>
</td><td><a href="mat_sum_sq.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>Appendix</option>
<option>speed</option>
<option>speed_utility</option>
<option>mat_sum_sq</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>Appendix-&gt;</option>
<option>Faq</option>
<option>speed</option>
<option>Theory</option>
<option>glossary</option>
<option>Bib</option>
<option>Bugs</option>
<option>WishList</option>
<option>whats_new</option>
<option>deprecated</option>
<option>License</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_utility-&gt;</option>
<option>uniform_01</option>
<option>det_of_minor</option>
<option>det_by_minor</option>
<option>det_by_lu</option>
<option>det_33</option>
<option>det_grad_33</option>
<option>mat_sum_sq</option>
<option>ode_evaluate</option>
<option>sparse_evaluate</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>mat_sum_sq-&gt;</option>
<option>mat_sum_sq.cpp</option>
<option>mat_sum_sq.hpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Syntax</option>
<option>Purpose</option>
<option>Inclusion</option>
<option>n</option>
<option>x</option>
<option>y</option>
<option>z</option>
<option>Vector</option>
<option>Example</option>
<option>Source Code</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>Sum Elements of a Matrix Times Itself</big></big></b></center>
<br/>
<b><big><a name="Syntax" id="Syntax">Syntax</a></big></b>

<br/>

<code><font color="blue"><span style='white-space: nowrap'>#&#xA0;include&#xA0;&lt;cppad/speed/mat_sum_sq.hpp&gt;<br/>
</span></font></code>

<code><i><font color="black"><span style='white-space: nowrap'>mat_sum_sq(</span></font></i><font color="blue"><span style='white-space: nowrap'>n</span></font><i><font color="black"><span style='white-space: nowrap'>,&#xA0;</span></font></i><font color="blue"><span style='white-space: nowrap'>x</span></font><i><font color="black"><span style='white-space: nowrap'>,&#xA0;</span></font></i><font color="blue"><span style='white-space: nowrap'>y</span></font><i><font color="black"><span style='white-space: nowrap'>,&#xA0;</span></font></i><font color="blue"><span style='white-space: nowrap'>z</span></font><i><font color="black"><span style='white-space: nowrap'>)</span></font></i></code>


<br/>
<br/>
<b><big><a name="Purpose" id="Purpose">Purpose</a></big></b>
<br/>
This routine is intended for use with the matrix multiply speed tests;
to be specific, it computes

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>y</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<munderover><mo displaystyle='true' largeop='true'>&#x02211;</mo>
<mrow><mi mathvariant='italic'>k</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
<mrow><mi mathvariant='italic'>n</mi>
<mn>-1</mn>
</mrow>
</munderover>
<msub><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>k</mi>
</mrow>
</msub>
<msub><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>k</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>z</mi>
<mn>0</mn>
</msub>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<munderover><mo displaystyle='true' largeop='true'>&#x02211;</mo>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
<mrow><mi mathvariant='italic'>n</mi>
<mn>-1</mn>
</mrow>
</munderover>
<munderover><mo displaystyle='true' largeop='true'>&#x02211;</mo>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
<mrow><mi mathvariant='italic'>n</mi>
<mn>-1</mn>
</mrow>
</munderover>
<msub><mi mathvariant='italic'>y</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
</mtd></mtr></mtable>
</mrow></math>

see <a href="link_mat_mul.xml" target="_top"><span style='white-space: nowrap'>link_mat_mul</span></a>
.

<br/>
<br/>
<b><big><a name="Inclusion" id="Inclusion">Inclusion</a></big></b>
<br/>
The template function <code><font color="blue">mat_sum_sq</font></code> is defined in the <code><font color="blue">CppAD</font></code>
namespace by including 
the file <code><font color="blue">cppad/speed/mat_sum_sq.hpp</font></code> 
(relative to the CppAD distribution directory).
It is only intended for example and testing purposes, 
so it is not automatically included by
<a href="cppad.xml" target="_top"><span style='white-space: nowrap'>cppad.hpp</span></a>
.

<br/>
<br/>
<b><big><a name="n" id="n">n</a></big></b>
<br/>
This argument has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;size_t&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
It specifies the size of the matrices.

<br/>
<br/>
<b><big><a name="x" id="x">x</a></big></b>
<br/>
The argument 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Vector</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
and 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.size()&#xA0;==&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;*&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
.
It contains the elements of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

 in row major order; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">[</mo>
<mi mathvariant='italic'>i</mi>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>n</mi>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>j</mi>
<mo stretchy="false">]</mo>
</mrow></math>

<br/>
<b><big><a name="y" id="y">y</a></big></b>
<br/>
The argument 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Vector</span></font></i><font color="blue"><span style='white-space: nowrap'>&amp;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
and 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>.size()&#xA0;==&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;*&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
.
The input value of its elements does not matter.
Upon return,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>y</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<munderover><mo displaystyle='true' largeop='true'>&#x02211;</mo>
<mrow><mi mathvariant='italic'>k</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
<mrow><mi mathvariant='italic'>n</mi>
<mn>-1</mn>
</mrow>
</munderover>
<msub><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>k</mi>
</mrow>
</msub>
<msub><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>k</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
<mi mathvariant='italic'>y</mi>
<mo stretchy="false">[</mo>
<mi mathvariant='italic'>i</mi>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>n</mi>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>j</mi>
<mo stretchy="false">]</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msub><mi mathvariant='italic'>y</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="z" id="z">z</a></big></b>
<br/>
The argument 
<code><i><font color="black"><span style='white-space: nowrap'>d</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Vector</span></font></i><font color="blue"><span style='white-space: nowrap'>&amp;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>z</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
.
The input value of its element does not matter.
Upon return

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>z</mi>
<mn>0</mn>
</msub>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<munderover><mo displaystyle='true' largeop='true'>&#x02211;</mo>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
<mrow><mi mathvariant='italic'>n</mi>
<mn>-1</mn>
</mrow>
</munderover>
<munderover><mo displaystyle='true' largeop='true'>&#x02211;</mo>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
<mi mathvariant='italic'>n</mi>
</munderover>
<msub><mi mathvariant='italic'>y</mi>
<mrow><mi mathvariant='italic'>i</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>j</mi>
</mrow>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
<mi mathvariant='italic'>z</mi>
<mo stretchy="false">[</mo>
<mn>0</mn>
<mo stretchy="false">]</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msub><mi mathvariant='italic'>z</mi>
<mn>0</mn>
</msub>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="Vector" id="Vector">Vector</a></big></b>
<br/>
The type 
<code><i><font color="black"><span style='white-space: nowrap'>Vector</span></font></i></code>
 is any
<a href="simplevector.xml" target="_top"><span style='white-space: nowrap'>SimpleVector</span></a>
 calls with a fixed element type.
The element type must support
addition, multiplication, and assignment to both its own type 
and to a double value.




<br/>
<br/>
<b><big><a name="Example" id="Example">Example</a></big></b>
<br/>
The file
<a href="mat_sum_sq.cpp.xml" target="_top"><span style='white-space: nowrap'>mat_sum_sq.cpp</span></a>
 
contains an example and test of <code><font color="blue">mat_sum_sq.hpp</font></code>.
It returns true if it succeeds and false otherwise.

<br/>
<br/>
<b><big><a name="Source Code" id="Source Code">Source Code</a></big></b>
<br/>
The file
<a href="mat_sum_sq.hpp.xml" target="_top"><span style='white-space: nowrap'>mat_sum_sq.hpp</span></a>
 
contains the source for this template function.


<hr/>Input File: cppad/speed/mat_sum_sq.hpp

</body>
</html>

