Jonathan H
Jonathan H

Reputation: 7953

Matrix exponential with Armadillo

I am currently developing with my own C++/Mex code and Matlab, but my project is getting big and I am considering switching to a proper linear algebra library. I have read very good things about Armadillo, but I can't find a few essential functions I need for my project.

I understand Armadillo links to LAPACK and BLAS libraries, but I couldn't find the matrix exponential function in Armdaillo's API, nor in the LAPACK functions.

Can anyone tell me if there is an add-on to compute matrix exponentials with Armadillo? If so, a short example code would be much appreciated.

Upvotes: 1

Views: 2632

Answers (3)

Jonathan H
Jonathan H

Reputation: 7953

This has been added as expmat to the latest release, see http://arma.sourceforge.net/docs.html#expmat

Upvotes: 4

tesch1
tesch1

Reputation: 2806

Here's a port of John Burkardt's c/c++ implementation of one of the 19 dubious to Armadillo...

https://gist.github.com/tesch1/0c03e43885cd66eceabe

Upvotes: 3

Dirk is no longer here
Dirk is no longer here

Reputation: 368301

The matrix exponential is something Matlab has. So Octave implemented it. So other Free Software projects looked at what Octave has and reimplemented it by borrowing this implementation.

I work a lot with R and Armadillo via the RcppArmadillo package (for which I'm a co-author). In one piece of recent work I needed expm() and borrowed it for use by Armadillo from the R package exmp.

The code goes like this:

arma::mat expm(arma::mat x) {
    arma::mat z(x.n_rows, x.n_cols);
    (*expmat)(x.begin(), x.n_rows, z.begin(), Ward_2);
    return z;
}

but it hinges of course on the fact that I get the function pointer to expmat from the R package exmp. The full file is here on Github which has the enum Ward_2 as well.

Upvotes: 4

Related Questions