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

 채택된 답변

Steven Lord
Steven Lord 2016년 10월 6일

1 개 추천

Consider using the polyvalm function.

추가 답변 (4개)

Walter Roberson
Walter Roberson 2015년 6월 19일

1 개 추천

total = A;
for K = 2 : n
total = total + A^K;
end
John D'Errico
John D'Errico 2016년 10월 6일
편집: John D'Errico 2016년 10월 6일

1 개 추천

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

Walter Roberson
Walter Roberson 2016년 10월 6일
편집: Walter Roberson 2016년 10월 6일
Cool approach for the infinite series!

댓글을 달려면 로그인하십시오.

Leonidas Savvides
Leonidas Savvides 2016년 9월 30일

0 개 추천

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

Walter Roberson
Walter Roberson 2016년 9월 30일
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
John D'Errico 2016년 10월 6일
편집: John D'Errico 2016년 10월 6일
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
Jan 2016년 10월 6일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2015년 6월 19일

편집:

2016년 10월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by