Mercurial > hg > octave-nkf
annotate doc/interpreter/matrix.txi @ 13017:aaf6fbb2512f stable
doc: Add cross references to "status of variables" in sections for predicates
* matrix.txi: Cross reference to Status of Variables
* numbers.txi: Ditto.
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Sat, 27 Aug 2011 13:37:31 -0500 |
parents | 4d777e05d47c |
children | 1653d3a86fca |
rev | line source |
---|---|
11523 | 1 @c Copyright (C) 1996-2011 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
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 | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
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 | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
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 | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Matrix Manipulation |
3294 | 20 @chapter Matrix Manipulation |
21 | |
22 There are a number of functions available for checking to see if the | |
23 elements of a matrix meet some condition, and for rearranging the | |
24 elements of a matrix. For example, Octave can easily tell you if all | |
25 the elements of a matrix are finite, or are less than some specified | |
26 value. Octave can also rotate the elements, extract the upper- or | |
27 lower-triangular parts, or sort the columns of a matrix. | |
28 | |
29 @menu | |
30 * Finding Elements and Checking Conditions:: | |
31 * Rearranging Matrices:: | |
6550 | 32 * Applying a Function to an Array:: |
3294 | 33 * Special Utility Matrices:: |
34 * Famous Matrices:: | |
35 @end menu | |
36 | |
4167 | 37 @node Finding Elements and Checking Conditions |
3294 | 38 @section Finding Elements and Checking Conditions |
39 | |
40 The functions @code{any} and @code{all} are useful for determining | |
41 whether any or all of the elements of a matrix satisfy some condition. | |
42 The @code{find} function is also useful in determining which elements of | |
43 a matrix meet a specified condition. | |
44 | |
3369 | 45 @DOCSTRING(any) |
3294 | 46 |
3369 | 47 @DOCSTRING(all) |
3294 | 48 |
49 Since the comparison operators (@pxref{Comparison Ops}) return matrices | |
50 of ones and zeros, it is easy to test a matrix for many things, not just | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
51 whether the elements are nonzero. For example, |
3294 | 52 |
53 @example | |
54 @group | |
55 all (all (rand (5) < 0.9)) | |
56 @result{} 0 | |
57 @end group | |
58 @end example | |
59 | |
60 @noindent | |
61 tests a random 5 by 5 matrix to see if all of its elements are less | |
62 than 0.9. | |
63 | |
64 Note that in conditional contexts (like the test clause of @code{if} and | |
65 @code{while} statements) Octave treats the test as if you had typed | |
66 @code{all (all (condition))}. | |
67 | |
3428 | 68 @DOCSTRING(xor) |
69 | |
3369 | 70 @DOCSTRING(diff) |
3294 | 71 |
3369 | 72 @DOCSTRING(isinf) |
3294 | 73 |
3369 | 74 @DOCSTRING(isnan) |
3294 | 75 |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10892
diff
changeset
|
76 @DOCSTRING(isfinite) |
3294 | 77 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
78 @DOCSTRING(common_size) |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
79 |
3369 | 80 @DOCSTRING(find) |
3294 | 81 |
9367 | 82 @DOCSTRING(lookup) |
3428 | 83 |
13017
aaf6fbb2512f
doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
84 If you wish to check if a variable exists at all, instead of properties |
aaf6fbb2512f
doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
85 its elements may have, consult @ref{Status of variables}. |
aaf6fbb2512f
doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
86 |
4167 | 87 @node Rearranging Matrices |
3294 | 88 @section Rearranging Matrices |
89 | |
3369 | 90 @DOCSTRING(fliplr) |
3294 | 91 |
3369 | 92 @DOCSTRING(flipud) |
3294 | 93 |
4869 | 94 @DOCSTRING(flipdim) |
95 | |
3369 | 96 @DOCSTRING(rot90) |
3294 | 97 |
4869 | 98 @DOCSTRING(rotdim) |
99 | |
4845 | 100 @DOCSTRING(cat) |
101 | |
102 @DOCSTRING(horzcat) | |
103 | |
104 @DOCSTRING(vertcat) | |
105 | |
106 @DOCSTRING(permute) | |
107 | |
108 @DOCSTRING(ipermute) | |
109 | |
3369 | 110 @DOCSTRING(reshape) |
3294 | 111 |
8432
c9cb8f0b8b4f
add reference to resize function in the manual
Francesco Potortì <pot@gnu.org>
parents:
8286
diff
changeset
|
112 @DOCSTRING(resize) |
c9cb8f0b8b4f
add reference to resize function in the manual
Francesco Potortì <pot@gnu.org>
parents:
8286
diff
changeset
|
113 |
4894 | 114 @DOCSTRING(circshift) |
115 | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
116 @DOCSTRING(shift) |
4894 | 117 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
118 @DOCSTRING(shiftdim) |
3294 | 119 |
3369 | 120 @DOCSTRING(sort) |
3294 | 121 |
6550 | 122 @DOCSTRING(sortrows) |
123 | |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8519
diff
changeset
|
124 @DOCSTRING(issorted) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8519
diff
changeset
|
125 |
12523
33f7d8f95f5b
Add nth_element function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12498
diff
changeset
|
126 @DOCSTRING(nth_element) |
33f7d8f95f5b
Add nth_element function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12498
diff
changeset
|
127 |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8133
diff
changeset
|
128 @anchor{doc-triu} |
3369 | 129 @DOCSTRING(tril) |
3294 | 130 |
3369 | 131 @DOCSTRING(vec) |
3294 | 132 |
3369 | 133 @DOCSTRING(vech) |
3294 | 134 |
3428 | 135 @DOCSTRING(prepad) |
136 | |
11539
6bac61388876
Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
137 @DOCSTRING(postpad) |
6bac61388876
Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
138 |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
139 @DOCSTRING(diag) |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
140 |
6550 | 141 @DOCSTRING(blkdiag) |
142 | |
143 @node Applying a Function to an Array | |
144 @section Applying a Function to an Array | |
145 | |
146 @DOCSTRING(arrayfun) | |
147 | |
6868 | 148 @DOCSTRING(bsxfun) |
149 | |
4167 | 150 @node Special Utility Matrices |
3294 | 151 @section Special Utility Matrices |
152 | |
3369 | 153 @DOCSTRING(eye) |
3294 | 154 |
3369 | 155 @DOCSTRING(ones) |
3294 | 156 |
3369 | 157 @DOCSTRING(zeros) |
3294 | 158 |
3920 | 159 @DOCSTRING(repmat) |
160 | |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
161 @DOCSTRING(repelems) |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
162 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
163 The functions @code{linspace} and @code{logspace} make it very easy to |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
164 create vectors with evenly or logarithmically spaced elements. |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
165 @xref{Ranges}. |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
166 |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
167 @DOCSTRING(linspace) |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
168 |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
169 @DOCSTRING(logspace) |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12523
diff
changeset
|
170 |
3369 | 171 @DOCSTRING(rand) |
3294 | 172 |
10892
20ce631f0f12
Add new randi function for random integers.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
173 @DOCSTRING(randi) |
20ce631f0f12
Add new randi function for random integers.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
174 |
3369 | 175 @DOCSTRING(randn) |
3294 | 176 |
5730 | 177 @DOCSTRING(rande) |
178 | |
179 @DOCSTRING(randp) | |
180 | |
181 @DOCSTRING(randg) | |
182 | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
183 The generators operate in the new or old style together, it is not |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
184 possible to mix the two. Initializing any generator with |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
185 @code{"state"} or @code{"seed"} causes the others to switch to the |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
186 same style for future calls. |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
187 |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
188 The state of each generator is independent and calls to different |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
189 generators can be interleaved without affecting the final result. For |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
190 example, |
3294 | 191 |
192 @example | |
193 @group | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
194 rand ("state", [11, 22, 33]); |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
195 randn ("state", [44, 55, 66]); |
3294 | 196 u = rand (100, 1); |
197 n = randn (100, 1); | |
198 @end group | |
199 @end example | |
200 | |
201 @noindent | |
202 and | |
203 | |
204 @example | |
205 @group | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
206 rand ("state", [11, 22, 33]); |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
207 randn ("state", [44, 55, 66]); |
3294 | 208 u = zeros (100, 1); |
209 n = zeros (100, 1); | |
210 for i = 1:100 | |
211 u(i) = rand (); | |
212 n(i) = randn (); | |
213 end | |
214 @end group | |
215 @end example | |
216 | |
217 @noindent | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
218 produce equivalent results. When the generators are initialized in |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
219 the old style with @code{"seed"} only @code{rand} and @code{randn} are |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
220 independent, because the old @code{rande}, @code{randg} and |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
221 @code{randp} generators make calls to @code{rand} and @code{randn}. |
3294 | 222 |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
223 The generators are initialized with random states at start-up, so |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
224 that the sequences of random numbers are not the same each time you run |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
225 Octave.@footnote{The old versions of @code{rand} and @code{randn} |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
226 obtain their initial seeds from the system clock.} If you really do |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
227 need to reproduce a sequence of numbers exactly, you can set the state |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
228 or seed to a specific value. |
3294 | 229 |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
230 If invoked without arguments, @code{rand} and @code{randn} return a |
3294 | 231 single element of a random sequence. |
232 | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
233 The original @code{rand} and @code{randn} functions use Fortran code from |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10801
diff
changeset
|
234 @sc{ranlib}, a library of Fortran routines for random number generation, |
3294 | 235 compiled by Barry W. Brown and James Lovato of the Department of |
236 Biomathematics at The University of Texas, M.D. Anderson Cancer Center, | |
237 Houston, TX 77030. | |
238 | |
3428 | 239 @DOCSTRING(randperm) |
240 | |
4167 | 241 @node Famous Matrices |
3294 | 242 @section Famous Matrices |
243 | |
244 The following functions return famous matrix forms. | |
245 | |
6502 | 246 @DOCSTRING(hadamard) |
247 | |
3369 | 248 @DOCSTRING(hankel) |
3294 | 249 |
3369 | 250 @DOCSTRING(hilb) |
3294 | 251 |
3369 | 252 @DOCSTRING(invhilb) |
3294 | 253 |
6502 | 254 @DOCSTRING(magic) |
255 | |
256 @DOCSTRING(pascal) | |
257 | |
258 @DOCSTRING(rosser) | |
259 | |
3369 | 260 @DOCSTRING(sylvester_matrix) |
3294 | 261 |
3369 | 262 @DOCSTRING(toeplitz) |
3294 | 263 |
3369 | 264 @DOCSTRING(vander) |
6502 | 265 |
266 @DOCSTRING(wilkinson) |