Contents
view
Description
Eigen is an open-source C++ library dedicated to matrix computations, linear algebra, and numerical operations.
It provides efficient data structures and algorithms for manipulating vectors, matrices, matrix decompositions, linear systems, and geometric transformations.
Eigen is a “header-only” library, which means that it does not require any additional compilation or linking step.
The goal is to provide a library that is easy to use, portable, and optimized for scientific applications, engineering, robotics, and high-performance computing.
Set up the environment
ml libs/eigen
- Available version(s) : 3.4.1
Tutorials
Use case: Solving a linear system
- The objective of this example is to solve a linear system of the form:
- where is the coefficient matrix, is the right-hand-side vector, and is the vector of unknowns.
- Create the file
resolution.cpp
#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
int main()
{
// Definition of the matrix A
Matrix3d A;
A << 3, 2, -1,
2, -2, 4,
-1, 0.5, -1;
// Definition of the vector b
Vector3d b;
b << 1, -2, 0;
// Solving the linear system A*x = b
Vector3d x = A.colPivHouseholderQr().solve(b);
// Display results
std::cout << "Solving the linear system A * x = b\n\n";
std::cout << "Matrix A =\n";
std::cout << A << "\n\n";
std::cout << "Vector b =\n";
std::cout << b << "\n\n";
std::cout << "Solution x =\n";
std::cout << x << std::endl;
return 0;
}
- Compile
ml libs/eigen
g++ -O3 -std=c++17 resolution.cpp -o resolution
- Run the program in a job
srun ./resolution
Note: The libs/eigen module must be loaded in the shell or job environment before compiling and before running the program.