root/library/doc/html/vector_and_matrix.html @ 651

Revision 651, 4.7 kB (checked in by mido, 15 years ago)

\doc directory cleaned a bit

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3<title>mixpp: A very simple tutorial about vectors and matrixes</title>
4<link href="tabs.css" rel="stylesheet" type="text/css">
5<link href="doxygen.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.5.9 -->
8<script type="text/javascript">
9<!--
10function changeDisplayState (e){
11  var num=this.id.replace(/[^[0-9]/g,'');
12  var button=this.firstChild;
13  var sectionDiv=document.getElementById('dynsection'+num);
14  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
15    sectionDiv.style.display='block';
16    button.src='open.gif';
17  }else{
18    sectionDiv.style.display='none';
19    button.src='closed.gif';
20  }
21}
22function initDynSections(){
23  var divs=document.getElementsByTagName('div');
24  var sectionCounter=1;
25  for(var i=0;i<divs.length-1;i++){
26    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
27      var header=divs[i];
28      var section=divs[i+1];
29      var button=header.firstChild;
30      if (button!='IMG'){
31        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
32        button=document.createElement('img');
33        divs[i].insertBefore(button,divs[i].firstChild);
34      }
35      header.style.cursor='pointer';
36      header.onclick=changeDisplayState;
37      header.id='dynheader'+sectionCounter;
38      button.src='closed.gif';
39      section.id='dynsection'+sectionCounter;
40      section.style.display='none';
41      section.style.marginLeft='14px';
42      sectionCounter++;
43    }
44  }
45}
46window.onload = initDynSections;
47-->
48</script>
49<div class="navigation" id="top">
50  <div class="tabs">
51    <ul>
52      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
53      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
54      <li><a href="annotated.html"><span>Classes</span></a></li>
55      <li><a href="files.html"><span>Files</span></a></li>
56    </ul>
57  </div>
58  <div class="navpath"><a class="el" href="dev_guide.html">BDM Use - in C++</a>
59  </div>
60</div>
61<div class="contents">
62<h1><a class="anchor" name="vector_and_matrix">A very simple tutorial about vectors and matrixes </a></h1>Let's start with a really simple example. Try to complile the following program:<p>
63<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;itpp/itbase.h&gt;</span>
64
65<span class="keyword">using namespace </span>itpp;
66
67<span class="comment">//These lines are needed for use of cout and endl</span>
68<span class="keyword">using</span> std::cout;
69<span class="keyword">using</span> std::endl;
70
71<span class="keywordtype">int</span> main() {
72        <span class="comment">//Declare vectors and matricies:</span>
73        vec a, b, c;
74        mat A, B;
75
76        <span class="comment">//Use the function linspace to define a vector:</span>
77        a = linspace ( 1.0, 2.0, 10 );
78
79        <span class="comment">//Use a string of values to define a vector:</span>
80        b = <span class="stringliteral">"0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0"</span>;
81
82        <span class="comment">//Add two vectors:</span>
83        c = a + b;
84
85        <span class="comment">//Print results:</span>
86        cout &lt;&lt; <span class="stringliteral">"a = "</span> &lt;&lt; a &lt;&lt; endl;
87        cout &lt;&lt; <span class="stringliteral">"b = "</span> &lt;&lt; b &lt;&lt; endl;
88        cout &lt;&lt; <span class="stringliteral">"c = "</span> &lt;&lt; c &lt;&lt; endl;
89
90        <span class="comment">//Use a string to define a matrix:</span>
91        A = <span class="stringliteral">"1.0 2.0;3.0 4.0"</span>;
92
93        <span class="comment">//Calculate the inverse of matrix A:</span>
94        B = inv ( A );
95
96        <span class="comment">//Print results:</span>
97        cout &lt;&lt; <span class="stringliteral">"A = "</span> &lt;&lt; A &lt;&lt; endl;
98        cout &lt;&lt; <span class="stringliteral">"B = "</span> &lt;&lt; B &lt;&lt; endl;
99
100        <span class="comment">//Exit program:</span>
101        <span class="keywordflow">return</span> 0;
102
103}
104</pre></div><p>
105When you run this program, the output shall look like this<p>
106<div class="fragment"><pre class="fragment">a = [1 1.11111 1.22222 1.33333 1.44444 1.55556 1.66667 1.77778 1.88889 2]
107b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]
108c = [1.1 1.31111 1.52222 1.73333 1.94444 2.15556 2.36667 2.57778 2.78889 3]
109A = [[1 2]
110 [3 4]]
111B = [[-2 1]
112 [1.5 -0.5]]
113</pre></div><p>
114If this is what you see, then congratulations! You have managed to compile your first it++ program! </div>
115<hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 7 17:34:45 2009 for mixpp by&nbsp;
116<a href="http://www.doxygen.org/index.html">
117<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
118</body>
119</html>
Note: See TracBrowser for help on using the browser.