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.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function 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 | } |
---|
22 | function 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 | } |
---|
46 | window.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 Page</span></a></li> |
---|
53 | <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="navpath"><a class="el" href="manual.html">User Manual</a> |
---|
60 | </div> |
---|
61 | </div> |
---|
62 | <div class="contents"> |
---|
63 | <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> |
---|
64 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <itpp/itbase.h></span> |
---|
65 | |
---|
66 | <span class="keyword">using namespace </span>itpp; |
---|
67 | |
---|
68 | <span class="comment">//These lines are needed for use of cout and endl</span> |
---|
69 | <span class="keyword">using</span> std::cout; |
---|
70 | <span class="keyword">using</span> std::endl; |
---|
71 | |
---|
72 | <span class="keywordtype">int</span> main() |
---|
73 | { |
---|
74 | <span class="comment">//Declare vectors and matricies:</span> |
---|
75 | vec a, b, c; |
---|
76 | mat A, B; |
---|
77 | |
---|
78 | <span class="comment">//Use the function linspace to define a vector:</span> |
---|
79 | a = linspace(1.0, 2.0, 10); |
---|
80 | |
---|
81 | <span class="comment">//Use a string of values to define a vector:</span> |
---|
82 | 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>; |
---|
83 | |
---|
84 | <span class="comment">//Add two vectors:</span> |
---|
85 | c = a + b; |
---|
86 | |
---|
87 | <span class="comment">//Print results:</span> |
---|
88 | cout << <span class="stringliteral">"a = "</span> << a << endl; |
---|
89 | cout << <span class="stringliteral">"b = "</span> << b << endl; |
---|
90 | cout << <span class="stringliteral">"c = "</span> << c << endl; |
---|
91 | |
---|
92 | <span class="comment">//Use a string to define a matrix:</span> |
---|
93 | A = <span class="stringliteral">"1.0 2.0;3.0 4.0"</span>; |
---|
94 | |
---|
95 | <span class="comment">//Calculate the inverse of matrix A:</span> |
---|
96 | B = inv(A); |
---|
97 | |
---|
98 | <span class="comment">//Print results:</span> |
---|
99 | cout << <span class="stringliteral">"A = "</span> << A << endl; |
---|
100 | cout << <span class="stringliteral">"B = "</span> << B << endl; |
---|
101 | |
---|
102 | <span class="comment">//Exit program:</span> |
---|
103 | <span class="keywordflow">return</span> 0; |
---|
104 | |
---|
105 | } |
---|
106 | </pre></div><p> |
---|
107 | When you run this program, the output shall look like this<p> |
---|
108 | <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] |
---|
109 | b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] |
---|
110 | c = [1.1 1.31111 1.52222 1.73333 1.94444 2.15556 2.36667 2.57778 2.78889 3] |
---|
111 | A = [[1 2] |
---|
112 | [3 4]] |
---|
113 | B = [[-2 1] |
---|
114 | [1.5 -0.5]] |
---|
115 | </pre></div><p> |
---|
116 | If this is what you see, then congratulations! You have managed to compile your first it++ program! </div> |
---|
117 | <hr size="1"><address style="text-align: right;"><small>Generated on Wed Apr 8 16:12:37 2009 for mixpp by |
---|
118 | <a href="http://www.doxygen.org/index.html"> |
---|
119 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
120 | </body> |
---|
121 | </html> |
---|