Try the following (I donβt have access to Matlab now), it should work
A = [1 2 9; 3 0 7; 3 1 4];
B = [];
for i = 1: n
B = [B A. ^ i];
end
B = [B (:, 1: 3: end) B (:, 2: 3: end) B (:, 3: 3: end)];
Additional RAM:
A = [1 2 9; 3 0 7; 3 1 4];
B = zeros (3.3 * n);
for i = 1: n
B (3 * (i-1) +1: 3 * (i-1) +3, :) = A. ^ i;
end
B = [B (:, 1: 3: end) B (:, 2: 3: end) B (:, 3: 3: end)];
source share