필터 지우기
필터 지우기

Matrix Generation from other matrices

조회 수: 2 (최근 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 CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by