(Block) tri-diagonal matrices

バージョン 1.0.0.0 (42.2 KB) 作成者: John D'Errico
Generate (block) tridiagonal matrices
ダウンロード: 7.6K
更新 2007/12/14

ライセンスの表示

Every once in a while I need to generate a tridiagonal matrix with replicated elements down the diagonals. Sometimes its nice to generate block tridiagonal matrices of the same form.

full(blktridiag(2,-1,-1,5))
ans =
2 -1 0 0 0
-1 2 -1 0 0
0 -1 2 -1 0
0 0 -1 2 -1
0 0 0 -1 2

full(blktridiag(ones(2),2*ones(2),3*ones(2),3))
ans =
1 1 3 3 0 0
1 1 3 3 0 0
2 2 1 1 3 3
2 2 1 1 3 3
0 0 2 2 1 1
0 0 2 2 1 1

This can of course be easily extended to handle general blocks, so since I saw an interest from a user, this release does that too.

Amd = reshape(1:16,[2,2,4]);
Asub = reshape(101:112,[2,2,3]);
Asup = reshape(201:212,[2,2,3]);
A = blktridiag(Amd,Asub,Asup);

full(A)
ans =
1 3 201 203 0 0 0 0
2 4 202 204 0 0 0 0
101 103 5 7 205 207 0 0
102 104 6 8 206 208 0 0
0 0 105 107 9 11 209 211
0 0 106 108 10 12 210 212
0 0 0 0 109 111 13 15
0 0 0 0 110 112 14 16

I've also seen a request to allow non-square blocks. This too is now accommodated in the latest release.

A = blktridiag([1;2],[3;4],[5;6],4);
full(A)
ans =
1 5 0 0
2 6 0 0
3 1 5 0
4 2 6 0
0 3 1 5
0 4 2 6
0 0 3 1
0 0 4 2

引用

John D'Errico (2024). (Block) tri-diagonal matrices (https://www.mathworks.com/matlabcentral/fileexchange/10603-block-tri-diagonal-matrices), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R14SP1
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

BLKTRIDIAG/demo/html/

バージョン 公開済み リリース ノート
1.0.0.0

(Release 4) Extend the tool to allow non-square blocks