Using kron to create a large matrix

2 ビュー (過去 30 日間)
SA
SA 2019 年 4 月 24 日
コメント済み: SA 2019 年 4 月 24 日
I wrote this code to create a block tridiagonal matrix with I (I is the identity matrix) on the sub-diagoanls and A as the square matrix on the main diagonal.
How do I repeat this process so that I can have the 11 A's on the main diagonal and 10 I's on the subdiagonals. So eventually, i get a larger tridiagonal matrix.
A = [-4 2 0;1 -4 1;0 2 -4]; %main diagonal
B = [0 1 0; 0 0 1; 0 0 0]; %sub-diagonal
W = kron(eye(3),A) + kron(B,eye(3))+ kron(B',eye(3))
  2 件のコメント
Guillaume
Guillaume 2019 年 4 月 24 日
I'm unclear on what result you want, in particular what the 11 B's refers to. As far as I can tell there's only one B.
SA
SA 2019 年 4 月 24 日
Sorry, I typed the question wrongly.
The code gives me 3 A's on the main diagonal and two I's on the subdiagonals which gives me a tridiagonal matrix but I want a larger matrix with 11 A's on the main diagonal and 10 I's on the subdiagonals. So eventually I get a larger tridiagonal matrix.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 4 月 24 日
n = 11;
A = [-4 2 0;1 -4 1;0 2 -4]; %main diagonal
m = size(A,1);
mn = m*n;
o1 = ones(mn,1);
out = full(spdiags([o1,repmat(spdiags(A),n,1),o1],[-3,-1:1,3],mn,mn));
  1 件のコメント
SA
SA 2019 年 4 月 24 日
It worked.Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by