Sophie

Sophie

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

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: Getting started</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('GettingStarted.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">Getting started </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This is a very short guide on how to get started with <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a>. It has a dual purpose. It serves as a minimal introduction to the <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> library for people who want to start coding as soon as possible. You can also read this page as the first part of the Tutorial, which explains the library in more detail; in this case you will continue with <a class="el" href="group__TutorialMatrixClass.html">The Matrix class</a>.</p>
<h1><a class="anchor" id="GettingStartedInstallation"></a>
How to "install" Eigen?</h1>
<p>In order to use <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a>, you just need to download and extract <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a>'s source code (see <a href="http://eigen.tuxfamily.org/index.php?title=Main_Page#Download">the wiki</a> for download instructions). In fact, the header files in the <code><a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a></code> subdirectory are the only files required to compile programs using <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a>. The header files are the same for all platforms. It is not necessary to use CMake or install anything.</p>
<h1><a class="anchor" id="GettingStartedFirstProgram"></a>
A simple first program</h1>
<p>Here is a rather simple program to get you started.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using</span> <a class="code" href="group__matrixtypedefs.html#ga0750af9a6b82761985a15fe77256de87">Eigen::MatrixXd</a>;</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="group__matrixtypedefs.html#ga0750af9a6b82761985a15fe77256de87">MatrixXd</a> m(2,2);</div>
<div class="line">  m(0,0) = 3;</div>
<div class="line">  m(1,0) = 2.5;</div>
<div class="line">  m(0,1) = -1;</div>
<div class="line">  m(1,1) = m(1,0) + m(0,1);</div>
<div class="line">  std::cout &lt;&lt; m &lt;&lt; std::endl;</div>
<div class="line">}</div>
</div><!-- fragment --><p>We will explain the program after telling you how to compile it.</p>
<h1><a class="anchor" id="GettingStartedCompiling"></a>
Compiling and running your first program</h1>
<p>There is no library to link to. The only thing that you need to keep in mind when compiling the above program is that the compiler must be able to find the <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> header files. The directory in which you placed <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a>'s source code must be in the include path. With GCC you use the -I option to achieve this, so you can compile the program with a command like this:</p>
<div class="fragment"><div class="line">g++ -I /path/to/eigen/ my_program.cpp -o my_program </div>
</div><!-- fragment --><p>On Linux or Mac OS X, another option is to symlink or copy the <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> folder into /usr/local/include/. This way, you can compile the program with:</p>
<div class="fragment"><div class="line">g++ my_program.cpp -o my_program </div>
</div><!-- fragment --><p>When you run the program, it produces the following output:</p>
<div class="fragment"><div class="line">  3  -1</div>
<div class="line">2.5 1.5</div>
</div><!-- fragment --><h1><a class="anchor" id="GettingStartedExplanation"></a>
Explanation of the first program</h1>
<p>The <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> header files define many types, but for simple applications it may be enough to use only the <code>MatrixXd</code> type. This represents a matrix of arbitrary size (hence the <code>X</code> in <code>MatrixXd</code>), in which every entry is a <code>double</code> (hence the <code>d</code> in <code>MatrixXd</code>). See the <a class="el" href="group__QuickRefPage.html#QuickRef_Types">quick reference guide</a> for an overview of the different types you can use to represent a matrix.</p>
<p>The <code>Eigen/Dense</code> header file defines all member functions for the MatrixXd type and related types (see also the <a class="el" href="group__QuickRefPage.html#QuickRef_Headers">table of header files</a>). All classes and functions defined in this header file (and other <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a> header files) are in the <code><a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library. ">Eigen</a></code> namespace.</p>
<p>The first line of the <code>main</code> function declares a variable of type <code>MatrixXd</code> and specifies that it is a matrix with 2 rows and 2 columns (the entries are not initialized). The statement <code>m(0,0) = 3</code> sets the entry in the top-left corner to 3. You need to use round parentheses to refer to entries in the matrix. As usual in computer science, the index of the first index is 0, as opposed to the convention in mathematics that the first index is 1.</p>
<p>The following three statements sets the other three entries. The final line outputs the matrix <code>m</code> to the standard output stream.</p>
<h1><a class="anchor" id="GettingStartedExample2"></a>
Example 2: Matrices and vectors</h1>
<p>Here is another example, which combines matrices with vectors. Concentrate on the left-hand program for now; we will talk about the right-hand program later.</p>
<table  class="manual">
<tr>
<th>Size set at run time:</th><th>Size set at compile time: </th></tr>
<tr>
<td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&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">MatrixXd</a> m = <a class="code" href="classEigen_1_1DenseBase.html#a8e759dafdd9ecc446d397b7f5435f60a">MatrixXd::Random</a>(3,3);</div>
<div class="line">  m = (m + <a class="code" href="classEigen_1_1DenseBase.html#abb7652b9ae2c6ee26be9db276613c4f6">MatrixXd::Constant</a>(3,3,1.2)) * 50;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;m =&quot;</span> &lt;&lt; endl &lt;&lt; m &lt;&lt; endl;</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">VectorXd</a> v(3);</div>
<div class="line">  v &lt;&lt; 1, 2, 3;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;m * v =&quot;</span> &lt;&lt; endl &lt;&lt; m * v &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment -->  </td><td><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;Eigen/Dense&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">Matrix3d</a> m = <a class="code" href="classEigen_1_1DenseBase.html#a8e759dafdd9ecc446d397b7f5435f60a">Matrix3d::Random</a>();</div>
<div class="line">  m = (m + <a class="code" href="classEigen_1_1DenseBase.html#abb7652b9ae2c6ee26be9db276613c4f6">Matrix3d::Constant</a>(1.2)) * 50;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;m =&quot;</span> &lt;&lt; endl &lt;&lt; m &lt;&lt; endl;</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">Vector3d</a> v(1,2,3);</div>
<div class="line">  </div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;m * v =&quot;</span> &lt;&lt; endl &lt;&lt; m * v &lt;&lt; endl;</div>
<div class="line">}</div>
</div><!-- fragment --> </td></tr>
</table>
<p>The output is as follows:</p>
<div class="fragment"><div class="line">m =</div>
<div class="line">  94 89.8 43.5</div>
<div class="line">49.4  101 86.8</div>
<div class="line">88.3 29.8 37.8</div>
<div class="line">m * v =</div>
<div class="line">404</div>
<div class="line">512</div>
<div class="line">261</div>
</div><!-- fragment --><h1><a class="anchor" id="GettingStartedExplanation2"></a>
Explanation of the second example</h1>
<p>The second example starts by declaring a 3-by-3 matrix <code>m</code> which is initialized using the <a class="el" href="classEigen_1_1DenseBase.html#a78061942c4ccb57f5b1dde173fdd8bd0">Random() </a> method with random values between -1 and 1. The next line applies a linear mapping such that the values are between 10 and 110. The function call <a class="el" href="classEigen_1_1DenseBase.html#abb7652b9ae2c6ee26be9db276613c4f6">MatrixXd::Constant</a>(3,3,1.2) returns a 3-by-3 matrix expression having all coefficients equal to 1.2. The rest is standard arithmetics.</p>
<p>The next line of the <code>main</code> function introduces a new type: <code>VectorXd</code>. This represents a (column) vector of arbitrary size. Here, the vector <code>v</code> is created to contain <code>3</code> coefficients which are left unitialized. The one but last line uses the so-called comma-initializer, explained in <a class="el" href="group__TutorialAdvancedInitialization.html">Advanced initialization</a>, to set all coefficients of the vector <code>v</code> to be as follows:</p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ v = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}. \]" src="form_175.png"/>
</p>
<p>The final line of the program multiplies the matrix <code>m</code> with the vector <code>v</code> and outputs the result.</p>
<p>Now look back at the second example program. We presented two versions of it. In the version in the left column, the matrix is of type <code>MatrixXd</code> which represents matrices of arbitrary size. The version in the right column is similar, except that the matrix is of type <code>Matrix3d</code>, which represents matrices of a fixed size (here 3-by-3). Because the type already encodes the size of the matrix, it is not necessary to specify the size in the constructor; compare <code>MatrixXd m(3,3)</code> with <code>Matrix3d m</code>. Similarly, we have <code>VectorXd</code> on the left (arbitrary size) versus <code>Vector3d</code> on the right (fixed size). Note that here the coefficients of vector <code>v</code> are directly set in the constructor, though the same syntax of the left example could be used too.</p>
<p>The use of fixed-size matrices and vectors has two advantages. The compiler emits better (faster) code because it knows the size of the matrices and vectors. Specifying the size in the type also allows for more rigorous checking at compile-time. For instance, the compiler will complain if you try to multiply a <code>Matrix4d</code> (a 4-by-4 matrix) with a <code>Vector3d</code> (a vector of size 3). However, the use of many types increases compilation time and the size of the executable. The size of the matrix may also not be known at compile-time. A rule of thumb is to use fixed-size matrices for size 4-by-4 and smaller.</p>
<h1><a class="anchor" id="GettingStartedConclusion"></a>
Where to go from here?</h1>
<p>It's worth taking the time to read the <a class="el" href="group__TutorialMatrixClass.html">long tutorial</a>.</p>
<p>However if you think you don't need it, you can directly use the classes documentation and our <a class="el" href="group__QuickRefPage.html">Quick reference guide</a>.</p>
<ul>
<li><b>Next:</b> <a class="el" href="group__TutorialMatrixClass.html">The Matrix class</a> </li>
</ul>
</div></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>