フィルターのクリア

Calculating a matrix from other matrices

1 回表示 (過去 30 日間)
Saleh Msaddi
Saleh Msaddi 2021 年 2 月 15 日
編集済み: Matt J 2021 年 2 月 15 日
How can I write the following matrix?
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];
A, B, and C are 2D arrays with size(A)=(n,n), size(B)=(n,p), and size(C)=(q,n). N is a positive integer.
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 15 日
I posted code for the 2D version of this a couple of years ago, where the values were being copied down the diagonals.
Unfortunately it has been far too long for me to recall the key words that would needed to find it within my other posts :(

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

回答 (1 件)

Matt J
Matt J 2021 年 2 月 15 日
Q=eye(n);
Mcell=cell(n,1);
for i=1:N
Mcell{i}=C*Q*B;
Q=A*Q+Q;
end
M=cell2mat(Mcell);
  2 件のコメント
Saleh Msaddi
Saleh Msaddi 2021 年 2 月 15 日
Thanks @Matt J for your answer. However, I tried to execute the code and compre the results but they are not the same (only the first 2 rows are the same)
N = 4;
A = rand(4);
B = rand(4,1);
C = rand(1,4);
[n,p] = size(B);
R = [C*B;
C*A*B + C*B;
C*A^2*B + C*A*B + C*B;
C*A^3*B + C*A^2*B + C*A*B + C*B];
Q=eye(n);
Mcell=cell(n,1);
for i=1:N
Mcell{i}=C*Q*B;
Q=A*Q+Q;
end
M=cell2mat(Mcell);
R == M
Matt J
Matt J 2021 年 2 月 15 日
編集済み: Matt J 2021 年 2 月 15 日
Sorry, it should be
N = 4;
A = rand(4);
B = rand(4,1);
C = rand(1,4);
[n,p] = size(B);
R = [C*B;
C*A*B + C*B;
C*A^2*B + C*A*B + C*B;
C*A^3*B + C*A^2*B + C*A*B + C*B];
[Q,Q0]=deal(eye(n));
Mcell=cell(n,1);
for i=1:N
Mcell{i}=C*Q*B;
Q=A*Q+Q0;
end
M=cell2mat(Mcell);
difference=norm(R-M)
difference = 1.8310e-15

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by