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