matrix power and summation
12 views (last 30 days)
Show older comments
Hi, I was wondering how to calculate matrix with power and Summation in matlab, for example, for matrix A, how to calculate A+A^2+A^3....A^n
Thanks
0 Comments
Accepted Answer
More Answers (4)
John D'Errico
on 6 Oct 2016
Edited: John D'Errico
on 6 Oct 2016
Why do people never use the basic methods available? (Only kidding, as I suppose this is not obvious that what I show is valid for a matrix A. It is.) In this case, this is just an n-term geometric series, with a "ratio" between terms of A.
https://en.wikipedia.org/wiki/Geometric_series
Yes, I know that everyone thinks about this as appropriate for SCALARS. In fact however, as long as the matrix A does not have an eigenvalue of 1, we have a simple formula that is completely valid. First, the loops form to convince you that it is valid.
A = rand(3);
n = 20;
B = A;
for i = 2:n
B = B + A^i;
end
B
B =
336.893406676369 454.133952892778 295.131937851577
193.036906910648 259.86866195271 168.859953528597
311.848524182241 419.850392065738 272.579343092041
So that is what you get from the loop. How about a simple algebraic expression using matrices?
C = A*(eye(size(A)) - A^n)*pinv(eye(size(A)) - A)
C =
336.893406676369 454.133952892778 295.131937851577
193.036906910648 259.86866195271 168.859953528597
311.848524182241 419.850392065738 272.579343092041
This should be more efficient than a loop, certainly is n is large.
The expression I wrote is simply the standard form for the sum of a finite geometric series, adapted for matrices. The reason it fails is if A has any eigenvalues exactly equal to 1, then the pinv computation will be inappropriate here. Otherwise, this result will be exact.
1 Comment
Walter Roberson
on 6 Oct 2016
Edited: Walter Roberson
on 6 Oct 2016
Cool approach for the infinite series!
Leonidas Savvides
on 30 Sep 2016
exist any special function in MatLab find power of a Matrix? like above
Also any function in MatLab in Discrete Math [Relations] find connectivity relation R* that is [M]R∗ = M ∨ M^[2] ∨ M^[3] ∨ · · · ∨ M^[n] ...?
If no Exist then ... how calculate matrix=M=M1 ∧ M2 or M=M1 ∨ M2...?
2 Comments
Walter Roberson
on 30 Sep 2016
Leonidas Savvides: Are you looking for sum of X^k for matrix X, k = 1 to n? Or are you looking for sum of (X^k)/factorial(k) for matrix X, k = 0 to infinity? If you happen to be looking for that, then expm() calculates that.
Is your ∨ symbol intend to indicate element-by-element "or", and is your ∧ symbol intended to indicate element-by-element "and" ? Would those be binary matrices? Is the first of those intended to be "the set of places that can be reached from each starting node and taking at most n steps" ? The interpretation of the other does not spring to my mind at the moment.
John D'Errico
on 6 Oct 2016
Edited: John D'Errico
on 6 Oct 2016
Moved an answer intended as a comment by Leonids to a comment. Please stop adding answers every time you want to make a comment. Use the blue comment link instead.
"Are you looking for sum of X^k for matrix X, k = 1 to n? YES , but Not the other Not factorial involved
yes, all binary matrices only 1 and 0 elements...
Is the first of those intended to be "the set of places that can be reached from each starting node and taking at most n steps" ? YES
Is your ∨ symbol intend to indicate element-by-element "or", and is your ∧ symbol intended to indicate element-by-element "and" ? YES"
Jan
on 6 Oct 2016
The power operation is expensive. But you can avoid it:
S = A;
AA = A;
for K = 2 : n
AA = AA * A;
S = S + AA;
end
0 Comments
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!