Matrix Raised to a Power in Excel

To Whom it May Concern,

I am working with matrices in Excel 2010 and happened upon a problem.  Excel can perform matrix multiplication (e.g. A1:B2 times A3:B4) by the mmult function and yields the correct answer.  However, there is a problem when attempting to raise a single matrix to a power - e.g. A^3 (for some array I refer to as A).

Various fora online all suggest using the power function on an array (thus, using the ctrl + shift + enter).  This takes each entry of the matrix and raises it to the given power.  This is NOT the same as raising the matrix to the given power, and thus yields an incorrect result if the user is hoping to perform such an operation.  Effectively, I'm curious as to the existence of an excel function that uses the method of mmult for raising a matrix to a power.

I'm not sure if this is an error in an excel function or something that exists in an add on.  Please let me know if there is a way to properly raise a matrix to a power in excel.

Thanks,

Louis

January 23rd, 2012 3:52pm

Only way I know is to use multiple MMULT like this;

=MMULT(A1:B2,MMULT(A1:B2,MMULT(A1:B2,A1:B2)))

 

Free Windows Admin Tool Kit Click here and download it now
January 23rd, 2012 11:46pm

Thanks Ed.  That's the type of thing I was thinking.  An alternative method (really just a rephrasing of your concept) would be to generate various powers of the matrix using mmult, and then to iteratively create higher powers of the matrix.

 

So it would seem that there is no simple excel matrix power function...?  Also, I just hope people on other sites' threads see this.  They were using the power function on an array and thinking it was raising the matrix to a power.

 

-Louis

January 24th, 2012 4:18am

Well, you can make your own simple matrix power function, like this;

Function PowerMatrix(rngInp As Range, lngPow As Long) As Variant
Dim i As Long
PowerMatrix = rngInp
If lngPow > 1 Then
  For i = 2 To lngPow
    PowerMatrix = Application.WorksheetFunction.MMult(rngInp, PowerMatrix)
  Next
End If
End Function


Use it in a range like;

=PowerMatrix(A1:B2,3)

to get the matrix to the third power. Enter the function as an array formula.

This simple function does not test for a square matrix (which you need if you are going to multiply a matrix by itself).

Free Windows Admin Tool Kit Click here and download it now
January 24th, 2012 6:09am

Sounds great.  Thanks a lot!
March 2nd, 2012 5:05pm

thanks very much , i have Excel 2013 and this is the only solution that works with me , but i had to read these two Articles first to be able to make and save this as an adds-on then putting it at the Excel's XLStart :

Sorry cannot add links until verified :)

but if any one don't know how to make it , please search for these topics :

1) How to Create a User Defined Function in Microsoft Excel

2) Quick tip: Find Excel's XLStart folder fast

Free Windows Admin Tool Kit Click here and download it now
April 15th, 2013 1:08am

Well, you can make your own simple matrix power function, like this;

Function PowerMatrix(rngInp As Range, lngPow As Long) As Variant
Dim i As Long
PowerMatrix = rngInp
If lngPow > 1 Then
  For i = 2 To lngPow
    PowerMatrix = Application.WorksheetFunction.MMult(rngInp, PowerMatrix)
  Next
End If
End Function


Use it in a range like;

=PowerMatrix(A1:B2,3)

to get the matrix to the third power. Enter the function as an array formula.

This simple function does not test for a square matrix (which you need if you are going to multiply a matrix by itself).

April 22nd, 2014 12:13pm

thank you

Free Windows Admin Tool Kit Click here and download it now
March 27th, 2015 5:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics