Hot answers tagged

8 votes
Accepted

Eigen - Max and minimum eigenvalues of a sparse matrix

There are two relatively convenient options for calculating selected (e.g. a few largest or smallest) eigenvalues using Eigen. The first is Spectra, a header-only C++ library based on Eigen that uses ...
Bill Greene's user avatar
  • 5,854
6 votes
Accepted

Inversion of a matrix using c++ library armadillo or eigen

Please make following changes in your code and check the answer ...
Shainath's user avatar
  • 489
6 votes
Accepted

Eigen - store sparse matrix as binary

I've rolled my own. Here is a MCVE: ...
Avi Ginsburg's user avatar
6 votes
Accepted

'Eigen' matrices with static dimension

No, in the general case, there is no suitable workaround. C++ is a statically typed language, and the compiler needs to know all types at compilation time. If your code worked, the following would ...
davidhigh's user avatar
  • 2,982
5 votes

Eigen C++ Library Over 4x Slower than Fortran

Despite my initial conviction that I was including all relevant compiler flags, in fact I wasn't. I forgot the -fopenmp flag on the C++ compiler, which enables ...
Robert Bassett's user avatar
5 votes

A misunderstanding or a bug in LAPACK's solver for generalized eigenvalue problems?

The other answers already tell you what went wrong, but I will add a terminology note: the term for what is happening is that the pencil $A - \lambda B$ is a singular matrix pencil, i.e., $\det (A - \...
Federico Poloni's user avatar
4 votes

In Eigen, can a sparse matrix contain vectors/objects instead of simple scalar values?

Certainly. There are a few things you have to define for your type that are listed on this page in the documentation: https://eigen.tuxfamily.org/dox/TopicCustomizing_CustomScalar.html It basically ...
Tyler Olsen's user avatar
  • 1,522
3 votes
Accepted

A misunderstanding or a bug in LAPACK's solver for generalized eigenvalue problems?

I suspect the root of your trouble is what has been detected in the comments by Vibe: For any number $\omega\in \mathbb{K}$ (with $\mathbb{K}= \mathbb{R}$ or $\mathbb{C}$) you can find $\boldsymbol{X}$...
BenBoulderite's user avatar
3 votes

Dense decomposition of very non-square matrices

As others have mentioned in comments, solving $A^TAx=A^Tb$ (the so-called least-norm solution) can be performed without explicitly forming $A^TA$ with the QR decomposition. It works like this: $$A=QR$$...
Charlie S's user avatar
  • 661
3 votes

Solving Linear Equations using Eigen

...
user7440094's user avatar
2 votes

How to re-use the coefficient matrix decomposition result when solving linear systems by Eigen C++

Given that the accepted answer has typos and does not give full code, I decided to post mine. ...
Yair Daon's user avatar
  • 261
2 votes
Accepted

Matlab - Compute approximative common eigenvectors basis between two matrices as a function of tolerance

This problem is known as joint diagonalization, and it has two variants: orthogonal, in which the basis vectors are orthonormal, and non-orthogonal, which is harder to solve, but which may be more ...
Amit Hochman's user avatar
  • 1,071
2 votes
Accepted

Dynamic Sized Identity Matrix in Eigen

Off the top of my head (for elements of type double): int n = 100; auto mat = Eigen::MatrixXd::Identity(n,n); This uses the ...
davidhigh's user avatar
  • 2,982
1 vote
Accepted

How to initialize Eigen C++ parameters within for-loop?

You used Eigen::MatrixXd::Zero for initialising BetaH. Why not follow the same for initialising the variables inside the loop?
Chenna K's user avatar
  • 845
1 vote

Matlab - Compute approximative common eigenvectors basis between two matrices as a function of tolerance

As its documentation suggests in multiple places, rref is "mainly of academic interest" (read: "used only to explain Gaussian elimination to ...
Federico Poloni's user avatar
1 vote
Accepted

Range of a matrix from its complete orthogonal decomposition

I get it. ...
Stéphane Laurent's user avatar
1 vote

Eigen - Max and minimum eigenvalues of a sparse matrix

You can use arpack [1], that implements the Arnoldi algorithm for computing eigenpairs. Since arpack communicates with client code only through matrix vector product, you can use your own matrix type (...
BrunoLevy's user avatar
  • 2,285
1 vote

Eigen - Solving Complex Generalized Eigenvalue Problem

If one of the matrices is invertible, you can convert it to a standard eigenvalue problem $(B^{-1}A) x = \lambda x$. With Eigen, you can thus do: ...
ggael's user avatar
  • 666
1 vote
Accepted

Solving a sparse linear system using transpose of lower triangular matrix without copying

EDIT: I just noticed a glitch in your code. You used selfadjoint and triangular. Try this: L.triangularView<Lower>().transpose().solve(b); The rest of my ...
Charlie S's user avatar
  • 661
1 vote
Accepted

Good C, C++ library for efficient grid search / tuples, ideally with bindings to Eigen

I would second the opinion expressed in the context. For that small problem and limited usage, you don't need a library. Generation of a structured grid and retrieving points can be coded up in at ...
Anton Menshov's user avatar
  • 8,572
1 vote
Accepted

C++: Efficient library for dense linear algebra operations (determinant & principal minors)

The answer to your question is benchmarking. Both Armadillo and Eigen provide some benchmarks in their documentation. The only problem is that they don't compare to the same libraries, but you can ...
Jakub Klinkovský's user avatar
1 vote

How to do a Generalized Complex Schur (or QZ) Decomposition with Eigen C++?

Numerical computation of Generalized Complex Schur decomposition can be performed by calling zgges() LAPACK function. For example, see NETLIB zgees documentation, or a documentation for any other BLAS/...
Anton Menshov's user avatar
  • 8,572
1 vote

How can I speed up this code for sparse matrix-vector multiplication?

After your second edit, you are already here: ...
Wolfgang Bangerth's user avatar
1 vote

Why do I get “estimated error” -1.#IND when doing BICGSTAB linear solver using ILUT perconditioner in eigen

This is an old question and it does not contain enough information to answer it with certainty. But since I already stumbled on it once, I want to propose a list of actions which should be able to ...
Anton Menshov's user avatar
  • 8,572

Only top scored, non community-wiki answers of a minimum length are eligible