Mercurial > hg > octave-lyh
annotate doc/interpreter/diagperm.txi @ 14856:c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
* OctaveFAQ.texi, basics.txi, container.txi, contrib.txi, diagperm.txi,
diffeq.txi, dynamic.txi, errors.txi, eval.txi, expr.txi, func.txi,
geometry.txi, interp.txi, intro.txi, numbers.txi, oop.txi, plot.txi, poly.txi,
quad.txi, set.txi, sparse.txi, stmt.txi, testfun.txi, vectorize.txi,
refcard.tex: Use Octave coding conventions for cuddling parentheses.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 09 Jul 2012 17:00:46 -0700 |
parents | 72b8b39e12be |
children | 12005245b645 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11593
diff
changeset
|
1 @c Copyright (C) 2009-2012 Jaroslav Hajek |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 @c |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 @c This file is part of Octave. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 @c |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 @c Octave is free software; you can redistribute it and/or modify it |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 @c under the terms of the GNU General Public License as published by the |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 @c Free Software Foundation; either version 3 of the License, or (at |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 @c your option) any later version. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 @c |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 @c for more details. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 @c |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 @c You should have received a copy of the GNU General Public License |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 @c along with Octave; see the file COPYING. If not, see |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 @c <http://www.gnu.org/licenses/>. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 @node Diagonal and Permutation Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 @chapter Diagonal and Permutation Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 @menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 * Basic Usage:: Creation and Manipulation of Diagonal and Permutation Matrices |
9032
349616d9c38e
Cleanup top-level documentation menu in octave.texi
Rik <rdrider0-list@yahoo.com>
parents:
8917
diff
changeset
|
24 * Matrix Algebra:: Linear Algebra with Diagonal and Permutation Matrices |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 * Function Support:: Functions That Are Aware of These Matrices |
14421
0ec73cf71556
doc: Source code is a mass noun (no "source codes")
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14420
diff
changeset
|
26 * Example Code:: Some Examples of Usage |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 * Zeros Treatment:: The Differences in Treatment of Zero Elements |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 @end menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 @node Basic Usage |
8917 | 31 @section Creating and Manipulating Diagonal and Permutation Matrices |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
33 A diagonal matrix is defined as a matrix that has zero entries outside the main |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
34 diagonal; that is, |
8917 | 35 @tex |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
36 $D_{ij} = 0$ if $i \neq j$ |
8917 | 37 @end tex |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
38 @ifnottex |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
39 @code{D(i,j) == 0} if @code{i != j}. |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
40 @end ifnottex |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
41 Most often, square diagonal matrices are considered; however, the definition can |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
42 equally be applied to non-square matrices, in which case we usually speak of a |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
43 rectangular diagonal matrix. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
45 A permutation matrix is defined as a square matrix that has a single element |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
46 equal to unity in each row and each column; all other elements are zero. That |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
47 is, there exists a permutation (vector) |
8917 | 48 @tex |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
49 $p$ such that $P_{ij}=1$ if $j = p_i$ and |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
50 $P_{ij}=0$ otherwise. |
8917 | 51 @end tex |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
52 @ifnottex |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
53 @code{p} such that @code{P(i,j) == 1} if @code{j == p(i)} and |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
54 @code{P(i,j) == 0} otherwise. |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
55 @end ifnottex |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
56 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
57 Octave provides special treatment of real and complex rectangular diagonal |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
58 matrices, as well as permutation matrices. They are stored as special objects, |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
59 using efficient storage and algorithms, facilitating writing both readable and |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
60 efficient matrix algebra expressions in the Octave language. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 @menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 * Creating Diagonal Matrices:: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 * Creating Permutation Matrices:: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 * Explicit and Implicit Conversions:: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 @end menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 @node Creating Diagonal Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 @subsection Creating Diagonal Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
71 The most common and easiest way to create a diagonal matrix is using the |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
72 built-in function @dfn{diag}. The expression @code{diag (v)}, with @var{v} a |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
73 vector, will create a square diagonal matrix with elements on the main diagonal |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
74 given by the elements of @var{v}, and size equal to the length of @var{v}. |
8917 | 75 @code{diag (v, m, n)} can be used to construct a rectangular diagonal matrix. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
76 The result of these expressions will be a special diagonal matrix object, rather |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 than a general matrix object. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
78 |
8917 | 79 Diagonal matrix with unit elements can be created using @dfn{eye}. |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
80 Some other built-in functions can also return diagonal matrices. Examples |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
81 include |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
82 @dfn{balance} or @dfn{inv}. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
83 |
8917 | 84 Example: |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
85 |
8917 | 86 @example |
87 diag (1:4) | |
88 @result{} | |
89 Diagonal Matrix | |
90 | |
91 1 0 0 0 | |
92 0 2 0 0 | |
93 0 0 3 0 | |
94 0 0 0 4 | |
95 | |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
96 diag (1:3,5,3) |
8917 | 97 |
98 @result{} | |
99 Diagonal Matrix | |
100 | |
101 1 0 0 | |
102 0 2 0 | |
103 0 0 3 | |
104 0 0 0 | |
105 0 0 0 | |
106 @end example | |
107 | |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
108 @node Creating Permutation Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
109 @subsection Creating Permutation Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
110 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
111 For creating permutation matrices, Octave does not introduce a new function, but |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
112 rather overrides an existing syntax: permutation matrices can be conveniently |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
113 created by indexing an identity matrix by permutation vectors. |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
114 That is, if @var{q} is a permutation vector of length @var{n}, the expression |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
115 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
116 @example |
8917 | 117 P = eye (n) (:, q); |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
118 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
119 |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
120 @noindent |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
121 will create a permutation matrix - a special matrix object. |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
122 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
123 @example |
8917 | 124 eye (n) (q, :) |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
125 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
126 |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
127 @noindent |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
128 will also work (and create a row permutation matrix), as well as |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
129 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
130 @example |
8917 | 131 eye (n) (q1, q2). |
132 @end example | |
133 | |
134 For example: | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
135 |
8917 | 136 @example |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
137 @group |
8917 | 138 eye (4) ([1,3,2,4],:) |
139 @result{} | |
140 Permutation Matrix | |
141 | |
142 1 0 0 0 | |
143 0 0 1 0 | |
144 0 1 0 0 | |
145 0 0 0 1 | |
146 | |
147 eye (4) (:,[1,3,2,4]) | |
148 @result{} | |
149 Permutation Matrix | |
150 | |
151 1 0 0 0 | |
152 0 0 1 0 | |
153 0 1 0 0 | |
154 0 0 0 1 | |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
155 @end group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
156 @end example |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
157 |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
158 Mathematically, an identity matrix is both diagonal and permutation matrix. |
8917 | 159 In Octave, @code{eye (n)} returns a diagonal matrix, because a matrix |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
160 can only have one class. You can convert this diagonal matrix to a permutation |
8917 | 161 matrix by indexing it by an identity permutation, as shown below. |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
162 This is a special property of the identity matrix; indexing other diagonal |
8917 | 163 matrices generally produces a full matrix. |
164 | |
165 @example | |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
166 @group |
8917 | 167 eye (3) |
168 @result{} | |
169 Diagonal Matrix | |
170 | |
171 1 0 0 | |
172 0 1 0 | |
173 0 0 1 | |
174 | |
175 eye(3)(1:3,:) | |
176 @result{} | |
177 Permutation Matrix | |
178 | |
179 1 0 0 | |
180 0 1 0 | |
181 0 0 1 | |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
182 @end group |
8917 | 183 @end example |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
184 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
185 Some other built-in functions can also return permutation matrices. Examples |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
186 include |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
187 @dfn{inv} or @dfn{lu}. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
188 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
189 @node Explicit and Implicit Conversions |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
190 @subsection Explicit and Implicit Conversions |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
191 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
192 The diagonal and permutation matrices are special objects in their own right. A |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
193 number of operations and built-in functions are defined for these matrices to |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
194 use special, more efficient code than would be used for a full matrix in the |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
195 same place. Examples are given in further sections. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
196 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
197 To facilitate smooth mixing with full matrices, backward compatibility, and |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
198 compatibility with @sc{matlab}, the diagonal and permutation matrices should |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
199 allow any operation that works on full matrices, and will either treat it |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
200 specially, or implicitly convert themselves to full matrices. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
201 |
8917 | 202 Instances include matrix indexing, except for extracting a single element or |
203 a leading submatrix, indexed assignment, or applying most mapper functions, | |
204 such as @dfn{exp}. | |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
205 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
206 An explicit conversion to a full matrix can be requested using the built-in |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
207 function @dfn{full}. It should also be noted that the diagonal and permutation |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
208 matrix objects will cache the result of the conversion after it is first |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
209 requested (explicitly or implicitly), so that subsequent conversions will |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
210 be very cheap. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
211 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
212 @node Matrix Algebra |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
213 @section Linear Algebra with Diagonal and Permutation Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
214 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
215 As has been already said, diagonal and permutation matrices make it |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
216 possible to use efficient algorithms while preserving natural linear |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
217 algebra syntax. This section describes in detail the operations that |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
218 are treated specially when performed on these special matrix objects. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
219 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
220 @menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
221 * Expressions Involving Diagonal Matrices:: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
222 * Expressions Involving Permutation Matrices:: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
223 @end menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
224 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
225 @node Expressions Involving Diagonal Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
226 @subsection Expressions Involving Diagonal Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
227 |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
228 Assume @var{D} is a diagonal matrix. If @var{M} is a full matrix, |
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
229 then @code{D*M} will scale the rows of @var{M}. That means, |
8917 | 230 if @code{S = D*M}, then for each pair of indices |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
231 i,j it holds |
8917 | 232 @tex |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
233 $$S_{ij} = D_{ii} M_{ij}$$ |
8917 | 234 @end tex |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
235 @ifnottex |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
236 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
237 @example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
238 S(i,j) = D(i,i) * M(i,j). |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
239 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
240 |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
241 @end ifnottex |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
242 Similarly, @code{M*D} will do a column scaling. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
243 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
244 The matrix @var{D} may also be rectangular, m-by-n where @code{m != n}. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
245 If @code{m < n}, then the expression @code{D*M} is equivalent to |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
246 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
247 @example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
248 D(:,1:m) * M(1:m,:), |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
249 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
250 |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
251 @noindent |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
252 i.e., trailing @code{n-m} rows of @var{M} are ignored. If @code{m > n}, |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
253 then @code{D*M} is equivalent to |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
254 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
255 @example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
256 [D(1:n,n) * M; zeros(m-n, columns (M))], |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
257 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
258 |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
259 @noindent |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
260 i.e., null rows are appended to the result. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
261 The situation for right-multiplication @code{M*D} is analogous. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
262 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
263 The expressions @code{D \ M} and @code{M / D} perform inverse scaling. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
264 They are equivalent to solving a diagonal (or rectangular diagonal) |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
265 in a least-squares minimum-norm sense. In exact arithmetic, this is |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
266 equivalent to multiplying by a pseudoinverse. The pseudoinverse of |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
267 a rectangular diagonal matrix is again a rectangular diagonal matrix |
8917 | 268 with swapped dimensions, where each nonzero diagonal element is replaced |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
269 by its reciprocal. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
270 The matrix division algorithms do, in fact, use division rather than |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
271 multiplication by reciprocals for better numerical accuracy; otherwise, they |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
272 honor the above definition. Note that a diagonal matrix is never truncated due |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
273 to ill-conditioning; otherwise, it would not be much useful for scaling. This |
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
274 is typically consistent with linear algebra needs. A full matrix that only |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
275 happens to be diagonal (an is thus not a special object) is of course treated |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
276 normally. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
277 |
9047 | 278 Multiplication and division by diagonal matrices works efficiently also when |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
279 combined with sparse matrices, i.e., @code{D*S}, where @var{D} is a diagonal |
9047 | 280 matrix and @var{S} is a sparse matrix scales the rows of the sparse matrix and |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
281 returns a sparse matrix. The expressions @code{S*D}, @code{D\S}, @code{S/D} |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
282 work analogically. |
9047 | 283 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
284 If @var{D1} and @var{D2} are both diagonal matrices, then the expressions |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
285 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
286 @example |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
287 @group |
8917 | 288 D1 + D2 |
289 D1 - D2 | |
290 D1 * D2 | |
291 D1 / D2 | |
292 D1 \ D2 | |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
293 @end group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
294 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
295 |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
296 @noindent |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
297 again produce diagonal matrices, provided that normal |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
298 dimension matching rules are obeyed. The relations used are same as described |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
299 above. |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
300 |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
301 Also, a diagonal matrix @var{D} can be multiplied or divided by a scalar, or |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
302 raised to a scalar power if it is square, producing diagonal matrix result in |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
303 all cases. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
304 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
305 A diagonal matrix can also be transposed or conjugate-transposed, giving the |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
306 expected result. Extracting a leading submatrix of a diagonal matrix, i.e., |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
307 @code{D(1:m,1:n)}, will produce a diagonal matrix, other indexing expressions |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
308 will implicitly convert to full matrix. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
309 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
310 Adding a diagonal matrix to a full matrix only operates on the diagonal |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
311 elements. Thus, |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
312 |
8917 | 313 @example |
314 A = A + eps * eye (n) | |
315 @end example | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
316 |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
317 @noindent |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
318 is an efficient method of augmenting the diagonal of a matrix. Subtraction |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
319 works analogically. |
8917 | 320 |
321 When involved in expressions with other element-by-element operators, @code{.*}, | |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
322 @code{./}, @code{.\} or @code{.^}, an implicit conversion to full matrix will |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
323 take place. This is not always strictly necessary but chosen to facilitate |
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
324 better consistency with @sc{matlab}. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
325 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
326 @node Expressions Involving Permutation Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
327 @subsection Expressions Involving Permutation Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
328 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
329 If @var{P} is a permutation matrix and @var{M} a matrix, the expression |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
330 @code{P*M} will permute the rows of @var{M}. Similarly, @code{M*P} will |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
331 yield a column permutation. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
332 Matrix division @code{P\M} and @code{M/P} can be used to do inverse permutation. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
333 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
334 The previously described syntax for creating permutation matrices can actually |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
335 help an user to understand the connection between a permutation matrix and |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
336 a permuting vector. Namely, the following holds, where @code{I = eye (n)} |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
337 is an identity matrix: |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
338 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
339 @example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
340 I(p,:) * M = (I*M) (p,:) = M(p,:) |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
341 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
342 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
343 Similarly, |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
344 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
345 @example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
346 M * I(:,p) = (M*I) (:,p) = M(:,p) |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
347 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
348 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
349 The expressions @code{I(p,:)} and @code{I(:,p)} are permutation matrices. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
350 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
351 A permutation matrix can be transposed (or conjugate-transposed, which is the |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
352 same, because a permutation matrix is never complex), inverting the |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
353 permutation, or equivalently, turning a row-permutation matrix into a |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
354 column-permutation one. For permutation matrices, transpose is equivalent to |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
355 inversion, thus @code{P\M} is equivalent to @code{P'*M}. Transpose of a |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
356 permutation matrix (or inverse) is a constant-time operation, flipping only a |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
357 flag internally, and thus the choice between the two above equivalent |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
358 expressions for inverse permuting is completely up to the user's taste. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
359 |
9047 | 360 Multiplication and division by permutation matrices works efficiently also when |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
361 combined with sparse matrices, i.e., @code{P*S}, where @var{P} is a permutation |
9047 | 362 matrix and @var{S} is a sparse matrix permutes the rows of the sparse matrix and |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
363 returns a sparse matrix. The expressions @code{S*P}, @code{P\S}, @code{S/P} |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
364 work analogically. |
9047 | 365 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
366 Two permutation matrices can be multiplied or divided (if their sizes match), |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
367 performing a composition of permutations. Also a permutation matrix can be |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
368 indexed by a permutation vector (or two vectors), giving again a permutation |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
369 matrix. Any other operations do not generally yield a permutation matrix and |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
370 will thus trigger the implicit conversion. |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
371 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
372 @node Function Support |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
373 @section Functions That Are Aware of These Matrices |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
374 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
375 This section lists the built-in functions that are aware of diagonal and |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
376 permutation matrices on input, or can return them as output. Passed to other |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
377 functions, these matrices will in general trigger an implicit conversion. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
378 (Of course, user-defined dynamically linked functions may also work with |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
379 diagonal or permutation matrices). |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
380 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
381 @menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
382 * Diagonal Matrix Functions:: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
383 * Permutation Matrix Functions:: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
384 @end menu |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
385 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
386 @node Diagonal Matrix Functions |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
387 @subsection Diagonal Matrix Functions |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
388 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
389 @dfn{inv} and @dfn{pinv} can be applied to a diagonal matrix, yielding again |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
390 a diagonal matrix. @dfn{det} will use an efficient straightforward calculation |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
391 when given a diagonal matrix, as well as @dfn{cond}. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
392 The following mapper functions can be applied to a diagonal matrix |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
393 without converting it to a full one: |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
394 @dfn{abs}, @dfn{real}, @dfn{imag}, @dfn{conj}, @dfn{sqrt}. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
395 A diagonal matrix can also be returned from the @dfn{balance} |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
396 and @dfn{svd} functions. |
9047 | 397 The @dfn{sparse} function will convert a diagonal matrix efficiently to a |
398 sparse matrix. | |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
399 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
400 @node Permutation Matrix Functions |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
401 @subsection Permutation Matrix Functions |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
402 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
403 @dfn{inv} and @dfn{pinv} will invert a permutation matrix, preserving its |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
404 specialness. @dfn{det} can be applied to a permutation matrix, efficiently |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
405 calculating the sign of the permutation (which is equal to the determinant). |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
406 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
407 A permutation matrix can also be returned from the built-in functions |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
408 @dfn{lu} and @dfn{qr}, if a pivoted factorization is requested. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
409 |
9047 | 410 The @dfn{sparse} function will convert a permutation matrix efficiently to a |
411 sparse matrix. | |
412 The @dfn{find} function will also work efficiently with a permutation matrix, | |
413 making it possible to conveniently obtain the permutation indices. | |
414 | |
14421
0ec73cf71556
doc: Source code is a mass noun (no "source codes")
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14420
diff
changeset
|
415 @node Example Code |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
416 @section Some Examples of Usage |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
417 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
418 The following can be used to solve a linear system @code{A*x = b} |
11593
1577c6f80926
Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
419 using the pivoted LU@tie{}factorization: |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
420 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
421 @example |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
422 @group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
423 [L, U, P] = lu (A); ## now L*U = P*A |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
424 x = U \ L \ P*b; |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
425 @end group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
426 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
427 |
8917 | 428 @noindent |
14420
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
429 This is one way to normalize columns of a matrix @var{X} to unit norm: |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
430 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
431 @example |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
432 @group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
433 s = norm (X, "columns"); |
14423
62cb605af1af
doc: Further fixes diagperm (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14421
diff
changeset
|
434 X /= diag (s); |
14420
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
435 @end group |
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
436 @end example |
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
437 |
14423
62cb605af1af
doc: Further fixes diagperm (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14421
diff
changeset
|
438 @noindent |
62cb605af1af
doc: Further fixes diagperm (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14421
diff
changeset
|
439 The same can also be accomplished with broadcasting |
62cb605af1af
doc: Further fixes diagperm (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14421
diff
changeset
|
440 (@pxref{Broadcasting}): |
14420
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
441 |
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
442 @example |
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
443 @group |
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
444 s = norm (X, "columns"); |
dfb33a5723d2
doc: Fix incorrect diagonal matrix division (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
445 X ./= s; |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
446 @end group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
447 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
448 |
8917 | 449 @noindent |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
450 The following expression is a way to efficiently calculate the sign of a |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
451 permutation, given by a permutation vector @var{p}. It will also work |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
452 in earlier versions of Octave, but slowly. |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
453 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
454 @example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
455 det (eye (length (p))(p, :)) |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
456 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
457 |
8917 | 458 @noindent |
14423
62cb605af1af
doc: Further fixes diagperm (bug #35666)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14421
diff
changeset
|
459 Finally, here's how you solve a linear system @code{A*x = b} |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
460 with Tikhonov regularization (ridge regression) using SVD (a skeleton only): |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
461 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
462 @example |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
463 @group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
464 m = rows (A); n = columns (A); |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
465 [U, S, V] = svd (A); |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
466 ## determine the regularization factor alpha |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
467 ## alpha = @dots{} |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
468 ## transform to orthogonal basis |
8917 | 469 b = U'*b; |
470 ## Use the standard formula, replacing A with S. | |
471 ## S is diagonal, so the following will be very fast and accurate. | |
472 x = (S'*S + alpha^2 * eye (n)) \ (S' * b); | |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
473 ## transform to solution basis |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
474 x = V*x; |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
475 @end group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
476 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
477 |
8917 | 478 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
479 @node Zeros Treatment |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
480 @section The Differences in Treatment of Zero Elements |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
481 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
482 Making diagonal and permutation matrices special matrix objects in their own |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
483 right and the consequent usage of smarter algorithms for certain operations |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
484 implies, as a side effect, small differences in treating zeros. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
485 The contents of this section applies also to sparse matrices, discussed in |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
486 the following chapter. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
487 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
488 The IEEE standard defines the result of the expressions @code{0*Inf} and |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
489 @code{0*NaN} as @code{NaN}, as it has been generally agreed that this is the |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
490 best compromise. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
491 Numerical software dealing with structured and sparse matrices (including |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
492 Octave) however, almost always makes a distinction between a "numerical zero" |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
493 and an "assumed zero". |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
494 A "numerical zero" is a zero value occurring in a place where any floating-point |
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
495 value could occur. It is normally stored somewhere in memory as an explicit |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
496 value. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
497 An "assumed zero", on the contrary, is a zero matrix element implied by the |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
498 matrix structure (diagonal, triangular) or a sparsity pattern; its value is |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
499 usually not stored explicitly anywhere, but is implied by the underlying |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
500 data structure. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
501 |
8917 | 502 The primary distinction is that an assumed zero, when multiplied |
503 by any number, or divided by any nonzero number, | |
504 yields *always* a zero, even when, e.g., multiplied by @code{Inf} | |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
505 or divided by @code{NaN}. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
506 The reason for this behavior is that the numerical multiplication is not |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
507 actually performed anywhere by the underlying algorithm; the result is |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
508 just assumed to be zero. Equivalently, one can say that the part of the |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
509 computation involving assumed zeros is performed symbolically, not numerically. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
510 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
511 This behavior not only facilitates the most straightforward and efficient |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
512 implementation of algorithms, but also preserves certain useful invariants, |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
513 like: |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14423
diff
changeset
|
514 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
515 @itemize |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
516 @item scalar * diagonal matrix is a diagonal matrix |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
517 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
518 @item sparse matrix / scalar preserves the sparsity pattern |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
519 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
520 @item permutation matrix * matrix is equivalent to permuting rows |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
521 @end itemize |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
522 all of these natural mathematical truths would be invalidated by treating |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
523 assumed zeros as numerical ones. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
524 |
11573
6f8ffe2c6f76
Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
525 Note that @sc{matlab} does not strictly follow this principle and converts |
11479
746609dd54fd
Remove Matlab euphemisms in docs and use @file macro for filenames
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
526 assumed zeros to numerical zeros in certain cases, while not doing so in |
11573
6f8ffe2c6f76
Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
527 other cases. As of today, there are no intentions to mimic such behavior |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
528 in Octave. |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
529 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
530 Examples of effects of assumed zeros vs. numerical zeros: |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
531 |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
532 @example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
533 Inf * eye (3) |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
534 @result{} |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
535 Inf 0 0 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
536 0 Inf 0 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
537 0 0 Inf |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
538 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
539 Inf * speye (3) |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
540 @result{} |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
541 Compressed Column Sparse (rows = 3, cols = 3, nnz = 3 [33%]) |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
542 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
543 (1, 1) -> Inf |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
544 (2, 2) -> Inf |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
545 (3, 3) -> Inf |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
546 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
547 Inf * full (eye (3)) |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
548 @result{} |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
549 Inf NaN NaN |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
550 NaN Inf NaN |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
551 NaN NaN Inf |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
552 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
553 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
554 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
555 @example |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
556 @group |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
557 diag (1:3) * [NaN; 1; 1] |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
558 @result{} |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
559 NaN |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
560 2 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
561 3 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
562 |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
563 sparse (1:3,1:3,1:3) * [NaN; 1; 1] |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
564 @result{} |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
565 NaN |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
566 2 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
567 3 |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
568 [1,0,0;0,2,0;0,0,3] * [NaN; 1; 1] |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
569 @result{} |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
570 NaN |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
571 NaN |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
572 NaN |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9047
diff
changeset
|
573 @end group |
8839
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
574 @end example |
fcba62cc4549
add chapter about diagonal and permutation matrices to manual
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
575 |