Mercurial > hg > octave-lyh
annotate doc/interpreter/numbers.txi @ 17289:bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Macro handles options ("on") or properties ("position") more elegantly
than @code{"text"}.
* doc/interpreter/macros.texi: Add new @qcode macro.
* doc/interpreter/tips.txi: Add documentation about @qcode macro.
* doc/interpreter/basics.txi, doc/interpreter/container.txi,
doc/interpreter/emacs.txi, doc/interpreter/errors.txi,
doc/interpreter/eval.txi, doc/interpreter/expr.txi,
doc/interpreter/external.txi, doc/interpreter/func.txi,
doc/interpreter/grammar.txi, doc/interpreter/image.txi,
doc/interpreter/install.txi, doc/interpreter/interp.txi,
doc/interpreter/io.txi, doc/interpreter/matrix.txi,
doc/interpreter/numbers.txi, doc/interpreter/oop.txi,
doc/interpreter/package.txi, doc/interpreter/plot.txi,
doc/interpreter/quad.txi, doc/interpreter/sparse.txi,
doc/interpreter/strings.txi, doc/interpreter/system.txi,
doc/interpreter/vectorize.txi, libinterp/corefcn/balance.cc,
libinterp/corefcn/bitfcns.cc, libinterp/corefcn/cellfun.cc,
libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc,
libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc,
libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lu.cc,
libinterp/corefcn/luinc.cc, libinterp/corefcn/matrix_type.cc,
libinterp/corefcn/oct-hist.cc, libinterp/corefcn/pager.cc,
libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc,
libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc,
libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/toplev.cc,
libinterp/corefcn/tril.cc, libinterp/corefcn/typecast.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/chol.cc,
libinterp/dldfcn/colamd.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc,
libinterp/dldfcn/symbfact.cc, libinterp/octave-value/ov-base.cc,
libinterp/octave-value/ov-fcn-handle.cc,
libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc,
libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-usr-fcn.cc, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc,
libinterp/parse-tree/pt-mat.cc, scripts/@ftp/ftp.m,
scripts/deprecated/java_convert_matrix.m, scripts/deprecated/java_debug.m,
scripts/deprecated/java_unsigned_conversion.m, scripts/deprecated/shell_cmd.m,
scripts/general/dblquad.m, scripts/general/display.m,
scripts/general/genvarname.m, scripts/general/idivide.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/interpn.m, scripts/general/isa.m,
scripts/general/profexplore.m, scripts/general/profile.m,
scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/triplequad.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/voronoi.m, scripts/help/help.m,
scripts/help/lookfor.m, scripts/image/cmpermute.m, scripts/image/colormap.m,
scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m,
scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m,
scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/lines.m,
scripts/image/rgb2ind.m, scripts/image/spinmap.m, scripts/io/dlmwrite.m,
scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m,
scripts/java/javaclasspath.m, scripts/java/usejava.m,
scripts/miscellaneous/bzip2.m, scripts/miscellaneous/computer.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m,
scripts/miscellaneous/gzip.m, scripts/miscellaneous/license.m,
scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m,
scripts/miscellaneous/parseparams.m, scripts/miscellaneous/unix.m,
scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m,
scripts/optimization/fminunc.m, scripts/optimization/fsolve.m,
scripts/optimization/fzero.m, scripts/optimization/glpk.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/optimset.m,
scripts/optimization/pqpnonneg.m, scripts/pkg/pkg.m, scripts/plot/allchild.m,
scripts/plot/ancestor.m, scripts/plot/area.m, scripts/plot/axis.m,
scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/box.m,
scripts/plot/caxis.m, scripts/plot/cla.m, scripts/plot/clabel.m,
scripts/plot/clf.m, scripts/plot/close.m, scripts/plot/colorbar.m,
scripts/plot/daspect.m, scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m,
scripts/plot/ezsurf.m, scripts/plot/ezsurfc.m, scripts/plot/findall.m,
scripts/plot/findobj.m, scripts/plot/gcbo.m, scripts/plot/gcf.m,
scripts/plot/gco.m, scripts/plot/grid.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/hidden.m, scripts/plot/hold.m,
scripts/plot/isonormals.m, scripts/plot/isosurface.m, scripts/plot/legend.m,
scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m,
scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m,
scripts/plot/patch.m, scripts/plot/pbaspect.m, scripts/plot/pcolor.m,
scripts/plot/plot.m, scripts/plot/print.m,
scripts/plot/private/__add_default_menu__.m, scripts/plot/quiver.m,
scripts/plot/quiver3.m, scripts/plot/refreshdata.m, scripts/plot/saveas.m,
scripts/plot/scatter.m, scripts/plot/scatter3.m, scripts/plot/shading.m,
scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/stem.m,
scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m,
scripts/plot/tetramesh.m, scripts/plot/uigetfile.m, scripts/plot/uimenu.m,
scripts/plot/uiputfile.m, scripts/plot/waterfall.m, scripts/plot/whitebg.m,
scripts/plot/xlim.m, scripts/plot/ylim.m, scripts/plot/zlim.m,
scripts/polynomial/conv.m, scripts/polynomial/polyout.m,
scripts/polynomial/splinefit.m, scripts/set/ismember.m, scripts/set/powerset.m,
scripts/set/setdiff.m, scripts/set/union.m, scripts/set/unique.m,
scripts/signal/detrend.m, scripts/signal/filter2.m, scripts/signal/freqz.m,
scripts/signal/periodogram.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/sparse/eigs.m, scripts/sparse/svds.m,
scripts/specfun/legendre.m, scripts/special-matrix/gallery.m,
scripts/statistics/base/mean.m, scripts/statistics/base/moment.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/sign_test.m,
scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m,
scripts/strings/index.m, scripts/strings/isstrprop.m,
scripts/strings/mat2str.m, scripts/strings/regexptranslate.m,
scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m,
scripts/strings/strjust.m, scripts/strings/strmatch.m,
scripts/strings/validatestring.m, scripts/testfun/demo.m,
scripts/testfun/example.m, scripts/testfun/test.m, scripts/time/addtodate.m,
scripts/time/asctime.m, scripts/time/datestr.m, scripts/time/datetick.m,
scripts/time/weekday.m, scripts/ui/errordlg.m, scripts/ui/helpdlg.m,
scripts/ui/inputdlg.m, scripts/ui/listdlg.m, scripts/ui/msgbox.m,
scripts/ui/questdlg.m, scripts/ui/warndlg.m: Use new @qcode macro.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 19 Aug 2013 20:46:38 -0700 |
parents | f2a8592b8fbd |
children | 4bcd301754ce |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13019
diff
changeset
|
1 @c Copyright (C) 1996-2012 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Numeric Data Types |
3294 | 20 @chapter Numeric Data Types |
21 @cindex numeric constant | |
22 @cindex numeric value | |
23 | |
24 A @dfn{numeric constant} may be a scalar, a vector, or a matrix, and it | |
25 may contain complex values. | |
26 | |
27 The simplest form of a numeric constant, a scalar, is a single number | |
28 that can be an integer, a decimal fraction, a number in scientific | |
6620 | 29 (exponential) notation, or a complex number. Note that by default numeric |
3294 | 30 constants are represented within Octave in double-precision floating |
31 point format (complex constants are stored as pairs of double-precision | |
17101
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16939
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 | 36 |
37 @example | |
38 @group | |
39 105 | |
40 1.05e+2 | |
41 1050e-1 | |
42 @end group | |
43 @end example | |
44 | |
45 To specify complex constants, you can write an expression of the form | |
46 | |
47 @example | |
48 @group | |
49 3 + 4i | |
50 3.0 + 4.0i | |
51 0.3e1 + 40e-1i | |
52 @end group | |
53 @end example | |
54 | |
6620 | 55 @noindent |
3294 | 56 all of which are equivalent. The letter @samp{i} in the previous example |
57 stands for the pure imaginary constant, defined as | |
58 @tex | |
59 $\sqrt{-1}$. | |
60 @end tex | |
6620 | 61 @ifnottex |
3294 | 62 @code{sqrt (-1)}. |
6620 | 63 @end ifnottex |
3294 | 64 |
65 For Octave to recognize a value as the imaginary part of a complex | |
66 constant, a space must not appear between the number and the @samp{i}. | |
67 If it does, Octave will print an error message, like this: | |
68 | |
69 @example | |
70 @group | |
71 octave:13> 3 + 4 i | |
72 | |
73 parse error: | |
74 | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
75 syntax error |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
76 |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
77 >>> 3 + 4 i |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
78 ^ |
3294 | 79 @end group |
80 @end example | |
81 | |
6620 | 82 @noindent |
3294 | 83 You may also use @samp{j}, @samp{I}, or @samp{J} in place of the |
84 @samp{i} above. All four forms are equivalent. | |
85 | |
6549 | 86 @DOCSTRING(double) |
87 | |
88 @DOCSTRING(complex) | |
89 | |
3294 | 90 @menu |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
91 * Matrices:: |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
92 * Ranges:: |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
93 * Single Precision Data Types:: |
6549 | 94 * Integer Data Types:: |
6781 | 95 * Bit Manipulations:: |
17160
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
17101
diff
changeset
|
96 * Logical Values:: |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
97 * Promotion and Demotion of Data Types:: |
17160
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
17101
diff
changeset
|
98 * Predicates for Numeric Objects:: |
3294 | 99 @end menu |
100 | |
4167 | 101 @node Matrices |
3294 | 102 @section Matrices |
103 @cindex matrices | |
104 | |
105 @opindex [ | |
106 @opindex ] | |
107 @opindex ; | |
108 @opindex , | |
109 | |
110 It is easy to define a matrix of values in Octave. The size of the | |
111 matrix is determined automatically, so it is not necessary to explicitly | |
112 state the dimensions. The expression | |
113 | |
114 @example | |
115 a = [1, 2; 3, 4] | |
116 @end example | |
117 | |
118 @noindent | |
119 results in the matrix | |
120 @tex | |
121 $$ a = \left[ \matrix{ 1 & 2 \cr 3 & 4 } \right] $$ | |
122 @end tex | |
6620 | 123 @ifnottex |
3294 | 124 |
125 @example | |
126 @group | |
127 | |
128 / \ | |
129 | 1 2 | | |
130 a = | | | |
131 | 3 4 | | |
132 \ / | |
133 | |
134 @end group | |
135 @end example | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
136 |
6620 | 137 @end ifnottex |
3294 | 138 |
139 Elements of a matrix may be arbitrary expressions, provided that the | |
140 dimensions all make sense when combining the various pieces. For | |
141 example, given the above matrix, the expression | |
142 | |
143 @example | |
144 [ a, a ] | |
145 @end example | |
146 | |
147 @noindent | |
148 produces the matrix | |
149 | |
150 @example | |
151 @group | |
152 ans = | |
153 | |
154 1 2 1 2 | |
155 3 4 3 4 | |
156 @end group | |
157 @end example | |
158 | |
159 @noindent | |
160 but the expression | |
161 | |
162 @example | |
163 [ a, 1 ] | |
164 @end example | |
165 | |
166 @noindent | |
167 produces the error | |
168 | |
169 @example | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
170 error: number of rows must match (1 != 2) near line 13, column 6 |
3294 | 171 @end example |
172 | |
173 @noindent | |
174 (assuming that this expression was entered as the first thing on line | |
175 13, of course). | |
176 | |
177 Inside the square brackets that delimit a matrix expression, Octave | |
178 looks at the surrounding context to determine whether spaces and newline | |
179 characters should be converted into element and row separators, or | |
4476 | 180 simply ignored, so an expression like |
3294 | 181 |
182 @example | |
183 @group | |
184 a = [ 1 2 | |
185 3 4 ] | |
186 @end group | |
187 @end example | |
188 | |
189 @noindent | |
190 will work. However, some possible sources of confusion remain. For | |
191 example, in the expression | |
192 | |
193 @example | |
194 [ 1 - 1 ] | |
195 @end example | |
196 | |
197 @noindent | |
198 the @samp{-} is treated as a binary operator and the result is the | |
199 scalar 0, but in the expression | |
200 | |
201 @example | |
202 [ 1 -1 ] | |
203 @end example | |
204 | |
205 @noindent | |
206 the @samp{-} is treated as a unary operator and the result is the | |
4476 | 207 vector @code{[ 1, -1 ]}. Similarly, the expression |
208 | |
209 @example | |
210 [ sin (pi) ] | |
211 @end example | |
212 | |
213 @noindent | |
214 will be parsed as | |
215 | |
216 @example | |
217 [ sin, (pi) ] | |
218 @end example | |
3294 | 219 |
4476 | 220 @noindent |
221 and will result in an error since the @code{sin} function will be | |
222 called with no arguments. To get around this, you must omit the space | |
223 between @code{sin} and the opening parenthesis, or enclose the | |
224 expression in a set of parentheses: | |
225 | |
226 @example | |
227 [ (sin (pi)) ] | |
228 @end example | |
229 | |
230 Whitespace surrounding the single quote character (@samp{'}, used as a | |
231 transpose operator and for delimiting character strings) can also cause | |
232 confusion. Given @code{a = 1}, the expression | |
3294 | 233 |
234 @example | |
235 [ 1 a' ] | |
236 @end example | |
237 | |
238 @noindent | |
4476 | 239 results in the single quote character being treated as a |
3294 | 240 transpose operator and the result is the vector @code{[ 1, 1 ]}, but the |
241 expression | |
242 | |
243 @example | |
244 [ 1 a ' ] | |
245 @end example | |
246 | |
247 @noindent | |
248 produces the error message | |
249 | |
250 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
251 @group |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
252 parse error: |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
253 |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
254 syntax 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 >>> [ 1 a ' ] |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
257 ^ |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
258 @end group |
3294 | 259 @end example |
260 | |
261 @noindent | |
6620 | 262 because not doing so would cause trouble when parsing the valid expression |
3294 | 263 |
264 @example | |
265 [ a 'foo' ] | |
266 @end example | |
267 | |
268 For clarity, it is probably best to always use commas and semicolons to | |
4476 | 269 separate matrix elements and rows. |
3294 | 270 |
12190
66b2c377b38e
Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
271 The maximum number of elements in a matrix is fixed when Octave is compiled. |
66b2c377b38e
Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
272 The allowable number can be queried with the function @code{sizemax}. Note |
66b2c377b38e
Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
273 that other factors, such as the amount of memory available on your machine, |
66b2c377b38e
Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
274 may limit the maximum size of matrices to something smaller. |
66b2c377b38e
Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
275 |
66b2c377b38e
Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
276 @DOCSTRING(sizemax) |
66b2c377b38e
Add sizemax function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11573
diff
changeset
|
277 |
3294 | 278 When you type a matrix or the name of a variable whose value is a |
279 matrix, Octave responds by printing the matrix in with neatly aligned | |
280 rows and columns. If the rows of the matrix are too large to fit on the | |
281 screen, Octave splits the matrix and displays a header before each | |
282 section to indicate which columns are being displayed. You can use the | |
283 following variables to control the format of the output. | |
284 | |
3321 | 285 @DOCSTRING(output_max_field_width) |
3294 | 286 |
3321 | 287 @DOCSTRING(output_precision) |
3294 | 288 |
289 It is possible to achieve a wide range of output styles by using | |
290 different values of @code{output_precision} and | |
291 @code{output_max_field_width}. Reasonable combinations can be set using | |
292 the @code{format} function. @xref{Basic Input and Output}. | |
293 | |
3321 | 294 @DOCSTRING(split_long_rows) |
3294 | 295 |
296 Octave automatically switches to scientific notation when values become | |
297 very large or very small. This guarantees that you will see several | |
298 significant figures for every value in a matrix. If you would prefer to | |
299 see all values in a matrix printed in a fixed point format, you can set | |
300 the built-in variable @code{fixed_point_format} to a nonzero value. But | |
301 doing so is not recommended, because it can produce output that can | |
302 easily be misinterpreted. | |
303 | |
3321 | 304 @DOCSTRING(fixed_point_format) |
3294 | 305 |
306 @menu | |
17160
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
17101
diff
changeset
|
307 * Empty Matrices:: |
3294 | 308 @end menu |
309 | |
4167 | 310 @node Empty Matrices |
3294 | 311 @subsection Empty Matrices |
312 | |
313 A matrix may have one or both dimensions zero, and operations on empty | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
314 matrices are handled as described by Carl @nospell{de} Boor in @cite{An Empty |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
315 Exercise}, SIGNUM, Volume 25, pages 2-6, 1990 and C. N. Nett and W. M. |
3294 | 316 Haddad, in @cite{A System-Theoretic Appropriate Realization of the Empty |
317 Matrix Concept}, IEEE Transactions on Automatic Control, Volume 38, | |
318 Number 5, May 1993. | |
319 @tex | |
320 Briefly, given a scalar $s$, an $m\times n$ matrix $M_{m\times n}$, | |
321 and an $m\times n$ empty matrix $[\,]_{m\times n}$ (with either one or | |
322 both dimensions equal to zero), the following are true: | |
323 $$ | |
324 \eqalign{% | |
325 s \cdot [\,]_{m\times n} = [\,]_{m\times n} \cdot s &= [\,]_{m\times n}\cr | |
326 [\,]_{m\times n} + [\,]_{m\times n} &= [\,]_{m\times n}\cr | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
327 [\,]_{0\times m} \cdot M_{m\times n} &= [\,]_{0\times n}\cr |
3294 | 328 M_{m\times n} \cdot [\,]_{n\times 0} &= [\,]_{m\times 0}\cr |
329 [\,]_{m\times 0} \cdot [\,]_{0\times n} &= 0_{m\times n}} | |
330 $$ | |
331 @end tex | |
6620 | 332 @ifnottex |
3294 | 333 Briefly, given a scalar @var{s}, an @var{m} by |
334 @var{n} matrix @code{M(mxn)}, and an @var{m} by @var{n} empty matrix | |
335 @code{[](mxn)} (with either one or both dimensions equal to zero), the | |
336 following are true: | |
337 | |
338 @example | |
339 @group | |
340 s * [](mxn) = [](mxn) * s = [](mxn) | |
341 | |
342 [](mxn) + [](mxn) = [](mxn) | |
343 | |
344 [](0xm) * M(mxn) = [](0xn) | |
345 | |
346 M(mxn) * [](nx0) = [](mx0) | |
347 | |
348 [](mx0) * [](0xn) = 0(mxn) | |
349 @end group | |
350 @end example | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
351 |
6620 | 352 @end ifnottex |
3294 | 353 |
354 By default, dimensions of the empty matrix are printed along with the | |
355 empty matrix symbol, @samp{[]}. The built-in variable | |
356 @code{print_empty_dimensions} controls this behavior. | |
357 | |
3321 | 358 @DOCSTRING(print_empty_dimensions) |
3294 | 359 |
360 Empty matrices may also be used in assignment statements as a convenient | |
361 way to delete rows or columns of matrices. | |
17101
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16939
diff
changeset
|
362 @xref{Assignment Ops,,Assignment Expressions}. |
3294 | 363 |
364 When Octave parses a matrix expression, it examines the elements of the | |
365 list to determine whether they are all constants. If they are, it | |
366 replaces the list with a single matrix constant. | |
367 | |
4167 | 368 @node Ranges |
3294 | 369 @section Ranges |
370 @cindex range expressions | |
371 @cindex expression, range | |
372 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
11392
diff
changeset
|
373 @opindex : |
3294 | 374 |
375 A @dfn{range} is a convenient way to write a row vector with evenly | |
376 spaced elements. A range expression is defined by the value of the first | |
377 element in the range, an optional value for the increment between | |
378 elements, and a maximum value which the elements of the range will not | |
379 exceed. The base, increment, and limit are separated by colons (the | |
380 @samp{:} character) and may contain any arithmetic expressions and | |
381 function calls. If the increment is omitted, it is assumed to be 1. | |
382 For example, the range | |
383 | |
384 @example | |
385 1 : 5 | |
386 @end example | |
387 | |
388 @noindent | |
389 defines the set of values @samp{[ 1, 2, 3, 4, 5 ]}, and the range | |
390 | |
391 @example | |
392 1 : 3 : 5 | |
393 @end example | |
394 | |
395 @noindent | |
396 defines the set of values @samp{[ 1, 4 ]}. | |
397 | |
398 Although a range constant specifies a row vector, Octave does @emph{not} | |
399 convert range constants to vectors unless it is necessary to do so. | |
400 This allows you to write a constant like @samp{1 : 10000} without using | |
401 80,000 bytes of storage on a typical 32-bit workstation. | |
402 | |
11179
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
403 A common example of when it does become necessary to convert ranges into |
11573
6f8ffe2c6f76
Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
404 vectors occurs when they appear within a vector (i.e., inside square |
6f8ffe2c6f76
Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
405 brackets). For instance, whereas |
11179
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
406 |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
407 @example |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
408 x = 0 : 0.1 : 1; |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
409 @end example |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
410 |
11573
6f8ffe2c6f76
Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
411 @noindent |
11179
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
412 defines @var{x} to be a variable of type @code{range} and occupies 24 |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
413 bytes of memory, the expression |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
414 |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
415 @example |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
416 y = [ 0 : 0.1 : 1]; |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
417 @end example |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
418 |
11573
6f8ffe2c6f76
Grammarcheck txi files for 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
419 @noindent |
11179
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
420 defines @var{y} to be of type @code{matrix} and occupies 88 bytes of |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
421 memory. |
6ead75935ebf
Explain that ranges in vectors do get expanded
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
10846
diff
changeset
|
422 |
3294 | 423 Note that the upper (or lower, if the increment is negative) bound on |
424 the range is not always included in the set of values, and that ranges | |
425 defined by floating point values can produce surprising results because | |
426 Octave uses floating point arithmetic to compute the values in the | |
427 range. If it is important to include the endpoints of a range and the | |
428 number of elements is known, you should use the @code{linspace} function | |
429 instead (@pxref{Special Utility Matrices}). | |
430 | |
9158 | 431 When adding a scalar to a range, subtracting a scalar from it (or subtracting a |
432 range from a scalar) and multiplying by scalar, Octave will attempt to avoid | |
433 unpacking the range and keep the result as a range, too, if it can determine | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
434 that it is safe to do so. For instance, doing |
9158 | 435 |
436 @example | |
437 a = 2*(1:1e7) - 1; | |
438 @end example | |
439 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
440 @noindent |
9158 | 441 will produce the same result as @samp{1:2:2e7-1}, but without ever forming a |
442 vector with ten million elements. | |
443 | |
444 Using zero as an increment in the colon notation, as @samp{1:0:1} is not | |
445 allowed, because a division by zero would occur in determining the number of | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
446 range elements. However, ranges with zero increment (i.e., all elements equal) |
9158 | 447 are useful, especially in indexing, and Octave allows them to be constructed |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
448 using the built-in function @dfn{ones}. Note that because a range must be a row |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
449 vector, @samp{ones (1, 10)} produces a range, while @samp{ones (10, 1)} does |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
450 not. |
9158 | 451 |
3294 | 452 When Octave parses a range expression, it examines the elements of the |
453 expression to determine whether they are all constants. If they are, it | |
454 replaces the range expression with a single range constant. | |
455 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
456 @node Single Precision Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
457 @section Single Precision Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
458 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
459 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
|
460 functions in Octave accept single precision values and return single |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
461 precision answers. A single precision variable is created with the |
8534
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
462 @code{single} function. |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
463 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
464 @DOCSTRING(single) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
465 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
466 for example: |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
467 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
468 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
469 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
470 sngl = single (rand (2, 2)) |
8534
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
471 @result{} sngl = |
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
472 0.37569 0.92982 |
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
473 0.11962 0.50876 |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
474 class (sngl) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
475 @result{} single |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
476 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
477 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
478 |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
479 Many functions can also return single precision values directly. For |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
480 example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
481 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
482 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
483 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
484 ones (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
485 zeros (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
486 eye (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
487 rand (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
488 NaN (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
489 NA (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
490 Inf (2, 2, "single") |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
491 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
492 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
493 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
494 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
495 will all return single precision matrices. |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
496 |
6549 | 497 @node Integer Data Types |
498 @section Integer Data Types | |
499 | |
6620 | 500 Octave supports integer matrices as an alternative to using double |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
501 precision. It is possible to use both signed and unsigned integers |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
502 represented by 8, 16, 32, or 64 bits. It should be noted that most |
6620 | 503 computations require floating point data, meaning that integers will |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
504 often change type when involved in numeric computations. For this |
6620 | 505 reason integers are most often used to store data, and not for |
506 calculations. | |
507 | |
508 In general most integer matrices are created by casting | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
509 existing matrices to integers. The following example shows how to cast |
6620 | 510 a matrix into 32 bit integers. |
511 | |
512 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
513 @group |
6620 | 514 float = rand (2, 2) |
515 @result{} float = 0.37569 0.92982 | |
516 0.11962 0.50876 | |
517 integer = int32 (float) | |
518 @result{} integer = 0 1 | |
519 0 1 | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
520 @end group |
6620 | 521 @end example |
522 | |
523 @noindent | |
524 As can be seen, floating point values are rounded to the nearest integer | |
525 when converted. | |
526 | |
6549 | 527 @DOCSTRING(isinteger) |
528 | |
529 @DOCSTRING(int8) | |
530 | |
531 @DOCSTRING(uint8) | |
532 | |
533 @DOCSTRING(int16) | |
534 | |
535 @DOCSTRING(uint16) | |
536 | |
537 @DOCSTRING(int32) | |
538 | |
539 @DOCSTRING(uint32) | |
540 | |
541 @DOCSTRING(int64) | |
542 | |
543 @DOCSTRING(uint64) | |
544 | |
545 @DOCSTRING(intmax) | |
546 | |
547 @DOCSTRING(intmin) | |
548 | |
6624 | 549 @menu |
550 * Integer Arithmetic:: | |
551 @end menu | |
552 | |
6620 | 553 @node Integer Arithmetic |
554 @subsection Integer Arithmetic | |
555 | |
556 While many numerical computations can't be carried out in integers, | |
557 Octave does support basic operations like addition and multiplication | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
558 on integers. The operators @code{+}, @code{-}, @code{.*}, and @code{./} |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
559 work on integers of the same type. So, it is possible to add two 32 bit |
6620 | 560 integers, but not to add a 32 bit integer and a 16 bit integer. |
561 | |
562 When doing integer arithmetic one should consider the possibility of | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
563 underflow and overflow. This happens when the result of the computation |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
564 can't be represented using the chosen integer type. As an example it is |
6620 | 565 not possible to represent the result of @math{10 - 20} when using |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
566 unsigned integers. Octave makes sure that the result of integer |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
567 computations is the integer that is closest to the true result. So, the |
6620 | 568 result of @math{10 - 20} when using unsigned integers is zero. |
569 | |
570 When doing integer division Octave will round the result to the nearest | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
571 integer. This is different from most programming languages, where the |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
572 result is often floored to the nearest integer. So, the result of |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14402
diff
changeset
|
573 @code{int32 (5) ./ int32 (8)} is @code{1}. |
6620 | 574 |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
575 @DOCSTRING(idivide) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
576 |
6781 | 577 @node Bit Manipulations |
578 @section Bit Manipulations | |
579 | |
580 Octave provides a number of functions for the manipulation of numeric | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
581 values on a bit by bit basis. The basic functions to set and obtain the |
6781 | 582 values of individual bits are @code{bitset} and @code{bitget}. |
583 | |
584 @DOCSTRING(bitset) | |
585 | |
586 @DOCSTRING(bitget) | |
587 | |
588 The arguments to all of Octave's bitwise operations can be scalar or | |
589 arrays, except for @code{bitcmp}, whose @var{k} argument must a | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
590 scalar. In the case where more than one argument is an array, then all |
6781 | 591 arguments must have the same shape, and the bitwise operator is applied |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
592 to each of the elements of the argument individually. If at least one |
6781 | 593 argument is a scalar and one an array, then the scalar argument is |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
594 duplicated. Therefore |
6781 | 595 |
596 @example | |
597 bitget (100, 8:-1:1) | |
598 @end example | |
599 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
600 @noindent |
6781 | 601 is the same as |
602 | |
603 @example | |
604 bitget (100 * ones (1, 8), 8:-1:1) | |
605 @end example | |
606 | |
607 It should be noted that all values passed to the bit manipulation | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
608 functions of Octave are treated as integers. Therefore, even though the |
6781 | 609 example for @code{bitset} above passes the floating point value |
610 @code{10}, it is treated as the bits @code{[1, 0, 1, 0]} rather than the | |
611 bits of the native floating point format representation of @code{10}. | |
612 | |
8828 | 613 As the maximum value that can be represented by a number is important |
6781 | 614 for bit manipulation, particularly when forming masks, Octave supplies |
615 the function @code{bitmax}. | |
616 | |
17101
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16939
diff
changeset
|
617 @anchor{XREFflintmax} |
6781 | 618 @DOCSTRING(bitmax) |
619 | |
16939
06897f865f0b
Add flintmax() as an alias for function bitmax().
Rik <rik@octave.org>
parents:
14856
diff
changeset
|
620 This is the double precision version of the function @code{intmax}, |
6781 | 621 previously discussed. |
622 | |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17160
diff
changeset
|
623 Octave also includes the basic bitwise 'and', 'or', and 'exclusive or' |
6781 | 624 operators. |
625 | |
626 @DOCSTRING(bitand) | |
627 | |
628 @DOCSTRING(bitor) | |
629 | |
630 @DOCSTRING(bitxor) | |
631 | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
632 The bitwise 'not' operator is a unary operator that performs a logical |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
633 negation of each of the bits of the value. For this to make sense, the |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
634 mask against which the value is negated must be defined. Octave's |
6781 | 635 bitwise 'not' operator is @code{bitcmp}. |
636 | |
637 @DOCSTRING(bitcmp) | |
638 | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
639 Octave also includes the ability to left-shift and right-shift values bitwise. |
6781 | 640 |
641 @DOCSTRING(bitshift) | |
642 | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
643 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
|
644 also uses arithmetic shifts, where the sign bit of the value is kept |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
645 during a right shift. For example: |
6781 | 646 |
647 @example | |
648 @group | |
649 bitshift (-10, -1) | |
650 @result{} -5 | |
651 bitshift (int8 (-1), -1) | |
652 @result{} -1 | |
653 @end group | |
654 @end example | |
655 | |
656 Note that @code{bitshift (int8 (-1), -1)} is @code{-1} since the bit | |
657 representation of @code{-1} in the @code{int8} data type is @code{[1, 1, | |
658 1, 1, 1, 1, 1, 1]}. | |
659 | |
4167 | 660 @node Logical Values |
3428 | 661 @section Logical Values |
662 | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
663 Octave has built-in support for logical values, i.e., variables that |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
664 are either @code{true} or @code{false}. When comparing two variables, |
6620 | 665 the result will be a logical value whose value depends on whether or |
666 not the comparison is true. | |
667 | |
668 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
|
669 which correspond to ``Logical And'', ``Logical Or'', and ``Logical |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
670 Negation''. These operations all follow the usual rules of logic. |
6620 | 671 |
672 It is also possible to use logical values as part of standard numerical | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
673 calculations. In this case @code{true} is converted to @code{1}, and |
6620 | 674 @code{false} to 0, both represented using double precision floating |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
675 point numbers. So, the result of @code{true*22 - false/6} is @code{22}. |
6620 | 676 |
677 Logical values can also be used to index matrices and cell arrays. | |
678 When indexing with a logical array the result will be a vector containing | |
679 the values corresponding to @code{true} parts of the logical array. | |
680 The following example illustrates this. | |
681 | |
682 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
683 @group |
6620 | 684 data = [ 1, 2; 3, 4 ]; |
685 idx = (data <= 2); | |
686 data(idx) | |
9136
537a73861cb7
Fix small mistake in example.
Ansgar Burchard <ansgar@43-1.org>
parents:
9036
diff
changeset
|
687 @result{} ans = [ 1; 2 ] |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
688 @end group |
6620 | 689 @end example |
690 | |
691 @noindent | |
692 Instead of creating the @code{idx} array it is possible to replace | |
11376
567ca09a97aa
Remove obsolete documentation about 64-bit integer arithmetic.
Rik <octave@nomad.inbox5.com>
parents:
11179
diff
changeset
|
693 @code{data(idx)} with @w{@code{data( data <= 2 )}} in the above code. |
6620 | 694 |
8828 | 695 Logical values can also be constructed by |
6620 | 696 casting numeric objects to logical values, or by using the @code{true} |
697 or @code{false} functions. | |
698 | |
6549 | 699 @DOCSTRING(logical) |
700 | |
3428 | 701 @DOCSTRING(true) |
702 | |
703 @DOCSTRING(false) | |
704 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
705 @node Promotion and Demotion of Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
706 @section Promotion and Demotion of Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
707 |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
708 Many operators and functions can work with mixed data types. For example, |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
709 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
710 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
711 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
712 uint8 (1) + 1 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
713 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
714 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
715 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
716 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
717 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
718 where the above operator works with an 8-bit integer and a double precision |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
719 value and returns an 8-bit integer value. Note that the type is demoted |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
720 to an 8-bit integer, rather than promoted to a double precision value as |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
721 might be expected. The reason is that if Octave promoted values in |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
722 expressions like the above with all numerical constants would need to be |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
723 explicitly cast to the appropriate data type like |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
724 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
725 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
726 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
727 uint8 (1) + uint8 (1) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
728 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
729 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
730 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
731 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
732 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
733 which becomes difficult for the user to apply uniformly and might allow |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
734 hard to find bugs to be introduced. The same applies to single precision |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
735 values where a mixed operation such as |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
736 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
737 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
738 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
739 single (1) + 1 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
740 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
741 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
742 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
743 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
744 @noindent |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
745 returns a single precision value. The mixed operations that are valid |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
746 and their returned data types are |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
747 |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
748 @multitable @columnfractions .2 .3 .3 .2 |
11447
76f15f3da207
Use @headitem macro to create column heads for @multitable entries.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
749 @headitem @tab Mixed Operation @tab Result @tab |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
750 @item @tab double OP single @tab single @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
751 @item @tab double OP integer @tab integer @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
752 @item @tab double OP char @tab double @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
753 @item @tab double OP logical @tab double @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
754 @item @tab single OP integer @tab integer @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
755 @item @tab single OP char @tab single @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
756 @item @tab single OP logical @tab single @tab |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
757 @end multitable |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
758 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
759 The same logic applies to functions with mixed arguments such as |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
760 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
761 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
762 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
763 min (single (1), 0) |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
764 @result{} 0 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
765 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
766 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
767 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
768 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
769 where the returned value is single precision. |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
770 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
771 In the case of mixed type indexed assignments, the type is not |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
772 changed. For example, |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
773 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
774 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
775 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
776 x = ones (2, 2); |
14402
cbcaf5602469
doc: Make spacing nicer for Strings chapter of manual.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
777 x(1, 1) = single (2) |
cbcaf5602469
doc: Make spacing nicer for Strings chapter of manual.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
778 @result{} x = 2 1 |
cbcaf5602469
doc: Make spacing nicer for Strings chapter of manual.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
779 1 1 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
780 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
781 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
782 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
783 @noindent |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
784 where @code{x} remains of the double precision type. |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
785 |
4167 | 786 @node Predicates for Numeric Objects |
3294 | 787 @section Predicates for Numeric Objects |
788 | |
6620 | 789 Since the type of a variable may change during the execution of a |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
790 program, it can be necessary to do type checking at run-time. Doing this |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
791 also allows you to change the behavior of a function depending on the |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
792 type of the input. As an example, this naive implementation of @code{abs} |
7001 | 793 returns the absolute value of the input if it is a real number, and the |
6620 | 794 length of the input if it is a complex number. |
795 | |
796 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
797 @group |
6620 | 798 function a = abs (x) |
799 if (isreal (x)) | |
800 a = sign (x) .* x; | |
801 elseif (iscomplex (x)) | |
802 a = sqrt (real(x).^2 + imag(x).^2); | |
803 endif | |
804 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
805 @end group |
6620 | 806 @end example |
807 | |
808 The following functions are available for determining the type of a | |
809 variable. | |
810 | |
3428 | 811 @DOCSTRING(isnumeric) |
812 | |
12581
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12488
diff
changeset
|
813 @DOCSTRING(isfloat) |
3428 | 814 |
12581
c8be316f9543
Group commonly used isXXX functions together in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12488
diff
changeset
|
815 @DOCSTRING(isreal) |
7638
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7018
diff
changeset
|
816 |
4029 | 817 @DOCSTRING(iscomplex) |
3428 | 818 |
4029 | 819 @DOCSTRING(ismatrix) |
3294 | 820 |
4029 | 821 @DOCSTRING(isvector) |
3294 | 822 |
12488
bea828c03969
Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents:
12190
diff
changeset
|
823 @DOCSTRING(isrow) |
bea828c03969
Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents:
12190
diff
changeset
|
824 |
bea828c03969
Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents:
12190
diff
changeset
|
825 @DOCSTRING(iscolumn) |
bea828c03969
Add new isrow, iscolumn functions.
Rik <octave@nomad.inbox5.com>
parents:
12190
diff
changeset
|
826 |
4029 | 827 @DOCSTRING(isscalar) |
3294 | 828 |
4029 | 829 @DOCSTRING(issquare) |
3294 | 830 |
4029 | 831 @DOCSTRING(issymmetric) |
3428 | 832 |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
833 @DOCSTRING(ishermitian) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
834 |
6550 | 835 @DOCSTRING(isdefinite) |
836 | |
6688 | 837 @DOCSTRING(islogical) |
6550 | 838 |
839 @DOCSTRING(isprime) | |
13017
aaf6fbb2512f
doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12581
diff
changeset
|
840 |
aaf6fbb2512f
doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12581
diff
changeset
|
841 If instead of knowing properties of variables, you wish to know which |
aaf6fbb2512f
doc: Add cross references to "status of variables" in sections for predicates
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12581
diff
changeset
|
842 variables are defined and to gather other information about the |
17101
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16939
diff
changeset
|
843 workspace itself, @pxref{Status of Variables}. |