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

Revision 472, 4.6 kB (checked in by mido, 15 years ago)

obnovena dokumentace, vcetne pridani mnoha novych doc-souboru do svn

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="manual.html">User Manual</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{
73  <span class="comment">//Declare vectors and matricies:</span>
74  vec a, b, c;
75  mat A, B;
76
77  <span class="comment">//Use the function linspace to define a vector:</span>
78  a = linspace(1.0, 2.0, 10);
79
80  <span class="comment">//Use a string of values to define a vector:</span>
81  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>;
82
83  <span class="comment">//Add two vectors:</span>
84  c = a + b;
85
86  <span class="comment">//Print results:</span>
87  cout &lt;&lt; <span class="stringliteral">"a = "</span> &lt;&lt; a &lt;&lt; endl;
88  cout &lt;&lt; <span class="stringliteral">"b = "</span> &lt;&lt; b &lt;&lt; endl;
89  cout &lt;&lt; <span class="stringliteral">"c = "</span> &lt;&lt; c &lt;&lt; endl;
90
91  <span class="comment">//Use a string to define a matrix:</span>
92  A = <span class="stringliteral">"1.0 2.0;3.0 4.0"</span>;
93
94  <span class="comment">//Calculate the inverse of matrix A:</span>
95  B = inv(A);
96
97  <span class="comment">//Print results:</span>
98  cout &lt;&lt; <span class="stringliteral">"A = "</span> &lt;&lt; A &lt;&lt; endl;
99  cout &lt;&lt; <span class="stringliteral">"B = "</span> &lt;&lt; B &lt;&lt; endl;
100
101  <span class="comment">//Exit program:</span>
102  <span class="keywordflow">return</span> 0;
103
104}
105</pre></div><p>
106When you run this program, the output shall look like this<p>
107<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]
108b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]
109c = [1.1 1.31111 1.52222 1.73333 1.94444 2.15556 2.36667 2.57778 2.78889 3]
110A = [[1 2]
111 [3 4]]
112B = [[-2 1]
113 [1.5 -0.5]]
114</pre></div><p>
115If this is what you see, then congratulations! You have managed to compile your first it++ program! </div>
116<hr size="1"><address style="text-align: right;"><small>Generated on Wed Aug 5 00:06:51 2009 for mixpp by&nbsp;
117<a href="http://www.doxygen.org/index.html">
118<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
119</body>
120</html>
Note: See TracBrowser for help on using the browser.