Filter löschen
Filter löschen

how can I calculate A^n when n is a symbolic positive integer?

6 Ansichten (letzte 30 Tage)
A = [1/2,1/2,0,0;1/2,0,1/2,0;1/2,0,0,1/2;0,0,0,1]
syms n positive integer
A^n
This would not work because it got stuck and could never stop.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Jan. 2023
Bearbeitet: Walter Roberson am 24 Jan. 2023
syms N positive integer
[V, D] = eig(sym(A))
result = V*diag(diag(D).^N)/V
Note those are the matrix operations * and / not element by element operations
  8 Kommentare
Songbai Jin
Songbai Jin am 25 Jan. 2023
Thank you for your help! It really helps me a lot!
Although I do not know how to remove i from A^N result, I find a way to get real root result.
C = [1 2 -3 -4];
syms a3 a2 a1 a0 x
p = a3*x^3 + a2*x^2 + a1*x + a0;
sols = solve(p, 'maxdegree', 3);
subsols = subs(sols, [a3 a2 a1 a0], C)
subsols = 
result = simplify(subsols,'Steps',100)
result = 
This method does not work in A^N result, probably because it needs more steps, or MATLAB just can not simplify the A^N answer.
Songbai Jin
Songbai Jin am 25 Jan. 2023
What's more, I find the mpower function implemented by MATLAB needs improving.
A = [1,3;0,1];
syms N positive integer
A^N
ans = 
A = [1,1;0,0];
syms N positive integer
A^N
Error using ^
Singularity.
The function throws error if A is singular matrix, but it can calculate A^N if A is not diagonalizable.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 23 Jan. 2023
A = [1/2,1/2,0,0;1/2,0,1/2,0;1/2,0,0,1/2;0,0,0,1]
A = 4×4
0.5000 0.5000 0 0 0.5000 0 0.5000 0 0.5000 0 0 0.5000 0 0 0 1.0000
syms n positive integer
A.^n
ans = 
  3 Kommentare
Songbai Jin
Songbai Jin am 24 Jan. 2023
I hope to calculate matrix multiplication A^n not elementwise product A.^n.
Thank you for your help.
KSSV
KSSV am 24 Jan. 2023
A = [1/2,1/2,0,0;1/2,0,1/2,0;1/2,0,0,1/2;0,0,0,1]
n = 10 ;
B = eye(size(A)) ;
for i = 1:n
B = B*A ;
end

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by