Yusuf Kasim
Yusuf Kasim

Reputation: 13

Complex matrix exponential with Armadillo library

I'm doing some physics simulation in C++ using Armadillo. I need to calculate a product looking like:

Q = R * exp(neg_i*Lambda*t) * R.t() * Q

Where Q,R are cx_mat class of the same size, Lambda is a mat class of the same size as Q,R and is diagonal, neg_i is -i the complex number and t is a double. I should get a unitary matrix as a solution but what I'm getting is non unitary. I was wondering if the exponential function works well with complex matrices? or if not what should I replace it with?

Upvotes: 1

Views: 683

Answers (1)

user213305
user213305

Reputation: 486

You need to use the expmat() function for a matrix exponential, exp() calculates an element-wise exponential.

For example, some code I'm currently using for a physics simulation:

arma::cx_mat f;  // A hermitian matrix
double delta_t ;  // A time step
std::complex<double> i_imag(0.0,1.0) ;  // i, the imaginary number

std::vector<arma::cx_mat> U; // A vector of complex unitary matrices.

U.push_back(arma::expmat(-i_imag * delta_t * f));

Have tested this code, taking the matrix exponential of anti-hermitian matrices to get unitary transformation and works fine.

Upvotes: 1

Related Questions