Reputation: 150
I am trying to calculate P^100
where P
is my transition matrix. I want to do this by diagonalizing P
so that way we have P = Q*D*Q^-1
.
Of course, if I can get P
to be of this form, then I can easily calculate P^100 = Q*D^100*Q^-1
(where *
denotes matrix multiplication).
I discovered that if you just do P^5
that all you'll get in return is a matrix where each of your entries of P were raised to the 5th power, rather than the fifth power of the matrix (P*P*P*P*P
).
I found a question on here that asks how to check if a matrix is diagonalizable but not how to explicitly construct the diagonalization of a matrix. In MATLAB it's super easy but well, I'm using R and not MATLAB.
Upvotes: 0
Views: 777
Reputation: 226182
The eigen()
function will compute eigenvalues and eigenvectors for you (the matrix of eigenvectors is Q
in your expression, diag()
of the eigenvalues is D
).
You could also use the %^%
operator in the expm package, or functions from other packages described in the answers to this question.
The advantages of using someone else's code are that it's already been tested and debugged, and may use faster or more robust algorithms (e.g., it's often more efficient to compute the matrix power by composing powers of two of the matrix rather than doing the eigenvector computations). The advantage of writing your own method is that you'll understand it better.
Upvotes: 6