(Block) tri-diagonal matrices

Generate (block) tridiagonal matrices
7,7K Descargas
Actualizado 14 dic 2007

Ver licencia

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

Citar como

John D'Errico (2026). (Block) tri-diagonal matrices (https://la.mathworks.com/matlabcentral/fileexchange/10603-block-tri-diagonal-matrices), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R14SP1
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Operating on Diagonal Matrices en Help Center y MATLAB Answers.

BLKTRIDIAG/demo/html/

Versión Publicado Notas de la versión
1.0.0.0

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