annotate doc/interpreter/sparse.txi @ 19630:0e1f5a750d00

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jan 2015 10:24:46 -0500
parents 861a46deae1f 446c46af4b42
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1 @c Copyright (C) 2004-2013 David Bateman
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
2 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
3 @c This file is part of Octave.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
4 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
5 @c Octave is free software; you can redistribute it and/or modify it
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
6 @c under the terms of the GNU General Public License as published by the
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
7 @c Free Software Foundation; either version 3 of the License, or (at
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
8 @c your option) any later version.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
9 @c
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
13 @c for more details.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
14 @c
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
15 @c You should have received a copy of the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
16 @c along with Octave; see the file COPYING. If not, see
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7007
diff changeset
17 @c <http://www.gnu.org/licenses/>.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
18
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
19 @ifhtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
20 @set htmltex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
21 @end ifhtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
22 @iftex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
23 @set htmltex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
24 @end iftex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
25
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
26 @node Sparse Matrices
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
27 @chapter Sparse Matrices
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
28
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
29 @menu
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
30 * Basics:: Creation and Manipulation of Sparse Matrices
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
31 * Sparse Linear Algebra:: Linear Algebra on Sparse Matrices
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
32 * Iterative Techniques:: Iterative Techniques
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
33 * Real Life Example:: Using Sparse Matrices
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
34 @end menu
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
35
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
36 @node Basics
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
37 @section Creation and Manipulation of Sparse Matrices
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
39 The size of mathematical problems that can be treated at any particular
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
40 time is generally limited by the available computing resources. Both,
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41 the speed of the computer and its available memory place limitation on
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
42 the problem size.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
43
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5324
diff changeset
44 There are many classes of mathematical problems which give rise to
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
45 matrices, where a large number of the elements are zero. In this case
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46 it makes sense to have a special matrix type to handle this class of
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
47 problems where only the nonzero elements of the matrix are
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
48 stored. Not only does this reduce the amount of memory to store the
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
49 matrix, but it also means that operations on this type of matrix can
18830
322eb69e30ad doc: Fix some Latin wording in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
50 take advantage of the a priori knowledge of the positions of the
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
51 nonzero elements to accelerate their calculations.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
52
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
53 A matrix type that stores only the nonzero elements is generally called
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
54 sparse. It is the purpose of this document to discuss the basics of the
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
55 storage and creation of sparse matrices and the fundamental operations
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
56 on them.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
57
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
58 @menu
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
59 * Storage of Sparse Matrices::
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
60 * Creating Sparse Matrices::
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
61 * Information::
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
62 * Operators and Functions::
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
63 @end menu
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
64
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
65 @node Storage of Sparse Matrices
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
66 @subsection Storage of Sparse Matrices
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
67
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
68 It is not strictly speaking necessary for the user to understand how
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
69 sparse matrices are stored. However, such an understanding will help
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
70 to get an understanding of the size of sparse matrices. Understanding
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
71 the storage technique is also necessary for those users wishing to
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
72 create their own oct-files.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
73
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
74 There are many different means of storing sparse matrix data. What all
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
75 of the methods have in common is that they attempt to reduce the complexity
18830
322eb69e30ad doc: Fix some Latin wording in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
76 and storage given a priori knowledge of the particular class of problems
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
77 that will be solved. A good summary of the available techniques for storing
19074
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 18851
diff changeset
78 sparse matrix is given by @nospell{Saad} @footnote{Y. Saad "SPARSKIT: A basic
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 18851
diff changeset
79 toolkit for sparse matrix computation", 1994,
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
80 @url{http://www-users.cs.umn.edu/~saad/software/SPARSKIT/paper.ps}}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
81 With full matrices, knowledge of the point of an element of the matrix
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
82 within the matrix is implied by its position in the computers memory.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
83 However, this is not the case for sparse matrices, and so the positions
19630
0e1f5a750d00 maint: Periodic merge of gui-release to default.
John W. Eaton <jwe@octave.org>
parents: 19195 19627
diff changeset
84 of the nonzero elements of the matrix must equally be stored.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
85
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
86 An obvious way to do this is by storing the elements of the matrix as
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
87 triplets, with two elements being their position in the array
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
88 (rows and column) and the third being the data itself. This is conceptually
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
89 easy to grasp, but requires more storage than is strictly needed.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
90
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
91 The storage technique used within Octave is the compressed column
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16792
diff changeset
92 format. It is similar to the Yale format.
16600
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
93 @footnote{@url{http://en.wikipedia.org/wiki/Sparse_matrix#Yale_format}}
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
94 In this format the position of each element in a row and the data are
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16792
diff changeset
95 stored as previously. However, if we assume that all elements in the
16600
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
96 same column are stored adjacent in the computers memory, then we only
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
97 need to store information on the number of nonzero elements in each
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16792
diff changeset
98 column, rather than their positions. Thus assuming that the matrix has
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
99 more nonzero elements than there are columns in the matrix, we win in
16600
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
100 terms of the amount of memory used.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
101
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
102 In fact, the column index contains one more element than the number of
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
103 columns, with the first element always being zero. The advantage of
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6939
diff changeset
104 this is a simplification in the code, in that there is no special case
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
105 for the first or last columns. A short example, demonstrating this in
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
106 C is.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
107
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
108 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
109 @group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
110 for (j = 0; j < nc; j++)
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
111 for (i = cidx(j); i < cidx(j+1); i++)
19630
0e1f5a750d00 maint: Periodic merge of gui-release to default.
John W. Eaton <jwe@octave.org>
parents: 19195 19627
diff changeset
112 printf ("nonzero element (%i,%i) is %d\n",
10599
d0e0bb2ebebb Remove tabs in .txi files causing problems with pdf formatting.
Rik <octave@nomad.inbox5.com>
parents: 9906
diff changeset
113 ridx(i), j, data(i));
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
114 @end group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
115 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
116
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
117 A clear understanding might be had by considering an example of how the
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
118 above applies to an example matrix. Consider the matrix
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
119
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
120 @example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
121 @group
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
122 1 2 0 0
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
123 0 0 0 3
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
124 0 0 0 4
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125 @end group
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
126 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
127
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
128 The nonzero elements of this matrix are
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
129
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130 @example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
131 @group
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
132 (1, 1) @result{} 1
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
133 (1, 2) @result{} 2
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
134 (2, 4) @result{} 3
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
135 (3, 4) @result{} 4
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
136 @end group
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
137 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
138
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
139 This will be stored as three vectors @var{cidx}, @var{ridx} and @var{data},
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
140 representing the column indexing, row indexing and data respectively. The
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
141 contents of these three vectors for the above matrix will be
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
142
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
143 @example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
144 @group
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5324
diff changeset
145 @var{cidx} = [0, 1, 2, 2, 4]
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
146 @var{ridx} = [0, 0, 1, 2]
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
147 @var{data} = [1, 2, 3, 4]
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
148 @end group
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
149 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
150
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
151 Note that this is the representation of these elements with the first row
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
152 and column assumed to start at zero, while in Octave itself the row and
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
153 column indexing starts at one. Thus the number of elements in the
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
154 @var{i}-th column is given by @code{@var{cidx} (@var{i} + 1) -
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
155 @var{cidx} (@var{i})}.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
156
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
157 Although Octave uses a compressed column format, it should be noted
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
158 that compressed row formats are equally possible. However, in the
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
159 context of mixed operations between mixed sparse and dense matrices,
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
160 it makes sense that the elements of the sparse matrices are in the
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
161 same order as the dense matrices. Octave stores dense matrices in
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
162 column major ordering, and so sparse matrices are equally stored in
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
163 this manner.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
164
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
165 A further constraint on the sparse matrix storage used by Octave is that
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
166 all elements in the rows are stored in increasing order of their row
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
167 index, which makes certain operations faster. However, it imposes
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
168 the need to sort the elements on the creation of sparse matrices. Having
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6939
diff changeset
169 disordered elements is potentially an advantage in that it makes operations
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
170 such as concatenating two sparse matrices together easier and faster, however
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
171 it adds complexity and speed problems elsewhere.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
172
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
173 @node Creating Sparse Matrices
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
174 @subsection Creating Sparse Matrices
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
175
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
176 There are several means to create sparse matrix.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
177
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
178 @table @asis
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
179 @item Returned from a function
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
180 There are many functions that directly return sparse matrices. These include
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
181 @dfn{speye}, @dfn{sprand}, @dfn{diag}, etc.
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
182
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
183 @item Constructed from matrices or vectors
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
184 The function @dfn{sparse} allows a sparse matrix to be constructed from
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
185 three vectors representing the row, column and data. Alternatively, the
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
186 function @dfn{spconvert} uses a three column matrix format to allow easy
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
187 importation of data from elsewhere.
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
188
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
189 @item Created and then filled
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
190 The function @dfn{sparse} or @dfn{spalloc} can be used to create an empty
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
191 matrix that is then filled by the user
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
192
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
193 @item From a user binary program
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
194 The user can directly create the sparse matrix within an oct-file.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
195 @end table
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
196
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
197 There are several basic functions to return specific sparse
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
198 matrices. For example the sparse identity matrix, is a matrix that is
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
199 often needed. It therefore has its own function to create it as
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
200 @code{speye (@var{n})} or @code{speye (@var{r}, @var{c})}, which
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
201 creates an @var{n}-by-@var{n} or @var{r}-by-@var{c} sparse identity
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
202 matrix.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
203
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
204 Another typical sparse matrix that is often needed is a random distribution
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
205 of random elements. The functions @dfn{sprand} and @dfn{sprandn} perform
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
206 this for uniform and normal random distributions of elements. They have exactly
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5324
diff changeset
207 the same calling convention, where @code{sprand (@var{r}, @var{c}, @var{d})},
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5324
diff changeset
208 creates an @var{r}-by-@var{c} sparse matrix with a density of filled
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
209 elements of @var{d}.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
210
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6939
diff changeset
211 Other functions of interest that directly create sparse matrices, are
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
212 @dfn{diag} or its generalization @dfn{spdiags}, that can take the
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
213 definition of the diagonals of the matrix and create the sparse matrix
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
214 that corresponds to this. For example,
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
215
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
216 @example
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
217 s = diag (sparse (randn (1,n)), -1);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
218 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
219
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
220 @noindent
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
221 creates a sparse (@var{n}+1)-by-(@var{n}+1) sparse matrix with a single
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
222 diagonal defined.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
223
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
224 @DOCSTRING(spdiags)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
225
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
226 @DOCSTRING(speye)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
227
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
228 @DOCSTRING(spones)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
229
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
230 @DOCSTRING(sprand)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
231
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
232 @DOCSTRING(sprandn)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
233
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
234 @DOCSTRING(sprandsym)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
235
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
236 The recommended way for the user to create a sparse matrix, is to create
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
237 two vectors containing the row and column index of the data and a third
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
238 vector of the same size containing the data to be stored. For example,
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
239
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
240 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
241 @group
6421
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
242 ri = ci = d = [];
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
243 for j = 1:c
13198
0a1774f1a70d Update example in sparse.txi to use new calling form of randperm
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11593
diff changeset
244 ri = [ri; randperm(r,n)'];
6421
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
245 ci = [ci; j*ones(n,1)];
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
246 d = [d; rand(n,1)];
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
247 endfor
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
248 s = sparse (ri, ci, d, r, c);
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
249 @end group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
250 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
251
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
252 @noindent
6421
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
253 creates an @var{r}-by-@var{c} sparse matrix with a random distribution
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
254 of @var{n} (<@var{r}) elements per column. The elements of the vectors
6421
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
255 do not need to be sorted in any particular order as Octave will sort
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
256 them prior to storing the data. However, pre-sorting the data will
6421
cac156381f81 [project @ 2007-03-20 17:39:19 by jwe]
jwe
parents: 6411
diff changeset
257 make the creation of the sparse matrix faster.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
258
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
259 The function @dfn{spconvert} takes a three or four column real matrix.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
260 The first two columns represent the row and column index respectively and
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
261 the third and four columns, the real and imaginary parts of the sparse
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
262 matrix. The matrix can contain zero elements and the elements can be
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
263 sorted in any order. Adding zero elements is a convenient way to define
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
264 the size of the sparse matrix. For example:
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
265
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
266 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
267 @group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
268 s = spconvert ([1 2 3 4; 1 3 4 4; 1 2 3 0]')
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
269 @result{} Compressed Column Sparse (rows=4, cols=4, nnz=3)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
270 (1 , 1) -> 1
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
271 (2 , 3) -> 2
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
272 (3 , 4) -> 3
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
273 @end group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
274 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
275
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
276 An example of creating and filling a matrix might be
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
277
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
278 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
279 @group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
280 k = 5;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
281 nz = r * k;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
282 s = spalloc (r, c, nz)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
283 for j = 1:c
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
284 idx = randperm (r);
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
285 s (:, j) = [zeros(r - k, 1); ...
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
286 rand(k, 1)] (idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
287 endfor
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
288 @end group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
289 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
290
5324
d2d11284528e [project @ 2005-04-29 14:56:45 by jwe]
jwe
parents: 5322
diff changeset
291 It should be noted, that due to the way that the Octave
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
292 assignment functions are written that the assignment will reallocate
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
293 the memory used by the sparse matrix at each iteration of the above loop.
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
294 Therefore the @dfn{spalloc} function ignores the @var{nz} argument and
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
295 does not pre-assign the memory for the matrix. Therefore, it is vitally
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
296 important that code using to above structure should be vectorized
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
297 as much as possible to minimize the number of assignments and reduce the
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
298 number of memory allocations.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
299
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
300 @DOCSTRING(full)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
301
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
302 @DOCSTRING(spalloc)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
303
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
304 @DOCSTRING(sparse)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
305
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
306 @DOCSTRING(spconvert)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
307
8106
8a42498edb30 Clarify doc for sparse function
David Bateman <dbateman@free.fr>
parents: 7681
diff changeset
308 The above problem of memory reallocation can be avoided in
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
309 oct-files. However, the construction of a sparse matrix from an oct-file
17097
e7a059a9a644 doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents: 16867
diff changeset
310 is more complex than can be discussed here. @xref{External Code Interface},
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17152
diff changeset
311 for a full description of the techniques involved.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
312
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
313 @node Information
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
314 @subsection Finding Information about Sparse Matrices
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
315
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
316 There are a number of functions that allow information concerning
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
317 sparse matrices to be obtained. The most basic of these is
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
318 @dfn{issparse} that identifies whether a particular Octave object is
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
319 in fact a sparse matrix.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
320
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
321 Another very basic function is @dfn{nnz} that returns the number of
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
322 nonzero entries there are in a sparse matrix, while the function
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
323 @dfn{nzmax} returns the amount of storage allocated to the sparse
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
324 matrix. Note that Octave tends to crop unused memory at the first
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
325 opportunity for sparse objects. There are some cases of user created
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
326 sparse objects where the value returned by @dfn{nzmax} will not be
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
327 the same as @dfn{nnz}, but in general they will give the same
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
328 result. The function @dfn{spstats} returns some basic statistics on
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
329 the columns of a sparse matrix including the number of elements, the
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
330 mean and the variance of each column.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
331
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
332 @DOCSTRING(issparse)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
333
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
334 @DOCSTRING(nnz)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
335
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
336 @DOCSTRING(nonzeros)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
337
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
338 @DOCSTRING(nzmax)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
339
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
340 @DOCSTRING(spstats)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
341
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
342 When solving linear equations involving sparse matrices Octave
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
343 determines the means to solve the equation based on the type of the
17097
e7a059a9a644 doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents: 16867
diff changeset
344 matrix (@pxref{Sparse Linear Algebra}). Octave probes the
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
345 matrix type when the div (/) or ldiv (\) operator is first used with
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
346 the matrix and then caches the type. However the @dfn{matrix_type}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
347 function can be used to determine the type of the sparse matrix prior
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
348 to use of the div or ldiv operators. For example,
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
349
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
350 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
351 @group
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
352 a = tril (sprandn (1024, 1024, 0.02), -1) ...
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
353 + speye (1024);
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
354 matrix_type (a);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
355 ans = Lower
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
356 @end group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
357 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
358
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
359 @noindent
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
360 shows that Octave correctly determines the matrix type for lower
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
361 triangular matrices. @dfn{matrix_type} can also be used to force
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
362 the type of a matrix to be a particular type. For example:
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
363
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
364 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
365 @group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
366 a = matrix_type (tril (sprandn (1024, ...
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
367 1024, 0.02), -1) + speye (1024), "Lower");
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
368 @end group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
369 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
370
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
371 This allows the cost of determining the matrix type to be
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
372 avoided. However, incorrectly defining the matrix type will result in
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
373 incorrect results from solutions of linear equations, and so it is
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
374 entirely the responsibility of the user to correctly identify the
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
375 matrix type
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
376
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
377 There are several graphical means of finding out information about
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
378 sparse matrices. The first is the @dfn{spy} command, which displays
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
379 the structure of the nonzero elements of the
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
380 matrix. @xref{fig:spmatrix}, for an example of the use of
5704
3d8d8ce93c2c [project @ 2006-03-21 21:53:56 by jwe]
jwe
parents: 5681
diff changeset
381 @dfn{spy}. More advanced graphical information can be obtained with the
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
382 @dfn{treeplot}, @dfn{etreeplot} and @dfn{gplot} commands.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
383
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
384 @float Figure,fig:spmatrix
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
385 @center @image{spmatrix,4in}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
386 @caption{Structure of simple sparse matrix.}
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
387 @end float
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
388
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
389 One use of sparse matrices is in graph theory, where the
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6939
diff changeset
390 interconnections between nodes are represented as an adjacency
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
391 matrix. That is, if the i-th node in a graph is connected to the j-th
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
392 node. Then the ij-th node (and in the case of undirected graphs the
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
393 @nospell{ji-th} node) of the sparse adjacency matrix is nonzero. If each node
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
394 is then associated with a set of coordinates, then the @dfn{gplot}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
395 command can be used to graphically display the interconnections
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
396 between nodes.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
397
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
398 As a trivial example of the use of @dfn{gplot} consider the example,
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
399
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
400 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
401 @group
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
402 A = sparse ([2,6,1,3,2,4,3,5,4,6,1,5],
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
403 [1,1,2,2,3,3,4,4,5,5,6,6],1,6,6);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
404 xy = [0,4,8,6,4,2;5,0,5,7,5,7]';
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
405 gplot (A,xy)
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
406 @end group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
407 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
408
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
409 @noindent
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
410 which creates an adjacency matrix @code{A} where node 1 is connected
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
411 to nodes 2 and 6, node 2 with nodes 1 and 3, etc. The coordinates of
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
412 the nodes are given in the n-by-2 matrix @code{xy}.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
413 @ifset htmltex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
414 @xref{fig:gplot}.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
415
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
416 @float Figure,fig:gplot
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
417 @center @image{gplot,4in}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
418 @caption{Simple use of the @dfn{gplot} command.}
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
419 @end float
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
420 @end ifset
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
421
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
422 The dependencies between the nodes of a Cholesky@tie{}factorization can be
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
423 calculated in linear time without explicitly needing to calculate the
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
424 Cholesky@tie{}factorization by the @code{etree} command. This command
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
425 returns the elimination tree of the matrix and can be displayed
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
426 graphically by the command @code{treeplot (etree (A))} if @code{A} is
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
427 symmetric or @code{treeplot (etree (A+A'))} otherwise.
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
428
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
429 @DOCSTRING(spy)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
430
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
431 @DOCSTRING(etree)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
432
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
433 @DOCSTRING(etreeplot)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
434
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
435 @DOCSTRING(gplot)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
436
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
437 @DOCSTRING(treeplot)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
438
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
439 @DOCSTRING(treelayout)
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
440
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
441 @node Operators and Functions
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
442 @subsection Basic Operators and Functions on Sparse Matrices
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
443
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
444 @menu
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
445 * Sparse Functions::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
446 * Return Types of Operators and Functions::
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
447 * Mathematical Considerations::
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
448 @end menu
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
449
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
450 @node Sparse Functions
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
451 @subsubsection Sparse Functions
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
452
11396
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
453 Many Octave functions have been overloaded to work with either sparse or full
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
454 matrices. There is no difference in calling convention when using an
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
455 overloaded function with a sparse matrix, however, there is also no access to
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
456 potentially sparse-specific features. At any time the sparse matrix specific
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
457 version of a function can be used by explicitly calling its function name.
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
458
11396
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
459 The table below lists all of the sparse functions of Octave. Note that the
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
460 names of the specific sparse forms of the functions are typically the same as
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
461 the general versions with a @dfn{sp} prefix. In the table below, and in the
7b563cf94d8d Remove documentation on deprecated function dispatch
Rik <octave@nomad.inbox5.com>
parents: 11392
diff changeset
462 rest of this article, the specific sparse versions of functions are used.
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
463
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
464 @c Table includes in comments the missing sparse functions
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
465
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
466 @table @asis
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
467 @item Generate sparse matrices:
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
468 @dfn{spalloc}, @dfn{spdiags}, @dfn{speye}, @dfn{sprand},
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
469 @dfn{sprandn}, @dfn{sprandsym}
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
470
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
471 @item Sparse matrix conversion:
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7455
diff changeset
472 @dfn{full}, @dfn{sparse}, @dfn{spconvert}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
473
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
474 @item Manipulate sparse matrices
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
475 @dfn{issparse}, @dfn{nnz}, @dfn{nonzeros}, @dfn{nzmax},
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
476 @dfn{spfun}, @dfn{spones}, @dfn{spy}
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
477
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
478 @item Graph Theory:
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
479 @dfn{etree}, @dfn{etreeplot}, @dfn{gplot},
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
480 @dfn{treeplot}
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
481 @c @dfn{treelayout}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
482
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
483 @item Sparse matrix reordering:
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents: 7515
diff changeset
484 @dfn{amd}, @dfn{ccolamd}, @dfn{colamd}, @dfn{colperm}, @dfn{csymamd},
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
485 @dfn{dmperm}, @dfn{symamd}, @dfn{randperm}, @dfn{symrcm}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
486
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
487 @item Linear algebra:
19089
38937efbee21 Incorporate new functions ichol and ilu into Octave.
Rik <rik@octave.org>
parents: 19074
diff changeset
488 @dfn{condest}, @dfn{eigs}, @dfn{matrix_type},
38937efbee21 Incorporate new functions ichol and ilu into Octave.
Rik <rik@octave.org>
parents: 19074
diff changeset
489 @dfn{normest}, @dfn{sprank}, @dfn{spaugment}, @dfn{svds}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
490
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
491 @item Iterative techniques:
19182
e278c939a419 Deprecate luinc.
Rik <rik@octave.org>
parents: 19089
diff changeset
492 @dfn{ichol}, @dfn{ilu}, @dfn{pcg}, @dfn{pcr}
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
493 @c @dfn{bicg}, @dfn{bicgstab}, @dfn{cholinc}, @dfn{cgs}, @dfn{gmres},
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
494 @c @dfn{lsqr}, @dfn{minres}, @dfn{qmr}, @dfn{symmlq}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
495
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
496 @item Miscellaneous:
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
497 @dfn{spparms}, @dfn{symbfact}, @dfn{spstats}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
498 @end table
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
499
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
500 In addition all of the standard Octave mapper functions (i.e., basic
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
501 math functions that take a single argument) such as @dfn{abs}, etc.
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
502 can accept sparse matrices. The reader is referred to the documentation
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
503 supplied with these functions within Octave itself for further
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
504 details.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
505
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
506 @node Return Types of Operators and Functions
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
507 @subsubsection Return Types of Operators and Functions
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
508
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
509 The two basic reasons to use sparse matrices are to reduce the memory
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
510 usage and to not have to do calculations on zero elements. The two are
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
511 closely related in that the computation time on a sparse matrix operator
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
512 or function is roughly linear with the number of nonzero elements.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
513
19630
0e1f5a750d00 maint: Periodic merge of gui-release to default.
John W. Eaton <jwe@octave.org>
parents: 19195 19627
diff changeset
514 Therefore, there is a certain density of nonzero elements of a matrix
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
515 where it no longer makes sense to store it as a sparse matrix, but rather
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
516 as a full matrix. For this reason operators and functions that have a
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
517 high probability of returning a full matrix will always return one. For
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
518 example adding a scalar constant to a sparse matrix will almost always
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
519 make it a full matrix, and so the example,
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
520
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
521 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
522 @group
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
523 speye (3) + 0
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
524 @result{} 1 0 0
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
525 0 1 0
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
526 0 0 1
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
527 @end group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
528 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
529
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
530 @noindent
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
531 returns a full matrix as can be seen.
7330
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
532
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
533
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
534 Additionally, if @code{sparse_auto_mutate} is true, all sparse functions
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
535 test the amount of memory occupied by the sparse matrix to see if the
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
536 amount of storage used is larger than the amount used by the full
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
537 equivalent. Therefore @code{speye (2) * 1} will return a full matrix as
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
538 the memory used is smaller for the full version than the sparse version.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
539
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
540 As all of the mixed operators and functions between full and sparse
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
541 matrices exist, in general this does not cause any problems. However,
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
542 one area where it does cause a problem is where a sparse matrix is
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
543 promoted to a full matrix, where subsequent operations would resparsify
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
544 the matrix. Such cases are rare, but can be artificially created, for
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
545 example @code{(fliplr (speye (3)) + speye (3)) - speye (3)} gives a full
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
546 matrix when it should give a sparse one. In general, where such cases
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
547 occur, they impose only a small memory penalty.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
548
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
549 There is however one known case where this behavior of Octave's
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
550 sparse matrices will cause a problem. That is in the handling of the
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
551 @dfn{diag} function. Whether @dfn{diag} returns a sparse or full matrix
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
552 depending on the type of its input arguments. So
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
553
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
554 @example
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
555 a = diag (sparse ([1,2,3]), -1);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
556 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
557
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
558 @noindent
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
559 should return a sparse matrix. To ensure this actually happens, the
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
560 @dfn{sparse} function, and other functions based on it like @dfn{speye},
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
561 always returns a sparse matrix, even if the memory used will be larger
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
562 than its full representation.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
563
7330
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
564 @DOCSTRING(sparse_auto_mutate)
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
565
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
566 Note that the @code{sparse_auto_mutate} option is incompatible with
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
567 @sc{matlab}, and so it is off by default.
7330
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7189
diff changeset
568
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
569 @node Mathematical Considerations
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
570 @subsubsection Mathematical Considerations
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
571
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
572 The attempt has been made to make sparse matrices behave in exactly the
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
573 same manner as there full counterparts. However, there are certain differences
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
574 and especially differences with other products sparse implementations.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
575
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
576 First, the @qcode{"./"} and @qcode{".^"} operators must be used with care.
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
577 Consider what the examples
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
578
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
579 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
580 @group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
581 s = speye (4);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
582 a1 = s .^ 2;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
583 a2 = s .^ s;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
584 a3 = s .^ -2;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
585 a4 = s ./ 2;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
586 a5 = 2 ./ s;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
587 a6 = s ./ s;
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
588 @end group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
589 @end example
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
590
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
591 @noindent
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
592 will give. The first example of @var{s} raised to the power of 2 causes
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
593 no problems. However @var{s} raised element-wise to itself involves a
6431
ff87ad14403f [project @ 2007-03-22 18:20:31 by jwe]
jwe
parents: 6421
diff changeset
594 large number of terms @code{0 .^ 0} which is 1. There @code{@var{s} .^
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
595 @var{s}} is a full matrix.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
596
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8286
diff changeset
597 Likewise @code{@var{s} .^ -2} involves terms like @code{0 .^ -2} which
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
598 is infinity, and so @code{@var{s} .^ -2} is equally a full matrix.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
599
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
600 For the "./" operator @code{@var{s} ./ 2} has no problems, but
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
601 @code{2 ./ @var{s}} involves a large number of infinity terms as well
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
602 and is equally a full matrix. The case of @code{@var{s} ./ @var{s}}
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
603 involves terms like @code{0 ./ 0} which is a @code{NaN} and so this
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
604 is equally a full matrix with the zero elements of @var{s} filled with
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
605 @code{NaN} values.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
606
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
607 The above behavior is consistent with full matrices, but is not
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
608 consistent with sparse implementations in other products.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
609
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
610 A particular problem of sparse matrices comes about due to the fact that
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
611 as the zeros are not stored, the sign-bit of these zeros is equally not
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
612 stored. In certain cases the sign-bit of zero is important. For example:
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
613
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
614 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
615 @group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
616 a = 0 ./ [-1, 1; 1, -1];
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
617 b = 1 ./ a
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
618 @result{} -Inf Inf
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
619 Inf -Inf
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
620 c = 1 ./ sparse (a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
621 @result{} Inf Inf
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
622 Inf Inf
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
623 @end group
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
624 @end example
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
625
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
626 To correct this behavior would mean that zero elements with a negative
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
627 sign-bit would need to be stored in the matrix to ensure that their
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
628 sign-bit was respected. This is not done at this time, for reasons of
6750
2de995da10b8 [project @ 2007-06-24 21:37:08 by dbateman]
dbateman
parents: 6620
diff changeset
629 efficiency, and so the user is warned that calculations where the sign-bit
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
630 of zero is important must not be done using sparse matrices.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
631
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
632 In general any function or operator used on a sparse matrix will
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
633 result in a sparse matrix with the same or a larger number of nonzero
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
634 elements than the original matrix. This is particularly true for the
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
635 important case of sparse matrix factorizations. The usual way to
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
636 address this is to reorder the matrix, such that its factorization is
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
637 sparser than the factorization of the original matrix. That is the
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
638 factorization of @code{L * U = P * S * Q} has sparser terms @code{L}
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
639 and @code{U} than the equivalent factorization @code{L * U = S}.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
640
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
641 Several functions are available to reorder depending on the type of the
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
642 matrix to be factorized. If the matrix is symmetric positive-definite,
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
643 then @dfn{symamd} or @dfn{csymamd} should be used. Otherwise
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
644 @dfn{amd}, @dfn{colamd} or @dfn{ccolamd} should be used. For completeness
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
645 the reordering functions @dfn{colperm} and @dfn{randperm} are
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
646 also available.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
647
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
648 @xref{fig:simplematrix}, for an example of the structure of a simple
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
649 positive definite matrix.
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5324
diff changeset
650
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
651 @float Figure,fig:simplematrix
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
652 @center @image{spmatrix,4in}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
653 @caption{Structure of simple sparse matrix.}
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
654 @end float
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5324
diff changeset
655
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
656 The standard Cholesky@tie{}factorization of this matrix can be
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
657 obtained by the same command that would be used for a full
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
658 matrix. This can be visualized with the command
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
659 @code{r = chol (A); spy (r);}.
5652
f37b562ec93c [project @ 2006-03-09 15:12:20 by dbateman]
dbateman
parents: 5648
diff changeset
660 @xref{fig:simplechol}.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
661 The original matrix had
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
662 @ifinfo
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
663 @ifnothtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
664 43
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
665 @end ifnothtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
666 @end ifinfo
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
667 @ifset htmltex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
668 598
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
669 @end ifset
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
670 nonzero terms, while this Cholesky@tie{}factorization has
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
671 @ifinfo
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
672 @ifnothtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
673 71,
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
674 @end ifnothtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
675 @end ifinfo
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
676 @ifset htmltex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
677 10200,
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
678 @end ifset
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
679 with only half of the symmetric matrix being stored. This
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
680 is a significant level of fill in, and although not an issue
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
681 for such a small test case, can represents a large overhead
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
682 in working with other sparse matrices.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
683
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
684 The appropriate sparsity preserving permutation of the original
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
685 matrix is given by @dfn{symamd} and the factorization using this
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
686 reordering can be visualized using the command @code{q = symamd (A);
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
687 r = chol (A(q,q)); spy (r)}. This gives
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
688 @ifinfo
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
689 @ifnothtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
690 29
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
691 @end ifnothtml
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
692 @end ifinfo
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
693 @ifset htmltex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
694 399
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
695 @end ifset
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
696 nonzero terms which is a significant improvement.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
697
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
698 The Cholesky@tie{}factorization itself can be used to determine the
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
699 appropriate sparsity preserving reordering of the matrix during the
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
700 factorization, In that case this might be obtained with three return
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
701 arguments as @code{[r, p, q] = chol (A); spy (r)}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
702
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
703 @float Figure,fig:simplechol
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
704 @center @image{spchol,4in}
16826
a4969508008e doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents: 16816
diff changeset
705 @caption{Structure of the unpermuted Cholesky@tie{}factorization of the above matrix.}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
706 @end float
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
707
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
708 @float Figure,fig:simplecholperm
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
709 @center @image{spcholperm,4in}
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
710 @caption{Structure of the permuted Cholesky@tie{}factorization of the above matrix.}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
711 @end float
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
712
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
713 In the case of an asymmetric matrix, the appropriate sparsity
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
714 preserving permutation is @dfn{colamd} and the factorization using
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
715 this reordering can be visualized using the command
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
716 @code{q = colamd (A); [l, u, p] = lu (A(:,q)); spy (l+u)}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
717
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
718 Finally, Octave implicitly reorders the matrix when using the div (/)
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
719 and ldiv (\) operators, and so no the user does not need to explicitly
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
720 reorder the matrix to maximize performance.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
721
7619
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents: 7515
diff changeset
722 @DOCSTRING(amd)
56012914972a Add the amd function
David Bateman <dbateman@free.fr>
parents: 7515
diff changeset
723
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
724 @DOCSTRING(ccolamd)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
725
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
726 @DOCSTRING(colamd)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
727
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
728 @DOCSTRING(colperm)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
729
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
730 @DOCSTRING(csymamd)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
731
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
732 @DOCSTRING(dmperm)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
733
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
734 @DOCSTRING(symamd)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
735
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
736 @DOCSTRING(symrcm)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
737
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
738 @node Sparse Linear Algebra
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
739 @section Linear Algebra on Sparse Matrices
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
740
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
741 Octave includes a polymorphic solver for sparse matrices, where
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
742 the exact solver used to factorize the matrix, depends on the properties
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
743 of the sparse matrix itself. Generally, the cost of determining the matrix type
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5282
diff changeset
744 is small relative to the cost of factorizing the matrix itself, but in any
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5282
diff changeset
745 case the matrix type is cached once it is calculated, so that it is not
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5282
diff changeset
746 re-determined each time it is used in a linear equation.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
747
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
748 The selection tree for how the linear equation is solve is
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
749
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
750 @enumerate 1
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
751 @item If the matrix is diagonal, solve directly and goto 8
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
752
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
753 @item If the matrix is a permuted diagonal, solve directly taking into
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
754 account the permutations. Goto 8
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
755
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
756 @item If the matrix is square, banded and if the band density is less
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
757 than that given by @code{spparms ("bandden")} continue, else goto 4.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
758
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
759 @enumerate a
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
760 @item If the matrix is tridiagonal and the right-hand side is not sparse
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
761 continue, else goto 3b.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
762
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
763 @enumerate
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
764 @item If the matrix is Hermitian, with a positive real diagonal, attempt
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
765 Cholesky@tie{}factorization using @sc{lapack} xPTSV.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
766
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
767 @item If the above failed or the matrix is not Hermitian with a positive
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
768 real diagonal use Gaussian elimination with pivoting using
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
769 @sc{lapack} xGTSV, and goto 8.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
770 @end enumerate
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
771
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
772 @item If the matrix is Hermitian with a positive real diagonal, attempt
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
773 Cholesky@tie{}factorization using @sc{lapack} xPBTRF.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
774
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
775 @item if the above failed or the matrix is not Hermitian with a positive
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
776 real diagonal use Gaussian elimination with pivoting using
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
777 @sc{lapack} xGBTRF, and goto 8.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
778 @end enumerate
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
779
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
780 @item If the matrix is upper or lower triangular perform a sparse forward
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
781 or backward substitution, and goto 8
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
782
11573
6f8ffe2c6f76 Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
783 @item If the matrix is an upper triangular matrix with column permutations
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
784 or lower triangular matrix with row permutations, perform a sparse forward
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
785 or backward substitution, and goto 8
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
786
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
787 @item If the matrix is square, Hermitian with a real positive diagonal, attempt
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
788 sparse Cholesky@tie{}factorization using @sc{cholmod}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
789
11593
1577c6f80926 Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
790 @item If the sparse Cholesky@tie{}factorization failed or the matrix is not
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
791 Hermitian with a real positive diagonal, and the matrix is square, factorize
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10668
diff changeset
792 using @sc{umfpack}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
793
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
794 @item If the matrix is not square, or any of the previous solvers flags
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
795 a singular or near singular matrix, find a minimum norm solution using
18713
a142f35f3cb6 doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
796 @sc{cxsparse}@footnote{The @sc{cholmod}, @sc{umfpack} and @sc{cxsparse}
a142f35f3cb6 doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
797 packages were written by Tim Davis and are available at
16792
b157ba28f123 doc: Use Texinfo @url command consistently throughout documentation.
Rik <rik@octave.org>
parents: 16601
diff changeset
798 @url{http://www.cise.ufl.edu/research/sparse/}}.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
799 @end enumerate
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
800
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18845
diff changeset
801 The band density is defined as the number of nonzero values in the band
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16792
diff changeset
802 divided by the total number of values in the full band. The banded
16600
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
803 matrix solvers can be entirely disabled by using @dfn{spparms} to set
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
804 @code{bandden} to 1 (i.e., @code{spparms ("bandden", 1)}).
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
805
19074
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 18851
diff changeset
806 The QR@tie{}solver factorizes the problem with a @nospell{Dulmage-Mendelsohn}
16600
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
807 decomposition, to separate the problem into blocks that can be treated
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
808 as over-determined, multiple well determined blocks, and a final
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16792
diff changeset
809 over-determined block. For matrices with blocks of strongly connected
16600
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
810 nodes this is a big win as LU@tie{}decomposition can be used for many
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16792
diff changeset
811 blocks. It also significantly improves the chance of finding a solution
16600
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
812 to over-determined problems rather than just returning a vector of
f2f5dd09e97d doc: fix some minor sparse documentation oversights
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
813 @dfn{NaN}'s.
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5652
diff changeset
814
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5652
diff changeset
815 All of the solvers above, can calculate an estimate of the condition
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
816 number. This can be used to detect numerical stability problems in the
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
817 solution and force a minimum norm solution to be used. However, for
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5652
diff changeset
818 narrow banded, triangular or diagonal matrices, the cost of
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5652
diff changeset
819 calculating the condition number is significant, and can in fact
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
820 exceed the cost of factoring the matrix. Therefore the condition
6939
46d1ad37d943 [project @ 2007-10-01 16:12:20 by jwe]
jwe
parents: 6754
diff changeset
821 number is not calculated in these cases, and Octave relies on simpler
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
822 techniques to detect singular matrices or the underlying @sc{lapack} code in
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5652
diff changeset
823 the case of banded matrices.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
824
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5282
diff changeset
825 The user can force the type of the matrix with the @code{matrix_type}
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
826 function. This overcomes the cost of discovering the type of the matrix.
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8286
diff changeset
827 However, it should be noted that identifying the type of the matrix incorrectly
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5282
diff changeset
828 will lead to unpredictable results, and so @code{matrix_type} should be
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5324
diff changeset
829 used with care.
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5282
diff changeset
830
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
831 @DOCSTRING(normest)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
832
8286
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8106
diff changeset
833 @DOCSTRING(onenormest)
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8106
diff changeset
834
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7096
diff changeset
835 @DOCSTRING(condest)
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7096
diff changeset
836
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
837 @DOCSTRING(spparms)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
838
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
839 @DOCSTRING(sprank)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
840
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
841 @DOCSTRING(symbfact)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
842
7681
b1c1133641ee Add the spaugment function
David Bateman <dbateman@free.fr>
parents: 7619
diff changeset
843 For non square matrices, the user can also utilize the @code{spaugment}
b1c1133641ee Add the spaugment function
David Bateman <dbateman@free.fr>
parents: 7619
diff changeset
844 function to find a least squares solution to a linear equation.
b1c1133641ee Add the spaugment function
David Bateman <dbateman@free.fr>
parents: 7619
diff changeset
845
b1c1133641ee Add the spaugment function
David Bateman <dbateman@free.fr>
parents: 7619
diff changeset
846 @DOCSTRING(spaugment)
b1c1133641ee Add the spaugment function
David Bateman <dbateman@free.fr>
parents: 7619
diff changeset
847
8417
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
848 Finally, the function @code{eigs} can be used to calculate a limited
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
849 number of eigenvalues and eigenvectors based on a selection criteria
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
850 and likewise for @code{svds} which calculates a limited number of
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
851 singular values and vectors.
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
852
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
853 @DOCSTRING(eigs)
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
854
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
855 @DOCSTRING(svds)
654bcfb937bf Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents: 8347
diff changeset
856
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
857 @node Iterative Techniques
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
858 @section Iterative Techniques Applied to Sparse Matrices
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
859
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
860 The left division @code{\} and right division @code{/} operators,
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
861 discussed in the previous section, use direct solvers to resolve a
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
862 linear equation of the form @code{@var{x} = @var{A} \ @var{b}} or
19089
38937efbee21 Incorporate new functions ichol and ilu into Octave.
Rik <rik@octave.org>
parents: 19074
diff changeset
863 @code{@var{x} = @var{b} / @var{A}}. Octave also includes a number of
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
864 functions to solve sparse linear equations using iterative techniques.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
865
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
866 @DOCSTRING(pcg)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
867
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
868 @DOCSTRING(pcr)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents: 5708
diff changeset
869
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
870 The speed with which an iterative solver converges to a solution can be
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
871 accelerated with the use of a pre-conditioning matrix @var{M}. In this
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
872 case the linear equation @code{@var{M}^-1 * @var{x} = @var{M}^-1 *
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
873 @var{A} \ @var{b}} is solved instead. Typical pre-conditioning matrices
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
874 are partial factorizations of the original matrix.
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
875
19089
38937efbee21 Incorporate new functions ichol and ilu into Octave.
Rik <rik@octave.org>
parents: 19074
diff changeset
876 @DOCSTRING(ichol)
38937efbee21 Incorporate new functions ichol and ilu into Octave.
Rik <rik@octave.org>
parents: 19074
diff changeset
877
38937efbee21 Incorporate new functions ichol and ilu into Octave.
Rik <rik@octave.org>
parents: 19074
diff changeset
878 @DOCSTRING(ilu)
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6570
diff changeset
879
8817
03b7f618ab3d include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents: 8488
diff changeset
880 @node Real Life Example
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
881 @section Real Life Example using Sparse Matrices
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
882
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
883 A common application for sparse matrices is in the solution of Finite
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
884 Element Models. Finite element models allow numerical solution of
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
885 partial differential equations that do not have closed form solutions,
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
886 typically because of the complex shape of the domain.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
887
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
888 In order to motivate this application, we consider the boundary value
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
889 Laplace equation. This system can model scalar potential fields, such
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
890 as heat or electrical potential. Given a medium
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
891 @tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
892 $\Omega$ with boundary $\partial\Omega$. At all points on the $\partial\Omega$
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
893 the boundary conditions are known, and we wish to calculate the potential in
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
894 $\Omega$.
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
895 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
896 @ifnottex
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
897 Omega with boundary dOmega. At all points on the dOmega
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
898 the boundary conditions are known, and we wish to calculate the potential in
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
899 Omega.
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
900 @end ifnottex
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
901 Boundary conditions may specify the potential (Dirichlet
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
902 boundary condition), its normal derivative across the boundary
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
903 (Neumann boundary condition), or a weighted sum of the potential and
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
904 its derivative (Cauchy boundary condition).
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
905
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
906 In a thermal model, we want to calculate the temperature in
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
907 @tex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
908 $\Omega$
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
909 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
910 @ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
911 Omega
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
912 @end ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
913 and know the boundary temperature (Dirichlet condition)
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
914 or heat flux (from which we can calculate the Neumann condition
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
915 by dividing by the thermal conductivity at the boundary). Similarly,
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
916 in an electrical model, we want to calculate the voltage in
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
917 @tex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
918 $\Omega$
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
919 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
920 @ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
921 Omega
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
922 @end ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
923 and know the boundary voltage (Dirichlet) or current
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
924 (Neumann condition after diving by the electrical conductivity).
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
925 In an electrical model, it is common for much of the boundary
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
926 to be electrically isolated; this is a Neumann boundary condition
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
927 with the current equal to zero.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
928
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
929 The simplest finite element models will divide
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
930 @tex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
931 $\Omega$
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
932 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
933 @ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
934 Omega
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
935 @end ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
936 into simplexes (triangles in 2D, pyramids in 3D).
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
937 @ifset htmltex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
938 We take as a 3-D example a cylindrical liquid filled tank with a small
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
939 non-conductive ball from the EIDORS project@footnote{EIDORS - Electrical
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
940 Impedance Tomography and Diffuse optical Tomography Reconstruction Software
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
941 @url{http://eidors3d.sourceforge.net}}. This is model is designed to reflect
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
942 an application of electrical impedance tomography, where current patterns
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
943 are applied to such a tank in order to image the internal conductivity
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
944 distribution. In order to describe the FEM geometry, we have a matrix of
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
945 vertices @code{nodes} and simplices @code{elems}.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
946 @end ifset
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
947
11573
6f8ffe2c6f76 Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
948 The following example creates a simple rectangular 2-D electrically
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
949 conductive medium with 10 V and 20 V imposed on opposite sides
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
950 (Dirichlet boundary conditions). All other edges are electrically
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
951 isolated.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
952
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
953 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
954 @group
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
955 node_y = [1;1.2;1.5;1.8;2]*ones(1,11);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
956 node_x = ones(5,1)*[1,1.05,1.1,1.2, ...
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
957 1.3,1.5,1.7,1.8,1.9,1.95,2];
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
958 nodes = [node_x(:), node_y(:)];
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
959
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
960 [h,w] = size (node_x);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
961 elems = [];
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
962 for idx = 1:w-1
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
963 widx = (idx-1)*h;
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
964 elems = [elems; ...
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
965 widx+[(1:h-1);(2:h);h+(1:h-1)]'; ...
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
966 widx+[(2:h);h+(2:h);h+(1:h-1)]' ];
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
967 endfor
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
968
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
969 E = size (elems,1); # No. of simplices
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
970 N = size (nodes,1); # No. of vertices
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
971 D = size (elems,2); # dimensions+1
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
972 @end group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
973 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
974
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
975 This creates a N-by-2 matrix @code{nodes} and a E-by-3 matrix
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
976 @code{elems} with values, which define finite element triangles:
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
977
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
978 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
979 @group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
980 nodes(1:7,:)'
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
981 1.00 1.00 1.00 1.00 1.00 1.05 1.05 @dots{}
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
982 1.00 1.20 1.50 1.80 2.00 1.00 1.20 @dots{}
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
983
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
984 elems(1:7,:)'
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
985 1 2 3 4 2 3 4 @dots{}
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
986 2 3 4 5 7 8 9 @dots{}
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
987 6 7 8 9 6 7 8 @dots{}
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
988 @end group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
989 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
990
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
991 Using a first order FEM, we approximate the electrical conductivity
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
992 distribution in
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
993 @tex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
994 $\Omega$
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
995 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
996 @ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
997 Omega
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
998 @end ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
999 as constant on each simplex (represented by the vector @code{conductivity}).
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1000 Based on the finite element geometry, we first calculate a system (or
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1001 stiffness) matrix for each simplex (represented as 3-by-3 elements on the
19630
0e1f5a750d00 maint: Periodic merge of gui-release to default.
John W. Eaton <jwe@octave.org>
parents: 19195 19627
diff changeset
1002 diagonal of the element-wise system matrix @code{SE}). Based on @code{SE}
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1003 and a N-by-DE connectivity matrix @code{C}, representing the connections
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6939
diff changeset
1004 between simplices and vertices, the global connectivity matrix @code{S} is
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1005 calculated.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1006
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1007 @example
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1008 ## Element conductivity
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1009 conductivity = [1*ones(1,16), ...
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1010 2*ones(1,48), 1*ones(1,16)];
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1011
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1012 ## Connectivity matrix
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1013 C = sparse ((1:D*E), reshape (elems', ...
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1014 D*E, 1), 1, D*E, N);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1015
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1016 ## Calculate system matrix
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1017 Siidx = floor ([0:D*E-1]'/D) * D * ...
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1018 ones(1,D) + ones(D*E,1)*(1:D) ;
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1019 Sjidx = [1:D*E]'*ones (1,D);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1020 Sdata = zeros (D*E,D);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1021 dfact = factorial (D-1);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1022 for j = 1:E
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1023 a = inv ([ones(D,1), ...
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1024 nodes(elems(j,:), :)]);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1025 const = conductivity(j) * 2 / ...
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1026 dfact / abs (det (a));
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1027 Sdata(D*(j-1)+(1:D),:) = const * ...
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1028 a(2:D,:)' * a(2:D,:);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1029 endfor
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1030 ## Element-wise system matrix
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1031 SE = sparse(Siidx,Sjidx,Sdata);
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1032 ## Global system matrix
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1033 S = C'* SE *C;
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1034 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1035
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1036 The system matrix acts like the conductivity
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1037 @tex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1038 $S$
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1039 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
1040 @ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1041 @code{S}
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
1042 @end ifnottex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1043 in Ohm's law
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1044 @tex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1045 $SV = I$.
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1046 @end tex
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
1047 @ifnottex
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1048 @code{S * V = I}.
10668
72585f1ca7a2 Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents: 10599
diff changeset
1049 @end ifnottex
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1050 Based on the Dirichlet and Neumann boundary conditions, we are able to
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1051 solve for the voltages at each vertex @code{V}.
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1052
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1053 @example
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1054 ## Dirichlet boundary conditions
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1055 D_nodes = [1:5, 51:55];
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1056 D_value = [10*ones(1,5), 20*ones(1,5)];
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1057
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1058 V = zeros (N,1);
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1059 V(D_nodes) = D_value;
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1060 idx = 1:N; # vertices without Dirichlet
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1061 # boundary condns
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1062 idx(D_nodes) = [];
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1063
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1064 ## Neumann boundary conditions. Note that
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1065 ## N_value must be normalized by the
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1066 ## boundary length and element conductivity
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1067 N_nodes = [];
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1068 N_value = [];
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1069
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1070 Q = zeros (N,1);
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1071 Q(N_nodes) = N_value;
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1072
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1073 V(idx) = S(idx,idx) \ ( Q(idx) - ...
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1074 S(idx,D_nodes) * V(D_nodes));
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1075 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1076
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1077 Finally, in order to display the solution, we show each solved voltage
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1078 value in the z-axis for each simplex vertex.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1079 @ifset htmltex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1080 @xref{fig:femmodel}.
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1081 @end ifset
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1082
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1083 @example
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
1084 @group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1085 elemx = elems(:,[1,2,3,1])';
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1086 xelems = reshape (nodes(elemx, 1), 4, E);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1087 yelems = reshape (nodes(elemx, 2), 4, E);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1088 velems = reshape (V(elemx), 4, E);
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1089 plot3 (xelems,yelems,velems,"k");
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1090 print "grid.eps";
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
1091 @end group
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1092 @end example
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1093
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1094
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1095 @ifset htmltex
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1096 @float Figure,fig:femmodel
9088
77e71f3da3d6 Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents: 9066
diff changeset
1097 @center @image{grid,4in}
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18830
diff changeset
1098 @caption{Example finite element model the showing triangular elements.
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1099 The height of each vertex corresponds to the solution value.}
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1100 @end float
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5576
diff changeset
1101 @end ifset