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

조회 수: 1 (최근 30일)
Songbai Jin
Songbai Jin 2023년 1월 23일
댓글: Songbai Jin 2023년 1월 25일
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