aboutsummaryrefslogtreecommitdiff
path: root/doc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/.krazy2
-rw-r--r--doc/examples/CMakeLists.txt20
-rw-r--r--doc/examples/DenseBase_middleCols_int.cpp15
-rw-r--r--doc/examples/DenseBase_middleRows_int.cpp15
-rw-r--r--doc/examples/DenseBase_template_int_middleCols.cpp15
-rw-r--r--doc/examples/DenseBase_template_int_middleRows.cpp15
-rw-r--r--doc/examples/MatrixBase_cwise_const.cpp18
-rw-r--r--doc/examples/QuickStart_example.cpp14
-rw-r--r--doc/examples/QuickStart_example2_dynamic.cpp15
-rw-r--r--doc/examples/QuickStart_example2_fixed.cpp15
-rw-r--r--doc/examples/TemplateKeyword_flexible.cpp22
-rw-r--r--doc/examples/TemplateKeyword_simple.cpp20
-rw-r--r--doc/examples/TutorialLinAlgComputeTwice.cpp23
-rw-r--r--doc/examples/TutorialLinAlgExComputeSolveError.cpp14
-rw-r--r--doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp17
-rw-r--r--doc/examples/TutorialLinAlgExSolveLDLT.cpp16
-rw-r--r--doc/examples/TutorialLinAlgInverseDeterminant.cpp16
-rw-r--r--doc/examples/TutorialLinAlgRankRevealing.cpp20
-rw-r--r--doc/examples/TutorialLinAlgSVDSolve.cpp15
-rw-r--r--doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp18
-rw-r--r--doc/examples/TutorialLinAlgSetThreshold.cpp16
-rw-r--r--doc/examples/Tutorial_ArrayClass_accessors.cpp24
-rw-r--r--doc/examples/Tutorial_ArrayClass_addition.cpp23
-rw-r--r--doc/examples/Tutorial_ArrayClass_cwise_other.cpp19
-rw-r--r--doc/examples/Tutorial_ArrayClass_interop.cpp22
-rw-r--r--doc/examples/Tutorial_ArrayClass_interop_matrix.cpp26
-rw-r--r--doc/examples/Tutorial_ArrayClass_mult.cpp16
-rw-r--r--doc/examples/Tutorial_BlockOperations_block_assignment.cpp18
-rw-r--r--doc/examples/Tutorial_BlockOperations_colrow.cpp17
-rw-r--r--doc/examples/Tutorial_BlockOperations_corner.cpp17
-rw-r--r--doc/examples/Tutorial_BlockOperations_print_block.cpp20
-rw-r--r--doc/examples/Tutorial_BlockOperations_vector.cpp14
-rw-r--r--doc/examples/Tutorial_PartialLU_solve.cpp18
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp24
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple.cpp21
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple_rowwise.cpp20
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_colwise.cpp13
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp20
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp21
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp28
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_rowwise.cpp13
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp26
-rw-r--r--doc/examples/Tutorial_simple_example_dynamic_size.cpp22
-rw-r--r--doc/examples/Tutorial_simple_example_fixed_size.cpp15
-rw-r--r--doc/examples/class_Block.cpp27
-rw-r--r--doc/examples/class_CwiseBinaryOp.cpp18
-rw-r--r--doc/examples/class_CwiseUnaryOp.cpp19
-rw-r--r--doc/examples/class_CwiseUnaryOp_ptrfun.cpp20
-rw-r--r--doc/examples/class_FixedBlock.cpp27
-rw-r--r--doc/examples/class_FixedVectorBlock.cpp27
-rw-r--r--doc/examples/class_VectorBlock.cpp27
-rw-r--r--doc/examples/function_taking_eigenbase.cpp18
-rw-r--r--doc/examples/tut_arithmetic_add_sub.cpp22
-rw-r--r--doc/examples/tut_arithmetic_dot_cross.cpp15
-rw-r--r--doc/examples/tut_arithmetic_matrix_mul.cpp19
-rw-r--r--doc/examples/tut_arithmetic_redux_basic.cpp16
-rw-r--r--doc/examples/tut_arithmetic_scalar_mul_div.cpp17
-rw-r--r--doc/examples/tut_matrix_coefficient_accessors.cpp18
-rw-r--r--doc/examples/tut_matrix_resize.cpp18
-rw-r--r--doc/examples/tut_matrix_resize_fixed_size.cpp12
60 files changed, 1118 insertions, 0 deletions
diff --git a/doc/examples/.krazy b/doc/examples/.krazy
new file mode 100644
index 000000000..00b99405d
--- /dev/null
+++ b/doc/examples/.krazy
@@ -0,0 +1,2 @@
+EXCLUDE copyright
+EXCLUDE license
diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt
new file mode 100644
index 000000000..13ec0c123
--- /dev/null
+++ b/doc/examples/CMakeLists.txt
@@ -0,0 +1,20 @@
+file(GLOB examples_SRCS "*.cpp")
+
+add_custom_target(all_examples)
+
+foreach(example_src ${examples_SRCS})
+ get_filename_component(example ${example_src} NAME_WE)
+ add_executable(${example} ${example_src})
+ if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
+ target_link_libraries(${example} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
+ endif()
+ get_target_property(example_executable
+ ${example} LOCATION)
+ add_custom_command(
+ TARGET ${example}
+ POST_BUILD
+ COMMAND ${example_executable}
+ ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out
+ )
+ add_dependencies(all_examples ${example})
+endforeach(example_src)
diff --git a/doc/examples/DenseBase_middleCols_int.cpp b/doc/examples/DenseBase_middleCols_int.cpp
new file mode 100644
index 000000000..0ebd955ec
--- /dev/null
+++ b/doc/examples/DenseBase_middleCols_int.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(1..3,:) =\n" << A.middleCols(1,3) << endl;
+ return 0;
+}
diff --git a/doc/examples/DenseBase_middleRows_int.cpp b/doc/examples/DenseBase_middleRows_int.cpp
new file mode 100644
index 000000000..a6fe9e844
--- /dev/null
+++ b/doc/examples/DenseBase_middleRows_int.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(2..3,:) =\n" << A.middleRows(2,2) << endl;
+ return 0;
+}
diff --git a/doc/examples/DenseBase_template_int_middleCols.cpp b/doc/examples/DenseBase_template_int_middleCols.cpp
new file mode 100644
index 000000000..6191d79c8
--- /dev/null
+++ b/doc/examples/DenseBase_template_int_middleCols.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(:,1..3) =\n" << A.middleCols<3>(1) << endl;
+ return 0;
+}
diff --git a/doc/examples/DenseBase_template_int_middleRows.cpp b/doc/examples/DenseBase_template_int_middleRows.cpp
new file mode 100644
index 000000000..7e8b6573f
--- /dev/null
+++ b/doc/examples/DenseBase_template_int_middleRows.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(1..3,:) =\n" << A.middleRows<3>(1) << endl;
+ return 0;
+}
diff --git a/doc/examples/MatrixBase_cwise_const.cpp b/doc/examples/MatrixBase_cwise_const.cpp
new file mode 100644
index 000000000..23700e0b6
--- /dev/null
+++ b/doc/examples/MatrixBase_cwise_const.cpp
@@ -0,0 +1,18 @@
+#define EIGEN2_SUPPORT
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main()
+{
+ Matrix3i m = Matrix3i::Random();
+ cout << "Here is the matrix m:" << endl << m << endl;
+ Matrix3i n = Matrix3i::Random();
+ cout << "And here is the matrix n:" << endl << n << endl;
+ cout << "The coefficient-wise product of m and n is:" << endl;
+ cout << m.cwise() * n << endl;
+ cout << "Taking the cube of the coefficients of m yields:" << endl;
+ cout << m.cwise().pow(3) << endl;
+}
diff --git a/doc/examples/QuickStart_example.cpp b/doc/examples/QuickStart_example.cpp
new file mode 100644
index 000000000..7238c0c43
--- /dev/null
+++ b/doc/examples/QuickStart_example.cpp
@@ -0,0 +1,14 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using Eigen::MatrixXd;
+
+int main()
+{
+ MatrixXd m(2,2);
+ m(0,0) = 3;
+ m(1,0) = 2.5;
+ m(0,1) = -1;
+ m(1,1) = m(1,0) + m(0,1);
+ std::cout << m << std::endl;
+}
diff --git a/doc/examples/QuickStart_example2_dynamic.cpp b/doc/examples/QuickStart_example2_dynamic.cpp
new file mode 100644
index 000000000..672ac82e9
--- /dev/null
+++ b/doc/examples/QuickStart_example2_dynamic.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+using namespace std;
+
+int main()
+{
+ MatrixXf m = MatrixXf::Random(3,3);
+ m = (m + MatrixXf::Constant(3,3,1.2)) * 50;
+ cout << "m =" << endl << m << endl;
+ VectorXf v(3);
+ v << 1, 2, 3;
+ cout << "m * v =" << endl << m * v << endl;
+}
diff --git a/doc/examples/QuickStart_example2_fixed.cpp b/doc/examples/QuickStart_example2_fixed.cpp
new file mode 100644
index 000000000..edf3268cd
--- /dev/null
+++ b/doc/examples/QuickStart_example2_fixed.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+using namespace std;
+
+int main()
+{
+ Matrix3f m = Matrix3f::Random();
+ m = (m + Matrix3f::Constant(1.2)) * 50;
+ cout << "m =" << endl << m << endl;
+ Vector3f v(1,2,3);
+
+ cout << "m * v =" << endl << m * v << endl;
+}
diff --git a/doc/examples/TemplateKeyword_flexible.cpp b/doc/examples/TemplateKeyword_flexible.cpp
new file mode 100644
index 000000000..9d85292dd
--- /dev/null
+++ b/doc/examples/TemplateKeyword_flexible.cpp
@@ -0,0 +1,22 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+
+template <typename Derived1, typename Derived2>
+void copyUpperTriangularPart(MatrixBase<Derived1>& dst, const MatrixBase<Derived2>& src)
+{
+ /* Note the 'template' keywords in the following line! */
+ dst.template triangularView<Upper>() = src.template triangularView<Upper>();
+}
+
+int main()
+{
+ MatrixXi m1 = MatrixXi::Ones(5,5);
+ MatrixXi m2 = MatrixXi::Random(4,4);
+ std::cout << "m2 before copy:" << std::endl;
+ std::cout << m2 << std::endl << std::endl;
+ copyUpperTriangularPart(m2, m1.topLeftCorner(4,4));
+ std::cout << "m2 after copy:" << std::endl;
+ std::cout << m2 << std::endl << std::endl;
+}
diff --git a/doc/examples/TemplateKeyword_simple.cpp b/doc/examples/TemplateKeyword_simple.cpp
new file mode 100644
index 000000000..6998c1769
--- /dev/null
+++ b/doc/examples/TemplateKeyword_simple.cpp
@@ -0,0 +1,20 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+
+void copyUpperTriangularPart(MatrixXf& dst, const MatrixXf& src)
+{
+ dst.triangularView<Upper>() = src.triangularView<Upper>();
+}
+
+int main()
+{
+ MatrixXf m1 = MatrixXf::Ones(4,4);
+ MatrixXf m2 = MatrixXf::Random(4,4);
+ std::cout << "m2 before copy:" << std::endl;
+ std::cout << m2 << std::endl << std::endl;
+ copyUpperTriangularPart(m2, m1);
+ std::cout << "m2 after copy:" << std::endl;
+ std::cout << m2 << std::endl << std::endl;
+}
diff --git a/doc/examples/TutorialLinAlgComputeTwice.cpp b/doc/examples/TutorialLinAlgComputeTwice.cpp
new file mode 100644
index 000000000..06ba6461a
--- /dev/null
+++ b/doc/examples/TutorialLinAlgComputeTwice.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix2f A, b;
+ LLT<Matrix2f> llt;
+ A << 2, -1, -1, 3;
+ b << 1, 2, 3, 1;
+ cout << "Here is the matrix A:\n" << A << endl;
+ cout << "Here is the right hand side b:\n" << b << endl;
+ cout << "Computing LLT decomposition..." << endl;
+ llt.compute(A);
+ cout << "The solution is:\n" << llt.solve(b) << endl;
+ A(1,1)++;
+ cout << "The matrix A is now:\n" << A << endl;
+ cout << "Computing LLT decomposition..." << endl;
+ llt.compute(A);
+ cout << "The solution is now:\n" << llt.solve(b) << endl;
+}
diff --git a/doc/examples/TutorialLinAlgExComputeSolveError.cpp b/doc/examples/TutorialLinAlgExComputeSolveError.cpp
new file mode 100644
index 000000000..f362fb71a
--- /dev/null
+++ b/doc/examples/TutorialLinAlgExComputeSolveError.cpp
@@ -0,0 +1,14 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ MatrixXd A = MatrixXd::Random(100,100);
+ MatrixXd b = MatrixXd::Random(100,50);
+ MatrixXd x = A.fullPivLu().solve(b);
+ double relative_error = (A*x - b).norm() / b.norm(); // norm() is L2 norm
+ cout << "The relative error is:\n" << relative_error << endl;
+}
diff --git a/doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp b/doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp
new file mode 100644
index 000000000..3a99a94d7
--- /dev/null
+++ b/doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix3f A;
+ Vector3f b;
+ A << 1,2,3, 4,5,6, 7,8,10;
+ b << 3, 3, 4;
+ cout << "Here is the matrix A:\n" << A << endl;
+ cout << "Here is the vector b:\n" << b << endl;
+ Vector3f x = A.colPivHouseholderQr().solve(b);
+ cout << "The solution is:\n" << x << endl;
+}
diff --git a/doc/examples/TutorialLinAlgExSolveLDLT.cpp b/doc/examples/TutorialLinAlgExSolveLDLT.cpp
new file mode 100644
index 000000000..f8beacd27
--- /dev/null
+++ b/doc/examples/TutorialLinAlgExSolveLDLT.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix2f A, b;
+ A << 2, -1, -1, 3;
+ b << 1, 2, 3, 1;
+ cout << "Here is the matrix A:\n" << A << endl;
+ cout << "Here is the right hand side b:\n" << b << endl;
+ Matrix2f x = A.ldlt().solve(b);
+ cout << "The solution is:\n" << x << endl;
+}
diff --git a/doc/examples/TutorialLinAlgInverseDeterminant.cpp b/doc/examples/TutorialLinAlgInverseDeterminant.cpp
new file mode 100644
index 000000000..43970ff05
--- /dev/null
+++ b/doc/examples/TutorialLinAlgInverseDeterminant.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix3f A;
+ A << 1, 2, 1,
+ 2, 1, 0,
+ -1, 1, 2;
+ cout << "Here is the matrix A:\n" << A << endl;
+ cout << "The determinant of A is " << A.determinant() << endl;
+ cout << "The inverse of A is:\n" << A.inverse() << endl;
+} \ No newline at end of file
diff --git a/doc/examples/TutorialLinAlgRankRevealing.cpp b/doc/examples/TutorialLinAlgRankRevealing.cpp
new file mode 100644
index 000000000..c5165077f
--- /dev/null
+++ b/doc/examples/TutorialLinAlgRankRevealing.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix3f A;
+ A << 1, 2, 5,
+ 2, 1, 4,
+ 3, 0, 3;
+ cout << "Here is the matrix A:\n" << A << endl;
+ FullPivLU<Matrix3f> lu_decomp(A);
+ cout << "The rank of A is " << lu_decomp.rank() << endl;
+ cout << "Here is a matrix whose columns form a basis of the null-space of A:\n"
+ << lu_decomp.kernel() << endl;
+ cout << "Here is a matrix whose columns form a basis of the column-space of A:\n"
+ << lu_decomp.image(A) << endl; // yes, have to pass the original A
+}
diff --git a/doc/examples/TutorialLinAlgSVDSolve.cpp b/doc/examples/TutorialLinAlgSVDSolve.cpp
new file mode 100644
index 000000000..9fbc031de
--- /dev/null
+++ b/doc/examples/TutorialLinAlgSVDSolve.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ MatrixXf A = MatrixXf::Random(3, 2);
+ cout << "Here is the matrix A:\n" << A << endl;
+ VectorXf b = VectorXf::Random(3);
+ cout << "Here is the right hand side b:\n" << b << endl;
+ cout << "The least-squares solution is:\n"
+ << A.jacobiSvd(ComputeThinU | ComputeThinV).solve(b) << endl;
+}
diff --git a/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp b/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp
new file mode 100644
index 000000000..8d1d1ed65
--- /dev/null
+++ b/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix2f A;
+ A << 1, 2, 2, 3;
+ cout << "Here is the matrix A:\n" << A << endl;
+ SelfAdjointEigenSolver<Matrix2f> eigensolver(A);
+ if (eigensolver.info() != Success) abort();
+ cout << "The eigenvalues of A are:\n" << eigensolver.eigenvalues() << endl;
+ cout << "Here's a matrix whose columns are eigenvectors of A \n"
+ << "corresponding to these eigenvalues:\n"
+ << eigensolver.eigenvectors() << endl;
+}
diff --git a/doc/examples/TutorialLinAlgSetThreshold.cpp b/doc/examples/TutorialLinAlgSetThreshold.cpp
new file mode 100644
index 000000000..3956b13a3
--- /dev/null
+++ b/doc/examples/TutorialLinAlgSetThreshold.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix2d A;
+ A << 2, 1,
+ 2, 0.9999999999;
+ FullPivLU<Matrix2d> lu(A);
+ cout << "By default, the rank of A is found to be " << lu.rank() << endl;
+ lu.setThreshold(1e-5);
+ cout << "With threshold 1e-5, the rank of A is found to be " << lu.rank() << endl;
+}
diff --git a/doc/examples/Tutorial_ArrayClass_accessors.cpp b/doc/examples/Tutorial_ArrayClass_accessors.cpp
new file mode 100644
index 000000000..dc720ff58
--- /dev/null
+++ b/doc/examples/Tutorial_ArrayClass_accessors.cpp
@@ -0,0 +1,24 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main()
+{
+ ArrayXXf m(2,2);
+
+ // assign some values coefficient by coefficient
+ m(0,0) = 1.0; m(0,1) = 2.0;
+ m(1,0) = 3.0; m(1,1) = m(0,1) + m(1,0);
+
+ // 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
+ cout << m << endl;
+}
diff --git a/doc/examples/Tutorial_ArrayClass_addition.cpp b/doc/examples/Tutorial_ArrayClass_addition.cpp
new file mode 100644
index 000000000..480ffb00f
--- /dev/null
+++ b/doc/examples/Tutorial_ArrayClass_addition.cpp
@@ -0,0 +1,23 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+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;
+
+ // 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_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
new file mode 100644
index 000000000..371f07068
--- /dev/null
+++ b/doc/examples/Tutorial_ArrayClass_interop.cpp
@@ -0,0 +1,22 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main()
+{
+ MatrixXf m(2,2);
+ MatrixXf n(2,2);
+ MatrixXf result(2,2);
+
+ m << 1,2,
+ 3,4;
+ n << 5,6,
+ 7,8;
+
+ result = (m.array() + 4).matrix() * m;
+ cout << "-- Combination 1: --" << endl << result << endl << endl;
+ result = (m.array() * n.array()).matrix() * m;
+ cout << "-- Combination 2: --" << endl << result << endl << endl;
+}
diff --git a/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp
new file mode 100644
index 000000000..101427511
--- /dev/null
+++ b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp
@@ -0,0 +1,26 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main()
+{
+ MatrixXf m(2,2);
+ MatrixXf n(2,2);
+ MatrixXf result(2,2);
+
+ m << 1,2,
+ 3,4;
+ n << 5,6,
+ 7,8;
+
+ result = m * n;
+ cout << "-- Matrix m*n: --" << endl << result << endl << endl;
+ result = m.array() * n.array();
+ 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;
+}
diff --git a/doc/examples/Tutorial_ArrayClass_mult.cpp b/doc/examples/Tutorial_ArrayClass_mult.cpp
new file mode 100644
index 000000000..6cb439ff7
--- /dev/null
+++ b/doc/examples/Tutorial_ArrayClass_mult.cpp
@@ -0,0 +1,16 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+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;
+}
diff --git a/doc/examples/Tutorial_BlockOperations_block_assignment.cpp b/doc/examples/Tutorial_BlockOperations_block_assignment.cpp
new file mode 100644
index 000000000..76f49f2fb
--- /dev/null
+++ b/doc/examples/Tutorial_BlockOperations_block_assignment.cpp
@@ -0,0 +1,18 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Array22f m;
+ m << 1,2,
+ 3,4;
+ Array44f a = Array44f::Constant(0.6);
+ cout << "Here is the array a:" << endl << a << endl << endl;
+ a.block<2,2>(1,1) = m;
+ cout << "Here is now a with m copied into its central 2x2 block:" << endl << a << endl << endl;
+ a.block(0,0,2,3) = a.block(2,1,2,3);
+ cout << "Here is now a with bottom-right 2x3 block copied into top-left 2x2 block:" << endl << a << endl << endl;
+}
diff --git a/doc/examples/Tutorial_BlockOperations_colrow.cpp b/doc/examples/Tutorial_BlockOperations_colrow.cpp
new file mode 100644
index 000000000..2e7eb009b
--- /dev/null
+++ b/doc/examples/Tutorial_BlockOperations_colrow.cpp
@@ -0,0 +1,17 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ Eigen::MatrixXf m(3,3);
+ m << 1,2,3,
+ 4,5,6,
+ 7,8,9;
+ cout << "Here is the matrix m:" << endl << m << endl;
+ cout << "2nd Row: " << m.row(1) << endl;
+ m.col(2) += 3 * m.col(0);
+ cout << "After adding 3 times the first column into the third column, the matrix m is:\n";
+ cout << m << endl;
+}
diff --git a/doc/examples/Tutorial_BlockOperations_corner.cpp b/doc/examples/Tutorial_BlockOperations_corner.cpp
new file mode 100644
index 000000000..3a31507aa
--- /dev/null
+++ b/doc/examples/Tutorial_BlockOperations_corner.cpp
@@ -0,0 +1,17 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ Eigen::Matrix4f m;
+ m << 1, 2, 3, 4,
+ 5, 6, 7, 8,
+ 9, 10,11,12,
+ 13,14,15,16;
+ cout << "m.leftCols(2) =" << endl << m.leftCols(2) << endl << endl;
+ cout << "m.bottomRows<2>() =" << endl << m.bottomRows<2>() << endl << endl;
+ m.topLeftCorner(1,3) = m.bottomRightCorner(3,1).transpose();
+ cout << "After assignment, m = " << endl << m << endl;
+}
diff --git a/doc/examples/Tutorial_BlockOperations_print_block.cpp b/doc/examples/Tutorial_BlockOperations_print_block.cpp
new file mode 100644
index 000000000..edea4aefe
--- /dev/null
+++ b/doc/examples/Tutorial_BlockOperations_print_block.cpp
@@ -0,0 +1,20 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ Eigen::MatrixXf m(4,4);
+ m << 1, 2, 3, 4,
+ 5, 6, 7, 8,
+ 9,10,11,12,
+ 13,14,15,16;
+ cout << "Block in the middle" << endl;
+ cout << m.block<2,2>(1,1) << endl << endl;
+ for (int i = 1; i <= 3; ++i)
+ {
+ cout << "Block of size " << i << "x" << i << endl;
+ cout << m.block(0,0,i,i) << endl << endl;
+ }
+}
diff --git a/doc/examples/Tutorial_BlockOperations_vector.cpp b/doc/examples/Tutorial_BlockOperations_vector.cpp
new file mode 100644
index 000000000..4a0b02342
--- /dev/null
+++ b/doc/examples/Tutorial_BlockOperations_vector.cpp
@@ -0,0 +1,14 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ Eigen::ArrayXf v(6);
+ v << 1, 2, 3, 4, 5, 6;
+ cout << "v.head(3) =" << endl << v.head(3) << endl << endl;
+ cout << "v.tail<3>() = " << endl << v.tail<3>() << endl << endl;
+ v.segment(1,4) *= 2;
+ cout << "after 'v.segment(1,4) *= 2', v =" << endl << v << endl;
+}
diff --git a/doc/examples/Tutorial_PartialLU_solve.cpp b/doc/examples/Tutorial_PartialLU_solve.cpp
new file mode 100644
index 000000000..a5608792f
--- /dev/null
+++ b/doc/examples/Tutorial_PartialLU_solve.cpp
@@ -0,0 +1,18 @@
+#include <Eigen/Core>
+#include <Eigen/LU>
+#include <iostream>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Matrix3f A;
+ Vector3f b;
+ A << 1,2,3, 4,5,6, 7,8,10;
+ b << 3, 3, 4;
+ cout << "Here is the matrix A:" << endl << A << endl;
+ cout << "Here is the vector b:" << endl << b << endl;
+ Vector3f x = A.lu().solve(b);
+ cout << "The solution is:" << endl << x << endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp
new file mode 100644
index 000000000..334b4d852
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp
@@ -0,0 +1,24 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Eigen::MatrixXf m(2,4);
+ Eigen::VectorXf v(2);
+
+ m << 1, 23, 6, 9,
+ 3, 11, 7, 2;
+
+ v << 2,
+ 3;
+
+ MatrixXf::Index index;
+ // find nearest neighbour
+ (m.colwise() - v).colwise().squaredNorm().minCoeff(&index);
+
+ cout << "Nearest neighbour is column " << index << ":" << endl;
+ cout << m.col(index) << endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple.cpp
new file mode 100644
index 000000000..e6c87c6a4
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+int main()
+{
+ Eigen::MatrixXf mat(2,4);
+ Eigen::VectorXf v(2);
+
+ mat << 1, 2, 6, 9,
+ 3, 1, 7, 2;
+
+ v << 0,
+ 1;
+
+ //add v to each column of m
+ mat.colwise() += v;
+
+ std::cout << "Broadcasting result: " << std::endl;
+ std::cout << mat << std::endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple_rowwise.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple_rowwise.cpp
new file mode 100644
index 000000000..d87c96ab1
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple_rowwise.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+int main()
+{
+ Eigen::MatrixXf mat(2,4);
+ Eigen::VectorXf v(4);
+
+ mat << 1, 2, 6, 9,
+ 3, 1, 7, 2;
+
+ v << 0,1,2,3;
+
+ //add v to each row of m
+ mat.rowwise() += v.transpose();
+
+ std::cout << "Broadcasting result: " << std::endl;
+ std::cout << mat << std::endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_colwise.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_colwise.cpp
new file mode 100644
index 000000000..df6825663
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_colwise.cpp
@@ -0,0 +1,13 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+int main()
+{
+ Eigen::MatrixXf mat(2,4);
+ mat << 1, 2, 6, 9,
+ 3, 1, 7, 2;
+
+ std::cout << "Column's maximum: " << std::endl
+ << mat.colwise().maxCoeff() << std::endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp
new file mode 100644
index 000000000..049c747b0
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+int main()
+{
+ MatrixXf mat(2,4);
+ mat << 1, 2, 6, 9,
+ 3, 1, 7, 2;
+
+ MatrixXf::Index maxIndex;
+ float maxNorm = mat.colwise().sum().maxCoeff(&maxIndex);
+
+ std::cout << "Maximum sum at position " << maxIndex << std::endl;
+
+ std::cout << "The corresponding vector is: " << std::endl;
+ std::cout << mat.col( maxIndex ) << std::endl;
+ std::cout << "And its sum is is: " << maxNorm << std::endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp
new file mode 100644
index 000000000..0cca37f36
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp
@@ -0,0 +1,21 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ ArrayXXf a(2,2);
+
+ a << 1,2,
+ 3,4;
+
+ cout << "(a > 0).all() = " << (a > 0).all() << endl;
+ cout << "(a > 0).any() = " << (a > 0).any() << endl;
+ cout << "(a > 0).count() = " << (a > 0).count() << endl;
+ cout << endl;
+ cout << "(a > 2).all() = " << (a > 2).all() << endl;
+ cout << "(a > 2).any() = " << (a > 2).any() << endl;
+ cout << "(a > 2).count() = " << (a > 2).count() << endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp
new file mode 100644
index 000000000..740439fb3
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp
@@ -0,0 +1,28 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ VectorXf v(2);
+ MatrixXf m(2,2), n(2,2);
+
+ v << -1,
+ 2;
+
+ m << 1,-2,
+ -3,4;
+
+ cout << "v.squaredNorm() = " << v.squaredNorm() << endl;
+ cout << "v.norm() = " << v.norm() << endl;
+ cout << "v.lpNorm<1>() = " << v.lpNorm<1>() << endl;
+ cout << "v.lpNorm<Infinity>() = " << v.lpNorm<Infinity>() << endl;
+
+ cout << endl;
+ cout << "m.squaredNorm() = " << m.squaredNorm() << endl;
+ cout << "m.norm() = " << m.norm() << endl;
+ cout << "m.lpNorm<1>() = " << m.lpNorm<1>() << endl;
+ cout << "m.lpNorm<Infinity>() = " << m.lpNorm<Infinity>() << endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_rowwise.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_rowwise.cpp
new file mode 100644
index 000000000..80427c9f7
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_rowwise.cpp
@@ -0,0 +1,13 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+int main()
+{
+ Eigen::MatrixXf mat(2,4);
+ mat << 1, 2, 6, 9,
+ 3, 1, 7, 2;
+
+ std::cout << "Row's maximum: " << std::endl
+ << mat.rowwise().maxCoeff() << std::endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp
new file mode 100644
index 000000000..b54e9aa31
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ Eigen::MatrixXf m(2,2);
+
+ m << 1, 2,
+ 3, 4;
+
+ //get location of maximum
+ MatrixXf::Index maxRow, maxCol;
+ float max = m.maxCoeff(&maxRow, &maxCol);
+
+ //get location of minimum
+ MatrixXf::Index minRow, minCol;
+ float min = m.minCoeff(&minRow, &minCol);
+
+ cout << "Max: " << max << ", at: " <<
+ maxRow << "," << maxCol << endl;
+ cout << "Min: " << min << ", at: " <<
+ minRow << "," << minCol << endl;
+}
diff --git a/doc/examples/Tutorial_simple_example_dynamic_size.cpp b/doc/examples/Tutorial_simple_example_dynamic_size.cpp
new file mode 100644
index 000000000..0f0280e0e
--- /dev/null
+++ b/doc/examples/Tutorial_simple_example_dynamic_size.cpp
@@ -0,0 +1,22 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+
+int main()
+{
+ for (int size=1; size<=4; ++size)
+ {
+ MatrixXi m(size,size+1); // a (size)x(size+1)-matrix of int's
+ for (int j=0; j<m.cols(); ++j) // loop over columns
+ for (int i=0; i<m.rows(); ++i) // loop over rows
+ m(i,j) = i+j*m.rows(); // to access matrix coefficients,
+ // use operator()(int,int)
+ std::cout << m << "\n\n";
+ }
+
+ VectorXf v(4); // a vector of 4 float's
+ // to access vector coefficients, use either operator () or operator []
+ v[0] = 1; v[1] = 2; v(2) = 3; v(3) = 4;
+ std::cout << "\nv:\n" << v << std::endl;
+}
diff --git a/doc/examples/Tutorial_simple_example_fixed_size.cpp b/doc/examples/Tutorial_simple_example_fixed_size.cpp
new file mode 100644
index 000000000..bc4f95d79
--- /dev/null
+++ b/doc/examples/Tutorial_simple_example_fixed_size.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+
+int main()
+{
+ Matrix3f m3;
+ m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
+ Matrix4f m4 = Matrix4f::Identity();
+ Vector4i v4(1, 2, 3, 4);
+
+ std::cout << "m3\n" << m3 << "\nm4:\n"
+ << m4 << "\nv4:\n" << v4 << std::endl;
+}
diff --git a/doc/examples/class_Block.cpp b/doc/examples/class_Block.cpp
new file mode 100644
index 000000000..ace719afc
--- /dev/null
+++ b/doc/examples/class_Block.cpp
@@ -0,0 +1,27 @@
+#include <Eigen/Core>
+#include <iostream>
+using namespace Eigen;
+using namespace std;
+
+template<typename Derived>
+Eigen::Block<Derived>
+topLeftCorner(MatrixBase<Derived>& m, int rows, int cols)
+{
+ return Eigen::Block<Derived>(m.derived(), 0, 0, rows, cols);
+}
+
+template<typename Derived>
+const Eigen::Block<const Derived>
+topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols)
+{
+ return Eigen::Block<const Derived>(m.derived(), 0, 0, rows, cols);
+}
+
+int main(int, char**)
+{
+ Matrix4d m = Matrix4d::Identity();
+ cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version
+ topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
+ cout << "Now the matrix m is:" << endl << m << endl;
+ return 0;
+}
diff --git a/doc/examples/class_CwiseBinaryOp.cpp b/doc/examples/class_CwiseBinaryOp.cpp
new file mode 100644
index 000000000..682af46de
--- /dev/null
+++ b/doc/examples/class_CwiseBinaryOp.cpp
@@ -0,0 +1,18 @@
+#include <Eigen/Core>
+#include <iostream>
+using namespace Eigen;
+using namespace std;
+
+// define a custom template binary functor
+template<typename Scalar> struct MakeComplexOp {
+ EIGEN_EMPTY_STRUCT_CTOR(MakeComplexOp)
+ typedef complex<Scalar> result_type;
+ complex<Scalar> operator()(const Scalar& a, const Scalar& b) const { return complex<Scalar>(a,b); }
+};
+
+int main(int, char**)
+{
+ Matrix4d m1 = Matrix4d::Random(), m2 = Matrix4d::Random();
+ cout << m1.binaryExpr(m2, MakeComplexOp<double>()) << endl;
+ return 0;
+}
diff --git a/doc/examples/class_CwiseUnaryOp.cpp b/doc/examples/class_CwiseUnaryOp.cpp
new file mode 100644
index 000000000..a5fcc153d
--- /dev/null
+++ b/doc/examples/class_CwiseUnaryOp.cpp
@@ -0,0 +1,19 @@
+#include <Eigen/Core>
+#include <iostream>
+using namespace Eigen;
+using namespace std;
+
+// define a custom template unary functor
+template<typename Scalar>
+struct CwiseClampOp {
+ CwiseClampOp(const Scalar& inf, const Scalar& sup) : m_inf(inf), m_sup(sup) {}
+ const Scalar operator()(const Scalar& x) const { return x<m_inf ? m_inf : (x>m_sup ? m_sup : x); }
+ Scalar m_inf, m_sup;
+};
+
+int main(int, char**)
+{
+ Matrix4d m1 = Matrix4d::Random();
+ cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(CwiseClampOp<double>(-0.5,0.5)) << endl;
+ return 0;
+}
diff --git a/doc/examples/class_CwiseUnaryOp_ptrfun.cpp b/doc/examples/class_CwiseUnaryOp_ptrfun.cpp
new file mode 100644
index 000000000..36706d8ed
--- /dev/null
+++ b/doc/examples/class_CwiseUnaryOp_ptrfun.cpp
@@ -0,0 +1,20 @@
+#include <Eigen/Core>
+#include <iostream>
+using namespace Eigen;
+using namespace std;
+
+// define function to be applied coefficient-wise
+double ramp(double x)
+{
+ if (x > 0)
+ return x;
+ else
+ return 0;
+}
+
+int main(int, char**)
+{
+ Matrix4d m1 = Matrix4d::Random();
+ cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(ptr_fun(ramp)) << endl;
+ return 0;
+}
diff --git a/doc/examples/class_FixedBlock.cpp b/doc/examples/class_FixedBlock.cpp
new file mode 100644
index 000000000..9978b32e8
--- /dev/null
+++ b/doc/examples/class_FixedBlock.cpp
@@ -0,0 +1,27 @@
+#include <Eigen/Core>
+#include <iostream>
+using namespace Eigen;
+using namespace std;
+
+template<typename Derived>
+Eigen::Block<Derived, 2, 2>
+topLeft2x2Corner(MatrixBase<Derived>& m)
+{
+ return Eigen::Block<Derived, 2, 2>(m.derived(), 0, 0);
+}
+
+template<typename Derived>
+const Eigen::Block<const Derived, 2, 2>
+topLeft2x2Corner(const MatrixBase<Derived>& m)
+{
+ return Eigen::Block<const Derived, 2, 2>(m.derived(), 0, 0);
+}
+
+int main(int, char**)
+{
+ Matrix3d m = Matrix3d::Identity();
+ cout << topLeft2x2Corner(4*m) << endl; // calls the const version
+ topLeft2x2Corner(m) *= 2; // calls the non-const version
+ cout << "Now the matrix m is:" << endl << m << endl;
+ return 0;
+}
diff --git a/doc/examples/class_FixedVectorBlock.cpp b/doc/examples/class_FixedVectorBlock.cpp
new file mode 100644
index 000000000..c88c9fbf1
--- /dev/null
+++ b/doc/examples/class_FixedVectorBlock.cpp
@@ -0,0 +1,27 @@
+#include <Eigen/Core>
+#include <iostream>
+using namespace Eigen;
+using namespace std;
+
+template<typename Derived>
+Eigen::VectorBlock<Derived, 2>
+firstTwo(MatrixBase<Derived>& v)
+{
+ return Eigen::VectorBlock<Derived, 2>(v.derived(), 0);
+}
+
+template<typename Derived>
+const Eigen::VectorBlock<const Derived, 2>
+firstTwo(const MatrixBase<Derived>& v)
+{
+ return Eigen::VectorBlock<const Derived, 2>(v.derived(), 0);
+}
+
+int main(int, char**)
+{
+ Matrix<int,1,6> v; v << 1,2,3,4,5,6;
+ cout << firstTwo(4*v) << endl; // calls the const version
+ firstTwo(v) *= 2; // calls the non-const version
+ cout << "Now the vector v is:" << endl << v << endl;
+ return 0;
+}
diff --git a/doc/examples/class_VectorBlock.cpp b/doc/examples/class_VectorBlock.cpp
new file mode 100644
index 000000000..dc213df20
--- /dev/null
+++ b/doc/examples/class_VectorBlock.cpp
@@ -0,0 +1,27 @@
+#include <Eigen/Core>
+#include <iostream>
+using namespace Eigen;
+using namespace std;
+
+template<typename Derived>
+Eigen::VectorBlock<Derived>
+segmentFromRange(MatrixBase<Derived>& v, int start, int end)
+{
+ return Eigen::VectorBlock<Derived>(v.derived(), start, end-start);
+}
+
+template<typename Derived>
+const Eigen::VectorBlock<const Derived>
+segmentFromRange(const MatrixBase<Derived>& v, int start, int end)
+{
+ return Eigen::VectorBlock<const Derived>(v.derived(), start, end-start);
+}
+
+int main(int, char**)
+{
+ Matrix<int,1,6> v; v << 1,2,3,4,5,6;
+ cout << segmentFromRange(2*v, 2, 4) << endl; // calls the const version
+ segmentFromRange(v, 1, 3) *= 5; // calls the non-const version
+ cout << "Now the vector v is:" << endl << v << endl;
+ return 0;
+}
diff --git a/doc/examples/function_taking_eigenbase.cpp b/doc/examples/function_taking_eigenbase.cpp
new file mode 100644
index 000000000..49d94b3d6
--- /dev/null
+++ b/doc/examples/function_taking_eigenbase.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+#include <Eigen/Core>
+using namespace Eigen;
+
+template <typename Derived>
+void print_size(const EigenBase<Derived>& b)
+{
+ std::cout << "size (rows, cols): " << b.size() << " (" << b.rows()
+ << ", " << b.cols() << ")" << std::endl;
+}
+
+int main()
+{
+ Vector3f v;
+ print_size(v);
+ // v.asDiagonal() returns a 3x3 diagonal matrix pseudo-expression
+ print_size(v.asDiagonal());
+}
diff --git a/doc/examples/tut_arithmetic_add_sub.cpp b/doc/examples/tut_arithmetic_add_sub.cpp
new file mode 100644
index 000000000..e97477b6e
--- /dev/null
+++ b/doc/examples/tut_arithmetic_add_sub.cpp
@@ -0,0 +1,22 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+
+int main()
+{
+ Matrix2d a;
+ a << 1, 2,
+ 3, 4;
+ MatrixXd b(2,2);
+ b << 2, 3,
+ 1, 4;
+ std::cout << "a + b =\n" << a + b << std::endl;
+ std::cout << "a - b =\n" << a - b << std::endl;
+ std::cout << "Doing a += b;" << std::endl;
+ a += b;
+ std::cout << "Now a =\n" << a << std::endl;
+ Vector3d v(1,2,3);
+ Vector3d w(1,0,0);
+ std::cout << "-v + w - v =\n" << -v + w - v << std::endl;
+}
diff --git a/doc/examples/tut_arithmetic_dot_cross.cpp b/doc/examples/tut_arithmetic_dot_cross.cpp
new file mode 100644
index 000000000..631c9a5e0
--- /dev/null
+++ b/doc/examples/tut_arithmetic_dot_cross.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+using namespace std;
+int main()
+{
+ Vector3d v(1,2,3);
+ Vector3d w(0,1,2);
+
+ cout << "Dot product: " << v.dot(w) << endl;
+ double dp = v.adjoint()*w; // automatic conversion of the inner product to a scalar
+ cout << "Dot product via a matrix product: " << dp << endl;
+ cout << "Cross product:\n" << v.cross(w) << endl;
+}
diff --git a/doc/examples/tut_arithmetic_matrix_mul.cpp b/doc/examples/tut_arithmetic_matrix_mul.cpp
new file mode 100644
index 000000000..f21390241
--- /dev/null
+++ b/doc/examples/tut_arithmetic_matrix_mul.cpp
@@ -0,0 +1,19 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+int main()
+{
+ Matrix2d mat;
+ mat << 1, 2,
+ 3, 4;
+ Vector2d u(-1,1), v(2,0);
+ std::cout << "Here is mat*mat:\n" << mat*mat << std::endl;
+ std::cout << "Here is mat*u:\n" << mat*u << std::endl;
+ std::cout << "Here is u^T*mat:\n" << u.transpose()*mat << std::endl;
+ std::cout << "Here is u^T*v:\n" << u.transpose()*v << std::endl;
+ std::cout << "Here is u*v^T:\n" << u*v.transpose() << std::endl;
+ std::cout << "Let's multiply mat by itself" << std::endl;
+ mat = mat*mat;
+ std::cout << "Now mat is mat:\n" << mat << std::endl;
+}
diff --git a/doc/examples/tut_arithmetic_redux_basic.cpp b/doc/examples/tut_arithmetic_redux_basic.cpp
new file mode 100644
index 000000000..5632fb52e
--- /dev/null
+++ b/doc/examples/tut_arithmetic_redux_basic.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace std;
+int main()
+{
+ Eigen::Matrix2d mat;
+ mat << 1, 2,
+ 3, 4;
+ cout << "Here is mat.sum(): " << mat.sum() << endl;
+ cout << "Here is mat.prod(): " << mat.prod() << endl;
+ cout << "Here is mat.mean(): " << mat.mean() << endl;
+ cout << "Here is mat.minCoeff(): " << mat.minCoeff() << endl;
+ cout << "Here is mat.maxCoeff(): " << mat.maxCoeff() << endl;
+ cout << "Here is mat.trace(): " << mat.trace() << endl;
+}
diff --git a/doc/examples/tut_arithmetic_scalar_mul_div.cpp b/doc/examples/tut_arithmetic_scalar_mul_div.cpp
new file mode 100644
index 000000000..d5f65b53e
--- /dev/null
+++ b/doc/examples/tut_arithmetic_scalar_mul_div.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+
+int main()
+{
+ Matrix2d a;
+ a << 1, 2,
+ 3, 4;
+ Vector3d v(1,2,3);
+ std::cout << "a * 2.5 =\n" << a * 2.5 << std::endl;
+ std::cout << "0.1 * v =\n" << 0.1 * v << std::endl;
+ std::cout << "Doing v *= 2;" << std::endl;
+ v *= 2;
+ std::cout << "Now v =\n" << v << std::endl;
+}
diff --git a/doc/examples/tut_matrix_coefficient_accessors.cpp b/doc/examples/tut_matrix_coefficient_accessors.cpp
new file mode 100644
index 000000000..c2da17158
--- /dev/null
+++ b/doc/examples/tut_matrix_coefficient_accessors.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+
+int main()
+{
+ MatrixXd m(2,2);
+ m(0,0) = 3;
+ m(1,0) = 2.5;
+ m(0,1) = -1;
+ m(1,1) = m(1,0) + m(0,1);
+ std::cout << "Here is the matrix m:\n" << m << std::endl;
+ VectorXd v(2);
+ v(0) = 4;
+ v(1) = v(0) - 1;
+ std::cout << "Here is the vector v:\n" << v << std::endl;
+}
diff --git a/doc/examples/tut_matrix_resize.cpp b/doc/examples/tut_matrix_resize.cpp
new file mode 100644
index 000000000..0392c3aa5
--- /dev/null
+++ b/doc/examples/tut_matrix_resize.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+
+int main()
+{
+ MatrixXd m(2,5);
+ m.resize(4,3);
+ std::cout << "The matrix m is of size "
+ << m.rows() << "x" << m.cols() << std::endl;
+ std::cout << "It has " << m.size() << " coefficients" << std::endl;
+ VectorXd v(2);
+ v.resize(5);
+ std::cout << "The vector v is of size " << v.size() << std::endl;
+ std::cout << "As a matrix, v is of size "
+ << v.rows() << "x" << v.cols() << std::endl;
+}
diff --git a/doc/examples/tut_matrix_resize_fixed_size.cpp b/doc/examples/tut_matrix_resize_fixed_size.cpp
new file mode 100644
index 000000000..dcbdfa783
--- /dev/null
+++ b/doc/examples/tut_matrix_resize_fixed_size.cpp
@@ -0,0 +1,12 @@
+#include <iostream>
+#include <Eigen/Dense>
+
+using namespace Eigen;
+
+int main()
+{
+ Matrix4d m;
+ m.resize(4,4); // no operation
+ std::cout << "The matrix m is of size "
+ << m.rows() << "x" << m.cols() << std::endl;
+}