Skip to content

Instantly share code, notes, and snippets.

@mattmcd
Last active December 15, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmcd/5261952 to your computer and use it in GitHub Desktop.
Save mattmcd/5261952 to your computer and use it in GitHub Desktop.
Installing and testing Eigen3 linear algebra C++ library.
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd; // m by n double matrix
int main()
{
// Example from Eigen3 doc
MatrixXd m(2,2);
// Comma initialization, row major order
m << 3, 2.5, -1, m(1,0) + m(0,1);
std::cout << m << std::endl;
/* Equivalent to:
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
*/
// vertcat( m, m)
MatrixXd m2(4,2);
m2 << m, m;
std::cout << std::endl << m2 << std::endl;
// horzcat( m, m)
MatrixXd m3(2,4);
m3 << m, m;
std::cout << std::endl << m3 << std::endl;
return 0;
}
all: HelloEigen
HelloEigen: HelloEigen.cpp
clang++ -std=c++0x -I /usr/include/eigen3 -o HelloEigen HelloEigen.cpp
# Install eigen3:
# sudo apt-get install libeigen3-dev libeigen3-doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment