Graphics Programs Reference
In-Depth Information
MATLAB does not cater to bandedmatrices explicitly. However, bandedmatrices
can betreatedas a sparse matrices forwhich MATLAB provides extensivesupport.A
bandedmatrix in sparse form can becreatedbythe following command:
A = spdiags(B,d,n,n) creates a n
n sparse matrix from the columnsofmatrix
B by placing the columns along the diagonals specifiedby d . The columnsof B
may belonger than the diagonals theyrepresent. A diagonal in the upper part
of A takes its elements from lower partofa column of B , while a lower diagonal
uses the upper partofB.
×
Here is an example of creating the 5
×
5 tridiagonal matrix
2
1
000
12
1
00
=
A
0
12
1
0
00
12
1
000
12
>>c=ones(5,1);
>>A=spdiags([-c2*c-c],[-101],5,5)
A=
(1,1)
2
(2,1)
-1
(1,2)
-1
(2,2)
2
(3,2)
-1
(2,3)
-1
(3,3)
2
(4,3)
-1
(3,4)
-1
(4,4)
2
(5,4)
-1
(4,5)
-1
(5,5)
2
If the matrix is declared sparse, MATLAB stores only the nonzero elements of the
matrix togetherwith information locating the position of each element in the matrix.
The printoutofa sparse matrix displays the values of these elements and their indices
(row and column numbers) in parentheses.
Almost all matrix functions, including the ones listedabove, also workon sparse
matrices.For example, [L,U] = lu(A) wouldreturn L and U in sparse matrix
Search WWH ::

Custom Search