Environmental Engineering Reference
In-Depth Information
MATLAB
has an extra variable type 'sparse array' in order to store and operate
with such matrices.
Although the problem of solving a system of equations is feasible, it may be very
hard depending on the dimension, the type of the differential equation, the (ir)
regularity of the model region and/or the mesh and the structure and dependencies
of the parameters.
Let's start with the dimension. In 1D one will usually have some 100s, maybe
1,000 grid points, called nodes . The size of the linear system is the lower or equal
1,000. The matrix has only diagonals with non-zero entries. For 2D the situation is
surely more severe: there are usually few 100 nodes in each direction, thus we
obtain 10,000-100,000 nodes easily. Using the same estimations for a 3D model
one easily comes to the order of one million nodes.
®
Sidebar 21.1: Sparse Matrices
Sparse matrices are stored in a different format in which the location of the
non-zero entries is stored and taken into account. Thus it becomes feasible to
work with matrices, which have more than a million rows and columns - in
most computers that is not possible for dense matrices. There are various
operations that work for sparse matrices only, for the transversion of matrices
of different type and there are also operations, which can be applied for sparse
matrices in the same manner as they are used for usual arrays. Here some
examples:
sparse(A)
converts a matrix into sparse form. Try for the matrix
A = [1 0 ; 0 3]
for demonstration of the representation (do not use the sparse type for such a
simple matrix in your programs). Using sparse with a longer list of input
parameters it is possible to assign each single element of the matrix. For a
complete description of the command see the help. The conversion from a
sparse matrix to a full matrix is performed by:
full(A)
If you want to know, if a matrix is internally stored in sparse form, use:
issparse(A)
Sparse systems can also be combined from vectors, better: from a matrix
containing the diagonals of the sparse matrix in columns. Use the spdiags
command. Here an example: the command
(continued)
 
Search WWH ::




Custom Search