Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Matrix Power

Gianluca_G_1
Beginner
1,279 Views

Hello,

I found this function: v?Powx, in order to compute the Matrix power with very high exponents.

But maybe it works only with vectors, because when I tested it for example with power of 2 I found different results compared with a simple multiplication A*A.

Is there any othe functions for my aims?


thankyou very much
Gianluca

0 Kudos
3 Replies
Gennady_F_Intel
Moderator
1,279 Views

v?Powx have to provide the similar output results when the input vector size ==1 or 100K as an example.The only difference would be is performance. Please play with different accuracy mode of this function.  

0 Kudos
Shane_S_Intel
Employee
1,279 Views

I could be mistaken, but I don't believe we have a matrix power function, say for example, matrix A to the power N. V?Powx raises each element of a vector to a constant power, which is different than raising a matrix to a power.

0 Kudos
Spencer_P_Intel
Employee
1,279 Views
Hi Gianluca, A traditional way to accomplish this for reasonably sized square matrices with good properties (for instance that have distinct eigenvalues or more generally that have a full eigenbasis) is through some sort of diagonalization of the matrix via the eigenvalue decomposition.  If there is a full linearly independent eigenbasis for your matrix then you can decompose the matrix into the form A = S^{-1} D S where D is a diagonal matrix of eigenvalues and S is the corresponding set of linearly independent eigenvectors. Then A*A = S^{-1} D S S^{-1} D S = S^{-1} D^2 S A^{n} = ... = S^{-1} D^{n} S for integer powers n>0 (if the matrix is invertible (no 0 eigenvalues) then it may also work for negative powers and if the eigenvalues are positive then it may also work for non integers as well). Thus powers of A reduce to powers of the diagonal matrix D. In this case, you can compute the eigenvalue decomposition using functionality from LAPACK and then you could actually use the v?Powx function or something like it to raise each element of the D matrix (thinking of it as a vector of diagonal values) to the desired power. Then you multiply back to get the desired matrix power. This can be rather expensive but comparatively less so for higher and higher powers and I would be somewhat cautious with the numerical stability of doing this (don't necessarily trust the results as exactly accurate) but it would probably get you in the right ball park and you can always try to check how accurate for powers 2 or 3 to give yourself some idea of how much it varies... recognizing as well that even matrix multiplication has some numerical inaccuracy :) Hope this helps a little. Best, Spencer
0 Kudos
Reply