root/doc/html/vector_and_matrix.html @ 270

Revision 270, 3.4 kB (checked in by smidl, 16 years ago)

Changes in the very root classes!
* rv and rvc are no longer compulsory,
* samplecond does not return ll
* BM has drv

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="doxygen.css" rel="stylesheet" type="text/css">
5<link href="tabs.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.5.6 -->
8<div class="navigation" id="top">
9  <div class="tabs">
10    <ul>
11      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
12      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
13      <li><a href="modules.html"><span>Modules</span></a></li>
14      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
15      <li><a href="classes.html"><span>Classes</span></a></li>
16      <li><a href="files.html"><span>Files</span></a></li>
17    </ul>
18  </div>
19</div>
20<div class="contents">
21<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>
22<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;itpp/itbase.h&gt;</span>
23
24<span class="keyword">using namespace </span>itpp;
25
26<span class="comment">//These lines are needed for use of cout and endl</span>
27<span class="keyword">using</span> std::cout;
28<span class="keyword">using</span> std::endl;
29
30<span class="keywordtype">int</span> main()
31{
32  <span class="comment">//Declare vectors and matricies:</span>
33  vec a, b, c;
34  mat A, B;
35
36  <span class="comment">//Use the function linspace to define a vector:</span>
37  a = linspace(1.0, 2.0, 10);
38
39  <span class="comment">//Use a string of values to define a vector:</span>
40  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>;
41
42  <span class="comment">//Add two vectors:</span>
43  c = a + b;
44
45  <span class="comment">//Print results:</span>
46  cout &lt;&lt; <span class="stringliteral">"a = "</span> &lt;&lt; a &lt;&lt; endl;
47  cout &lt;&lt; <span class="stringliteral">"b = "</span> &lt;&lt; b &lt;&lt; endl;
48  cout &lt;&lt; <span class="stringliteral">"c = "</span> &lt;&lt; c &lt;&lt; endl;
49
50  <span class="comment">//Use a string to define a matrix:</span>
51  A = <span class="stringliteral">"1.0 2.0;3.0 4.0"</span>;
52
53  <span class="comment">//Calculate the inverse of matrix A:</span>
54  B = inv(A);
55
56  <span class="comment">//Print results:</span>
57  cout &lt;&lt; <span class="stringliteral">"A = "</span> &lt;&lt; A &lt;&lt; endl;
58  cout &lt;&lt; <span class="stringliteral">"B = "</span> &lt;&lt; B &lt;&lt; endl;
59
60  <span class="comment">//Exit program:</span>
61  <span class="keywordflow">return</span> 0;
62
63}
64</pre></div><p>
65When you run this program, the output shall look like this<p>
66<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]
67b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]
68c = [1.1 1.31111 1.52222 1.73333 1.94444 2.15556 2.36667 2.57778 2.78889 3]
69A = [[1 2]
70 [3 4]]
71B = [[-2 1]
72 [1.5 -0.5]]
73</pre></div><p>
74If this is what you see, then congratulations! You have managed to compile your first it++ program! </div>
75<hr size="1"><address style="text-align: right;"><small>Generated on Wed Feb 11 23:33:57 2009 for mixpp by&nbsp;
76<a href="http://www.doxygen.org/index.html">
77<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
78</body>
79</html>
Note: See TracBrowser for help on using the browser.