[261] | 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> |
---|
[290] | 4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
[261] | 5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
| 6 | </head><body> |
---|
[472] | 7 | <!-- Generated by Doxygen 1.5.9 --> |
---|
[271] | 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> |
---|
[261] | 49 | <div class="navigation" id="top"> |
---|
| 50 | <div class="tabs"> |
---|
| 51 | <ul> |
---|
[271] | 52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
[290] | 53 | <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> |
---|
| 54 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
[261] | 55 | <li><a href="files.html"><span>Files</span></a></li> |
---|
| 56 | </ul> |
---|
| 57 | </div> |
---|
[271] | 58 | <div class="navpath"><a class="el" href="manual.html">User Manual</a> |
---|
| 59 | </div> |
---|
[261] | 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> |
---|
[354] | 63 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <itpp/itbase.h></span> |
---|
[261] | 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> |
---|
[354] | 78 | a = linspace(1.0, 2.0, 10); |
---|
[261] | 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 << <span class="stringliteral">"a = "</span> << a << endl; |
---|
| 88 | cout << <span class="stringliteral">"b = "</span> << b << endl; |
---|
| 89 | cout << <span class="stringliteral">"c = "</span> << c << 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> |
---|
[354] | 95 | B = inv(A); |
---|
[261] | 96 | |
---|
| 97 | <span class="comment">//Print results:</span> |
---|
| 98 | cout << <span class="stringliteral">"A = "</span> << A << endl; |
---|
| 99 | cout << <span class="stringliteral">"B = "</span> << B << endl; |
---|
| 100 | |
---|
| 101 | <span class="comment">//Exit program:</span> |
---|
| 102 | <span class="keywordflow">return</span> 0; |
---|
| 103 | |
---|
| 104 | } |
---|
| 105 | </pre></div><p> |
---|
| 106 | When 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] |
---|
| 108 | b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] |
---|
| 109 | c = [1.1 1.31111 1.52222 1.73333 1.94444 2.15556 2.36667 2.57778 2.78889 3] |
---|
| 110 | A = [[1 2] |
---|
| 111 | [3 4]] |
---|
| 112 | B = [[-2 1] |
---|
| 113 | [1.5 -0.5]] |
---|
| 114 | </pre></div><p> |
---|
| 115 | If this is what you see, then congratulations! You have managed to compile your first it++ program! </div> |
---|
[472] | 116 | <hr size="1"><address style="text-align: right;"><small>Generated on Wed Aug 5 00:06:51 2009 for mixpp by |
---|
[261] | 117 | <a href="http://www.doxygen.org/index.html"> |
---|
[472] | 118 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address> |
---|
[261] | 119 | </body> |
---|
| 120 | </html> |
---|