Matrix Generation from other matrices
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
DEEPAK SHARMA
el 20 de Mayo de 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; ......]
Respuestas (1)
Ameer Hamza
el 20 de Mayo de 2020
Editada: Ameer Hamza
el 20 de Mayo de 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{:});
0 comentarios
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!