Mercurial > hg > octave-nkf
annotate doc/interpreter/matrix.txi @ 12498:294c0927c762
Deprecate is_duplicate_entry.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 03 Mar 2011 09:46:00 -0800 |
parents | 6bac61388876 |
children | 33f7d8f95f5b |
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 |
3369 | 78 @DOCSTRING(find) |
3294 | 79 |
9367 | 80 @DOCSTRING(lookup) |
81 | |
3428 | 82 @DOCSTRING(common_size) |
83 | |
4167 | 84 @node Rearranging Matrices |
3294 | 85 @section Rearranging Matrices |
86 | |
3369 | 87 @DOCSTRING(fliplr) |
3294 | 88 |
3369 | 89 @DOCSTRING(flipud) |
3294 | 90 |
4869 | 91 @DOCSTRING(flipdim) |
92 | |
3369 | 93 @DOCSTRING(rot90) |
3294 | 94 |
4869 | 95 @DOCSTRING(rotdim) |
96 | |
4845 | 97 @DOCSTRING(cat) |
98 | |
99 @DOCSTRING(horzcat) | |
100 | |
101 @DOCSTRING(vertcat) | |
102 | |
103 @DOCSTRING(permute) | |
104 | |
105 @DOCSTRING(ipermute) | |
106 | |
3369 | 107 @DOCSTRING(reshape) |
3294 | 108 |
8432
c9cb8f0b8b4f
add reference to resize function in the manual
Francesco Potortì <pot@gnu.org>
parents:
8286
diff
changeset
|
109 @DOCSTRING(resize) |
c9cb8f0b8b4f
add reference to resize function in the manual
Francesco Potortì <pot@gnu.org>
parents:
8286
diff
changeset
|
110 |
4894 | 111 @DOCSTRING(circshift) |
112 | |
113 @DOCSTRING(shiftdim) | |
114 | |
3369 | 115 @DOCSTRING(shift) |
3294 | 116 |
3369 | 117 @DOCSTRING(sort) |
3294 | 118 |
6550 | 119 @DOCSTRING(sortrows) |
120 | |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8519
diff
changeset
|
121 @DOCSTRING(issorted) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8519
diff
changeset
|
122 |
3294 | 123 Since the @code{sort} function does not allow sort keys to be specified, |
124 it can't be used to order the rows of a matrix according to the values | |
125 of the elements in various columns@footnote{For example, to first sort | |
126 based on the values in column 1, and then, for any values that are | |
127 repeated in column 1, sort based on the values found in column 2, etc.} | |
128 in a single call. Using the second output, however, it is possible to | |
129 sort all rows based on the values in a given column. Here's an example | |
130 that sorts the rows of a matrix based on the values in the second | |
131 column. | |
132 | |
133 @example | |
134 @group | |
135 a = [1, 2; 2, 3; 3, 1]; | |
136 [s, i] = sort (a (:, 2)); | |
137 a (i, :) | |
138 @result{} 3 1 | |
139 1 2 | |
140 2 3 | |
141 @end group | |
142 @end example | |
143 | |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8133
diff
changeset
|
144 @anchor{doc-triu} |
3369 | 145 @DOCSTRING(tril) |
3294 | 146 |
3369 | 147 @DOCSTRING(vec) |
3294 | 148 |
3369 | 149 @DOCSTRING(vech) |
3294 | 150 |
3428 | 151 @DOCSTRING(prepad) |
152 | |
11539
6bac61388876
Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
153 @DOCSTRING(postpad) |
6bac61388876
Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
154 |
8851
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
155 @DOCSTRING(diag) |
d6de39523f03
improve the diag & perm matrices text
Jaroslav Hajek <highegg@gmail.com>
parents:
8839
diff
changeset
|
156 |
6550 | 157 @DOCSTRING(blkdiag) |
158 | |
159 @node Applying a Function to an Array | |
160 @section Applying a Function to an Array | |
161 | |
162 @DOCSTRING(arrayfun) | |
163 | |
6868 | 164 @DOCSTRING(bsxfun) |
165 | |
4167 | 166 @node Special Utility Matrices |
3294 | 167 @section Special Utility Matrices |
168 | |
3369 | 169 @DOCSTRING(eye) |
3294 | 170 |
3369 | 171 @DOCSTRING(ones) |
3294 | 172 |
3369 | 173 @DOCSTRING(zeros) |
3294 | 174 |
3920 | 175 @DOCSTRING(repmat) |
176 | |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
177 @DOCSTRING(repelems) |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
178 |
3369 | 179 @DOCSTRING(rand) |
3294 | 180 |
10892
20ce631f0f12
Add new randi function for random integers.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
181 @DOCSTRING(randi) |
20ce631f0f12
Add new randi function for random integers.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
182 |
3369 | 183 @DOCSTRING(randn) |
3294 | 184 |
5730 | 185 @DOCSTRING(rande) |
186 | |
187 @DOCSTRING(randp) | |
188 | |
189 @DOCSTRING(randg) | |
190 | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
191 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
|
192 possible to mix the two. Initializing any generator with |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
193 @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
|
194 same style for future calls. |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
195 |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
196 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
|
197 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
|
198 example, |
3294 | 199 |
200 @example | |
201 @group | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
202 rand ("state", [11, 22, 33]); |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
203 randn ("state", [44, 55, 66]); |
3294 | 204 u = rand (100, 1); |
205 n = randn (100, 1); | |
206 @end group | |
207 @end example | |
208 | |
209 @noindent | |
210 and | |
211 | |
212 @example | |
213 @group | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
214 rand ("state", [11, 22, 33]); |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
215 randn ("state", [44, 55, 66]); |
3294 | 216 u = zeros (100, 1); |
217 n = zeros (100, 1); | |
218 for i = 1:100 | |
219 u(i) = rand (); | |
220 n(i) = randn (); | |
221 end | |
222 @end group | |
223 @end example | |
224 | |
225 @noindent | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
226 produce equivalent results. When the generators are initialized in |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
227 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
|
228 independent, because the old @code{rande}, @code{randg} and |
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
229 @code{randp} generators make calls to @code{rand} and @code{randn}. |
3294 | 230 |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 or seed to a specific value. |
3294 | 237 |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
238 If invoked without arguments, @code{rand} and @code{randn} return a |
3294 | 239 single element of a random sequence. |
240 | |
8133
f38997cf9e5b
matrix.txi: update docs for random number generators
Brian Gough
parents:
7018
diff
changeset
|
241 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
|
242 @sc{ranlib}, a library of Fortran routines for random number generation, |
3294 | 243 compiled by Barry W. Brown and James Lovato of the Department of |
244 Biomathematics at The University of Texas, M.D. Anderson Cancer Center, | |
245 Houston, TX 77030. | |
246 | |
3428 | 247 @DOCSTRING(randperm) |
248 | |
3294 | 249 The functions @code{linspace} and @code{logspace} make it very easy to |
250 create vectors with evenly or logarithmically spaced elements. | |
251 @xref{Ranges}. | |
252 | |
3369 | 253 @DOCSTRING(linspace) |
3294 | 254 |
3369 | 255 @DOCSTRING(logspace) |
3294 | 256 |
4167 | 257 @node Famous Matrices |
3294 | 258 @section Famous Matrices |
259 | |
260 The following functions return famous matrix forms. | |
261 | |
6502 | 262 @DOCSTRING(hadamard) |
263 | |
3369 | 264 @DOCSTRING(hankel) |
3294 | 265 |
3369 | 266 @DOCSTRING(hilb) |
3294 | 267 |
3369 | 268 @DOCSTRING(invhilb) |
3294 | 269 |
6502 | 270 @DOCSTRING(magic) |
271 | |
272 @DOCSTRING(pascal) | |
273 | |
274 @DOCSTRING(rosser) | |
275 | |
3369 | 276 @DOCSTRING(sylvester_matrix) |
3294 | 277 |
3369 | 278 @DOCSTRING(toeplitz) |
3294 | 279 |
3369 | 280 @DOCSTRING(vander) |
6502 | 281 |
282 @DOCSTRING(wilkinson) |