diff options
author | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2010-07-12 22:45:57 +0100 |
---|---|---|
committer | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2010-07-12 22:45:57 +0100 |
commit | 140ad0908d9646c3c44dfe65ee4274c12c324770 (patch) | |
tree | a1f345d22368148e2b1dd45e01f13f09eac8f407 /doc/examples | |
parent | 8e776c94c173e3c8ea7ec32648f8b2f09bf09b37 (diff) |
Tutorial page 3: add more cwise operations, condense rest.
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_accessors.cpp | 8 | ||||
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_addition.cpp | 9 | ||||
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_addition_scalar.cpp | 17 | ||||
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_cwise_other.cpp | 19 | ||||
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_interop.cpp | 20 | ||||
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_interop_array.cpp | 34 | ||||
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_interop_matrix.cpp | 25 | ||||
-rw-r--r-- | doc/examples/Tutorial_ArrayClass_mult.cpp | 6 |
8 files changed, 36 insertions, 102 deletions
diff --git a/doc/examples/Tutorial_ArrayClass_accessors.cpp b/doc/examples/Tutorial_ArrayClass_accessors.cpp index 812ba61a4..dc720ff58 100644 --- a/doc/examples/Tutorial_ArrayClass_accessors.cpp +++ b/doc/examples/Tutorial_ArrayClass_accessors.cpp @@ -8,17 +8,17 @@ int main() { ArrayXXf m(2,2); - //assign some values coefficient by coefficient + // assign some values coefficient by coefficient m(0,0) = 1.0; m(0,1) = 2.0; - m(1,0) = 3.0; m(1,1) = 4.0; + m(1,0) = 3.0; m(1,1) = m(0,1) + m(1,0); - //print values to standard output + // print values to standard output cout << m << endl << endl; // using the comma-initializer is also allowed m << 1.0,2.0, 3.0,4.0; - //print values to standard output + // print values to standard output cout << m << endl; } diff --git a/doc/examples/Tutorial_ArrayClass_addition.cpp b/doc/examples/Tutorial_ArrayClass_addition.cpp index eae1957bd..480ffb00f 100644 --- a/doc/examples/Tutorial_ArrayClass_addition.cpp +++ b/doc/examples/Tutorial_ArrayClass_addition.cpp @@ -8,15 +8,16 @@ int main() { ArrayXXf a(3,3); ArrayXXf b(3,3); - a << 1,2,3, 4,5,6, 7,8,9; - b << 1,2,3, 1,2,3, 1,2,3; - cout << "a + b = " << endl - << a + b << endl; + // Adding two arrays + cout << "a + b = " << endl << a + b << endl << endl; + + // Subtracting a scalar from an array + cout << "a - 2 = " << endl << a - 2 << endl; } diff --git a/doc/examples/Tutorial_ArrayClass_addition_scalar.cpp b/doc/examples/Tutorial_ArrayClass_addition_scalar.cpp deleted file mode 100644 index 1c2665287..000000000 --- a/doc/examples/Tutorial_ArrayClass_addition_scalar.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include <Eigen/Dense> -#include <iostream> - -using namespace Eigen; -using namespace std; - -int main() -{ - ArrayXXf a(3,3); - - a << 1,2,3, - 4,5,6, - 7,8,9; - - cout << "a + 2 = " << endl - << a + 2 << endl; -} diff --git a/doc/examples/Tutorial_ArrayClass_cwise_other.cpp b/doc/examples/Tutorial_ArrayClass_cwise_other.cpp new file mode 100644 index 000000000..d9046c63d --- /dev/null +++ b/doc/examples/Tutorial_ArrayClass_cwise_other.cpp @@ -0,0 +1,19 @@ +#include <Eigen/Dense> +#include <iostream> + +using namespace Eigen; +using namespace std; + +int main() +{ + ArrayXf a = ArrayXf::Random(5); + a *= 2; + cout << "a =" << endl + << a << endl; + cout << "a.abs() =" << endl + << a.abs() << endl; + cout << "a.abs().sqrt() =" << endl + << a.abs().sqrt() << endl; + cout << "a.min(a.abs().sqrt()) =" << endl + << a.min(a.abs().sqrt()) << endl; +} diff --git a/doc/examples/Tutorial_ArrayClass_interop.cpp b/doc/examples/Tutorial_ArrayClass_interop.cpp index 72ac5d307..371f07068 100644 --- a/doc/examples/Tutorial_ArrayClass_interop.cpp +++ b/doc/examples/Tutorial_ArrayClass_interop.cpp @@ -8,31 +8,15 @@ int main() { MatrixXf m(2,2); MatrixXf n(2,2); - MatrixXf result(2,2); - //initialize matrices m << 1,2, 3,4; - n << 5,6, 7,8; - // mix of array and matrix operations - // first coefficient-wise addition - // then the result is used with matrix multiplication result = (m.array() + 4).matrix() * m; - - cout << "-- Combination 1: --" << endl - << result << endl << endl; - - - // mix of array and matrix operations - // first coefficient-wise multiplication - // then the result is used with matrix multiplication + cout << "-- Combination 1: --" << endl << result << endl << endl; result = (m.array() * n.array()).matrix() * m; - - cout << "-- Combination 2: --" << endl - << result << endl << endl; - + cout << "-- Combination 2: --" << endl << result << endl << endl; } diff --git a/doc/examples/Tutorial_ArrayClass_interop_array.cpp b/doc/examples/Tutorial_ArrayClass_interop_array.cpp deleted file mode 100644 index c2cb6bf3f..000000000 --- a/doc/examples/Tutorial_ArrayClass_interop_array.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include <Eigen/Dense> -#include <iostream> - -using namespace Eigen; -using namespace std; - -int main() -{ - ArrayXXf m(2,2); - ArrayXXf n(2,2); - - ArrayXXf result(2,2); - - //initialize arrays - m << 1,2, - 3,4; - - n << 5,6, - 7,8; - - - // --> array multiplication - result = m * n; - - cout << "-- Array m*n: --" << endl - << result << endl << endl; - - - // --> Matrix multiplication - result = m.matrix() * n.matrix(); - - cout << "-- Matrix m*n: --" << endl - << result << endl << endl; -} diff --git a/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp index b3d48b6ae..101427511 100644 --- a/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp +++ b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp @@ -8,34 +8,19 @@ int main() { MatrixXf m(2,2); MatrixXf n(2,2); - MatrixXf result(2,2); - //initialize matrices m << 1,2, 3,4; - n << 5,6, 7,8; - - // --> matrix multiplication result = m * n; - - cout << "-- Matrix m*n: --" << endl - << result << endl << endl; - - - // --> coeff-wise multiplication + cout << "-- Matrix m*n: --" << endl << result << endl << endl; result = m.array() * n.array(); - - cout << "-- Array m*n: --" << endl - << result << endl << endl; - - - // ->> coeff-wise addition of a scalar + cout << "-- Array m*n: --" << endl << result << endl << endl; + result = m.cwiseProduct(n); + cout << "-- With cwiseProduct: --" << endl << result << endl << endl; result = m.array() + 4; - - cout << "-- Array m + 4: --" << endl - << result << endl << endl; + cout << "-- Array m + 4: --" << endl << result << endl << endl; } diff --git a/doc/examples/Tutorial_ArrayClass_mult.cpp b/doc/examples/Tutorial_ArrayClass_mult.cpp index 27c83e040..6cb439ff7 100644 --- a/doc/examples/Tutorial_ArrayClass_mult.cpp +++ b/doc/examples/Tutorial_ArrayClass_mult.cpp @@ -8,13 +8,9 @@ int main() { ArrayXXf a(2,2); ArrayXXf b(2,2); - a << 1,2, 3,4; - b << 5,6, 7,8; - - cout << "a * b = " << endl - << a * b << endl; + cout << "a * b = " << endl << a * b << endl; } |