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

17 views (last 30 days)
Songbai Jin on 23 Jan 2023
Commented: Songbai Jin on 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.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Walter Roberson on 24 Jan 2023
Edited: Walter Roberson on 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 CommentsShowHide 7 older comments
Songbai Jin on 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.

Sign in to comment.

### More Answers (1)

KSSV on 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 CommentsShowHide 2 older comments
KSSV on 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

Sign in to comment.

### Categories

Find more on Linear Algebra in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by