1 | | Let's start with a really simple example. Try to complile the following program: |
2 | | |
3 | | |
4 | | |
5 | | \begin{DocInclude}\begin{verbatim}#include <itpp/itbase.h> |
6 | | |
7 | | using namespace itpp; |
8 | | |
9 | | //These lines are needed for use of cout and endl |
10 | | using std::cout; |
11 | | using std::endl; |
12 | | |
13 | | int main() |
14 | | { |
15 | | //Declare vectors and matricies: |
16 | | vec a, b, c; |
17 | | mat A, B; |
18 | | |
19 | | //Use the function linspace to define a vector: |
20 | | a = linspace(1.0, 2.0, 10); |
21 | | |
22 | | //Use a string of values to define a vector: |
23 | | b = "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0"; |
24 | | |
25 | | //Add two vectors: |
26 | | c = a + b; |
27 | | |
28 | | //Print results: |
29 | | cout << "a = " << a << endl; |
30 | | cout << "b = " << b << endl; |
31 | | cout << "c = " << c << endl; |
32 | | |
33 | | //Use a string to define a matrix: |
34 | | A = "1.0 2.0;3.0 4.0"; |
35 | | |
36 | | //Calculate the inverse of matrix A: |
37 | | B = inv(A); |
38 | | |
39 | | //Print results: |
40 | | cout << "A = " << A << endl; |
41 | | cout << "B = " << B << endl; |
42 | | |
43 | | //Exit program: |
44 | | return 0; |
45 | | |
46 | | } |
47 | | \end{verbatim} |
48 | | \end{DocInclude} |
49 | | |
50 | | |
51 | | When you run this program, the output shall look like this |
52 | | |
53 | | |
54 | | |
55 | | \begin{DocInclude}\begin{verbatim}a = [1 1.11111 1.22222 1.33333 1.44444 1.55556 1.66667 1.77778 1.88889 2] |
56 | | b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] |
57 | | c = [1.1 1.31111 1.52222 1.73333 1.94444 2.15556 2.36667 2.57778 2.78889 3] |
58 | | A = [[1 2] |
59 | | [3 4]] |
60 | | B = [[-2 1] |
61 | | [1.5 -0.5]] |
62 | | \end{verbatim} |
63 | | \end{DocInclude} |
64 | | |
65 | | |
66 | | If this is what you see, then congratulations! You have managed to compile your first it++ program! |