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

2 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2023-1-24
编辑:Walter Roberson 2023-1-24
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 个评论
Songbai Jin
Songbai Jin 2023-1-25
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 2023-1-25
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.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2023-1-23
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 个评论
Songbai Jin
Songbai Jin 2023-1-24
I hope to calculate matrix multiplication A^n not elementwise product A.^n.
Thank you for your help.
KSSV
KSSV 2023-1-24
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by