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