Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 99cb5ede6a5329071fbeecc8218deb35 > files > 1088

eigen3-doc-3.2-3.mga4.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.5"/>
<title>Eigen: The Array class and coefficient-wise operations</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css"   rel="stylesheet" type="text/css" />
<link href="eigendoxy.css" rel="stylesheet" type="text/css">
<!--  -->
<script type="text/javascript" src="eigen_navtree_hacks.js"></script>
<!-- <script type="text/javascript"> -->
<!-- </script> -->
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<!-- <a name="top"></a> -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="Eigen_Silly_Professor_64x64.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname"><a href="http://eigen.tuxfamily.org">Eigen</a>
   &#160;<span id="projectnumber">3.2.0</span>
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__TutorialArrayClass.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">The Array class and coefficient-wise operations<div class="ingroups"><a class="el" href="group__DenseMatrixManipulation__chapter.html">Dense matrix and array manipulation</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<p>This page aims to provide an overview and explanations on how to use <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a>'s <a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> class.</p>
<h1><a class="anchor" id="TutorialArrayClassIntro"></a>
What is the Array class?</h1>
<p>The <a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> class provides general-purpose arrays, as opposed to the <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> class which is intended for linear algebra. Furthermore, the <a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> class provides an easy way to perform coefficient-wise operations, which might not have a linear algebraic meaning, such as adding a constant to every coefficient in the array or multiplying two arrays coefficient-wise.</p>
<h1><a class="anchor" id="TutorialArrayClassTypes"></a>
Array types</h1>
<p><a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> is a class template taking the same template parameters as <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a>. As with <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a>, the first three template parameters are mandatory: </p>
<div class="fragment"><div class="line">Array&lt;typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime&gt;</div>
</div><!-- fragment --><p> The last three template parameters are optional. Since this is exactly the same as for <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a>, we won't explain it again here and just refer to <a class="el" href="group__TutorialMatrixClass.html">The Matrix class</a>.</p>
<p><a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> also provides typedefs for some common cases, in a way that is similar to the <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> typedefs but with some slight differences, as the word "array" is used for both 1-dimensional and 2-dimensional arrays. We adopt the convention that typedefs of the form ArrayNt stand for 1-dimensional arrays, where N and t are the size and the scalar type, as in the <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> typedefs explained on <a class="el" href="group__TutorialMatrixClass.html">this page</a>. For 2-dimensional arrays, we use typedefs of the form ArrayNNt. Some examples are shown in the following table:</p>
<table  class="manual">
<tr>
<th>Type  </th><th>Typedef   </th></tr>
<tr>
<td><div class="fragment"><div class="line">Array&lt;float,Dynamic,1&gt; </div>
</div><!-- fragment -->  </td><td><div class="fragment"><div class="line">ArrayXf </div>
</div><!-- fragment -->   </td></tr>
<tr>
<td><div class="fragment"><div class="line">Array&lt;float,3,1&gt; </div>
</div><!-- fragment -->  </td><td><div class="fragment"><div class="line">Array3f </div>
</div><!-- fragment -->   </td></tr>
<tr>
<td><div class="fragment"><div class="line">Array&lt;double,Dynamic,Dynamic&gt; </div>
</div><!-- fragment -->  </td><td><div class="fragment"><div class="line">ArrayXXd </div>
</div><!-- fragment -->   </td></tr>
<tr>
<td><div class="fragment"><div class="line">Array&lt;double,3,3&gt; </div>
</div><!-- fragment -->  </td><td><div class="fragment"><div class="line">Array33d </div>
</div><!-- fragment -->   </td></tr>
</table>
<h1><a class="anchor" id="TutorialArrayClassAccess"></a>
Accessing values inside an Array</h1>
<p>The parenthesis operator is overloaded to provide write and read access to the coefficients of an array, just as with matrices. Furthermore, the <code>&lt;&lt;</code> operator can be used to initialize arrays (via the comma initializer) or to print them.</p>
<table  class="example">
<tr>
<th>Example:</th><th>Output: </th></tr>
<tr>
<td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>Eigen;</div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">  ArrayXXf  m(2,2);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// assign some values coefficient by coefficient</span></div>
<div class="line">  m(0,0) = 1.0; m(0,1) = 2.0;</div>
<div class="line">  m(1,0) = 3.0; m(1,1) = m(0,1) + m(1,0);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// print values to standard output</span></div>
<div class="line">  cout &lt;&lt; m &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// using the comma-initializer is also allowed</span></div>
<div class="line">  m &lt;&lt; 1.0,2.0,</div>
<div class="line">       3.0,4.0;</div>
<div class="line">     </div>
<div class="line">  <span class="comment">// print values to standard output</span></div>
<div class="line">  cout &lt;&lt; m &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment -->  </td><td><pre class="fragment">1 2
3 5

1 2
3 4
</pre> </td></tr>
</table>
<p>For more information about the comma initializer, see <a class="el" href="group__TutorialAdvancedInitialization.html">Advanced initialization</a>.</p>
<h1><a class="anchor" id="TutorialArrayClassAddSub"></a>
Addition and subtraction</h1>
<p>Adding and subtracting two arrays is the same as for matrices. The operation is valid if both arrays have the same size, and the addition or subtraction is done coefficient-wise.</p>
<p>Arrays also support expressions of the form <code>array + scalar</code> which add a scalar to each coefficient in the array. This provides a functionality that is not directly available for <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> objects.</p>
<table  class="example">
<tr>
<th>Example:</th><th>Output: </th></tr>
<tr>
<td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>Eigen;</div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">  ArrayXXf a(3,3);</div>
<div class="line">  ArrayXXf b(3,3);</div>
<div class="line">  a &lt;&lt; 1,2,3,</div>
<div class="line">       4,5,6,</div>
<div class="line">       7,8,9;</div>
<div class="line">  b &lt;&lt; 1,2,3,</div>
<div class="line">       1,2,3,</div>
<div class="line">       1,2,3;</div>
<div class="line">       </div>
<div class="line">  <span class="comment">// Adding two arrays</span></div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;a + b = &quot;</span> &lt;&lt; endl &lt;&lt; a + b &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Subtracting a scalar from an array</span></div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;a - 2 = &quot;</span> &lt;&lt; endl &lt;&lt; a - 2 &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment -->  </td><td><pre class="fragment">a + b = 
 2  4  6
 5  7  9
 8 10 12

a - 2 = 
-1 0 1
2 3 4
5 6 7
</pre> </td></tr>
</table>
<h1><a class="anchor" id="TutorialArrayClassMult"></a>
Array multiplication</h1>
<p>First of all, of course you can multiply an array by a scalar, this works in the same way as matrices. Where arrays are fundamentally different from matrices, is when you multiply two together. Matrices interpret multiplication as matrix product and arrays interpret multiplication as coefficient-wise product. Thus, two arrays can be multiplied if and only if they have the same dimensions.</p>
<table  class="example">
<tr>
<th>Example:</th><th>Output: </th></tr>
<tr>
<td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>Eigen;</div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">  ArrayXXf a(2,2);</div>
<div class="line">  ArrayXXf b(2,2);</div>
<div class="line">  a &lt;&lt; 1,2,</div>
<div class="line">       3,4;</div>
<div class="line">  b &lt;&lt; 5,6,</div>
<div class="line">       7,8;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;a * b = &quot;</span> &lt;&lt; endl &lt;&lt; a * b &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment -->  </td><td><pre class="fragment">a * b = 
 5 12
21 32
</pre> </td></tr>
</table>
<h1><a class="anchor" id="TutorialArrayClassCwiseOther"></a>
Other coefficient-wise operations</h1>
<p>The <a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> class defines other coefficient-wise operations besides the addition, subtraction and multiplication operators described above. For example, the <a class="el" href="classEigen_1_1ArrayBase.html#a1b110a87160375196234ab5b3aea7e1b">.abs() </a> method takes the absolute value of each coefficient, while <a class="el" href="classEigen_1_1ArrayBase.html#ae9f5fba39401def562700a1cd7b0fd7e">.sqrt() </a> computes the square root of the coefficients. If you have two arrays of the same size, you can call <a class="el" href="classEigen_1_1ArrayBase.html#a916d59a95c3ac1784b4ee7fd35c1638d">.min(.) </a> to construct the array whose coefficients are the minimum of the corresponding coefficients of the two given arrays. These operations are illustrated in the following example.</p>
<table  class="example">
<tr>
<th>Example:</th><th>Output: </th></tr>
<tr>
<td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>Eigen;</div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">  ArrayXf a = ArrayXf::Random(5);</div>
<div class="line">  a *= 2;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;a =&quot;</span> &lt;&lt; endl </div>
<div class="line">       &lt;&lt; a &lt;&lt; endl;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;a.abs() =&quot;</span> &lt;&lt; endl </div>
<div class="line">       &lt;&lt; a.abs() &lt;&lt; endl;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;a.abs().sqrt() =&quot;</span> &lt;&lt; endl </div>
<div class="line">       &lt;&lt; a.abs().sqrt() &lt;&lt; endl;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;a.min(a.abs().sqrt()) =&quot;</span> &lt;&lt; endl </div>
<div class="line">       &lt;&lt; a.min(a.abs().sqrt()) &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment -->  </td><td><pre class="fragment">a =
1.36
-0.422
1.13
1.19
1.65
a.abs() =
1.36
0.422
1.13
1.19
1.65
a.abs().sqrt() =
1.17
0.65
1.06
1.09
1.28
a.min(a.abs().sqrt()) =
1.17
-0.422
1.06
1.09
1.28
</pre> </td></tr>
</table>
<p>More coefficient-wise operations can be found in the <a class="el" href="group__QuickRefPage.html">Quick reference guide</a>.</p>
<h1><a class="anchor" id="TutorialArrayClassConvert"></a>
Converting between array and matrix expressions</h1>
<p>When should you use objects of the <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> class and when should you use objects of the <a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> class? You cannot apply <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> operations on arrays, or <a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> operations on matrices. Thus, if you need to do linear algebraic operations such as matrix multiplication, then you should use matrices; if you need to do coefficient-wise operations, then you should use arrays. However, sometimes it is not that simple, but you need to use both <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> and <a class="el" href="classEigen_1_1Array.html" title="General-purpose arrays with easy API for coefficient-wise operations. ">Array</a> operations. In that case, you need to convert a matrix to an array or reversely. This gives access to all operations regardless of the choice of declaring objects as arrays or as matrices.</p>
<p><a class="el" href="classEigen_1_1MatrixBase.html">Matrix expressions </a> have an <a class="el" href="classEigen_1_1MatrixBase.html#a4545be7a9af33ba337a4ebb0101395fd">.array() </a> method that 'converts' them into <a class="el" href="classEigen_1_1ArrayBase.html">array expressions</a>, so that coefficient-wise operations can be applied easily. Conversely, <a class="el" href="classEigen_1_1ArrayBase.html">array expressions </a> have a <a class="el" href="classEigen_1_1ArrayBase.html#a534d52e9394efc21d065c79c189b78c2">.matrix() </a> method. As with all <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> expression abstractions, this doesn't have any runtime cost (provided that you let your compiler optimize). Both <a class="el" href="classEigen_1_1MatrixBase.html#a4545be7a9af33ba337a4ebb0101395fd">.array() </a> and <a class="el" href="classEigen_1_1ArrayBase.html#a534d52e9394efc21d065c79c189b78c2">.matrix() </a> can be used as rvalues and as lvalues.</p>
<p>Mixing matrices and arrays in an expression is forbidden with <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a>. For instance, you cannot add a matrix and array directly; the operands of a <code>+</code> operator should either both be matrices or both be arrays. However, it is easy to convert from one to the other with <a class="el" href="classEigen_1_1MatrixBase.html#a4545be7a9af33ba337a4ebb0101395fd">.array() </a> and <a class="el" href="classEigen_1_1ArrayBase.html#a534d52e9394efc21d065c79c189b78c2">.matrix()</a>. The exception to this rule is the assignment operator: it is allowed to assign a matrix expression to an array variable, or to assign an array expression to a matrix variable.</p>
<p>The following example shows how to use array operations on a <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors. ">Matrix</a> object by employing the <a class="el" href="classEigen_1_1MatrixBase.html#a4545be7a9af33ba337a4ebb0101395fd">.array() </a> method. For example, the statement <code>result = m.array() * n.array()</code> takes two matrices <code>m</code> and <code>n</code>, converts them both to an array, uses to multiply them coefficient-wise and assigns the result to the matrix variable <code>result</code> (this is legal because <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> allows assigning array expressions to matrix variables).</p>
<p>As a matter of fact, this usage case is so common that <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> provides a <a class="el" href="classEigen_1_1MatrixBase.html#ae759f49ab64f4d454e591bf610a09156">const .cwiseProduct(.) </a> method for matrices to compute the coefficient-wise product. This is also shown in the example program.</p>
<table  class="example">
<tr>
<th>Example:</th><th>Output: </th></tr>
<tr>
<td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>Eigen;</div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">MatrixXf</a> m(2,2);</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">MatrixXf</a> n(2,2);</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">MatrixXf</a> result(2,2);</div>
<div class="line"></div>
<div class="line">  m &lt;&lt; 1,2,</div>
<div class="line">       3,4;</div>
<div class="line">  n &lt;&lt; 5,6,</div>
<div class="line">       7,8;</div>
<div class="line"></div>
<div class="line">  result = m * n;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;-- Matrix m*n: --&quot;</span> &lt;&lt; endl &lt;&lt; result &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line">  result = m.array() * n.array();</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;-- Array m*n: --&quot;</span> &lt;&lt; endl &lt;&lt; result &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line">  result = m.cwiseProduct(n);</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;-- With cwiseProduct: --&quot;</span> &lt;&lt; endl &lt;&lt; result &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line">  result = m.array() + 4;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;-- Array m + 4: --&quot;</span> &lt;&lt; endl &lt;&lt; result &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment -->  </td><td><pre class="fragment">-- Matrix m*n: --
19 22
43 50

-- Array m*n: --
 5 12
21 32

-- With cwiseProduct: --
 5 12
21 32

-- Array m + 4: --
5 6
7 8

</pre> </td></tr>
</table>
<p>Similarly, if <code>array1</code> and <code>array2</code> are arrays, then the expression <code>array1.matrix() * array2.matrix()</code> computes their matrix product.</p>
<p>Here is a more advanced example. The expression <code>(m.array() + 4).matrix() * m</code> adds 4 to every coefficient in the matrix <code>m</code> and then computes the matrix product of the result with <code>m</code>. Similarly, the expression <code>(m.array() * n.array()).matrix() * m</code> computes the coefficient-wise product of the matrices <code>m</code> and <code>n</code> and then the matrix product of the result with <code>m</code>.</p>
<table  class="example">
<tr>
<th>Example:</th><th>Output: </th></tr>
<tr>
<td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>Eigen;</div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">MatrixXf</a> m(2,2);</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">MatrixXf</a> n(2,2);</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">MatrixXf</a> result(2,2);</div>
<div class="line"></div>
<div class="line">  m &lt;&lt; 1,2,</div>
<div class="line">       3,4;</div>
<div class="line">  n &lt;&lt; 5,6,</div>
<div class="line">       7,8;</div>
<div class="line">  </div>
<div class="line">  result = (m.array() + 4).matrix() * m;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;-- Combination 1: --&quot;</span> &lt;&lt; endl &lt;&lt; result &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line">  result = (m.array() * n.array()).matrix() * m;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;-- Combination 2: --&quot;</span> &lt;&lt; endl &lt;&lt; result &lt;&lt; endl &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment -->  </td><td><pre class="fragment">-- Combination 1: --
23 34
31 46

-- Combination 2: --
 41  58
117 170

</pre> </td></tr>
</table>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Oct 28 2013 11:04:27 for Eigen by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.5 </li>
  </ul>
</div>
<!-- Piwik --> 
<!--
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://stats.sylphide-consulting.com/piwik/" : "http://stats.sylphide-consulting.com/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 20);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://stats.sylphide-consulting.com/piwik/piwik.php?idsite=20" style="border:0" alt="" /></p></noscript>
-->
<!-- End Piwik Tracking Code -->
</body>
</html>