I understand your problem that you want to find out A^k of a square matrix A using diagonalization method. In the code attached, you have used rref(), for calculating row reduced echelon form and it returns an identity matrix.
I went through the code and ran it on MALAB version R2022b but was not able generate the output you are mentioning. The code itself is doing its task correctly of calculating A^k for the square matrix A.
Although, the reason rref() returns the identify matrix is hidden in its definition itself. Conditions for a matrix to be in the row reduced echelon form are:
- It is in row echelon form.
- The leading entry in each nonzero row is a 1 (called a leading 1).
- Each column containing a leading 1 has zeros in all its other entries.
Since you are working with symbolic variables and MATLAB treats symbolic variables as non-zero element, it ends up removing them from the final result using row tranformations.
For more information, I kindly encourage you to visit below mentioed hyperlinks: