annotate doc/interpreter/numbers.txi @ 27627:2890a931e647

Deprecated sizemax function (bug #47469). * scripts/deprecated/sizemax.m: New m-file to produce a warning and provide sizemax() behavior for the next two Octave releases. * scripts/deprecated/module.mk: Add sizemax.m to build system. * bitfcns.cc (Fsizemax): Remove function. * dim-vector.h (dim_max): Add OCTAVE_DEPRECATED macro to function. * dim-vector.cc (safe_numel): Call std::numeric_limits<octave_idx_type>::max rather than dim_max(). * __sprand__.m: Replace sizemax() invocation with new code. * numbers.txi: Remove DOCSTRING entry for sizemax and add text explaining actual size limitation imposed by size of index pointers when Octave was compiled.
author Rik <rik@octave.org>
date Mon, 04 Nov 2019 08:09:37 -0800
parents 757a7119e319
children 31b95261c7d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26301
diff changeset
1 @c Copyright (C) 1996-2019 John W. Eaton
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
2 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
3 @c This file is part of Octave.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
4 @c
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
5 @c Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
6 @c under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
7 @c the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
8 @c (at your option) any later version.
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
9 @c
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
10 @c Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
11 @c WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 @c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 @c GNU General Public License for more details.
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
14 @c
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
15 @c You should have received a copy of the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
16 @c along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
17 @c <https://www.gnu.org/licenses/>.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
18
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
19 @node Numeric Data Types
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
20 @chapter Numeric Data Types
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
21 @cindex numeric constant
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
22 @cindex numeric value
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
23
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
24 A @dfn{numeric constant} may be a scalar, a vector, or a matrix, and it may
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
25 contain complex values.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
26
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
27 The simplest form of a numeric constant, a scalar, is a single number. Note
23217
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
28 that by default numeric constants are represented within Octave by IEEE 754
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
29 double precision (binary64) floating-point format (complex constants are
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
30 stored as pairs of binary64 values). It is, however, possible to represent
23217
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
31 real integers as described in @ref{Integer Data Types}.
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
32
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
33 If the numeric constant is a real integer, it can be defined in decimal,
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
34 hexadecimal, or binary notation. Hexadecimal notation starts with @samp{0x} or
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
35 @samp{0X}, binary notation starts with @samp{0b} or @samp{0B}, otherwise
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
36 decimal notation is assumed. As a consequence, @samp{0b} is not a hexadecimal
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
37 number, in fact, it is not a valid number at all.
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
38
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
39 For better readability, digits may be partitioned by the underscore separator
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
40 @samp{_}, which is ignored by the Octave interpreter. Here are some examples
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
41 of real-valued integer constants, which all represent the same value and are
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
42 internally stored as binary64:
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
43
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
44 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
45 @group
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
46 42 # decimal notation
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
47 0x2A # hexadecimal notation
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
48 0b101010 # binary notation
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
49 0b10_1010 # underscore notation
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
50 round (42.1) # also binary64
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
51 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
52 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
53
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
54 In decimal notation, the numeric constant may be denoted as decimal fraction
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
55 or even in scientific (exponential) notation. Note that this is not possible
23217
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
56 for hexadecimal or binary notation. Again, in the following example all
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
57 numeric constants represent the same value:
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
58
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
59 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
60 @group
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
61 .105
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
62 1.05e-1
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
63 .00105e+2
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
64 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
65 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
66
23217
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
67 Unlike most programming languages, complex numeric constants are denoted as
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
68 the sum of real and imaginary parts. The imaginary part is denoted by a
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
69 real-valued numeric constant followed immediately by a complex value indicator
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
70 (@samp{i}, @samp{j}, @samp{I}, or @samp{J} which represents
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
71 @tex
23217
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
72 $\sqrt{-1}$).
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
73 @end tex
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
74 @ifnottex
23217
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
75 @code{sqrt (-1)}).
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
76 @end ifnottex
23217
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
77 No spaces are allowed between the numeric constant and the complex value
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
78 indicator. Some examples of complex numeric constants that all represent the
893d99338cc8 doc: Reword manual section on numeric constants for clarity.
Rik <rik@octave.org>
parents: 23212
diff changeset
79 same value:
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
80
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
81 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
82 @group
23212
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
83 3 + 42i
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
84 3 + 42j
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
85 3 + 42I
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
86 3 + 42J
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
87 3.0 + 42.0i
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
88 3.0 + 0x2Ai
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
89 3.0 + 0b10_1010i
0881e1671490 doc: Add documentation for hex and binary prefix and _ separator(bugs #50305, #50334)
Ernst Reissner <rei3ner@arcor.de>
parents: 22323
diff changeset
90 0.3e1 + 420e-1i
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
91 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
92 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
93
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
94 @DOCSTRING(double)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
95
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
96 @DOCSTRING(complex)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
97
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
98 @menu
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
99 * Matrices::
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
100 * Ranges::
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
101 * Single Precision Data Types::
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
102 * Integer Data Types::
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
103 * Bit Manipulations::
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
104 * Logical Values::
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
105 * Promotion and Demotion of Data Types::
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
106 * Predicates for Numeric Objects::
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
107 @end menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
108
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
109 @node Matrices
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
110 @section Matrices
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
111 @cindex matrices
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
112
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
113 @opindex [
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
114 @opindex ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
115 @opindex ;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
116 @opindex ,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
117
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
118 It is easy to define a matrix of values in Octave. The size of the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
119 matrix is determined automatically, so it is not necessary to explicitly
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
120 state the dimensions. The expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
121
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
122 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
123 a = [1, 2; 3, 4]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
124 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
125
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
126 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
127 results in the matrix
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
128 @tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
129 $$ a = \left[ \matrix{ 1 & 2 \cr 3 & 4 } \right] $$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
130 @end tex
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
131 @ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
132
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
133 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
134 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
135
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
136 / \
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
137 | 1 2 |
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
138 a = | |
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
139 | 3 4 |
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
140 \ /
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
141
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
142 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
143 @end example
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
144
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
145 @end ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
146
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
147 Elements of a matrix may be arbitrary expressions, provided that the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
148 dimensions all make sense when combining the various pieces. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
149 example, given the above matrix, the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
150
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
151 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
152 [ a, a ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
153 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
154
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
155 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
156 produces the matrix
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
157
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
158 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
159 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
160 ans =
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
161
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
162 1 2 1 2
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
163 3 4 3 4
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
164 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
165 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
166
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
167 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
168 but the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
169
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
170 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
171 [ a, 1 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
172 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
173
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
174 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
175 produces the error
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
176
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
177 @example
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
178 error: number of rows must match (1 != 2) near line 13, column 6
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
179 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
180
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
181 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
182 (assuming that this expression was entered as the first thing on line
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
183 13, of course).
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
184
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
185 Inside the square brackets that delimit a matrix expression, Octave
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
186 looks at the surrounding context to determine whether spaces and newline
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
187 characters should be converted into element and row separators, or
4476
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
188 simply ignored, so an expression like
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
189
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
190 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
191 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
192 a = [ 1 2
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
193 3 4 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
194 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
195 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
196
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
197 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
198 will work. However, some possible sources of confusion remain. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
199 example, in the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
200
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
201 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
202 [ 1 - 1 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
203 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
204
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
205 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
206 the @samp{-} is treated as a binary operator and the result is the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
207 scalar 0, but in the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
208
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
209 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
210 [ 1 -1 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
211 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
212
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
213 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
214 the @samp{-} is treated as a unary operator and the result is the
4476
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
215 vector @code{[ 1, -1 ]}. Similarly, the expression
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
216
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
217 @example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
218 [ sin (pi) ]
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
219 @end example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
220
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
221 @noindent
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
222 will be parsed as
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
223
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
224 @example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
225 [ sin, (pi) ]
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
226 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
227
4476
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
228 @noindent
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
229 and will result in an error since the @code{sin} function will be
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
230 called with no arguments. To get around this, you must omit the space
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
231 between @code{sin} and the opening parenthesis, or enclose the
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
232 expression in a set of parentheses:
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
233
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
234 @example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
235 [ (sin (pi)) ]
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
236 @end example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
237
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
238 Whitespace surrounding the single quote character (@samp{'}, used as a
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
239 transpose operator and for delimiting character strings) can also cause
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
240 confusion. Given @code{a = 1}, the expression
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
241
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
242 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
243 [ 1 a' ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
244 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
245
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
246 @noindent
4476
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
247 results in the single quote character being treated as a
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
248 transpose operator and the result is the vector @code{[ 1, 1 ]}, but the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
249 expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
250
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
251 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
252 [ 1 a ' ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
253 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
254
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
255 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
256 produces the error message
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
257
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
258 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
259 @group
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
260 parse error:
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
261
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
262 syntax error
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
263
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
264 >>> [ 1 a ' ]
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
265 ^
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
266 @end group
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
267 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
268
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
269 @noindent
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
270 because not doing so would cause trouble when parsing the valid expression
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
271
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
272 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
273 [ a 'foo' ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
274 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
275
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
276 For clarity, it is probably best to always use commas and semicolons to
4476
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
277 separate matrix elements and rows.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
278
12190
66b2c377b38e Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
279 The maximum number of elements in a matrix is fixed when Octave is compiled.
27627
2890a931e647 Deprecated sizemax function (bug #47469).
Rik <rik@octave.org>
parents: 27585
diff changeset
280 If compiled with 64-bit index pointers the limit is @code{intmax ("int64")},
2890a931e647 Deprecated sizemax function (bug #47469).
Rik <rik@octave.org>
parents: 27585
diff changeset
281 otherwise it is @code{intmax ("int32")}. Note that other factors, such as the
2890a931e647 Deprecated sizemax function (bug #47469).
Rik <rik@octave.org>
parents: 27585
diff changeset
282 amount of memory available on your machine, may limit the maximum size of
2890a931e647 Deprecated sizemax function (bug #47469).
Rik <rik@octave.org>
parents: 27585
diff changeset
283 matrices to something smaller.
12190
66b2c377b38e Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11573
diff changeset
284
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
285 When you type a matrix or the name of a variable whose value is a
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
286 matrix, Octave responds by printing the matrix in with neatly aligned
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
287 rows and columns. If the rows of the matrix are too large to fit on the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
288 screen, Octave splits the matrix and displays a header before each
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
289 section to indicate which columns are being displayed. You can use the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
290 following variables to control the format of the output.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
291
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
292 @DOCSTRING(output_precision)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
293
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
294 It is possible to achieve a wide range of output styles by using
26301
99318daeaddd Properly deprecate output_max_field_width from cset 4d945f2e5914.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25352
diff changeset
295 different values of @code{output_precision}. Reasonable combinations can be
99318daeaddd Properly deprecate output_max_field_width from cset 4d945f2e5914.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25352
diff changeset
296 set using the @code{format} function. @xref{Basic Input and Output}.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
297
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
298 @DOCSTRING(split_long_rows)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
299
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
300 Octave automatically switches to scientific notation when values become
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
301 very large or very small. This guarantees that you will see several
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
302 significant figures for every value in a matrix. If you would prefer to
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
303 see all values in a matrix printed in a fixed point format, you can set
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
304 the built-in variable @code{fixed_point_format} to a nonzero value. But
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
305 doing so is not recommended, because it can produce output that can
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
306 easily be misinterpreted.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
307
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
308 @DOCSTRING(fixed_point_format)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
309
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
310 @menu
17152
f2a8592b8fbd doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents: 17097
diff changeset
311 * Empty Matrices::
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
312 @end menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
313
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
314 @node Empty Matrices
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
315 @subsection Empty Matrices
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
316
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
317 A matrix may have one or both dimensions zero, and operations on empty
19040
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 18900
diff changeset
318 matrices are handled as described by @nospell{Carl de Boor} in
27585
757a7119e319 doc: Create en-dashes and em-dashes correctly in documentation.
Rik <rik@octave.org>
parents: 26376
diff changeset
319 @cite{An Empty Exercise}, SIGNUM, Volume 25, pages 2--6, 1990 and
19040
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 18900
diff changeset
320 @nospell{C. N. Nett and W. M. Haddad}, in
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 18900
diff changeset
321 @cite{A System-Theoretic Appropriate Realization of the Empty Matrix Concept},
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 18900
diff changeset
322 IEEE Transactions on Automatic Control, Volume 38, Number 5, May 1993.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
323 @tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
324 Briefly, given a scalar $s$, an $m\times n$ matrix $M_{m\times n}$,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
325 and an $m\times n$ empty matrix $[\,]_{m\times n}$ (with either one or
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
326 both dimensions equal to zero), the following are true:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
327 $$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
328 \eqalign{%
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
329 s \cdot [\,]_{m\times n} = [\,]_{m\times n} \cdot s &= [\,]_{m\times n}\cr
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
330 [\,]_{m\times n} + [\,]_{m\times n} &= [\,]_{m\times n}\cr
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
331 [\,]_{0\times m} \cdot M_{m\times n} &= [\,]_{0\times n}\cr
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
332 M_{m\times n} \cdot [\,]_{n\times 0} &= [\,]_{m\times 0}\cr
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
333 [\,]_{m\times 0} \cdot [\,]_{0\times n} &= 0_{m\times n}}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
334 $$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
335 @end tex
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
336 @ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
337 Briefly, given a scalar @var{s}, an @var{m} by
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
338 @var{n} matrix @code{M(mxn)}, and an @var{m} by @var{n} empty matrix
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
339 @code{[](mxn)} (with either one or both dimensions equal to zero), the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
340 following are true:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
341
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
342 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
343 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
344 s * [](mxn) = [](mxn) * s = [](mxn)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
345
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
346 [](mxn) + [](mxn) = [](mxn)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
347
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
348 [](0xm) * M(mxn) = [](0xn)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
349
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
350 M(mxn) * [](nx0) = [](mx0)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
351
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
352 [](mx0) * [](0xn) = 0(mxn)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
353 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
354 @end example
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
355
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
356 @end ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
357
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
358 By default, dimensions of the empty matrix are printed along with the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
359 empty matrix symbol, @samp{[]}. The built-in variable
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
360 @code{print_empty_dimensions} controls this behavior.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
361
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
362 @DOCSTRING(print_empty_dimensions)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
363
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
364 Empty matrices may also be used in assignment statements as a convenient
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
365 way to delete rows or columns of matrices.
17097
e7a059a9a644 doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents: 16939
diff changeset
366 @xref{Assignment Ops,,Assignment Expressions}.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
367
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
368 When Octave parses a matrix expression, it examines the elements of the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
369 list to determine whether they are all constants. If they are, it
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
370 replaces the list with a single matrix constant.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
371
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
372 @node Ranges
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
373 @section Ranges
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
374 @cindex range expressions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
375 @cindex expression, range
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
376
25352
3d5f953e2ef6 doc: Rewrite section on indexing for clarity (bug #53675).
Rik <rik@octave.org>
parents: 25054
diff changeset
377 @opindex :, range expressions
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
378
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
379 A @dfn{range} is a convenient way to write a row vector with evenly
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
380 spaced elements. A range expression is defined by the value of the first
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
381 element in the range, an optional value for the increment between
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
382 elements, and a maximum value which the elements of the range will not
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
383 exceed. The base, increment, and limit are separated by colons (the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
384 @samp{:} character) and may contain any arithmetic expressions and
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
385 function calls. If the increment is omitted, it is assumed to be 1.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
386 For example, the range
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
387
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
388 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
389 1 : 5
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
390 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
391
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
392 @noindent
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
393 defines the set of values @code{[ 1, 2, 3, 4, 5 ]}, and the range
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
394
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
395 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
396 1 : 3 : 5
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
397 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
398
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
399 @noindent
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
400 defines the set of values @code{[ 1, 4 ]}.
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
401
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
402 Although a range constant specifies a row vector, Octave does @emph{not}
19394
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 19040
diff changeset
403 normally convert range constants to vectors unless it is necessary to do so.
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
404 This allows you to write a constant like @code{1 : 10000} without using
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
405 80,000 bytes of storage on a typical 32-bit workstation.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
406
11179
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
407 A common example of when it does become necessary to convert ranges into
11573
6f8ffe2c6f76 Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
408 vectors occurs when they appear within a vector (i.e., inside square
6f8ffe2c6f76 Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
409 brackets). For instance, whereas
11179
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
410
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
411 @example
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
412 x = 0 : 0.1 : 1;
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
413 @end example
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
414
11573
6f8ffe2c6f76 Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
415 @noindent
11179
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
416 defines @var{x} to be a variable of type @code{range} and occupies 24
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
417 bytes of memory, the expression
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
418
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
419 @example
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
420 y = [ 0 : 0.1 : 1];
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
421 @end example
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
422
11573
6f8ffe2c6f76 Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
423 @noindent
11179
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
424 defines @var{y} to be of type @code{matrix} and occupies 88 bytes of
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
425 memory.
6ead75935ebf Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 10846
diff changeset
426
19394
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 19040
diff changeset
427 This space saving optimization may be disabled using the function
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 19040
diff changeset
428 @dfn{disable_range}.
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 19040
diff changeset
429
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 19040
diff changeset
430 @DOCSTRING(disable_range)
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 19040
diff changeset
431
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
432 Note that the upper (or lower, if the increment is negative) bound on
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
433 the range is not always included in the set of values, and that ranges
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
434 defined by floating point values can produce surprising results because
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
435 Octave uses floating point arithmetic to compute the values in the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
436 range. If it is important to include the endpoints of a range and the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
437 number of elements is known, you should use the @code{linspace} function
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
438 instead (@pxref{Special Utility Matrices}).
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
439
9158
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
440 When adding a scalar to a range, subtracting a scalar from it (or subtracting a
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
441 range from a scalar) and multiplying by scalar, Octave will attempt to avoid
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
442 unpacking the range and keep the result as a range, too, if it can determine
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
443 that it is safe to do so. For instance, doing
9158
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
444
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
445 @example
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
446 a = 2*(1:1e7) - 1;
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
447 @end example
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
448
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
449 @noindent
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
450 will produce the same result as @code{1:2:2e7-1}, but without ever forming a
9158
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
451 vector with ten million elements.
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
452
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
453 Using zero as an increment in the colon notation, as @code{1:0:1} is not
9158
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
454 allowed, because a division by zero would occur in determining the number of
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
455 range elements. However, ranges with zero increment (i.e., all elements equal)
9158
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
456 are useful, especially in indexing, and Octave allows them to be constructed
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
457 using the built-in function @code{ones}. Note that because a range must be a
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
458 row vector, @code{ones (1, 10)} produces a range, while @code{ones (10, 1)}
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 20716
diff changeset
459 does not.
9158
48ee8c73ff38 info about ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9136
diff changeset
460
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
461 When Octave parses a range expression, it examines the elements of the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
462 expression to determine whether they are all constants. If they are, it
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
463 replaces the range expression with a single range constant.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
464
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
465 @node Single Precision Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
466 @section Single Precision Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
467
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
468 Octave includes support for single precision data types, and most of the
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
469 functions in Octave accept single precision values and return single
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
470 precision answers. A single precision variable is created with the
8534
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
471 @code{single} function.
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
472
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
473 @DOCSTRING(single)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
474
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
475 for example:
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
476
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
477 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
478 @group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
479 sngl = single (rand (2, 2))
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
480 @result{} sngl =
8534
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
481 0.37569 0.92982
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
482 0.11962 0.50876
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
483 class (sngl)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
484 @result{} single
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
485 @end group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
486 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
487
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
488 Many functions can also return single precision values directly. For
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
489 example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
490
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
491 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
492 @group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
493 ones (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
494 zeros (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
495 eye (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
496 rand (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
497 NaN (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
498 NA (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
499 Inf (2, 2, "single")
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
500 @end group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
501 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
502
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
503 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
504 will all return single precision matrices.
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
505
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
506 @node Integer Data Types
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
507 @section Integer Data Types
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
508
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
509 Octave supports integer matrices as an alternative to using double
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
510 precision. It is possible to use both signed and unsigned integers
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
511 represented by 8, 16, 32, or 64 bits. It should be noted that most
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
512 computations require floating point data, meaning that integers will
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
513 often change type when involved in numeric computations. For this
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
514 reason integers are most often used to store data, and not for
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
515 calculations.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
516
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
517 In general most integer matrices are created by casting
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
518 existing matrices to integers. The following example shows how to cast
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
519 a matrix into 32 bit integers.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
520
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
521 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
522 @group
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
523 float = rand (2, 2)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
524 @result{} float = 0.37569 0.92982
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
525 0.11962 0.50876
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
526 integer = int32 (float)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
527 @result{} integer = 0 1
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
528 0 1
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
529 @end group
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
530 @end example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
531
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
532 @noindent
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
533 As can be seen, floating point values are rounded to the nearest integer
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
534 when converted.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
535
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
536 @DOCSTRING(isinteger)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
537
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
538 @DOCSTRING(int8)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
539
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
540 @DOCSTRING(uint8)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
541
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
542 @DOCSTRING(int16)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
543
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
544 @DOCSTRING(uint16)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
545
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
546 @DOCSTRING(int32)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
547
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
548 @DOCSTRING(uint32)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
550 @DOCSTRING(int64)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
551
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
552 @DOCSTRING(uint64)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
553
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
554 @DOCSTRING(intmax)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
555
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
556 @DOCSTRING(intmin)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
557
17390
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
558 @DOCSTRING(flintmax)
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
559
6624
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
560 @menu
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
561 * Integer Arithmetic::
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
562 @end menu
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
563
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
564 @node Integer Arithmetic
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
565 @subsection Integer Arithmetic
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
566
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
567 While many numerical computations can't be carried out in integers,
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
568 Octave does support basic operations like addition and multiplication
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
569 on integers. The operators @code{+}, @code{-}, @code{.*}, and @code{./}
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
570 work on integers of the same type. So, it is possible to add two 32 bit
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
571 integers, but not to add a 32 bit integer and a 16 bit integer.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
572
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
573 When doing integer arithmetic one should consider the possibility of
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
574 underflow and overflow. This happens when the result of the computation
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
575 can't be represented using the chosen integer type. As an example it is
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
576 not possible to represent the result of @math{10 - 20} when using
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
577 unsigned integers. Octave makes sure that the result of integer
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
578 computations is the integer that is closest to the true result. So, the
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
579 result of @math{10 - 20} when using unsigned integers is zero.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
580
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
581 When doing integer division Octave will round the result to the nearest
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
582 integer. This is different from most programming languages, where the
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
583 result is often floored to the nearest integer. So, the result of
14856
c3fd61c59e9c maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents: 14402
diff changeset
584 @code{int32 (5) ./ int32 (8)} is @code{1}.
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
585
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
586 @DOCSTRING(idivide)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
587
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
588 @node Bit Manipulations
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
589 @section Bit Manipulations
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
590
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
591 Octave provides a number of functions for the manipulation of numeric
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
592 values on a bit by bit basis. The basic functions to set and obtain the
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
593 values of individual bits are @code{bitset} and @code{bitget}.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
594
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
595 @DOCSTRING(bitset)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
596
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
597 @DOCSTRING(bitget)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
598
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
599 The arguments to all of Octave's bitwise operations can be scalar or
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
600 arrays, except for @code{bitcmp}, whose @var{k} argument must a
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
601 scalar. In the case where more than one argument is an array, then all
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
602 arguments must have the same shape, and the bitwise operator is applied
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
603 to each of the elements of the argument individually. If at least one
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
604 argument is a scalar and one an array, then the scalar argument is
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
605 duplicated. Therefore
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
606
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
607 @example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
608 bitget (100, 8:-1:1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
609 @end example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
610
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10828
diff changeset
611 @noindent
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
612 is the same as
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
613
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
614 @example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
615 bitget (100 * ones (1, 8), 8:-1:1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
616 @end example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
617
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
618 It should be noted that all values passed to the bit manipulation
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
619 functions of Octave are treated as integers. Therefore, even though the
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
620 example for @code{bitset} above passes the floating point value
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
621 @code{10}, it is treated as the bits @code{[1, 0, 1, 0]} rather than the
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
622 bits of the native floating point format representation of @code{10}.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
623
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8534
diff changeset
624 As the maximum value that can be represented by a number is important
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
625 for bit manipulation, particularly when forming masks, Octave supplies
20716
1ecee53513d7 doc: Peridodic grammar check of documentation.
Rik <rik@octave.org>
parents: 20486
diff changeset
626 two utility functions: @code{flintmax} for floating point integers, and
1ecee53513d7 doc: Peridodic grammar check of documentation.
Rik <rik@octave.org>
parents: 20486
diff changeset
627 @code{intmax} for integer objects (@code{uint8}, @code{int64}, etc.).
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
628
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17152
diff changeset
629 Octave also includes the basic bitwise 'and', 'or', and 'exclusive or'
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
630 operators.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
631
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
632 @DOCSTRING(bitand)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
633
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
634 @DOCSTRING(bitor)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
635
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
636 @DOCSTRING(bitxor)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
637
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
638 The bitwise 'not' operator is a unary operator that performs a logical
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
639 negation of each of the bits of the value. For this to make sense, the
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
640 mask against which the value is negated must be defined. Octave's
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
641 bitwise 'not' operator is @code{bitcmp}.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
642
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
643 @DOCSTRING(bitcmp)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
644
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
645 Octave also includes the ability to left-shift and right-shift values bitwise.
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
646
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
647 @DOCSTRING(bitshift)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
648
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
649 Bits that are shifted out of either end of the value are lost. Octave
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
650 also uses arithmetic shifts, where the sign bit of the value is kept
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
651 during a right shift. For example:
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
652
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
653 @example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
654 @group
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
655 bitshift (-10, -1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
656 @result{} -5
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
657 bitshift (int8 (-1), -1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
658 @result{} -1
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
659 @end group
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
660 @end example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
661
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
662 Note that @code{bitshift (int8 (-1), -1)} is @code{-1} since the bit
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
663 representation of @code{-1} in the @code{int8} data type is @code{[1, 1,
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
664 1, 1, 1, 1, 1, 1]}.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
665
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
666 @node Logical Values
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
667 @section Logical Values
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
668
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
669 Octave has built-in support for logical values, i.e., variables that
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
670 are either @code{true} or @code{false}. When comparing two variables,
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
671 the result will be a logical value whose value depends on whether or
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
672 not the comparison is true.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
673
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
674 The basic logical operations are @code{&}, @code{|}, and @code{!},
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
675 which correspond to ``Logical And'', ``Logical Or'', and ``Logical
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
676 Negation''. These operations all follow the usual rules of logic.
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
677
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
678 It is also possible to use logical values as part of standard numerical
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
679 calculations. In this case @code{true} is converted to @code{1}, and
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
680 @code{false} to 0, both represented using double precision floating
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
681 point numbers. So, the result of @code{true*22 - false/6} is @code{22}.
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
682
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
683 Logical values can also be used to index matrices and cell arrays.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
684 When indexing with a logical array the result will be a vector containing
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
685 the values corresponding to @code{true} parts of the logical array.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
686 The following example illustrates this.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
687
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
688 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
689 @group
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
690 data = [ 1, 2; 3, 4 ];
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
691 idx = (data <= 2);
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
692 data(idx)
9136
537a73861cb7 Fix small mistake in example.
Ansgar Burchard <ansgar@43-1.org>
parents: 9036
diff changeset
693 @result{} ans = [ 1; 2 ]
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
694 @end group
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
695 @end example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
696
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
697 @noindent
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
698 Instead of creating the @code{idx} array it is possible to replace
11376
567ca09a97aa Remove obsolete documentation about 64-bit integer arithmetic.
Rik <octave@nomad.inbox5.com>
parents: 11179
diff changeset
699 @code{data(idx)} with @w{@code{data( data <= 2 )}} in the above code.
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
700
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8534
diff changeset
701 Logical values can also be constructed by
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
702 casting numeric objects to logical values, or by using the @code{true}
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
703 or @code{false} functions.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
704
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
705 @DOCSTRING(logical)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
706
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
707 @DOCSTRING(true)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
708
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
709 @DOCSTRING(false)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
710
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
711 @node Promotion and Demotion of Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
712 @section Promotion and Demotion of Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
713
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
714 Many operators and functions can work with mixed data types. For example,
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
715
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
716 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
717 @group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
718 uint8 (1) + 1
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
719 @result{} 2
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
720 @end group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
721 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
722
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
723 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
724 where the above operator works with an 8-bit integer and a double precision
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
725 value and returns an 8-bit integer value. Note that the type is demoted
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
726 to an 8-bit integer, rather than promoted to a double precision value as
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
727 might be expected. The reason is that if Octave promoted values in
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
728 expressions like the above with all numerical constants would need to be
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
729 explicitly cast to the appropriate data type like
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
730
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
731 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
732 @group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
733 uint8 (1) + uint8 (1)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
734 @result{} 2
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
735 @end group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
736 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
737
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
738 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
739 which becomes difficult for the user to apply uniformly and might allow
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
740 hard to find bugs to be introduced. The same applies to single precision
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
741 values where a mixed operation such as
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
742
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
743 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
744 @group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
745 single (1) + 1
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
746 @result{} 2
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
747 @end group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
748 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
749
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
750 @noindent
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
751 returns a single precision value. The mixed operations that are valid
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
752 and their returned data types are
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
753
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
754 @multitable @columnfractions .2 .3 .3 .2
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
755 @headitem @tab Mixed Operation @tab Result @tab
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
756 @item @tab double OP single @tab single @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
757 @item @tab double OP integer @tab integer @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
758 @item @tab double OP char @tab double @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
759 @item @tab double OP logical @tab double @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
760 @item @tab single OP integer @tab integer @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
761 @item @tab single OP char @tab single @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
762 @item @tab single OP logical @tab single @tab
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
763 @end multitable
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
764
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
765 The same logic applies to functions with mixed arguments such as
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
766
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
767 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
768 @group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
769 min (single (1), 0)
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
770 @result{} 0
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
771 @end group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
772 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
773
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
774 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
775 where the returned value is single precision.
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
776
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
777 In the case of mixed type indexed assignments, the type is not
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
778 changed. For example,
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
779
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
780 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
781 @group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
782 x = ones (2, 2);
14402
cbcaf5602469 doc: Make spacing nicer for Strings chapter of manual.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
783 x(1, 1) = single (2)
cbcaf5602469 doc: Make spacing nicer for Strings chapter of manual.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
784 @result{} x = 2 1
cbcaf5602469 doc: Make spacing nicer for Strings chapter of manual.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
785 1 1
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
786 @end group
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
787 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
788
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
789 @noindent
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
790 where @code{x} remains of the double precision type.
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
791
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
792 @node Predicates for Numeric Objects
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
793 @section Predicates for Numeric Objects
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
794
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
795 Since the type of a variable may change during the execution of a
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
796 program, it can be necessary to do type checking at run-time. Doing this
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
797 also allows you to change the behavior of a function depending on the
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
798 type of the input. As an example, this naive implementation of @code{abs}
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6781
diff changeset
799 returns the absolute value of the input if it is a real number, and the
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
800 length of the input if it is a complex number.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
801
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
802 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
803 @group
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
804 function a = abs (x)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
805 if (isreal (x))
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
806 a = sign (x) .* x;
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
807 elseif (iscomplex (x))
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
808 a = sqrt (real(x).^2 + imag(x).^2);
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
809 endif
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
810 endfunction
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9158
diff changeset
811 @end group
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
812 @end example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
813
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
814 The following functions are available for determining the type of a
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
815 variable.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
816
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
817 @DOCSTRING(isnumeric)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
818
18900
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
819 @DOCSTRING(islogical)
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
820
12581
c8be316f9543 Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12488
diff changeset
821 @DOCSTRING(isfloat)
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
822
12581
c8be316f9543 Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12488
diff changeset
823 @DOCSTRING(isreal)
7638
2df457529cfa implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7018
diff changeset
824
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
825 @DOCSTRING(iscomplex)
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
826
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
827 @DOCSTRING(ismatrix)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
828
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
829 @DOCSTRING(isvector)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
830
12488
bea828c03969 Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents: 12190
diff changeset
831 @DOCSTRING(isrow)
bea828c03969 Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents: 12190
diff changeset
832
bea828c03969 Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents: 12190
diff changeset
833 @DOCSTRING(iscolumn)
bea828c03969 Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents: 12190
diff changeset
834
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
835 @DOCSTRING(isscalar)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
836
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
837 @DOCSTRING(issquare)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
838
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
839 @DOCSTRING(issymmetric)
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
840
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11403
diff changeset
841 @DOCSTRING(ishermitian)
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11403
diff changeset
842
6550
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
843 @DOCSTRING(isdefinite)
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
844
18900
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
845 @DOCSTRING(isbanded)
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
846
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
847 @DOCSTRING(isdiag)
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
848
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
849 @DOCSTRING(istril)
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
850
49961d67e4b9 Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 17744
diff changeset
851 @DOCSTRING(istriu)
6550
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
852
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
853 @DOCSTRING(isprime)
13017
aaf6fbb2512f doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12581
diff changeset
854
aaf6fbb2512f doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12581
diff changeset
855 If instead of knowing properties of variables, you wish to know which
aaf6fbb2512f doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12581
diff changeset
856 variables are defined and to gather other information about the
17097
e7a059a9a644 doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents: 16939
diff changeset
857 workspace itself, @pxref{Status of Variables}.