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 Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by