OpenCV has a exp(inMat, outMat)
function that returns a matrix where each cell, (i,j) is exp(inMat.at<>(i, j))
.
Is there a function that returns actually the exponent of a matrix (i.e., e^A)?
In MATLAB the function is expm(A)
.
CodePudding user response:
There is no function, however, it is possible to decompose the matrix into eigenvalues and use the exp(inMat, outMat)
function, namely,
void expm(const Mat& m0, Mat& m1)
{
Mat eval, evec;
cv::eigenNonSymmetric(m0, eval, evec);
Mat eveci = evec.t().inv();
Mat exp_eval;
cv::exp(eval, exp_eval);
m1 = evec.t() * Mat::diag(exp_eval) * eveci;
}
Usage example:
double a[] = {0, 1, -3, 4};
Mat m0(2, 2, CV_64FC1, a);
Mat m1(2, 2, CV_64FC1);
cout << "Matrix m0 : \n" << m0 << "\n";
expm(m0, m1);
cout << "Matrix m1 : \n" << m1 << "\n";