Effacer les filtres
Effacer les filtres

Matrix Generation from other matrices

2 vues (au cours des 30 derniers jours)
Saleh Msaddi
Saleh Msaddi le 20 Mai 2020
Modifié(e) : Ameer Hamza le 20 Mai 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 commentaire
DEEPAK SHARMA
DEEPAK SHARMA le 20 Mai 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; ......]

Connectez-vous pour commenter.

Réponses (1)

Ameer Hamza
Ameer Hamza le 20 Mai 2020
Modifié(e) : Ameer Hamza le 20 Mai 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{:});

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by