Matrix Generation from other matrices

1 回表示 (過去 30 日間)
Saleh Msaddi
Saleh Msaddi 2020 年 5 月 20 日
編集済み: Ameer Hamza 2020 年 5 月 20 日
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 件のコメント
DEEPAK SHARMA
DEEPAK SHARMA 2020 年 5 月 20 日
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; ......]

サインインしてコメントする。

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 5 月 20 日
編集済み: Ameer Hamza 2020 年 5 月 20 日
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{:});

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by