Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Songbai Jin
Songbai Jin le 23 Jan 2023
Commenté : Songbai Jin le 25 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]
syms n positive integer
A^n
This would not work because it got stuck and could never stop.

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Jan 2023
Modifié(e) : Walter Roberson le 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 commentaires
Songbai Jin
Songbai Jin le 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 le 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.

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 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 commentaires
Songbai Jin
Songbai Jin le 24 Jan 2023
I hope to calculate matrix multiplication A^n not elementwise product A.^n.
Thank you for your help.
KSSV
KSSV le 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

Connectez-vous pour commenter.

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by