Clear Filters
Clear Filters

Matrix Generation from other matrices

2 views (last 30 days)
Saleh Msaddi
Saleh Msaddi on 20 May 2020
Edited: Ameer Hamza on 20 May 2020
How can I write these matrices?
M = [C*B;
C*A*B + C*B;
C*A^2*B + C*A*B + C*B;
C*A^(n-1)*B + C*A^(n-2)*B ... C*B];
N = [A ; A^2 ; A^3 ; ... ; A^n];
A, B, and C are matrices and n is an integer.
  1 Comment
DEEPAK SHARMA
DEEPAK SHARMA on 20 May 2020
You need to use Dot operator for Matrix Operations.
Define matrix A,B and C
than you can use Dot operator and Multiplication to get your new matrix.
EX : M = [C.*B; C.*A.*B + C.*B; ......]

Sign in to comment.

Answers (1)

Ameer Hamza
Ameer Hamza on 20 May 2020
Edited: Ameer Hamza on 20 May 2020
See this example
A = [1 2 3; 4 5 6; 7 8 9];
B = [9 8 7; 6 5 4; 3 2 1];
C = [0 0 1; 1 0 0; 0 1 0];
n = 3;
M = zeros([size(A) n]);
N = zeros([size(A) n]);
for i=1:n
M(:,:,i) = A^i;
N(:,:,i) = C*A^(i-1)*B;
end
M = cumsum(M, 3);
M = reshape(permute(M, [2 1 3]), 3, []).';
N = reshape(permute(N, [2 1 3]), 3, []).';
Alternative:
M = arrayfun(@(x) {A^x}, 1:n);
M = cumsum(cat(3, M{:}), 3);
M = reshape(permute(M, [2 1 3]), 3, []).';
N = arrayfun(@(x) {C*A^(x)*B}, 0:n-1);
N = vertcat(N{:});

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!