22

I have a matrix of non-negative numbers, say $A$.

(1) How do we calculate $A^n$?

(2) How can we calculate $A^n$ using usual matrix exponential trick to do it fast ?

Edit 1 Also theres another property of matrix A that its diagonals consists always of 0 & other elements either 0 or 1.

Can we do this just by involving matrix multiplication ?

  • 2
    Do you know about diagonalization or Jordan Normal Form? – Git Gud Feb 12 '13 at 07:31
  • @GitGud : No , i dont know what they are ? – Kamesh Sandy Feb 12 '13 at 07:32
  • Diagonalization is a method for matrix decomposition in which you can write $A=PDP^{-1}$, where $D$ is a diagonal matrix. This makes computing $A^n$ very easy because it's just $$(PDP^{-1})^n=(PDP^{-1})(PDP^{-1})\cdots (PDP^{-1})=PD(P^{-1}P)\cdots (P^{-1}P)DP^{-1}=PD^nP^{-1}.$$ And since $D$ is diagonal, it's really easy to compute $D^n$. Jordan Normal Form is something similar, but more complicated. Is this question related to a course? – Git Gud Feb 12 '13 at 07:37
  • You need to find generalized eigenvalues of you matrix and reduce it to Jordan canonical form, so $A = C^{-1}JC$, where $J$ is a matrix that consists of Jordan blocks/cells/matrices and each cell is formed by corresponding eigenvalue, and $C$ is a matrix defined by generalized eigenvectors. Basically, for any $A$ $f(A) = C^{-1} f(J) C$ and $f(Z)$ can be easily found. Look here http://en.wikipedia.org/wiki/Jordan_canonical_form#Powers and here http://en.wikipedia.org/wiki/Jordan_matrix#Functions_of_matrices – Kaster Feb 12 '13 at 07:38
  • @GitGud : No it isnt related a course . I was just asking that say n=3 ,then A^3=(AA)A or A(AA) , in that sense ^_^ – Kamesh Sandy Feb 12 '13 at 07:41
  • @Kaster : Same reply to you (above) :) – Kamesh Sandy Feb 12 '13 at 07:42
  • 1
    @KameshSandy You should learn about JNF and diagonalization before tackling this problem. Please note that JNF is a general method that works for any matrix and diagonalization, despite being much simpler, isn't always possible. – Git Gud Feb 12 '13 at 07:43
  • @GitGud : JNF diagonalization is giving me swirl , is there simpler way to calculate A^n by hand using matrix multiplication just ? – Kamesh Sandy Feb 12 '13 at 07:46
  • 1
    @KameshSandy Not that I know of, unless the matrix has some special property. Maybe someone will reply with a trick. – Git Gud Feb 12 '13 at 07:48
  • @GitGud: Okay let A be matrix such that its diagonals have just 0s & other elements are either 1 or 0 . Now is it possible , maybe i should add this in the question :) – Kamesh Sandy Feb 12 '13 at 07:50
  • @KameshSandy if you don't want to use methods given, then you need to take you matrix and multiply it over and over, obviously. – Kaster Feb 12 '13 at 07:51
  • @Kaster : Yeah thats what i was trying :)
    I tried , for n=3 : (AA)A & A(AA) , both should give different answers & i wanted to know which is correct ^_^
    – Kamesh Sandy Feb 12 '13 at 07:54
  • @KameshSandy who told you that those are different? – Kaster Feb 12 '13 at 07:59
  • @Kaster : I have read AB doesnt equal to BA ? – Kamesh Sandy Feb 12 '13 at 08:03
  • 7
    Are you looking for a fast method to do this for large $n$? In that case 'square-and-multiply' is your friend. Calculate $A^2=A\cdot A$, $A^4=A^2\cdot A^2$, $A^8=A^4\cdot A^4$ et cetera until you have enough powers $A^{2^n}$. Then you combine these. So for example $A^97=A^{64+32+1}=A^{64}\cdot A^{32}\cdot A$. You need only 9 multiplications to get to $A^{97}$ this way. – Jyrki Lahtonen Feb 12 '13 at 08:03
  • 2
    @Kamesh: Yes it is possible that $AB\neq BA$. But matrix product is associative: $A(BC)=(AB)C$, and consequently $A(AA)=(AA)A$ so we can declare that to be $A^3$. Similarly with other powers. – Jyrki Lahtonen Feb 12 '13 at 08:05
  • 1
    Here's an explanation of square and multiply. The same approach works with numbers and with matrices. – Jyrki Lahtonen Feb 12 '13 at 08:08
  • @JyrkiLahtonen : Thanks dude , thats very very useful :D Any link for implementation in c++ ? – Kamesh Sandy Feb 12 '13 at 08:11

4 Answers4

11

One method is induction. Another way to calculate $A^{n}$ for a $2 \times2$ matrix generally is the Hamilton-Cayley Theorem: $A^{2}-Tr(A)\cdot A +\det{A} \cdot I_{2}=0$. This is a very useful theorem which can be applied for any $n \times n$ matrix.

for example if you have a $2 \times 2$ matrix with $\det{A}=0$ and $Tr(A)=\alpha$, the Hamilton-Cayley theorem then becomes:

$$A^2=\alpha\cdot A.$$ $$A^3=\alpha\cdot A^{2}=\alpha^{2}\cdot A$$ $$\vdots$$ $$A^{n}=\alpha^{n-1}\cdot A$$

This is a particular answer, but I recommend the following book (Matrix analysis - Roger Horn). If you have any problem to view this book, tell me.

EDIT:

Another way to calculate the power of matrix is binomial theorem. you will try to write your initial matrix $A$ like $A_{1}+I$ and then to observe a number $p$ for that $A_{1}^{p}=O. $

Iuli
  • 6,790
11

Another approach is called exponentiation by squaring. It still requires you to multiply out matrices like normal, but you only need $O(\log n)$ such multiplications.

This approach is most useful if you want a few values for $A^k$ with $k$ large. But if you want the values of $A^k$ for a sequence of values $k=0,1,\dots$ it is isn't much help.

Thomas Andrews
  • 177,126
  • I'm not sure how the treatment with generating functions, while interesting on its own, helps in this context. When trying to extract $[t^n]$ via linear recurrence I get back my matrix. Exponentiation by squaring on $\mathbb{F}[x] / p_A(x)$ starting with $x^1$ is logarithmic and doesn't require matrix products, only multiplication of polynomials in a field. – WorldSEnder Oct 28 '18 at 11:50
  • You're quite right, I should have just gone with the minimal polynomial, @WorldSEnder – Thomas Andrews Oct 29 '18 at 18:03
9

Using eigenvalues $\lambda_\pm$ of an $2 \times 2$ matrix $\textbf{A}$, you can find the expression

$$\textbf{A}^\zeta = \frac{\lambda_+^\zeta - \lambda_-^\zeta}{\lambda_+ - \lambda_-} \textbf{A} - \lambda_+ \lambda_- \frac{\lambda_+^{\zeta-1} - \lambda_-^{\zeta-1}}{\lambda_+ - \lambda_-} \textbf{I}$$

http://xphysics.wordpress.com/2011/12/03/raising-the-power-of-a-2%c3%972-matrix/

2

You may use Cayley-Hamilton Theorem which states every matrix satisfies its characteristic polynomial.

Suppose you have a $k\times k$ matrix $A$.

In order to find $A^n$ for a large n, you divide $x^n$ by $P(x)$, the characteristic polynomial to get a remainder $R(x)$ which has degree less than $k$.

Note that $ A^n = P(A)Q(A)+R(A) = R(A)$ where R(A) is easy to find.

For example if $n=100$ and $k=3$ then $R(x)$ is a polynomial of second degree.

  • 1
    Dividing $x^n / P(x)$ takes $O(n)$ time. You can do it in $O(\log n)$ via exponentiation by squaring, starting with $x^1$. – WorldSEnder Oct 28 '18 at 11:49