File: arith.txi

package info (click to toggle)
octave 4.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 94,200 kB
  • ctags: 52,925
  • sloc: cpp: 316,850; ansic: 43,469; fortran: 23,670; sh: 13,805; yacc: 8,204; objc: 7,939; lex: 3,631; java: 2,127; makefile: 1,746; perl: 1,022; awk: 988
file content (353 lines) | stat: -rw-r--r-- 6,346 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
@c Copyright (C) 1996-2015 John W. Eaton
@c
@c This file is part of Octave.
@c
@c Octave is free software; you can redistribute it and/or modify it
@c under the terms of the GNU General Public License as published by the
@c Free Software Foundation; either version 3 of the License, or (at
@c your option) any later version.
@c
@c Octave is distributed in the hope that it will be useful, but WITHOUT
@c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@c FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
@c for more details.
@c
@c You should have received a copy of the GNU General Public License
@c along with Octave; see the file COPYING.  If not, see
@c <http://www.gnu.org/licenses/>.

@node Arithmetic
@chapter Arithmetic

Unless otherwise noted, all of the functions described in this chapter
will work for real and complex scalar, vector, or matrix arguments.  Functions
described as @dfn{mapping functions} apply the given operation individually to
each element when given a matrix argument.  For example:

@example
@group
sin ([1, 2; 3, 4])
     @result{}  0.84147   0.90930
         0.14112  -0.75680
@end group
@end example

@menu
* Exponents and Logarithms::
* Complex Arithmetic::
* Trigonometry::
* Sums and Products::
* Utility Functions::
* Special Functions::
* Rational Approximations::
* Coordinate Transformations::
* Mathematical Constants::
@end menu

@node Exponents and Logarithms
@section Exponents and Logarithms

@DOCSTRING(exp)

@DOCSTRING(expm1)

@DOCSTRING(log)

@DOCSTRING(reallog)

@DOCSTRING(log1p)

@DOCSTRING(log10)

@DOCSTRING(log2)

@DOCSTRING(pow2)

@DOCSTRING(nextpow2)

@DOCSTRING(realpow)

@DOCSTRING(sqrt)

@DOCSTRING(realsqrt)

@DOCSTRING(cbrt)

@DOCSTRING(nthroot)

@node Complex Arithmetic
@section Complex Arithmetic

In the descriptions of the following functions,
@tex
$z$ is the complex number $x + iy$, where $i$ is defined as
$\sqrt{-1}$.
@end tex
@ifnottex
@var{z} is the complex number @var{x} + @var{i}@var{y}, where @var{i} is
defined as @code{sqrt (-1)}.
@end ifnottex

@DOCSTRING(abs)

@DOCSTRING(arg)

@DOCSTRING(conj)

@DOCSTRING(cplxpair)

@DOCSTRING(imag)

@DOCSTRING(real)

@node Trigonometry
@section Trigonometry

Octave provides the following trigonometric functions where angles are
specified in radians.  To convert from degrees to radians multiply by
@tex
$\pi/180$
@end tex
@ifnottex
@code{pi/180}
@end ifnottex
(e.g., @code{sin (30 * pi/180)} returns the sine of 30 degrees).  As
an alternative, Octave provides a number of trigonometric functions
which work directly on an argument specified in degrees.  These functions
are named after the base trigonometric function with a @samp{d} suffix.  For
example, @code{sin} expects an angle in radians while @code{sind} expects an
angle in degrees.

Octave uses the C library trigonometric functions.  It is expected that these
functions are defined by the ISO/IEC 9899 Standard.  This Standard is available
at: @url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf}.
Section F.9.1 deals with the trigonometric functions.  The behavior of most of
the functions is relatively straightforward.  However, there are some
exceptions to the standard behavior.  Many of the exceptions involve the
behavior for -0.  The most complex case is atan2.  Octave exactly implements
the behavior given in the Standard.  Including
@tex
$atan2(\pm0, -0)$ returns $\pm \pi$.
@end tex
@ifnottex
@code{atan2(+- 0, 0)} returns @code{+- pi}.
@end ifnottex

It should be noted that @sc{matlab} uses different definitions which apparently
do not distinguish -0.

@DOCSTRING(sin)
@DOCSTRING(cos)
@DOCSTRING(tan)
@DOCSTRING(sec)
@DOCSTRING(csc)
@DOCSTRING(cot)

@DOCSTRING(asin)
@DOCSTRING(acos)
@DOCSTRING(atan)
@DOCSTRING(asec)
@DOCSTRING(acsc)
@DOCSTRING(acot)

@DOCSTRING(sinh)
@DOCSTRING(cosh)
@DOCSTRING(tanh)
@DOCSTRING(sech)
@DOCSTRING(csch)
@DOCSTRING(coth)

@DOCSTRING(asinh)
@DOCSTRING(acosh)
@DOCSTRING(atanh)
@DOCSTRING(asech)
@DOCSTRING(acsch)
@DOCSTRING(acoth)

@DOCSTRING(atan2)

Octave provides the following trigonometric functions where angles are
specified in degrees.  These functions produce true zeros at the appropriate
intervals rather than the small round-off error that occurs when using
radians.  For example:

@example
@group
cosd (90)
     @result{} 0
cos (pi/2)
     @result{} 6.1230e-17
@end group
@end example

@DOCSTRING(sind)
@DOCSTRING(cosd)
@DOCSTRING(tand)
@DOCSTRING(secd)
@DOCSTRING(cscd)
@DOCSTRING(cotd)

@DOCSTRING(asind)
@DOCSTRING(acosd)
@DOCSTRING(atand)
@DOCSTRING(atan2d)
@DOCSTRING(asecd)
@DOCSTRING(acscd)
@DOCSTRING(acotd)

@node Sums and Products
@section Sums and Products

@DOCSTRING(sum)

@DOCSTRING(prod)

@DOCSTRING(cumsum)

@DOCSTRING(cumprod)

@DOCSTRING(sumsq)

@node Utility Functions
@section Utility Functions

@DOCSTRING(ceil)

@DOCSTRING(fix)

@DOCSTRING(floor)

@DOCSTRING(round)

@DOCSTRING(roundb)

@DOCSTRING(max)

@DOCSTRING(min)

@DOCSTRING(cummax)

@DOCSTRING(cummin)

@DOCSTRING(hypot)

@DOCSTRING(gradient)

@DOCSTRING(dot)

@DOCSTRING(cross)

@DOCSTRING(divergence)

@DOCSTRING(curl)

@DOCSTRING(del2)

@DOCSTRING(factorial)

@DOCSTRING(factor)

@DOCSTRING(gcd)

@DOCSTRING(lcm)

@DOCSTRING(chop)

@DOCSTRING(rem)

@DOCSTRING(mod)

@DOCSTRING(primes)

@DOCSTRING(list_primes)

@DOCSTRING(sign)

@DOCSTRING(signbit)

@node Special Functions
@section Special Functions

@DOCSTRING(airy)

@DOCSTRING(besselj)

@DOCSTRING(beta)

@DOCSTRING(betainc)

@DOCSTRING(betaincinv)

@DOCSTRING(betaln)

@DOCSTRING(bincoeff)

@DOCSTRING(commutation_matrix)

@DOCSTRING(duplication_matrix)

@DOCSTRING(dawson)

@DOCSTRING(ellipj)

@DOCSTRING(ellipke)

@DOCSTRING(erf)

@DOCSTRING(erfc)

@DOCSTRING(erfcx)

@DOCSTRING(erfi)

@DOCSTRING(erfinv)

@DOCSTRING(erfcinv)

@DOCSTRING(expint)

@DOCSTRING(gamma)

@DOCSTRING(gammainc)

@DOCSTRING(legendre)

@anchor{XREFgammaln}
@DOCSTRING(lgamma)

@node Rational Approximations
@section Rational Approximations

@DOCSTRING(rat)

@DOCSTRING(rats)

@node Coordinate Transformations
@section Coordinate Transformations

@DOCSTRING(cart2pol)

@DOCSTRING(pol2cart)

@DOCSTRING(cart2sph)

@DOCSTRING(sph2cart)

@node Mathematical Constants
@section Mathematical Constants

@DOCSTRING(e)

@DOCSTRING(pi)

@DOCSTRING(I)

@DOCSTRING(Inf)

@DOCSTRING(NaN)

@DOCSTRING(eps)

@DOCSTRING(realmax)

@DOCSTRING(realmin)