Mercurial > octave-nkf
comparison doc/interpreter/diagperm.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 | 9e5b64b3c1fe 446c46af4b42 |
children | 4197fc428c7d |
comparison
equal
deleted
inserted
replaced
19626:37d37297acf8 | 19630:0e1f5a750d00 |
---|---|
4 @c | 4 @c |
5 @c Octave is free software; you can redistribute it and/or modify it | 5 @c Octave is free software; you can redistribute it and/or modify it |
6 @c under the terms of the GNU General Public License as published by the | 6 @c under the terms of the GNU General Public License as published by the |
7 @c Free Software Foundation; either version 3 of the License, or (at | 7 @c Free Software Foundation; either version 3 of the License, or (at |
8 @c your option) any later version. | 8 @c your option) any later version. |
9 @c | 9 @c |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | 10 @c Octave is distributed in the hope that it will be useful, but WITHOUT |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13 @c for more details. | 13 @c for more details. |
14 @c | 14 @c |
15 @c You should have received a copy of the GNU General Public License | 15 @c You should have received a copy of the GNU General Public License |
16 @c along with Octave; see the file COPYING. If not, see | 16 @c along with Octave; see the file COPYING. If not, see |
17 @c <http://www.gnu.org/licenses/>. | 17 @c <http://www.gnu.org/licenses/>. |
18 | 18 |
19 @node Diagonal and Permutation Matrices | 19 @node Diagonal and Permutation Matrices |
31 | 31 |
32 @node Basic Usage | 32 @node Basic Usage |
33 @section Creating and Manipulating Diagonal/Permutation Matrices | 33 @section Creating and Manipulating Diagonal/Permutation Matrices |
34 | 34 |
35 A diagonal matrix is defined as a matrix that has zero entries outside the main | 35 A diagonal matrix is defined as a matrix that has zero entries outside the main |
36 diagonal; that is, | 36 diagonal; that is, |
37 @tex | 37 @tex |
38 $D_{ij} = 0$ if $i \neq j$ | 38 $D_{ij} = 0$ if $i \neq j$ |
39 @end tex | 39 @end tex |
40 @ifnottex | 40 @ifnottex |
41 @code{D(i,j) == 0} if @code{i != j}. | 41 @code{D(i,j) == 0} if @code{i != j}. |
44 equally be applied to non-square matrices, in which case we usually speak of a | 44 equally be applied to non-square matrices, in which case we usually speak of a |
45 rectangular diagonal matrix. | 45 rectangular diagonal matrix. |
46 | 46 |
47 A permutation matrix is defined as a square matrix that has a single element | 47 A permutation matrix is defined as a square matrix that has a single element |
48 equal to unity in each row and each column; all other elements are zero. That | 48 equal to unity in each row and each column; all other elements are zero. That |
49 is, there exists a permutation (vector) | 49 is, there exists a permutation (vector) |
50 @tex | 50 @tex |
51 $p$ such that $P_{ij}=1$ if $j = p_i$ and | 51 $p$ such that $P_{ij}=1$ if $j = p_i$ and |
52 $P_{ij}=0$ otherwise. | 52 $P_{ij}=0$ otherwise. |
53 @end tex | 53 @end tex |
54 @ifnottex | 54 @ifnottex |
55 @code{p} such that @code{P(i,j) == 1} if @code{j == p(i)} and | 55 @code{p} such that @code{P(i,j) == 1} if @code{j == p(i)} and |
56 @code{P(i,j) == 0} otherwise. | 56 @code{P(i,j) == 0} otherwise. |
57 @end ifnottex | 57 @end ifnottex |
58 | 58 |
59 Octave provides special treatment of real and complex rectangular diagonal | 59 Octave provides special treatment of real and complex rectangular diagonal |
60 matrices, as well as permutation matrices. They are stored as special objects, | 60 matrices, as well as permutation matrices. They are stored as special objects, |
61 using efficient storage and algorithms, facilitating writing both readable and | 61 using efficient storage and algorithms, facilitating writing both readable and |
122 1 0 0 | 122 1 0 0 |
123 0 2 0 | 123 0 2 0 |
124 0 0 3 | 124 0 0 3 |
125 0 0 0 | 125 0 0 0 |
126 0 0 0 | 126 0 0 0 |
127 @end example | 127 @end example |
128 | 128 |
129 @node Creating Permutation Matrices | 129 @node Creating Permutation Matrices |
130 @subsection Creating Permutation Matrices | 130 @subsection Creating Permutation Matrices |
131 | 131 |
132 For creating permutation matrices, Octave does not introduce a new function, but | 132 For creating permutation matrices, Octave does not introduce a new function, but |
140 | 140 |
141 @noindent | 141 @noindent |
142 will create a permutation matrix - a special matrix object. | 142 will create a permutation matrix - a special matrix object. |
143 | 143 |
144 @example | 144 @example |
145 eye (n) (q, :) | 145 eye (n) (q, :) |
146 @end example | 146 @end example |
147 | 147 |
148 @noindent | 148 @noindent |
149 will also work (and create a row permutation matrix), as well as | 149 will also work (and create a row permutation matrix), as well as |
150 | 150 |
151 @example | 151 @example |
152 eye (n) (q1, q2). | 152 eye (n) (q1, q2). |
153 @end example | 153 @end example |
154 | 154 |
248 @cindex diagonal matrix expressions | 248 @cindex diagonal matrix expressions |
249 | 249 |
250 Assume @var{D} is a diagonal matrix. If @var{M} is a full matrix, | 250 Assume @var{D} is a diagonal matrix. If @var{M} is a full matrix, |
251 then @code{D*M} will scale the rows of @var{M}. That means, | 251 then @code{D*M} will scale the rows of @var{M}. That means, |
252 if @code{S = D*M}, then for each pair of indices | 252 if @code{S = D*M}, then for each pair of indices |
253 i,j it holds | 253 i,j it holds |
254 @tex | 254 @tex |
255 $$S_{ij} = D_{ii} M_{ij}$$ | 255 $$S_{ij} = D_{ii} M_{ij}$$ |
256 @end tex | 256 @end tex |
257 @ifnottex | 257 @ifnottex |
258 | 258 |
269 @example | 269 @example |
270 D(:,1:m) * M(1:m,:), | 270 D(:,1:m) * M(1:m,:), |
271 @end example | 271 @end example |
272 | 272 |
273 @noindent | 273 @noindent |
274 i.e., trailing @code{n-m} rows of @var{M} are ignored. If @code{m > n}, | 274 i.e., trailing @code{n-m} rows of @var{M} are ignored. If @code{m > n}, |
275 then @code{D*M} is equivalent to | 275 then @code{D*M} is equivalent to |
276 | 276 |
277 @example | 277 @example |
278 [D(1:n,n) * M; zeros(m-n, columns (M))], | 278 [D(1:n,n) * M; zeros(m-n, columns (M))], |
279 @end example | 279 @end example |
280 | 280 |
288 in a least-squares minimum-norm sense. In exact arithmetic, this is | 288 in a least-squares minimum-norm sense. In exact arithmetic, this is |
289 equivalent to multiplying by a pseudoinverse. The pseudoinverse of | 289 equivalent to multiplying by a pseudoinverse. The pseudoinverse of |
290 a rectangular diagonal matrix is again a rectangular diagonal matrix | 290 a rectangular diagonal matrix is again a rectangular diagonal matrix |
291 with swapped dimensions, where each nonzero diagonal element is replaced | 291 with swapped dimensions, where each nonzero diagonal element is replaced |
292 by its reciprocal. | 292 by its reciprocal. |
293 The matrix division algorithms do, in fact, use division rather than | 293 The matrix division algorithms do, in fact, use division rather than |
294 multiplication by reciprocals for better numerical accuracy; otherwise, they | 294 multiplication by reciprocals for better numerical accuracy; otherwise, they |
295 honor the above definition. Note that a diagonal matrix is never truncated due | 295 honor the above definition. Note that a diagonal matrix is never truncated due |
296 to ill-conditioning; otherwise, it would not be of much use for scaling. This | 296 to ill-conditioning; otherwise, it would not be of much use for scaling. This |
297 is typically consistent with linear algebra needs. A full matrix that only | 297 is typically consistent with linear algebra needs. A full matrix that only |
298 happens to be diagonal (and is thus not a special object) is of course treated | 298 happens to be diagonal (and is thus not a special object) is of course treated |
307 If @var{D1} and @var{D2} are both diagonal matrices, then the expressions | 307 If @var{D1} and @var{D2} are both diagonal matrices, then the expressions |
308 | 308 |
309 @example | 309 @example |
310 @group | 310 @group |
311 D1 + D2 | 311 D1 + D2 |
312 D1 - D2 | 312 D1 - D2 |
313 D1 * D2 | 313 D1 * D2 |
314 D1 / D2 | 314 D1 / D2 |
315 D1 \ D2 | 315 D1 \ D2 |
316 @end group | 316 @end group |
317 @end example | 317 @end example |
318 | 318 |
319 @noindent | 319 @noindent |
321 dimension matching rules are obeyed. The relations used are same as described | 321 dimension matching rules are obeyed. The relations used are same as described |
322 above. | 322 above. |
323 | 323 |
324 Also, a diagonal matrix @var{D} can be multiplied or divided by a scalar, or | 324 Also, a diagonal matrix @var{D} can be multiplied or divided by a scalar, or |
325 raised to a scalar power if it is square, producing diagonal matrix result in | 325 raised to a scalar power if it is square, producing diagonal matrix result in |
326 all cases. | 326 all cases. |
327 | 327 |
328 A diagonal matrix can also be transposed or conjugate-transposed, giving the | 328 A diagonal matrix can also be transposed or conjugate-transposed, giving the |
329 expected result. Extracting a leading submatrix of a diagonal matrix, i.e., | 329 expected result. Extracting a leading submatrix of a diagonal matrix, i.e., |
330 @code{D(1:m,1:n)}, will produce a diagonal matrix, other indexing expressions | 330 @code{D(1:m,1:n)}, will produce a diagonal matrix, other indexing expressions |
331 will implicitly convert to full matrix. | 331 will implicitly convert to full matrix. |
349 @node Expressions Involving Permutation Matrices | 349 @node Expressions Involving Permutation Matrices |
350 @subsection Expressions Involving Permutation Matrices | 350 @subsection Expressions Involving Permutation Matrices |
351 | 351 |
352 If @var{P} is a permutation matrix and @var{M} a matrix, the expression | 352 If @var{P} is a permutation matrix and @var{M} a matrix, the expression |
353 @code{P*M} will permute the rows of @var{M}. Similarly, @code{M*P} will | 353 @code{P*M} will permute the rows of @var{M}. Similarly, @code{M*P} will |
354 yield a column permutation. | 354 yield a column permutation. |
355 Matrix division @code{P\M} and @code{M/P} can be used to do inverse permutation. | 355 Matrix division @code{P\M} and @code{M/P} can be used to do inverse permutation. |
356 | 356 |
357 The previously described syntax for creating permutation matrices can actually | 357 The previously described syntax for creating permutation matrices can actually |
358 help an user to understand the connection between a permutation matrix and | 358 help an user to understand the connection between a permutation matrix and |
359 a permuting vector. Namely, the following holds, where @code{I = eye (n)} | 359 a permuting vector. Namely, the following holds, where @code{I = eye (n)} |
412 @dfn{inv} and @dfn{pinv} can be applied to a diagonal matrix, yielding again | 412 @dfn{inv} and @dfn{pinv} can be applied to a diagonal matrix, yielding again |
413 a diagonal matrix. @dfn{det} will use an efficient straightforward calculation | 413 a diagonal matrix. @dfn{det} will use an efficient straightforward calculation |
414 when given a diagonal matrix, as well as @dfn{cond}. | 414 when given a diagonal matrix, as well as @dfn{cond}. |
415 The following mapper functions can be applied to a diagonal matrix | 415 The following mapper functions can be applied to a diagonal matrix |
416 without converting it to a full one: | 416 without converting it to a full one: |
417 @dfn{abs}, @dfn{real}, @dfn{imag}, @dfn{conj}, @dfn{sqrt}. | 417 @dfn{abs}, @dfn{real}, @dfn{imag}, @dfn{conj}, @dfn{sqrt}. |
418 A diagonal matrix can also be returned from the @dfn{balance} | 418 A diagonal matrix can also be returned from the @dfn{balance} |
419 and @dfn{svd} functions. | 419 and @dfn{svd} functions. |
420 The @dfn{sparse} function will convert a diagonal matrix efficiently to a | 420 The @dfn{sparse} function will convert a diagonal matrix efficiently to a |
421 sparse matrix. | 421 sparse matrix. |
422 | 422 |
520 normally stored somewhere in memory as an explicit value. An "assumed zero", on | 520 normally stored somewhere in memory as an explicit value. An "assumed zero", on |
521 the contrary, is a zero matrix element implied by the matrix structure | 521 the contrary, is a zero matrix element implied by the matrix structure |
522 (diagonal, triangular) or a sparsity pattern; its value is usually not stored | 522 (diagonal, triangular) or a sparsity pattern; its value is usually not stored |
523 explicitly anywhere, but is implied by the underlying data structure. | 523 explicitly anywhere, but is implied by the underlying data structure. |
524 | 524 |
525 The primary distinction is that an assumed zero, when multiplied | 525 The primary distinction is that an assumed zero, when multiplied |
526 by any number, or divided by any nonzero number, | 526 by any number, or divided by any nonzero number, |
527 yields *always* a zero, even when, e.g., multiplied by @code{Inf} | 527 yields *always* a zero, even when, e.g., multiplied by @code{Inf} |
528 or divided by @code{NaN}. | 528 or divided by @code{NaN}. |
529 The reason for this behavior is that the numerical multiplication is not | 529 The reason for this behavior is that the numerical multiplication is not |
530 actually performed anywhere by the underlying algorithm; the result is | 530 actually performed anywhere by the underlying algorithm; the result is |