Changeset 1064 for library/doc
- Timestamp:
- 06/09/10 14:00:40 (15 years ago)
- Location:
- library/doc/tutorial/src
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/doc/tutorial/src/timer.cpp
r477 r1064 8 8 9 9 int main() { 10 11 10 //Declare the scalars used: 11 long i, sum, N; 12 12 13 14 13 //Declare tt as an instance of the timer class: 14 Real_Timer tt; 15 15 16 17 18 16 //Initiate the variables: 17 N = 1000000; 18 sum = 0; 19 19 20 21 20 //Start and reset the timer: 21 tt.tic(); 22 22 23 24 25 26 23 //Do some processing 24 for ( i = 0; i < N; i++ ) { 25 sum += i; 26 } 27 27 28 29 28 // Print the elapsed time 29 tt.toc_print(); 30 30 31 32 31 //Print the result of the processing: 32 cout << "The sum of all integers from 0 to " << N - 1 << " equals " << sum << endl; 33 33 34 35 34 //Exit program: 35 return 0; 36 36 37 37 } -
library/doc/tutorial/src/vector_and_matrix.cpp
r477 r1064 8 8 9 9 int main() { 10 11 12 10 //Declare vectors and matricies: 11 vec a, b, c; 12 mat A, B; 13 13 14 15 14 //Use the function linspace to define a vector: 15 a = linspace ( 1.0, 2.0, 10 ); 16 16 17 18 17 //Use a string of values to define a vector: 18 b = "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0"; 19 19 20 21 20 //Add two vectors: 21 c = a + b; 22 22 23 24 25 26 23 //Print results: 24 cout << "a = " << a << endl; 25 cout << "b = " << b << endl; 26 cout << "c = " << c << endl; 27 27 28 29 28 //Use a string to define a matrix: 29 A = "1.0 2.0;3.0 4.0"; 30 30 31 32 31 //Calculate the inverse of matrix A: 32 B = inv ( A ); 33 33 34 35 36 34 //Print results: 35 cout << "A = " << A << endl; 36 cout << "B = " << B << endl; 37 37 38 39 38 //Exit program: 39 return 0; 40 40 41 41 } -
library/doc/tutorial/src/write_it_file.cpp
r477 r1064 4 4 5 5 int main() { 6 7 6 // Declare the it_file class 7 it_file ff; 8 8 9 10 9 // Open a file with the name "it_file_test.it" 10 ff.open ( "it_file_test.it" ); 11 11 12 13 12 // Create some data to put into the file 13 vec a = linspace ( 1, 20, 20 ); 14 14 15 16 17 15 // Put the variable a into the file. The Name("a") tells the file class 16 // that the next variable shall be named "a". 17 ff << Name ( "a" ) << a; 18 18 19 20 21 22 19 // Force the file to be written to disc. This is useful when performing 20 // iterations and ensures that the information is not stored in any cache 21 // memory. In this simple example it is not necessary to flush the file. 22 ff.flush(); 23 23 24 25 24 // Close the file 25 ff.close(); 26 26 27 28 27 // Exit program 28 return 0; 29 29 }