annotate doc/interpreter/numbers.txi @ 8828:8463d1a2e544

Doc fixes. * 2]$$. => 2].$$ * @var{extrapval} => @var{extrapval}. * call helloworld.oct => called @file{helloworld.oct} * @itemize => @table @code * shows. => shows: * save => @code{save} * @ref{Breakpoints} => @pxref{Breakpoints} * add @noindent following example * which is computed => and compute it * clarify wording * remove comma * good => well * set => number * by writing => with the command * has the option of directly calling => can call * [-like-] {+of the right size,+} * solvers => routines * handle => test for * add introductory section * add following * {+the+} [0..bitmax] => [0,bitmax] * of the => with * number => value * add usual * Besides when doing comparisons, logical => Logical {+also+} * array comparison => array, comparisons * param => parameter * works very similar => is similar * strings, => strings * most simple => simplest * easier => more easily * like => as * called => called, * clarify wording * you should simply type => use * clarify wording * means => way * equally => also * [-way much-] {+way+} * add with mean value parameter given by the first argument, @var{l} * add Functions described as @dfn{mapping functions} apply the given operation to each element when given a matrix argument. * in this brief introduction => here * It is worth noticing => Note * add following * means => ways
author Brian Gough <bjg@network-theory.co.uk>
date Fri, 20 Feb 2009 11:17:01 -0500
parents 0eb83938c8bc
children eb63fbe60fab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6778
083721ae3dfa [project @ 2007-07-18 17:03:10 by jwe]
jwe
parents: 6715
diff changeset
1 @c Copyright (C) 1996, 1997, 2007 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
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
5 @c Octave is free software; you can redistribute it and/or modify it
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
6 @c under the terms of the GNU General Public License as published by the
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
7 @c Free Software Foundation; either version 3 of the License, or (at
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
8 @c your option) any later version.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
9 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
13 @c for more details.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
14 @c
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
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
17 @c <http://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
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
24 A @dfn{numeric constant} may be a scalar, a vector, or a matrix, and it
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
25 may contain complex values.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
26
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
27 The simplest form of a numeric constant, a scalar, is a single number
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
28 that can be an integer, a decimal fraction, a number in scientific
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
29 (exponential) notation, or a complex number. Note that by default numeric
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
30 constants are represented within Octave in double-precision floating
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
31 point format (complex constants are stored as pairs of double-precision
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
32 floating point values). It is however possible to represent real
8534
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
33 integers as described in @ref{Integer Data Types}. Here are some
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
34 examples of real-valued numeric constants, which all have the same
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
35 value:
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
36
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
37 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
38 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
39 105
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
40 1.05e+2
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
41 1050e-1
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
42 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
43 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
44
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
45 To specify complex constants, you can write an expression of the form
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
46
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
47 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
48 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
49 3 + 4i
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
50 3.0 + 4.0i
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
51 0.3e1 + 40e-1i
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
52 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
53 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
54
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
55 @noindent
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
56 all of which are equivalent. The letter @samp{i} in the previous example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
57 stands for the pure imaginary constant, defined as
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
58 @iftex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
59 @tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
60 $\sqrt{-1}$.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
61 @end tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
62 @end iftex
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
63 @ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
64 @code{sqrt (-1)}.
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
65 @end ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
66
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
67 For Octave to recognize a value as the imaginary part of a complex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
68 constant, a space must not appear between the number and the @samp{i}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
69 If it does, Octave will print an error message, like this:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
70
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
71 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
72 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
73 octave:13> 3 + 4 i
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
74
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
75 parse error:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
76
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
77 syntax error
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
78
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
79 >>> 3 + 4 i
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
80 ^
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
81 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
82 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
83
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
84 @noindent
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
85 You may also use @samp{j}, @samp{I}, or @samp{J} in place of the
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
86 @samp{i} above. All four forms are equivalent.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
87
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
88 @DOCSTRING(double)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
89
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
90 @DOCSTRING(complex)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
91
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
92 @menu
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
93 * Matrices::
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
94 * Ranges::
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
95 * Single Precision Data Types::
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
96 * Integer Data Types::
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
97 * Bit Manipulations::
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
98 * Logical Values::
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
99 * Promotion and Demotion of Data Types::
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
100 * Predicates for Numeric Objects::
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
101 @end menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
102
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
103 @node Matrices
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
104 @section Matrices
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
105 @cindex matrices
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
106
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
107 @opindex [
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
108 @opindex ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
109 @opindex ;
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
110 @opindex ,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
111
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
112 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
113 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
114 state the dimensions. The expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
115
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
116 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
117 a = [1, 2; 3, 4]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
118 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
119
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
120 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
121 results in the matrix
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
122 @iftex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
123 @tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
124 $$ a = \left[ \matrix{ 1 & 2 \cr 3 & 4 } \right] $$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
125 @end tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
126 @end iftex
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
127 @ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
128
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
129 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
130 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
131
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 | 1 2 |
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
134 a = | |
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
135 | 3 4 |
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
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
138 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
139 @end example
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
140 @end ifnottex
3294
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 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
143 dimensions all make sense when combining the various pieces. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
144 example, given the above matrix, the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
145
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
146 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
147 [ a, a ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
148 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
149
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
150 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
151 produces the matrix
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
152
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
153 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
154 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
155 ans =
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
156
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
157 1 2 1 2
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
158 3 4 3 4
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
159 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
160 @end example
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 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
163 but the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
164
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
165 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
166 [ a, 1 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
167 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
168
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
169 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
170 produces the error
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
171
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
172 @example
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
173 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
174 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
175
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
176 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
177 (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
178 13, of course).
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
179
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
180 Inside the square brackets that delimit a matrix expression, Octave
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
181 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
182 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
183 simply ignored, so an expression like
3294
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 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
186 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
187 a = [ 1 2
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
188 3 4 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
189 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
190 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
191
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
192 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
193 will work. However, some possible sources of confusion remain. For
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
194 example, in the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
195
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
196 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
197 [ 1 - 1 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
198 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
199
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
200 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
201 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
202 scalar 0, but in the expression
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
203
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
204 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
205 [ 1 -1 ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
206 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
207
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
208 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
209 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
210 vector @code{[ 1, -1 ]}. Similarly, the expression
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
211
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
212 @example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
213 [ sin (pi) ]
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
214 @end example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
215
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
216 @noindent
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
217 will be parsed as
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
218
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
219 @example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
220 [ sin, (pi) ]
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
221 @end example
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
222
4476
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
223 @noindent
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
224 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
225 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
226 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
227 expression in a set of parentheses:
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
228
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
229 @example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
230 [ (sin (pi)) ]
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
231 @end example
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
232
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
233 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
234 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
235 confusion. Given @code{a = 1}, the expression
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
236
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
237 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
238 [ 1 a' ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
239 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
240
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
241 @noindent
4476
b7360f8eb035 [project @ 2003-07-30 17:17:21 by jwe]
jwe
parents: 4460
diff changeset
242 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
243 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
244 expression
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 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
247 [ 1 a ' ]
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
248 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
249
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
250 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
251 produces the error message
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
252
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
253 @example
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
254 parse error:
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
255
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
256 syntax error
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
257
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
258 >>> [ 1 a ' ]
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 7989
diff changeset
259 ^
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
260 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
261
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
262 @noindent
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
263 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
264
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
265 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
266 [ a 'foo' ]
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 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
270 separate matrix elements and rows.
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 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
273 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
274 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
275 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
276 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
277 following variables to control the format of the output.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
278
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
279 @DOCSTRING(output_max_field_width)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
280
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
281 @DOCSTRING(output_precision)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
282
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
283 It is possible to achieve a wide range of output styles by using
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
284 different values of @code{output_precision} and
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
285 @code{output_max_field_width}. Reasonable combinations can be set using
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
286 the @code{format} function. @xref{Basic Input and Output}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
287
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
288 @DOCSTRING(split_long_rows)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
289
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
290 Octave automatically switches to scientific notation when values become
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
291 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
292 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
293 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
294 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
295 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
296 easily be misinterpreted.
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(fixed_point_format)
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 @menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
301 * Empty Matrices::
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
302 @end menu
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
303
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
304 @node Empty Matrices
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
305 @subsection Empty Matrices
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
306
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
307 A matrix may have one or both dimensions zero, and operations on empty
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
308 matrices are handled as described by Carl de Boor in @cite{An Empty
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
309 Exercise}, SIGNUM, Volume 25, pages 2--6, 1990 and C. N. Nett and W. M.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
310 Haddad, in @cite{A System-Theoretic Appropriate Realization of the Empty
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
311 Matrix Concept}, IEEE Transactions on Automatic Control, Volume 38,
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
312 Number 5, May 1993.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
313 @iftex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
314 @tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
315 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
316 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
317 both dimensions equal to zero), the following are true:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
318 $$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
319 \eqalign{%
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
320 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
321 [\,]_{m\times n} + [\,]_{m\times n} &= [\,]_{m\times n}\cr
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
322 [\,]_{0\times m} \cdot M_{m\times n} &= [\,]_{0\times n}\cr
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
323 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
324 [\,]_{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
325 $$
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
326 @end tex
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
327 @end iftex
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
328 @ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
329 Briefly, given a scalar @var{s}, an @var{m} by
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
330 @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
331 @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
332 following are true:
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
333
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
334 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
335 @group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
336 s * [](mxn) = [](mxn) * s = [](mxn)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
337
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
338 [](mxn) + [](mxn) = [](mxn)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
339
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
340 [](0xm) * M(mxn) = [](0xn)
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 M(mxn) * [](nx0) = [](mx0)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
343
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
344 [](mx0) * [](0xn) = 0(mxn)
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
345 @end group
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
346 @end example
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
347 @end ifnottex
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
348
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
349 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
350 empty matrix symbol, @samp{[]}. The built-in variable
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
351 @code{print_empty_dimensions} controls this behavior.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
352
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3294
diff changeset
353 @DOCSTRING(print_empty_dimensions)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
354
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
355 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
356 way to delete rows or columns of matrices.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
357 @xref{Assignment Ops, ,Assignment Expressions}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
358
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
359 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
360 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
361 replaces the list with a single matrix constant.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
362
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
363 @node Ranges
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
364 @section Ranges
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
365 @cindex range expressions
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
366 @cindex expression, range
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
367
3920
87db95b22f8f [project @ 2002-05-01 04:07:31 by jwe]
jwe
parents: 3428
diff changeset
368 @opindex colon
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
369
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
370 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
371 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
372 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
373 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
374 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
375 @samp{:} character) and may contain any arithmetic expressions and
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
376 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
377 For example, the range
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 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
380 1 : 5
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
381 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
382
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
383 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
384 defines the set of values @samp{[ 1, 2, 3, 4, 5 ]}, and the range
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
385
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
386 @example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
387 1 : 3 : 5
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
388 @end example
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
389
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
390 @noindent
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
391 defines the set of values @samp{[ 1, 4 ]}.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
392
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
393 Although a range constant specifies a row vector, Octave does @emph{not}
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
394 convert range constants to vectors unless it is necessary to do so.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
395 This allows you to write a constant like @samp{1 : 10000} without using
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
396 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
397
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
398 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
399 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
400 defined by floating point values can produce surprising results because
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
401 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
402 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
403 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
404 instead (@pxref{Special Utility Matrices}).
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
405
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
406 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
407 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
408 replaces the range expression with a single range constant.
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
409
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
410 @node Single Precision Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
411 @section Single Precision Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
412
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
413 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
414 functions in Octave accept single precision values and return single
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
415 precion 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
416 @code{single} function.
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
417
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
418 @DOCSTRING(single)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
419
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
420 for example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
421
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
422 @example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
423 sngl = single (rand (2, 2))
8534
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
424 @result{} sngl =
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
425 0.37569 0.92982
0eb83938c8bc Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8347
diff changeset
426 0.11962 0.50876
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
427 class (sngl)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
428 @result{} single
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
429 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
430
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
431 Many functions can also return single precision values directly. For
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
432 example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
433
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
434 @example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
435 ones (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
436 zeros (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
437 eye (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
438 rand (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
439 NaN (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
440 NA (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
441 Inf (2, 2, "single")
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
442 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
443
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
444 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
445 will all return single precision matrices.
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
446
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
447 @node Integer Data Types
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
448 @section Integer Data Types
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
449
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
450 Octave supports integer matrices as an alternative to using double
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
451 precision. It is possible to use both signed and unsigned integers
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
452 represented by 8, 16, 32, or 64 bits. It should be noted that most
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
453 computations require floating point data, meaning that integers will
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
454 often change type when involved in numeric computations. For this
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
455 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
456 calculations.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
457
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
458 In general most integer matrices are created by casting
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
459 existing matrices to integers. The following example shows how to cast
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
460 a matrix into 32 bit integers.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
461
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
462 @example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
463 float = rand (2, 2)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
464 @result{} float = 0.37569 0.92982
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
465 0.11962 0.50876
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
466 integer = int32 (float)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
467 @result{} integer = 0 1
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
468 0 1
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
469 @end example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
470
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
471 @noindent
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
472 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
473 when converted.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
474
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
475 @DOCSTRING(isinteger)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
476
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
477 @DOCSTRING(int8)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
478
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
479 @DOCSTRING(uint8)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
480
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
481 @DOCSTRING(int16)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
482
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
483 @DOCSTRING(uint16)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
484
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
485 @DOCSTRING(int32)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
486
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
487 @DOCSTRING(uint32)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
488
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
489 @DOCSTRING(int64)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
490
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
491 @DOCSTRING(uint64)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
492
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
493 @DOCSTRING(intmax)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
494
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
495 @DOCSTRING(intmin)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
496
8039
cd90e2842080 Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents: 8015
diff changeset
497 @DOCSTRING(intwarning)
cd90e2842080 Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents: 8015
diff changeset
498
6624
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
499 @menu
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
500 * Integer Arithmetic::
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
501 @end menu
0d69a50fc5a9 [project @ 2007-05-15 20:17:27 by jwe]
jwe
parents: 6620
diff changeset
502
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
503 @node Integer Arithmetic
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
504 @subsection Integer Arithmetic
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
505
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
506 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
507 Octave does support basic operations like addition and multiplication
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
508 on integers. The operators @code{+}, @code{-}, @code{.*}, and @code{./}
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
509 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
510 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
511
6715
c729dcb215c6 [project @ 2007-06-13 11:06:47 by dbateman]
dbateman
parents: 6688
diff changeset
512 The arithmetic operations on integers are performed by casting the
c729dcb215c6 [project @ 2007-06-13 11:06:47 by dbateman]
dbateman
parents: 6688
diff changeset
513 integer values to double precision values, performing the operation, and
c729dcb215c6 [project @ 2007-06-13 11:06:47 by dbateman]
dbateman
parents: 6688
diff changeset
514 then re-casting the values back to the original integer type. As the
c729dcb215c6 [project @ 2007-06-13 11:06:47 by dbateman]
dbateman
parents: 6688
diff changeset
515 double precision type of Octave is only capable of representing integers
c729dcb215c6 [project @ 2007-06-13 11:06:47 by dbateman]
dbateman
parents: 6688
diff changeset
516 with up to 53 bits of precision, it is not possible to perform
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8534
diff changeset
517 arithmetic with 64 bit integer types.
6715
c729dcb215c6 [project @ 2007-06-13 11:06:47 by dbateman]
dbateman
parents: 6688
diff changeset
518
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
519 When doing integer arithmetic one should consider the possibility of
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
520 underflow and overflow. This happens when the result of the computation
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
521 can't be represented using the chosen integer type. As an example it is
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
522 not possible to represent the result of @math{10 - 20} when using
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
523 unsigned integers. Octave makes sure that the result of integer
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
524 computations is the integer that is closest to the true result. So, the
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
525 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
526
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
527 When doing integer division Octave will round the result to the nearest
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
528 integer. This is different from most programming languages, where the
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
529 result is often floored to the nearest integer. So, the result of
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
530 @code{int32(5)./int32(8)} is @code{1}.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
531
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
532 @DOCSTRING(idivide)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
533
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
534 @node Bit Manipulations
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
535 @section Bit Manipulations
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
536
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
537 Octave provides a number of functions for the manipulation of numeric
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
538 values on a bit by bit basis. The basic functions to set and obtain the
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
539 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
540
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
541 @DOCSTRING(bitset)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
542
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
543 @DOCSTRING(bitget)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
544
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
545 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
546 arrays, except for @code{bitcmp}, whose @var{k} argument must a
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
547 scalar. In the case where more than one argument is an array, then all
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
548 arguments must have the same shape, and the bitwise operator is applied
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
549 to each of the elements of the argument individually. If at least one
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
550 argument is a scalar and one an array, then the scalar argument is
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
551 duplicated. Therefore
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
552
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
553 @example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
554 bitget (100, 8:-1:1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
555 @end example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
556
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
557 is the same as
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
558
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
559 @example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
560 bitget (100 * ones (1, 8), 8:-1:1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
561 @end example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
562
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
563 It should be noted that all values passed to the bit manipulation
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
564 functions of Octave are treated as integers. Therefore, even though the
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
565 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
566 @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
567 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
568
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8534
diff changeset
569 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
570 for bit manipulation, particularly when forming masks, Octave supplies
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
571 the function @code{bitmax}.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
572
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
573 @DOCSTRING(bitmax)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
574
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
575 This is the double precision version of the functions @code{intmax},
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
576 previously discussed.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
577
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
578 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
579 operators.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
580
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
581 @DOCSTRING(bitand)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
582
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
583 @DOCSTRING(bitor)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
584
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
585 @DOCSTRING(bitxor)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
586
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
587 The bitwise 'not' operator is a unary operator that performs a logical
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
588 negation of each of the bits of the value. For this to make sense, the
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
589 mask against which the value is negated must be defined. Octave's
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
590 bitwise 'not' operator is @code{bitcmp}.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
591
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
592 @DOCSTRING(bitcmp)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
593
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
594 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
595
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
596 @DOCSTRING(bitshift)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
597
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
598 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
599 also uses arithmetic shifts, where the sign bit of the value is kept
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
600 during a right shift. For example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
601
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
602 @example
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
603 @group
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
604 bitshift (-10, -1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
605 @result{} -5
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
606 bitshift (int8 (-1), -1)
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
607 @result{} -1
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
608 @end group
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
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
611 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
612 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
613 1, 1, 1, 1, 1, 1]}.
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6778
diff changeset
614
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
615 @node Logical Values
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
616 @section Logical Values
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
617
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
618 Octave has built-in support for logical values, i.e. variables that
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
619 are either @code{true} or @code{false}. When comparing two variables,
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
620 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
621 not the comparison is true.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
622
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
623 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
624 which correspond to ``Logical And'', ``Logical Or'', and ``Logical
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8534
diff changeset
625 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
626
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
627 It is also possible to use logical values as part of standard numerical
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
628 calculations. In this case @code{true} is converted to @code{1}, and
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
629 @code{false} to 0, both represented using double precision floating
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
630 point numbers. So, the result of @code{true*22 - false/6} is @code{22}.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
631
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
632 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
633 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
634 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
635 The following example illustrates this.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
636
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
637 @example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
638 data = [ 1, 2; 3, 4 ];
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
639 idx = (data <= 2);
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
640 data(idx)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
641 @result{} ans = [ 1; 4 ]
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
642 @end example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
643
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
644 @noindent
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
645 Instead of creating the @code{idx} array it is possible to replace
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
646 @code{data(idx)} with @code{data( data <= 2 )} in the above code.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
647
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8534
diff changeset
648 Logical values can also be constructed by
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
649 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
650 or @code{false} functions.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
651
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
652 @DOCSTRING(logical)
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6501
diff changeset
653
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
654 @DOCSTRING(true)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
655
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
656 @DOCSTRING(false)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
657
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
658 @node Promotion and Demotion of Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
659 @section Promotion and Demotion of Data Types
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
660
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
661 Many operators and functions can work with mixed data types. For example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
662
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
663 @example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
664 uint8 (1) + 1
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
665 @result{} 2
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
666 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
667
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
668 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
669 where the above operator works with an 8-bit integer and a double precision
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
670 value and returns an 8-bit integer value. Note that the type is demoted
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
671 to an 8-bit integer, rather than promoted to a double precision value as
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
672 might be expected. The reason is that if Octave promoted values in
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
673 expressions like the above with all numerical constants would need to be
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
674 explicitly cast to the appropriate data type type like
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
675
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
676 @example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
677 uint8 (1) + uint8 (1)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
678 @result{} 2
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
679 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
680
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
681 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
682 which becomes difficult for the user to apply uniformly and might allow
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
683 hard to find bugs to be introduced. The same applies to single precision
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
684 values where a mixed operation such as
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
685
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
686 @example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
687 single (1) + 1
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
688 @result{} 2
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
689 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
690
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
691 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
692 returns a single precision value. The mixed operations that are valid
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
693 and their returned data types are
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
694
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
695 @multitable @columnfractions .2 .3 .3 .2
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
696 @item @tab Mixed Operation @tab Result @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
697 @item @tab double OP single @tab single @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
698 @item @tab double OP integer @tab integer @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
699 @item @tab double OP char @tab double @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
700 @item @tab double OP logical @tab double @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
701 @item @tab single OP integer @tab integer @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
702 @item @tab single OP char @tab single @tab
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
703 @item @tab single OP logical @tab single @tab
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
704 @end multitable
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
705
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
706 The same logic applies to functions with mixed arguments such as
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
707
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
708 @example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
709 min (single (1), 0)
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
710 @result{} 0
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
711 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
712
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
713 @noindent
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
714 where the returned value is single precision.
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 In the case of mixed type indexed assignments, the type is not
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
717 changed. For example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
718
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
719 @example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
720 x = ones (2, 2);
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
721 x (1, 1) = single (2)
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
722 @result{} x = 2 1
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
723 1 1
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
724 @end example
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
725
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
726 @noindent
7989
23c248d415b5 Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents: 7984
diff changeset
727 where @code{x} remains of the double precision type.
7984
bbaa5d7d0143 Some documentation updates
David Bateman <dbateman@free.fr>
parents: 7638
diff changeset
728
4167
aae05d51353c [project @ 2002-11-12 02:52:50 by jwe]
jwe
parents: 4029
diff changeset
729 @node Predicates for Numeric Objects
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
730 @section Predicates for Numeric Objects
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
731
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
732 Since the type of a variable may change during the execution of a
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8325
diff changeset
733 program, it can be necessary to do type checking at run-time. Doing this
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
734 also allows you to change the behaviour of a function depending on the
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
735 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
736 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
737 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
738
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
739 @example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
740 function a = abs (x)
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
741 if (isreal (x))
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
742 a = sign (x) .* x;
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
743 elseif (iscomplex (x))
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
744 a = sqrt (real(x).^2 + imag(x).^2);
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
745 endif
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
746 endfunction
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
747 @end example
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
748
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
749 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
750 variable.
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6550
diff changeset
751
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
752 @DOCSTRING(isnumeric)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
753
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
754 @DOCSTRING(isreal)
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
755
7638
2df457529cfa implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7018
diff changeset
756 @DOCSTRING(isfloat)
2df457529cfa implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7018
diff changeset
757
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
758 @DOCSTRING(iscomplex)
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
759
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
760 @DOCSTRING(ismatrix)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
761
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
762 @DOCSTRING(isvector)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
763
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
764 @DOCSTRING(isscalar)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
765
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
766 @DOCSTRING(issquare)
3294
bfe1573bd2ae [project @ 1999-10-19 10:06:07 by jwe]
jwe
parents:
diff changeset
767
4029
2cc57b6169cf [project @ 2002-08-09 07:36:15 by jwe]
jwe
parents: 3920
diff changeset
768 @DOCSTRING(issymmetric)
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3321
diff changeset
769
6550
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
770 @DOCSTRING(isdefinite)
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
771
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6624
diff changeset
772 @DOCSTRING(islogical)
6550
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
773
1b7a6061a05d [project @ 2007-04-20 07:40:26 by jwe]
jwe
parents: 6549
diff changeset
774 @DOCSTRING(isprime)