From 5d1a74da0a9a59c2c9f83df873b982df7e58ac03 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 11 Mar 2013 21:20:12 +0100 Subject: Update matlab-eigen quick ascii reff --- doc/AsciiQuickReference.txt | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'doc/AsciiQuickReference.txt') diff --git a/doc/AsciiQuickReference.txt b/doc/AsciiQuickReference.txt index 6f94aa45f..6b0a7cd6a 100644 --- a/doc/AsciiQuickReference.txt +++ b/doc/AsciiQuickReference.txt @@ -1,8 +1,7 @@ // A simple quickref for Eigen. Add anything that's missing. // Main author: Keir Mierle -#include -#include +#include Matrix A; // Fixed rows and cols. Same as Matrix3d. Matrix B; // Fixed rows, dynamic cols. @@ -11,6 +10,7 @@ Matrix E; // Row major; default is column-major. Matrix3f P, Q, R; // 3x3 float matrix. Vector3f x, y, z; // 3x1 float matrix. RowVector3f a, b, c; // 1x3 float matrix. +VectorXd v; // Dynamic column vector of doubles double s; // Basic usage @@ -31,9 +31,19 @@ A << 1, 2, 3, // Initialize A. The elements can also be 7, 8, 9; // and then the rows are stacked. B << A, A, A; // B is three horizontally stacked A's. A.fill(10); // Fill A with all 10's. -A.setRandom(); // Fill A with uniform random numbers in (-1, 1). - // Requires #include . -A.setIdentity(); // Fill A with the identity. + +// Eigen // Matlab +MatrixXd::Identity(rows,cols) // eye(rows,cols) +C.setIdentity(rows,cols) // C = eye(rows,cols) +MatrixXd::Zero(rows,cols) // zeros(rows,cols) +C.setZero(rows,cols) // C = ones(rows,cols) +MatrixXd::Ones(rows,cols) // ones(rows,cols) +C.setOnes(rows,cols) // C = ones(rows,cols) +MatrixXd::Random(rows,cols) // rand(rows,cols)*2-1 // MatrixXd::Random returns uniform random numbers in (-1, 1). +C.setRandom(rows,cols) // C = rand(rows,cols)*2-1 +VectorXd::LinSpace(size,low,high) // linspace(low,high,size)' +v.setLinSpace(size,low,high) // v = linspace(low,high,size)' + // Matrix slicing and blocks. All expressions listed here are read/write. // Templated size versions are faster. Note that Matlab is 1-based (a size N @@ -77,8 +87,7 @@ a *= M; R = P + Q; R = P/s; R += Q; R *= s; R -= Q; R /= s; - // Vectorized operations on each element independently - // (most require #include ) +// Vectorized operations on each element independently // Eigen // Matlab R = P.cwiseProduct(Q); // R = P .* Q R = P.array() * s.array();// R = P .* s @@ -150,12 +159,11 @@ MatrixXi mat2x2 = Map(data); MatrixXi mat2x2 = Map(data, 2, 2); // Solve Ax = b. Result stored in x. Matlab: x = A \ b. -bool solved; -solved = A.ldlt().solve(b, &x)); // A sym. p.s.d. #include -solved = A.llt() .solve(b, &x)); // A sym. p.d. #include -solved = A.lu() .solve(b, &x)); // Stable and fast. #include -solved = A.qr() .solve(b, &x)); // No pivoting. #include -solved = A.svd() .solve(b, &x)); // Stable, slowest. #include +x = A.ldlt().solve(b)); // A sym. p.s.d. #include +x = A.llt() .solve(b)); // A sym. p.d. #include +x = A.lu() .solve(b)); // Stable and fast. #include +x = A.qr() .solve(b)); // No pivoting. #include +x = A.svd() .solve(b)); // Stable, slowest. #include // .ldlt() -> .matrixL() and .matrixD() // .llt() -> .matrixL() // .lu() -> .matrixL() and .matrixU() @@ -168,3 +176,4 @@ A.eigenvalues(); // eig(A); EigenSolver eig(A); // [vec val] = eig(A) eig.eigenvalues(); // diag(val) eig.eigenvectors(); // vec +// For self-adjoint matrices use SelfAdjointEigenSolver<> -- cgit v1.2.3