121 by 121 Sparse Matrix

5 ビュー (過去 30 日間)
SA
SA 2019 年 4 月 23 日
コメント済み: SA 2019 年 4 月 23 日
I want to create a sparse matrix (121 by 121) with A repeating in the main diagonal.
I wrote a code below to create my 11 by 11 matrix A but how do i get a 121 by 121 sparse matrix with A repeating in the main diagonal.
n = 11;
D = sparse(1:n,1:n,-4*ones(1,n),n,n);
full(D);
E = sparse(2:n,1:n-1,ones(1,n-1),n,n);
E(11,10)=2;
full(E);
F = sparse(1:n-1,2:n,ones(1,n-1),n,n);
F(1,2)=2;
full(F);
S = E+D+F;
A=full(S)

採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 23 日
temp = repmat({S}, 1, 11);
result = blkdiag(temp{:});
  1 件のコメント
SA
SA 2019 年 4 月 23 日
It worked perfectly. Thanks a million

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

その他の回答 (0 件)

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by