GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
corefcn
mappers.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 1993-2013 John W. Eaton
4
Copyright (C) 2009-2010 VZLU Prague
5
6
This file is part of Octave.
7
8
Octave is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by the
10
Free Software Foundation; either version 3 of the License, or (at your
11
option) any later version.
12
13
Octave is distributed in the hope that it will be useful, but WITHOUT
14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with Octave; see the file COPYING. If not, see
20
<http://www.gnu.org/licenses/>.
21
22
*/
23
24
#ifdef HAVE_CONFIG_H
25
#include <config.h>
26
#endif
27
28
#include <cctype>
29
#include <cfloat>
30
31
#include "
lo-ieee.h
"
32
#include "
lo-specfun.h
"
33
#include "
lo-mappers.h
"
34
35
#include "
defun.h
"
36
#include "
error.h
"
37
#include "
variables.h
"
38
39
DEFUN
(
abs
, args, ,
40
"-*- texinfo -*-\n\
41
@deftypefn {Mapping Function} {} abs (@var{z})\n\
42
Compute the magnitude of @var{z}, defined as\n\
43
@tex\n\
44
$|z| = \\sqrt{x^2 + y^2}$.\n\
45
@end tex\n\
46
@ifnottex\n\
47
|@var{z}| = @code{sqrt (x^2 + y^2)}.\n\
48
@end ifnottex\n\
49
\n\
50
For example:\n\
51
\n\
52
@example\n\
53
@group\n\
54
abs (3 + 4i)\n\
55
@result{} 5\n\
56
@end group\n\
57
@end example\n\
58
@end deftypefn"
)
59
{
60
octave_value
retval;
61
if
(args.length () == 1)
62
retval = args(0).
abs
();
63
else
64
print_usage
();
65
66
return
retval;
67
}
68
69
/*
70
%!assert (abs (1), 1)
71
%!assert (abs (-3.5), 3.5)
72
%!assert (abs (3+4i), 5)
73
%!assert (abs (3-4i), 5)
74
%!assert (abs ([1.1, 3i; 3+4i, -3-4i]), [1.1, 3; 5, 5])
75
76
%!assert (abs (single (1)), single (1))
77
%!assert (abs (single (-3.5)), single (3.5))
78
%!assert (abs (single (3+4i)), single (5))
79
%!assert (abs (single (3-4i)), single (5))
80
%!assert (abs (single ([1.1, 3i; 3+4i, -3-4i])), single ([1.1, 3; 5, 5]))
81
82
%!error abs ()
83
%!error abs (1, 2)
84
*/
85
86
DEFUN
(
acos
, args, ,
87
"-*- texinfo -*-\n\
88
@deftypefn {Mapping Function} {} acos (@var{x})\n\
89
Compute the inverse cosine in radians for each element of @var{x}.\n\
90
@seealso{cos, acosd}\n\
91
@end deftypefn"
)
92
{
93
octave_value
retval;
94
if
(args.length () == 1)
95
retval = args(0).
acos
();
96
else
97
print_usage
();
98
99
return
retval;
100
}
101
102
/*
103
%!shared rt2, rt3
104
%! rt2 = sqrt (2);
105
%! rt3 = sqrt (3);
106
107
%!test
108
%! x = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
109
%! v = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
110
%! assert (acos (x), v, sqrt (eps));
111
112
%!test
113
%! x = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
114
%! v = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
115
%! assert (acos (x), v, sqrt (eps ("single")));
116
117
%!error acos ()
118
%!error acos (1, 2)
119
*/
120
121
DEFUN
(
acosh
, args, ,
122
"-*- texinfo -*-\n\
123
@deftypefn {Mapping Function} {} acosh (@var{x})\n\
124
Compute the inverse hyperbolic cosine for each element of @var{x}.\n\
125
@seealso{cosh}\n\
126
@end deftypefn"
)
127
{
128
octave_value
retval;
129
if
(args.length () == 1)
130
retval = args(0).
acosh
();
131
else
132
print_usage
();
133
134
return
retval;
135
}
136
137
/*
138
%!test
139
%! x = [1, 0, -1, 0];
140
%! v = [0, pi/2*i, pi*i, pi/2*i];
141
%! assert (acosh (x), v, sqrt (eps));
142
143
%!test
144
%! x = single ([1, 0, -1, 0]);
145
%! v = single ([0, pi/2*i, pi*i, pi/2*i]);
146
%! assert (acosh (x), v, sqrt (eps ("single")));
147
148
%!error acosh ()
149
%!error acosh (1, 2)
150
*/
151
152
DEFUN
(angle, args, ,
153
"-*- texinfo -*-\n\
154
@deftypefn {Mapping Function} {} angle (@var{z})\n\
155
See arg.\n\
156
@end deftypefn"
)
157
{
158
octave_value
retval;
159
if
(args.length () == 1)
160
retval = args(0).
arg
();
161
else
162
print_usage
();
163
164
return
retval;
165
}
166
167
DEFUN
(
arg
, args, ,
168
"-*- texinfo -*-\n\
169
@deftypefn {Mapping Function} {} arg (@var{z})\n\
170
@deftypefnx {Mapping Function} {} angle (@var{z})\n\
171
Compute the argument of @var{z}, defined as,\n\
172
@tex\n\
173
$\\theta = atan2 (y, x),$\n\
174
@end tex\n\
175
@ifnottex\n\
176
@var{theta} = @code{atan2 (@var{y}, @var{x})},\n\
177
@end ifnottex\n\
178
in radians.\n\
179
\n\
180
For example:\n\
181
\n\
182
@example\n\
183
@group\n\
184
arg (3 + 4i)\n\
185
@result{} 0.92730\n\
186
@end group\n\
187
@end example\n\
188
@end deftypefn"
)
189
{
190
octave_value
retval;
191
if
(args.length () == 1)
192
retval = args(0).
arg
();
193
else
194
print_usage
();
195
196
return
retval;
197
}
198
199
/*
200
%!assert (arg (1), 0)
201
%!assert (arg (i), pi/2)
202
%!assert (arg (-1), pi)
203
%!assert (arg (-i), -pi/2)
204
%!assert (arg ([1, i; -1, -i]), [0, pi/2; pi, -pi/2])
205
206
%!assert (arg (single (1)), single (0))
207
%!assert (arg (single (i)), single (pi/2))
208
%!test
209
%! if (ismac ())
210
%! ## Avoid failing for a MacOS feature
211
%! assert (arg (single (-1)), single (pi), 2*eps (single (1)));
212
%! else
213
%! assert (arg (single (-1)), single (pi));
214
%! endif
215
%!assert (arg (single (-i)), single (-pi/2))
216
%!assert (arg (single ([1, i; -1, -i])), single ([0, pi/2; pi, -pi/2]), 2e1*eps ("single"))
217
218
%!error arg ()
219
%!error arg (1, 2)
220
*/
221
222
DEFUN
(
asin
, args, ,
223
"-*- texinfo -*-\n\
224
@deftypefn {Mapping Function} {} asin (@var{x})\n\
225
Compute the inverse sine in radians for each element of @var{x}.\n\
226
@seealso{sin, asind}\n\
227
@end deftypefn"
)
228
{
229
octave_value
retval;
230
if
(args.length () == 1)
231
retval = args(0).
asin
();
232
else
233
print_usage
();
234
235
return
retval;
236
}
237
238
/*
239
%!test
240
%! rt2 = sqrt (2);
241
%! rt3 = sqrt (3);
242
%! x = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
243
%! v = [0, pi/6, pi/4, pi/3, pi/2, pi/3, pi/4, pi/6, 0];
244
%! assert (all (abs (asin (x) - v) < sqrt (eps)));
245
246
%!error asin ()
247
%!error asin (1, 2)
248
*/
249
250
DEFUN
(
asinh
, args, ,
251
"-*- texinfo -*-\n\
252
@deftypefn {Mapping Function} {} asinh (@var{x})\n\
253
Compute the inverse hyperbolic sine for each element of @var{x}.\n\
254
@seealso{sinh}\n\
255
@end deftypefn"
)
256
{
257
octave_value
retval;
258
if
(args.length () == 1)
259
retval = args(0).
asinh
();
260
else
261
print_usage
();
262
263
return
retval;
264
}
265
266
/*
267
%!test
268
%! v = [0, pi/2*i, 0, -pi/2*i];
269
%! x = [0, i, 0, -i];
270
%! assert (asinh (x), v, sqrt (eps));
271
272
%!test
273
%! v = single ([0, pi/2*i, 0, -pi/2*i]);
274
%! x = single ([0, i, 0, -i]);
275
%! assert (asinh (x), v, sqrt (eps ("single")));
276
277
%!error asinh ()
278
%!error asinh (1, 2)
279
*/
280
281
DEFUN
(
atan
, args, ,
282
"-*- texinfo -*-\n\
283
@deftypefn {Mapping Function} {} atan (@var{x})\n\
284
Compute the inverse tangent in radians for each element of @var{x}.\n\
285
@seealso{tan, atand}\n\
286
@end deftypefn"
)
287
{
288
octave_value
retval;
289
if
(args.length () == 1)
290
retval = args(0).
atan
();
291
else
292
print_usage
();
293
294
return
retval;
295
}
296
297
/*
298
%!shared rt2, rt3
299
%! rt2 = sqrt (2);
300
%! rt3 = sqrt (3);
301
302
%!test
303
%! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
304
%! x = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
305
%! assert (atan (x), v, sqrt (eps));
306
307
%!test
308
%! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
309
%! x = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
310
%! assert (atan (x), v, sqrt (eps ("single")));
311
312
%!error atan ()
313
%!error atan (1, 2)
314
*/
315
316
DEFUN
(
atanh
, args, ,
317
"-*- texinfo -*-\n\
318
@deftypefn {Mapping Function} {} atanh (@var{x})\n\
319
Compute the inverse hyperbolic tangent for each element of @var{x}.\n\
320
@seealso{tanh}\n\
321
@end deftypefn"
)
322
{
323
octave_value
retval;
324
if
(args.length () == 1)
325
retval = args(0).
atanh
();
326
else
327
print_usage
();
328
329
return
retval;
330
}
331
332
/*
333
%!test
334
%! v = [0, 0];
335
%! x = [0, 0];
336
%! assert (atanh (x), v, sqrt (eps));
337
338
%!test
339
%! v = single ([0, 0]);
340
%! x = single ([0, 0]);
341
%! assert (atanh (x), v, sqrt (eps ("single")));
342
343
%!error atanh ()
344
%!error atanh (1, 2)
345
*/
346
347
DEFUN
(
cbrt
, args, ,
348
"-*- texinfo -*-\n\
349
@deftypefn {Mapping Function} {} cbrt (@var{x})\n\
350
Compute the real cube root of each element of @var{x}.\n\
351
Unlike @code{@var{x}^(1/3)}, the result will be negative if @var{x} is\n\
352
negative.\n\
353
@seealso{nthroot}\n\
354
@end deftypefn"
)
355
{
356
octave_value
retval;
357
if
(args.length () == 1)
358
retval = args(0).
cbrt
();
359
else
360
print_usage
();
361
362
return
retval;
363
}
364
365
/*
366
%!assert (cbrt (64), 4)
367
%!assert (cbrt (-125), -5)
368
%!assert (cbrt (0), 0)
369
%!assert (cbrt (Inf), Inf)
370
%!assert (cbrt (-Inf), -Inf)
371
%!assert (cbrt (NaN), NaN)
372
%!assert (cbrt (2^300), 2^100)
373
%!assert (cbrt (125*2^300), 5*2^100)
374
375
%!error cbrt ()
376
%!error cbrt (1, 2)
377
*/
378
379
DEFUN
(
ceil
, args, ,
380
"-*- texinfo -*-\n\
381
@deftypefn {Mapping Function} {} ceil (@var{x})\n\
382
Return the smallest integer not less than @var{x}. This is equivalent to\n\
383
rounding towards positive infinity. If @var{x} is\n\
384
complex, return @code{ceil (real (@var{x})) + ceil (imag (@var{x})) * I}.\n\
385
\n\
386
@example\n\
387
@group\n\
388
ceil ([-2.7, 2.7])\n\
389
@result{} -2 3\n\
390
@end group\n\
391
@end example\n\
392
@seealso{floor, round, fix}\n\
393
@end deftypefn"
)
394
{
395
octave_value
retval;
396
if
(args.length () == 1)
397
retval = args(0).
ceil
();
398
else
399
print_usage
();
400
401
return
retval;
402
}
403
404
/*
405
## double precision
406
%!assert (ceil ([2, 1.1, -1.1, -1]), [2, 2, -1, -1])
407
408
## complex double precison
409
%!assert (ceil ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 2+2i, -1-i, -1-i])
410
411
## single precision
412
%!assert (ceil (single ([2, 1.1, -1.1, -1])), single ([2, 2, -1, -1]))
413
414
## complex single precision
415
%!assert (ceil (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 2+2i, -1-i, -1-i]))
416
417
%!error ceil ()
418
%!error ceil (1, 2)
419
*/
420
421
DEFUN
(
conj
, args, ,
422
"-*- texinfo -*-\n\
423
@deftypefn {Mapping Function} {} conj (@var{z})\n\
424
Return the complex conjugate of @var{z}, defined as\n\
425
@tex\n\
426
$\\bar{z} = x - iy$.\n\
427
@end tex\n\
428
@ifnottex\n\
429
@code{conj (@var{z})} = @var{x} - @var{i}@var{y}.\n\
430
@end ifnottex\n\
431
@seealso{real, imag}\n\
432
@end deftypefn"
)
433
{
434
octave_value
retval;
435
if
(args.length () == 1)
436
retval = args(0).
conj
();
437
else
438
print_usage
();
439
440
return
retval;
441
}
442
443
/*
444
%!assert (conj (1), 1)
445
%!assert (conj (i), -i)
446
%!assert (conj (1+i), 1-i)
447
%!assert (conj (1-i), 1+i)
448
%!assert (conj ([-1, -i; -1+i, -1-i]), [-1, i; -1-i, -1+i])
449
450
%!assert (conj (single (1)), single (1))
451
%!assert (conj (single (i)), single (-i))
452
%!assert (conj (single (1+i)), single (1-i))
453
%!assert (conj (single (1-i)), single (1+i))
454
%!assert (conj (single ([-1, -i; -1+i, -1-i])), single ([-1, i; -1-i, -1+i]))
455
456
%!error conj ()
457
%!error conj (1, 2)
458
*/
459
460
DEFUN
(cos, args, ,
461
"-*- texinfo -*-\n\
462
@deftypefn {Mapping Function} {} cos (@var{x})\n\
463
Compute the cosine for each element of @var{x} in radians.\n\
464
@seealso{acos, cosd, cosh}\n\
465
@end deftypefn"
)
466
{
467
octave_value
retval;
468
if
(args.length () == 1)
469
retval = args(0).
cos
();
470
else
471
print_usage
();
472
473
return
retval;
474
}
475
476
/*
477
%!shared rt2, rt3
478
%! rt2 = sqrt (2);
479
%! rt3 = sqrt (3);
480
481
%!test
482
%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
483
%! v = [1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1];
484
%! assert (cos (x), v, sqrt (eps));
485
486
%!test
487
%! rt2 = sqrt (2);
488
%! rt3 = sqrt (3);
489
%! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
490
%! v = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]);
491
%! assert (cos (x), v, sqrt (eps ("single")));
492
493
%!error cos ()
494
%!error cos (1, 2)
495
*/
496
497
DEFUN
(cosh, args, ,
498
"-*- texinfo -*-\n\
499
@deftypefn {Mapping Function} {} cosh (@var{x})\n\
500
Compute the hyperbolic cosine for each element of @var{x}.\n\
501
@seealso{acosh, sinh, tanh}\n\
502
@end deftypefn"
)
503
{
504
octave_value
retval;
505
if
(args.length () == 1)
506
retval = args(0).
cosh
();
507
else
508
print_usage
();
509
510
return
retval;
511
}
512
513
/*
514
%!test
515
%! x = [0, pi/2*i, pi*i, 3*pi/2*i];
516
%! v = [1, 0, -1, 0];
517
%! assert (cosh (x), v, sqrt (eps));
518
519
%!test
520
%! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
521
%! v = single ([1, 0, -1, 0]);
522
%! assert (cosh (x), v, sqrt (eps ("single")));
523
524
%!error cosh ()
525
%!error cosh (1, 2)
526
*/
527
528
DEFUN
(
erf
, args, ,
529
"-*- texinfo -*-\n\
530
@deftypefn {Mapping Function} {} erf (@var{z})\n\
531
Compute the error function,\n\
532
@tex\n\
533
$$\n\
534
{\\rm erf} (z) = {2 \\over \\sqrt{\\pi}}\\int_0^z e^{-t^2} dt\n\
535
$$\n\
536
@end tex\n\
537
@ifnottex\n\
538
\n\
539
@example\n\
540
@group\n\
541
z\n\
542
2 /\n\
543
erf (z) = --------- * | e^(-t^2) dt\n\
544
sqrt (pi) /\n\
545
t=0\n\
546
@end group\n\
547
@end example\n\
548
\n\
549
@end ifnottex\n\
550
@seealso{erfc, erfcx, erfi, dawson, erfinv, erfcinv}\n\
551
@end deftypefn"
)
552
{
553
octave_value
retval;
554
if
(args.length () == 1)
555
retval = args(0).
erf
();
556
else
557
print_usage
();
558
559
return
retval;
560
}
561
562
/*
563
%!test
564
%! a = -1i*sqrt (-1/(6.4187*6.4187));
565
%! assert (erf (a), erf (real (a)));
566
567
%!test
568
%! x = [0,.5,1];
569
%! v = [0, .520499877813047, .842700792949715];
570
%! assert (erf (x), v, 1.e-10);
571
%! assert (erf (-x), -v, 1.e-10);
572
%! assert (erfc (x), 1-v, 1.e-10);
573
%! assert (erfinv (v), x, 1.e-10);
574
575
%!test
576
%! a = -1i*sqrt (single (-1/(6.4187*6.4187)));
577
%! assert (erf (a), erf (real (a)));
578
579
%!test
580
%! x = single ([0,.5,1]);
581
%! v = single ([0, .520499877813047, .842700792949715]);
582
%! assert (erf (x), v, 1.e-6);
583
%! assert (erf (-x), -v, 1.e-6);
584
%! assert (erfc (x), 1-v, 1.e-6);
585
%! assert (erfinv (v), x, 1.e-6);
586
587
%!test
588
%! x = [1+2i,-1+2i,1e-6+2e-6i,0+2i];
589
%! v = [-0.53664356577857-5.04914370344703i, 0.536643565778565-5.04914370344703i, 0.112837916709965e-5+0.225675833419178e-5i, 18.5648024145755526i];
590
%! assert (erf (x), v, -1.e-10);
591
%! assert (erf (-x), -v, -1.e-10);
592
%! assert (erfc (x), 1-v, -1.e-10);
593
594
%!error erf ()
595
%!error erf (1, 2)
596
*/
597
598
DEFUN
(
erfinv
, args, ,
599
"-*- texinfo -*-\n\
600
@deftypefn {Mapping Function} {} erfinv (@var{x})\n\
601
Compute the inverse error function, i.e., @var{y} such that\n\
602
\n\
603
@example\n\
604
erf (@var{y}) == @var{x}\n\
605
@end example\n\
606
@seealso{erf, erfc, erfcx, erfi, dawson, erfcinv}\n\
607
@end deftypefn"
)
608
{
609
octave_value
retval;
610
if
(args.length () == 1)
611
retval = args(0).
erfinv
();
612
else
613
print_usage
();
614
615
return
retval;
616
}
617
618
/*
619
## middle region
620
%!assert (erf (erfinv ([-0.9 -0.3 0 0.4 0.8])), [-0.9 -0.3 0 0.4 0.8], eps)
621
%!assert (erf (erfinv (single ([-0.9 -0.3 0 0.4 0.8]))), single ([-0.9 -0.3 0 0.4 0.8]), eps ("single"))
622
## tail region
623
%!assert (erf (erfinv ([-0.999 -0.99 0.9999 0.99999])), [-0.999 -0.99 0.9999 0.99999], eps)
624
%!assert (erf (erfinv (single ([-0.999 -0.99 0.9999 0.99999]))), single ([-0.999 -0.99 0.9999 0.99999]), eps ("single"))
625
## backward - loss of accuracy
626
%!assert (erfinv (erf ([-3 -1 -0.4 0.7 1.3 2.8])), [-3 -1 -0.4 0.7 1.3 2.8], -1e-12)
627
%!assert (erfinv (erf (single ([-3 -1 -0.4 0.7 1.3 2.8]))), single ([-3 -1 -0.4 0.7 1.3 2.8]), -1e-4)
628
## exceptional
629
%!assert (erfinv ([-1, 1, 1.1, -2.1]), [-Inf, Inf, NaN, NaN])
630
%!error erfinv (1+2i)
631
632
%!error erfinv ()
633
%!error erfinv (1, 2)
634
*/
635
636
DEFUN
(
erfcinv
, args, ,
637
"-*- texinfo -*-\n\
638
@deftypefn {Mapping Function} {} erfcinv (@var{x})\n\
639
Compute the inverse complementary error function, i.e., @var{y} such that\n\
640
\n\
641
@example\n\
642
erfc (@var{y}) == @var{x}\n\
643
@end example\n\
644
@seealso{erfc, erf, erfcx, erfi, dawson, erfinv}\n\
645
@end deftypefn"
)
646
{
647
octave_value
retval;
648
if
(args.length () == 1)
649
retval = args(0).
erfcinv
();
650
else
651
print_usage
();
652
653
return
retval;
654
}
655
656
/*
657
## middle region
658
%!assert (erfc (erfcinv ([1.9 1.3 1 0.6 0.2])), [1.9 1.3 1 0.6 0.2], eps)
659
%!assert (erfc (erfcinv (single ([1.9 1.3 1 0.6 0.2]))), single ([1.9 1.3 1 0.6 0.2]), eps ("single"))
660
## tail region
661
%!assert (erfc (erfcinv ([0.001 0.01 1.9999 1.99999])), [0.001 0.01 1.9999 1.99999], eps)
662
%!assert (erfc (erfcinv (single ([0.001 0.01 1.9999 1.99999]))), single ([0.001 0.01 1.9999 1.99999]), eps ("single"))
663
## backward - loss of accuracy
664
%!assert (erfcinv (erfc ([-3 -1 -0.4 0.7 1.3 2.8])), [-3 -1 -0.4 0.7 1.3 2.8], -1e-12)
665
%!assert (erfcinv (erfc (single ([-3 -1 -0.4 0.7 1.3 2.8]))), single ([-3 -1 -0.4 0.7 1.3 2.8]), -1e-4)
666
## exceptional
667
%!assert (erfcinv ([2, 0, -0.1, 2.1]), [-Inf, Inf, NaN, NaN])
668
%!error erfcinv (1+2i)
669
670
%!error erfcinv ()
671
%!error erfcinv (1, 2)
672
*/
673
674
DEFUN
(
erfc
, args, ,
675
"-*- texinfo -*-\n\
676
@deftypefn {Mapping Function} {} erfc (@var{z})\n\
677
Compute the complementary error function,\n\
678
@tex\n\
679
$1 - {\\rm erf} (z)$.\n\
680
@end tex\n\
681
@ifnottex\n\
682
@w{@code{1 - erf (@var{z})}}.\n\
683
@end ifnottex\n\
684
@seealso{erfcinv, erfcx, erfi, dawson, erf, erfinv}\n\
685
@end deftypefn"
)
686
{
687
octave_value
retval;
688
if
(args.length () == 1)
689
retval = args(0).
erfc
();
690
else
691
print_usage
();
692
693
return
retval;
694
}
695
696
/*
697
%!test
698
%! a = -1i*sqrt (-1/(6.4187*6.4187));
699
%! assert (erfc (a), erfc (real (a)));
700
701
%!error erfc ()
702
%!error erfc (1, 2)
703
*/
704
705
DEFUN
(
erfcx
, args, ,
706
"-*- texinfo -*-\n\
707
@deftypefn {Mapping Function} {} erfcx (@var{z})\n\
708
Compute the scaled complementary error function,\n\
709
@tex\n\
710
$$\n\
711
e^{z^2} {\\rm erfc} (z) \\equiv e^{z^2} (1 - {\\rm erf} (z))\n\
712
$$\n\
713
@end tex\n\
714
@ifnottex\n\
715
\n\
716
@example\n\
717
exp (z^2) * erfc (z)\n\
718
@end example\n\
719
\n\
720
@end ifnottex\n\
721
@seealso{erfc, erf, erfi, dawson, erfinv, erfcinv}\n\
722
@end deftypefn"
)
723
{
724
octave_value
retval;
725
if
(args.length () == 1)
726
retval = args(0).
erfcx
();
727
else
728
print_usage
();
729
730
return
retval;
731
}
732
733
/*
734
735
%!test
736
%! x = [1+2i,-1+2i,1e-6+2e-6i,0+2i];
737
%! assert (erfcx (x), exp (x.^2) .* erfc(x), -1.e-10);
738
739
%!test
740
%! x = [100, 100+20i];
741
%! v = [0.0056416137829894329, 0.0054246791754558-0.00108483153786434i];
742
%! assert (erfcx (x), v, -1.e-10);
743
744
%!error erfcx ()
745
%!error erfcx (1, 2)
746
*/
747
748
DEFUN
(
erfi
, args, ,
749
"-*- texinfo -*-\n\
750
@deftypefn {Mapping Function} {} erfi (@var{z})\n\
751
Compute the imaginary error function,\n\
752
@tex\n\
753
$$\n\
754
-i {\\rm erf} (iz) \n\
755
$$\n\
756
@end tex\n\
757
@ifnottex\n\
758
\n\
759
@example\n\
760
-i * erf (i*z)\n\
761
@end example\n\
762
\n\
763
@end ifnottex\n\
764
@seealso{erfc, erf, erfcx, dawson, erfinv, erfcinv}\n\
765
@end deftypefn"
)
766
{
767
octave_value
retval;
768
if
(args.length () == 1)
769
retval = args(0).
erfi
();
770
else
771
print_usage
();
772
773
return
retval;
774
}
775
776
/*
777
778
%!test
779
%! x = [-0.1, 0.1, 1, 1+2i,-1+2i,1e-6+2e-6i,0+2i];
780
%! assert (erfi (x), -i * erf(i*x), -1.e-10);
781
782
%!error erfi ()
783
%!error erfi (1, 2)
784
*/
785
786
DEFUN
(
dawson
, args, ,
787
"-*- texinfo -*-\n\
788
@deftypefn {Mapping Function} {} dawson (@var{z})\n\
789
Compute the Dawson (scaled imaginary error) function,\n\
790
@tex\n\
791
$$\n\
792
{\\sqrt{\\pi} \\over 2} e^{-z^2} {\\rm erfi} (z) \\equiv -i {\\sqrt{\\pi} \\over 2} e^{-z^2} {\\rm erf} (iz)\n\
793
$$\n\
794
@end tex\n\
795
@ifnottex\n\
796
\n\
797
@example\n\
798
(sqrt (pi) / 2) * exp (-z^2) * erfi (z)\n\
799
@end example\n\
800
\n\
801
@end ifnottex\n\
802
@seealso{erfc, erf, erfcx, erfi, erfinv, erfcinv}\n\
803
@end deftypefn"
)
804
{
805
octave_value
retval;
806
if
(args.length () == 1)
807
retval = args(0).
dawson
();
808
else
809
print_usage
();
810
811
return
retval;
812
}
813
814
/*
815
816
%!test
817
%! x = [0.1, 1, 1+2i,-1+2i,1e-4+2e-4i,0+2i];
818
%! v = [0.099335992397852861, 0.53807950691, -13.38892731648-11.828715104i, 13.38892731648-11.828715104i, 0.0001000000073333+0.000200000001333i, 48.160012114291i];
819
%! assert (dawson (x), v, -1.e-10);
820
%! assert (dawson (-x), -v, -1.e-10);
821
822
%!error dawson ()
823
%!error dawson (1, 2)
824
*/
825
826
DEFUN
(exp, args, ,
827
"-*- texinfo -*-\n\
828
@deftypefn {Mapping Function} {} exp (@var{x})\n\
829
Compute\n\
830
@tex\n\
831
$e^{x}$\n\
832
@end tex\n\
833
@ifnottex\n\
834
@code{e^x}\n\
835
@end ifnottex\n\
836
for each element of @var{x}. To compute the matrix\n\
837
exponential, see @ref{Linear Algebra}.\n\
838
@seealso{log}\n\
839
@end deftypefn"
)
840
{
841
octave_value
retval;
842
if
(args.length () == 1)
843
retval = args(0).
exp
();
844
else
845
print_usage
();
846
847
return
retval;
848
}
849
850
/*
851
%!assert (exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps))
852
%!assert (exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps))
853
%!assert (exp (single ([0, 1, -1, -1000])), single ([1, e, 1/e, 0]), sqrt (eps ("single")))
854
%!assert (exp (single (1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps ("single")))
855
856
%!assert (exp ([Inf, -Inf, NaN]), [Inf 0 NaN])
857
%!assert (exp (single ([Inf, -Inf, NaN])), single ([Inf 0 NaN]))
858
859
%!error exp ()
860
%!error exp (1, 2)
861
*/
862
863
DEFUN
(
expm1
, args, ,
864
"-*- texinfo -*-\n\
865
@deftypefn {Mapping Function} {} expm1 (@var{x})\n\
866
Compute\n\
867
@tex\n\
868
$ e^{x} - 1 $\n\
869
@end tex\n\
870
@ifnottex\n\
871
@code{exp (@var{x}) - 1}\n\
872
@end ifnottex\n\
873
accurately in the neighborhood of zero.\n\
874
@seealso{exp}\n\
875
@end deftypefn"
)
876
{
877
octave_value
retval;
878
if
(args.length () == 1)
879
retval = args(0).
expm1
();
880
else
881
print_usage
();
882
883
return
retval;
884
}
885
886
/*
887
%!assert (expm1 (2*eps), 2*eps, 1e-29)
888
889
%!assert (expm1 ([Inf, -Inf, NaN]), [Inf -1 NaN])
890
%!assert (expm1 (single ([Inf, -Inf, NaN])), single ([Inf -1 NaN]))
891
892
%!error expm1 ()
893
%!error expm1 (1, 2)
894
*/
895
896
DEFUN
(isfinite, args, ,
897
"-*- texinfo -*-\n\
898
@deftypefn {Mapping Function} {} isfinite (@var{x})\n\
899
@deftypefnx {Mapping Function} {} finite (@var{x})\n\
900
Return a logical array which is true where the elements of @var{x} are\n\
901
finite values and false where they are not.\n\
902
For example:\n\
903
\n\
904
@example\n\
905
@group\n\
906
finite ([13, Inf, NA, NaN])\n\
907
@result{} [ 1, 0, 0, 0 ]\n\
908
@end group\n\
909
@end example\n\
910
@seealso{isinf, isnan, isna}\n\
911
@end deftypefn"
)
912
{
913
octave_value
retval;
914
if
(args.length () == 1)
915
retval = args(0).
finite
();
916
else
917
print_usage
();
918
919
return
retval;
920
}
921
922
/*
923
%!assert (!finite (Inf))
924
%!assert (!finite (NaN))
925
%!assert (finite (rand (1,10)))
926
927
%!assert (!finite (single (Inf)))
928
%!assert (!finite (single (NaN)))
929
%!assert (finite (single (rand (1,10))))
930
931
%!error finite ()
932
%!error finite (1, 2)
933
*/
934
935
DEFUN
(
fix
, args, ,
936
"-*- texinfo -*-\n\
937
@deftypefn {Mapping Function} {} fix (@var{x})\n\
938
Truncate fractional portion of @var{x} and return the integer portion. This\n\
939
is equivalent to rounding towards zero. If @var{x} is complex, return\n\
940
@code{fix (real (@var{x})) + fix (imag (@var{x})) * I}.\n\
941
\n\
942
@example\n\
943
@group\n\
944
fix ([-2.7, 2.7])\n\
945
@result{} -2 2\n\
946
@end group\n\
947
@end example\n\
948
@seealso{ceil, floor, round}\n\
949
@end deftypefn"
)
950
{
951
octave_value
retval;
952
if
(args.length () == 1)
953
retval = args(0).
fix
();
954
else
955
print_usage
();
956
957
return
retval;
958
}
959
960
/*
961
%!assert (fix ([1.1, 1, -1.1, -1]), [1, 1, -1, -1])
962
%!assert (fix ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i]), [1+i, 1+i, -1-i, -1-i])
963
%!assert (fix (single ([1.1, 1, -1.1, -1])), single ([1, 1, -1, -1]))
964
%!assert (fix (single ([1.1+1.1i, 1+i, -1.1-1.1i, -1-i])), single ([1+i, 1+i, -1-i, -1-i]))
965
966
%!error fix ()
967
%!error fix (1, 2)
968
*/
969
970
DEFUN
(
floor
, args, ,
971
"-*- texinfo -*-\n\
972
@deftypefn {Mapping Function} {} floor (@var{x})\n\
973
Return the largest integer not greater than @var{x}. This is equivalent to\n\
974
rounding towards negative infinity. If @var{x} is\n\
975
complex, return @code{floor (real (@var{x})) + floor (imag (@var{x})) * I}.\n\
976
\n\
977
@example\n\
978
@group\n\
979
floor ([-2.7, 2.7])\n\
980
@result{} -3 2\n\
981
@end group\n\
982
@end example\n\
983
@seealso{ceil, round, fix}\n\
984
@end deftypefn"
)
985
{
986
octave_value
retval;
987
if
(args.length () == 1)
988
retval = args(0).
floor
();
989
else
990
print_usage
();
991
992
return
retval;
993
}
994
995
/*
996
%!assert (floor ([2, 1.1, -1.1, -1]), [2, 1, -2, -1])
997
%!assert (floor ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 1+i, -2-2i, -1-i])
998
%!assert (floor (single ([2, 1.1, -1.1, -1])), single ([2, 1, -2, -1]))
999
%!assert (floor (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 1+i, -2-2i, -1-i]))
1000
1001
%!error floor ()
1002
%!error floor (1, 2)
1003
*/
1004
1005
DEFUN
(
gamma
, args, ,
1006
"-*- texinfo -*-\n\
1007
@deftypefn {Mapping Function} {} gamma (@var{z})\n\
1008
Compute the Gamma function,\n\
1009
@tex\n\
1010
$$\n\
1011
\\Gamma (z) = \\int_0^\\infty t^{z-1} e^{-t} dt.\n\
1012
$$\n\
1013
@end tex\n\
1014
@ifnottex\n\
1015
\n\
1016
@example\n\
1017
@group\n\
1018
infinity\n\
1019
/\n\
1020
gamma (z) = | t^(z-1) exp (-t) dt.\n\
1021
/\n\
1022
t=0\n\
1023
@end group\n\
1024
@end example\n\
1025
\n\
1026
@end ifnottex\n\
1027
@seealso{gammainc, lgamma}\n\
1028
@end deftypefn"
)
1029
{
1030
octave_value
retval;
1031
if
(args.length () == 1)
1032
retval = args(0).
gamma
();
1033
else
1034
print_usage
();
1035
1036
return
retval;
1037
}
1038
1039
/*
1040
%!test
1041
%! a = -1i*sqrt (-1/(6.4187*6.4187));
1042
%! assert (gamma (a), gamma (real (a)));
1043
1044
%!test
1045
%! x = [.5, 1, 1.5, 2, 3, 4, 5];
1046
%! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
1047
%! assert (gamma (x), v, sqrt (eps));
1048
1049
%!test
1050
%! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
1051
%! assert (gamma (a), gamma (real (a)));
1052
1053
%!test
1054
%! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
1055
%! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
1056
%! assert (gamma (x), v, sqrt (eps ("single")));
1057
1058
%!test
1059
%! ## Test exceptional values
1060
%! x = [-Inf, -1, -0, 0, 1, Inf, NaN];
1061
%! v = [NaN, NaN, -Inf, Inf, 1, Inf, NaN];
1062
%! assert (gamma (x), v);
1063
%! assert (gamma (single (x)), single (v));
1064
1065
%!error gamma ()
1066
%!error gamma (1, 2)
1067
*/
1068
1069
DEFUN
(
imag
, args, ,
1070
"-*- texinfo -*-\n\
1071
@deftypefn {Mapping Function} {} imag (@var{z})\n\
1072
Return the imaginary part of @var{z} as a real number.\n\
1073
@seealso{real, conj}\n\
1074
@end deftypefn"
)
1075
{
1076
octave_value
retval;
1077
if
(args.length () == 1)
1078
retval = args(0).
imag
();
1079
else
1080
print_usage
();
1081
1082
return
retval;
1083
}
1084
1085
/*
1086
%!assert (imag (1), 0)
1087
%!assert (imag (i), 1)
1088
%!assert (imag (1+i), 1)
1089
%!assert (imag ([i, 1; 1, i]), full (eye (2)))
1090
1091
%!assert (imag (single (1)), single (0))
1092
%!assert (imag (single (i)), single (1))
1093
%!assert (imag (single (1+i)), single (1))
1094
%!assert (imag (single ([i, 1; 1, i])), full (eye (2,"single")))
1095
1096
%!error imag ()
1097
%!error imag (1, 2)
1098
*/
1099
1100
DEFUNX
(
"isalnum"
,
Fisalnum
, args, ,
1101
"-*- texinfo -*-\n\
1102
@deftypefn {Mapping Function} {} isalnum (@var{s})\n\
1103
Return a logical array which is true where the elements of @var{s} are\n\
1104
letters or digits and false where they are not. This is equivalent to\n\
1105
(@code{isalpha (@var{s}) | isdigit (@var{s})}).\n\
1106
@seealso{isalpha, isdigit, ispunct, isspace, iscntrl}\n\
1107
@end deftypefn"
)
1108
{
1109
octave_value
retval;
1110
if
(args.length () == 1)
1111
retval = args(0).
xisalnum
();
1112
else
1113
print_usage
();
1114
1115
return
retval;
1116
}
1117
1118
/*
1119
%!test
1120
%! charset = char (0:127);
1121
%! result = false (1, 128);
1122
%! result(toascii ("A":"Z") + 1) = true;
1123
%! result(toascii ("0":"9") + 1) = true;
1124
%! result(toascii ("a":"z") + 1) = true;
1125
%! assert (isalnum (charset), result);
1126
1127
%!error isalnum ()
1128
%!error isalnum (1, 2)
1129
*/
1130
1131
DEFUNX
(
"isalpha"
,
Fisalpha
, args, ,
1132
"-*- texinfo -*-\n\
1133
@deftypefn {Mapping Function} {} isalpha (@var{s})\n\
1134
Return a logical array which is true where the elements of @var{s} are\n\
1135
letters and false where they are not. This is equivalent to\n\
1136
(@code{islower (@var{s}) | isupper (@var{s})}).\n\
1137
@seealso{isdigit, ispunct, isspace, iscntrl, isalnum, islower, isupper}\n\
1138
@end deftypefn"
)
1139
{
1140
octave_value
retval;
1141
if
(args.length () == 1)
1142
retval = args(0).
xisalpha
();
1143
else
1144
print_usage
();
1145
1146
return
retval;
1147
}
1148
1149
/*
1150
%!test
1151
%! charset = char (0:127);
1152
%! result = false (1, 128);
1153
%! result(toascii ("A":"Z") + 1) = true;
1154
%! result(toascii ("a":"z") + 1) = true;
1155
%! assert (isalpha (charset), result);
1156
1157
%!error isalpha ()
1158
%!error isalpha (1, 2)
1159
*/
1160
1161
DEFUNX
(
"isascii"
,
Fisascii
, args, ,
1162
"-*- texinfo -*-\n\
1163
@deftypefn {Mapping Function} {} isascii (@var{s})\n\
1164
Return a logical array which is true where the elements of @var{s} are\n\
1165
ASCII characters (in the range 0 to 127 decimal) and false where they are\n\
1166
not.\n\
1167
@end deftypefn"
)
1168
{
1169
octave_value
retval;
1170
if
(args.length () == 1)
1171
retval = args(0).
xisascii
();
1172
else
1173
print_usage
();
1174
1175
return
retval;
1176
}
1177
1178
/*
1179
%!test
1180
%! charset = char (0:127);
1181
%! result = true (1, 128);
1182
%! assert (isascii (charset), result);
1183
1184
%!error isascii ()
1185
%!error isascii (1, 2)
1186
*/
1187
1188
DEFUNX
(
"iscntrl"
,
Fiscntrl
, args, ,
1189
"-*- texinfo -*-\n\
1190
@deftypefn {Mapping Function} {} iscntrl (@var{s})\n\
1191
Return a logical array which is true where the elements of @var{s} are\n\
1192
control characters and false where they are not.\n\
1193
@seealso{ispunct, isspace, isalpha, isdigit}\n\
1194
@end deftypefn"
)
1195
{
1196
octave_value
retval;
1197
if
(args.length () == 1)
1198
retval = args(0).
xiscntrl
();
1199
else
1200
print_usage
();
1201
1202
return
retval;
1203
}
1204
1205
/*
1206
%!test
1207
%! charset = char (0:127);
1208
%! result = false (1, 128);
1209
%! result(1:32) = true;
1210
%! result(128) = true;
1211
%! assert (iscntrl (charset), result);
1212
1213
%!error iscntrl ()
1214
%!error iscntrl (1, 2)
1215
*/
1216
1217
DEFUNX
(
"isdigit"
,
Fisdigit
, args, ,
1218
"-*- texinfo -*-\n\
1219
@deftypefn {Mapping Function} {} isdigit (@var{s})\n\
1220
Return a logical array which is true where the elements of @var{s} are\n\
1221
decimal digits (0-9) and false where they are not.\n\
1222
@seealso{isxdigit, isalpha, isletter, ispunct, isspace, iscntrl}\n\
1223
@end deftypefn"
)
1224
{
1225
octave_value
retval;
1226
if
(args.length () == 1)
1227
retval = args(0).
xisdigit
();
1228
else
1229
print_usage
();
1230
1231
return
retval;
1232
}
1233
1234
/*
1235
%!test
1236
%! charset = char (0:127);
1237
%! result = false (1, 128);
1238
%! result(toascii ("0":"9") + 1) = true;
1239
%! assert (isdigit (charset), result);
1240
1241
%!error isdigit ()
1242
%!error isdigit (1, 2)
1243
*/
1244
1245
DEFUN
(isinf, args, ,
1246
"-*- texinfo -*-\n\
1247
@deftypefn {Mapping Function} {} isinf (@var{x})\n\
1248
Return a logical array which is true where the elements of @var{x} are\n\
1249
are infinite and false where they are not.\n\
1250
For example:\n\
1251
\n\
1252
@example\n\
1253
@group\n\
1254
isinf ([13, Inf, NA, NaN])\n\
1255
@result{} [ 0, 1, 0, 0 ]\n\
1256
@end group\n\
1257
@end example\n\
1258
@seealso{isfinite, isnan, isna}\n\
1259
@end deftypefn"
)
1260
{
1261
octave_value
retval;
1262
if
(args.length () == 1)
1263
retval = args(0).
isinf
();
1264
else
1265
print_usage
();
1266
1267
return
retval;
1268
}
1269
1270
/*
1271
%!assert (isinf (Inf))
1272
%!assert (!isinf (NaN))
1273
%!assert (!isinf (NA))
1274
%!assert (isinf (rand (1,10)), false (1,10))
1275
%!assert (isinf ([NaN -Inf -1 0 1 Inf NA]), [false, true, false, false, false, true, false])
1276
1277
%!assert (isinf (single (Inf)))
1278
%!assert (!isinf (single (NaN)))
1279
%!assert (!isinf (single (NA)))
1280
%!assert (isinf (single (rand (1,10))), false (1,10))
1281
%!assert (isinf (single ([NaN -Inf -1 0 1 Inf NA])), [false, true, false, false, false, true, false])
1282
1283
%!error isinf ()
1284
%!error isinf (1, 2)
1285
*/
1286
1287
DEFUNX
(
"isgraph"
,
Fisgraph
, args, ,
1288
"-*- texinfo -*-\n\
1289
@deftypefn {Mapping Function} {} isgraph (@var{s})\n\
1290
Return a logical array which is true where the elements of @var{s} are\n\
1291
printable characters (but not the space character) and false where they are\n\
1292
not.\n\
1293
@seealso{isprint}\n\
1294
@end deftypefn"
)
1295
{
1296
octave_value
retval;
1297
if
(args.length () == 1)
1298
retval = args(0).
xisgraph
();
1299
else
1300
print_usage
();
1301
1302
return
retval;
1303
}
1304
1305
/*
1306
%!test
1307
%! charset = char (0:127);
1308
%! result = false (1, 128);
1309
%! result(34:127) = true;
1310
%! assert (isgraph (charset), result);
1311
1312
%!error isgraph ()
1313
%!error isgraph (1, 2)
1314
*/
1315
1316
DEFUNX
(
"islower"
,
Fislower
, args, ,
1317
"-*- texinfo -*-\n\
1318
@deftypefn {Mapping Function} {} islower (@var{s})\n\
1319
Return a logical array which is true where the elements of @var{s} are\n\
1320
lowercase letters and false where they are not.\n\
1321
@seealso{isupper, isalpha, isletter, isalnum}\n\
1322
@end deftypefn"
)
1323
{
1324
octave_value
retval;
1325
if
(args.length () == 1)
1326
retval = args(0).
xislower
();
1327
else
1328
print_usage
();
1329
1330
return
retval;
1331
}
1332
1333
/*
1334
%!test
1335
%! charset = char (0:127);
1336
%! result = false (1, 128);
1337
%! result(toascii ("a":"z") + 1) = true;
1338
%! assert (islower (charset), result);
1339
1340
%!error islower ()
1341
%!error islower (1, 2)
1342
*/
1343
1344
DEFUN
(isna, args, ,
1345
"-*- texinfo -*-\n\
1346
@deftypefn {Mapping Function} {} isna (@var{x})\n\
1347
Return a logical array which is true where the elements of @var{x} are\n\
1348
NA (missing) values and false where they are not.\n\
1349
For example:\n\
1350
\n\
1351
@example\n\
1352
@group\n\
1353
isna ([13, Inf, NA, NaN])\n\
1354
@result{} [ 0, 0, 1, 0 ]\n\
1355
@end group\n\
1356
@end example\n\
1357
@seealso{isnan, isinf, isfinite}\n\
1358
@end deftypefn"
)
1359
{
1360
octave_value
retval;
1361
if
(args.length () == 1)
1362
retval = args(0).
isna
();
1363
else
1364
print_usage
();
1365
1366
return
retval;
1367
}
1368
1369
/*
1370
%!assert (!isna (Inf))
1371
%!assert (!isna (NaN))
1372
%!assert (isna (NA))
1373
%!assert (isna (rand (1,10)), false (1,10))
1374
%!assert (isna ([NaN -Inf -1 0 1 Inf NA]), [false, false, false, false, false, false, true])
1375
1376
%!assert (!isna (single (Inf)))
1377
%!assert (!isna (single (NaN)))
1378
%!assert (isna (single (NA)))
1379
%!assert (isna (single (rand (1,10))), false (1,10))
1380
%!assert (isna (single ([NaN -Inf -1 0 1 Inf NA])), [false, false, false, false, false, false, true])
1381
1382
%!error isna ()
1383
%!error isna (1, 2)
1384
*/
1385
1386
DEFUN
(isnan, args, ,
1387
"-*- texinfo -*-\n\
1388
@deftypefn {Mapping Function} {} isnan (@var{x})\n\
1389
Return a logical array which is true where the elements of @var{x} are\n\
1390
NaN values and false where they are not.\n\
1391
NA values are also considered NaN values. For example:\n\
1392
\n\
1393
@example\n\
1394
@group\n\
1395
isnan ([13, Inf, NA, NaN])\n\
1396
@result{} [ 0, 0, 1, 1 ]\n\
1397
@end group\n\
1398
@end example\n\
1399
@seealso{isna, isinf, isfinite}\n\
1400
@end deftypefn"
)
1401
{
1402
octave_value
retval;
1403
if
(args.length () == 1)
1404
retval = args(0).
isnan
();
1405
else
1406
print_usage
();
1407
1408
return
retval;
1409
}
1410
1411
/*
1412
%!assert (!isnan (Inf))
1413
%!assert (isnan (NaN))
1414
%!assert (isnan (NA))
1415
%!assert (isnan (rand (1,10)), false (1,10))
1416
%!assert (isnan ([NaN -Inf -1 0 1 Inf NA]), [true, false, false, false, false, false, true])
1417
1418
%!assert (!isnan (single (Inf)))
1419
%!assert (isnan (single (NaN)))
1420
%!assert (isnan (single (NA)))
1421
%!assert (isnan (single (rand (1,10))), false (1,10))
1422
%!assert (isnan (single ([NaN -Inf -1 0 1 Inf NA])), [true, false, false, false, false, false, true])
1423
1424
%!error isnan ()
1425
%!error isnan (1, 2)
1426
*/
1427
1428
DEFUNX
(
"isprint"
,
Fisprint
, args, ,
1429
"-*- texinfo -*-\n\
1430
@deftypefn {Mapping Function} {} isprint (@var{s})\n\
1431
Return a logical array which is true where the elements of @var{s} are\n\
1432
printable characters (including the space character) and false where they\n\
1433
are not.\n\
1434
@seealso{isgraph}\n\
1435
@end deftypefn"
)
1436
{
1437
octave_value
retval;
1438
if
(args.length () == 1)
1439
retval = args(0).
xisprint
();
1440
else
1441
print_usage
();
1442
1443
return
retval;
1444
}
1445
1446
/*
1447
%!test
1448
%! charset = char (0:127);
1449
%! result = false (1, 128);
1450
%! result(33:127) = true;
1451
%! assert (isprint (charset), result);
1452
1453
%!error isprint ()
1454
%!error isprint (1, 2)
1455
*/
1456
1457
DEFUNX
(
"ispunct"
,
Fispunct
, args, ,
1458
"-*- texinfo -*-\n\
1459
@deftypefn {Mapping Function} {} ispunct (@var{s})\n\
1460
Return a logical array which is true where the elements of @var{s} are\n\
1461
punctuation characters and false where they are not.\n\
1462
@seealso{isalpha, isdigit, isspace, iscntrl}\n\
1463
@end deftypefn"
)
1464
{
1465
octave_value
retval;
1466
if
(args.length () == 1)
1467
retval = args(0).
xispunct
();
1468
else
1469
print_usage
();
1470
1471
return
retval;
1472
}
1473
1474
/*
1475
%!test
1476
%! charset = char (0:127);
1477
%! result = false (1, 128);
1478
%! result(34:48) = true;
1479
%! result(59:65) = true;
1480
%! result(92:97) = true;
1481
%! result(124:127) = true;
1482
%! assert (ispunct (charset), result);
1483
1484
%!error ispunct ()
1485
%!error ispunct (1, 2)
1486
*/
1487
1488
DEFUNX
(
"isspace"
,
Fisspace
, args, ,
1489
"-*- texinfo -*-\n\
1490
@deftypefn {Mapping Function} {} isspace (@var{s})\n\
1491
Return a logical array which is true where the elements of @var{s} are\n\
1492
whitespace characters (space, formfeed, newline, carriage return, tab, and\n\
1493
vertical tab) and false where they are not.\n\
1494
@seealso{iscntrl, ispunct, isalpha, isdigit}\n\
1495
@end deftypefn"
)
1496
{
1497
octave_value
retval;
1498
if
(args.length () == 1)
1499
retval = args(0).
xisspace
();
1500
else
1501
print_usage
();
1502
1503
return
retval;
1504
}
1505
1506
/*
1507
%!test
1508
%! charset = char (0:127);
1509
%! result = false (1, 128);
1510
%! result(toascii (" \f\n\r\t\v") + 1) = true;
1511
%! assert (isspace (charset), result);
1512
1513
%!error isspace ()
1514
%!error isspace (1, 2)
1515
*/
1516
1517
DEFUNX
(
"isupper"
,
Fisupper
, args, ,
1518
"-*- texinfo -*-\n\
1519
@deftypefn {Mapping Function} {} isupper (@var{s})\n\
1520
Return a logical array which is true where the elements of @var{s} are\n\
1521
uppercase letters and false where they are not.\n\
1522
@seealso{islower, isalpha, isletter, isalnum}\n\
1523
@end deftypefn"
)
1524
{
1525
octave_value
retval;
1526
if
(args.length () == 1)
1527
retval = args(0).
xisupper
();
1528
else
1529
print_usage
();
1530
1531
return
retval;
1532
}
1533
1534
/*
1535
%!test
1536
%! charset = char (0:127);
1537
%! result = false (1, 128);
1538
%! result(toascii ("A":"Z") + 1) = true;
1539
%! assert (isupper (charset), result);
1540
1541
%!error isupper ()
1542
%!error isupper (1, 2)
1543
*/
1544
1545
DEFUNX
(
"isxdigit"
,
Fisxdigit
, args, ,
1546
"-*- texinfo -*-\n\
1547
@deftypefn {Mapping Function} {} isxdigit (@var{s})\n\
1548
Return a logical array which is true where the elements of @var{s} are\n\
1549
hexadecimal digits (0-9 and @nospell{a-fA-F}).\n\
1550
@seealso{isdigit}\n\
1551
@end deftypefn"
)
1552
{
1553
octave_value
retval;
1554
if
(args.length () == 1)
1555
retval = args(0).
xisxdigit
();
1556
else
1557
print_usage
();
1558
1559
return
retval;
1560
}
1561
1562
/*
1563
%!test
1564
%! charset = char (0:127);
1565
%! result = false (1, 128);
1566
%! result(toascii ("A":"F") + 1) = true;
1567
%! result(toascii ("0":"9") + 1) = true;
1568
%! result(toascii ("a":"f") + 1) = true;
1569
%! assert (isxdigit (charset), result);
1570
1571
%!error isxdigit ()
1572
%!error isxdigit (1, 2)
1573
*/
1574
1575
DEFUN
(lgamma, args, ,
1576
"-*- texinfo -*-\n\
1577
@deftypefn {Mapping Function} {} lgamma (@var{x})\n\
1578
@deftypefnx {Mapping Function} {} gammaln (@var{x})\n\
1579
Return the natural logarithm of the gamma function of @var{x}.\n\
1580
@seealso{gamma, gammainc}\n\
1581
@end deftypefn"
)
1582
{
1583
octave_value
retval;
1584
if
(args.length () == 1)
1585
retval = args(0).
lgamma
();
1586
else
1587
print_usage
();
1588
1589
return
retval;
1590
}
1591
1592
/*
1593
%!test
1594
%! a = -1i*sqrt (-1/(6.4187*6.4187));
1595
%! assert (lgamma (a), lgamma (real (a)));
1596
1597
%!test
1598
%! x = [.5, 1, 1.5, 2, 3, 4, 5];
1599
%! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24];
1600
%! assert (lgamma (x), log (v), sqrt (eps))
1601
1602
%!test
1603
%! a = single (-1i*sqrt (-1/(6.4187*6.4187)));
1604
%! assert (lgamma (a), lgamma (real (a)));
1605
1606
%!test
1607
%! x = single ([.5, 1, 1.5, 2, 3, 4, 5]);
1608
%! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]);
1609
%! assert (lgamma (x), log (v), sqrt (eps ("single")))
1610
1611
%!test
1612
%! x = [-1, 0, 1, Inf];
1613
%! v = [Inf, Inf, 0, Inf];
1614
%! assert (lgamma (x), v);
1615
%! assert (lgamma (single (x)), single (v));
1616
1617
%!error lgamma ()
1618
%!error lgamma (1,2)
1619
*/
1620
1621
DEFUN
(log, args, ,
1622
"-*- texinfo -*-\n\
1623
@deftypefn {Mapping Function} {} log (@var{x})\n\
1624
Compute the natural logarithm,\n\
1625
@tex\n\
1626
$\\ln{(x)},$\n\
1627
@end tex\n\
1628
@ifnottex\n\
1629
@code{ln (@var{x})},\n\
1630
@end ifnottex\n\
1631
for each element of @var{x}. To compute the\n\
1632
matrix logarithm, see @ref{Linear Algebra}.\n\
1633
@seealso{exp, log1p, log2, log10, logspace}\n\
1634
@end deftypefn"
)
1635
{
1636
octave_value
retval;
1637
if
(args.length () == 1)
1638
retval = args(0).
log
();
1639
else
1640
print_usage
();
1641
1642
return
retval;
1643
}
1644
1645
/*
1646
%!assert (log ([1, e, e^2]), [0, 1, 2], sqrt (eps))
1647
%!assert (log ([-0.5, -1.5, -2.5]), log ([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps))
1648
1649
%!assert (log (single ([1, e, e^2])), single ([0, 1, 2]), sqrt (eps ("single")))
1650
%!assert (log (single ([-0.5, -1.5, -2.5])), single (log ([0.5, 1.5, 2.5]) + pi*1i), 4*eps ("single"))
1651
1652
%!error log ()
1653
%!error log (1, 2)
1654
*/
1655
1656
DEFUN
(log10, args, ,
1657
"-*- texinfo -*-\n\
1658
@deftypefn {Mapping Function} {} log10 (@var{x})\n\
1659
Compute the base-10 logarithm of each element of @var{x}.\n\
1660
@seealso{log, log2, logspace, exp}\n\
1661
@end deftypefn"
)
1662
{
1663
octave_value
retval;
1664
if
(args.length () == 1)
1665
retval = args(0).
log10
();
1666
else
1667
print_usage
();
1668
1669
return
retval;
1670
}
1671
1672
/*
1673
%!assert (log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps))
1674
%!assert (log10 (single ([0.01, 0.1, 1, 10, 100])), single ([-2, -1, 0, 1, 2]), sqrt (eps ("single")))
1675
1676
%!error log10 ()
1677
%!error log10 (1, 2)
1678
*/
1679
1680
DEFUN
(
log1p
, args, ,
1681
"-*- texinfo -*-\n\
1682
@deftypefn {Mapping Function} {} log1p (@var{x})\n\
1683
Compute\n\
1684
@tex\n\
1685
$\\ln{(1 + x)}$\n\
1686
@end tex\n\
1687
@ifnottex\n\
1688
@code{log (1 + @var{x})}\n\
1689
@end ifnottex\n\
1690
accurately in the neighborhood of zero.\n\
1691
@seealso{log, exp, expm1}\n\
1692
@end deftypefn"
)
1693
{
1694
octave_value
retval;
1695
if
(args.length () == 1)
1696
retval = args(0).
log1p
();
1697
else
1698
print_usage
();
1699
1700
return
retval;
1701
}
1702
1703
/*
1704
%!assert (log1p ([0, 2*eps, -2*eps]), [0, 2*eps, -2*eps], 1e-29)
1705
%!assert (log1p (single ([0, 2*eps, -2*eps])), single ([0, 2*eps, -2*eps]), 1e-29)
1706
1707
%!error log1p ()
1708
%!error log1p (1, 2)
1709
*/
1710
1711
DEFUN
(
real
, args, ,
1712
"-*- texinfo -*-\n\
1713
@deftypefn {Mapping Function} {} real (@var{z})\n\
1714
Return the real part of @var{z}.\n\
1715
@seealso{imag, conj}\n\
1716
@end deftypefn"
)
1717
{
1718
octave_value
retval;
1719
if
(args.length () == 1)
1720
retval = args(0).
real
();
1721
else
1722
print_usage
();
1723
1724
return
retval;
1725
}
1726
1727
/*
1728
%!assert (real (1), 1)
1729
%!assert (real (i), 0)
1730
%!assert (real (1+i), 1)
1731
%!assert (real ([1, i; i, 1]), full (eye (2)))
1732
1733
%!assert (real (single (1)), single (1))
1734
%!assert (real (single (i)), single (0))
1735
%!assert (real (single (1+i)), single (1))
1736
%!assert (real (single ([1, i; i, 1])), full (eye (2,"single")))
1737
1738
%!error real ()
1739
%!error real (1, 2)
1740
*/
1741
1742
DEFUN
(round, args, ,
1743
"-*- texinfo -*-\n\
1744
@deftypefn {Mapping Function} {} round (@var{x})\n\
1745
Return the integer nearest to @var{x}. If @var{x} is complex, return\n\
1746
@code{round (real (@var{x})) + round (imag (@var{x})) * I}. If there\n\
1747
are two nearest integers, return the one further away from zero.\n\
1748
\n\
1749
@example\n\
1750
@group\n\
1751
round ([-2.7, 2.7])\n\
1752
@result{} -3 3\n\
1753
@end group\n\
1754
@end example\n\
1755
@seealso{ceil, floor, fix, roundb}\n\
1756
@end deftypefn"
)
1757
{
1758
octave_value
retval;
1759
if
(args.length () == 1)
1760
retval = args(0).
round
();
1761
else
1762
print_usage
();
1763
1764
return
retval;
1765
}
1766
1767
/*
1768
%!assert (round (1), 1)
1769
%!assert (round (1.1), 1)
1770
%!assert (round (5.5), 6)
1771
%!assert (round (i), i)
1772
%!assert (round (2.5+3.5i), 3+4i)
1773
%!assert (round (-2.6), -3)
1774
%!assert (round ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
1775
1776
%!assert (round (single (1)), single (1))
1777
%!assert (round (single (1.1)), single (1))
1778
%!assert (round (single (5.5)), single (6))
1779
%!assert (round (single (i)), single (i))
1780
%!assert (round (single (2.5+3.5i)), single (3+4i))
1781
%!assert (round (single (-2.6)), single (-3))
1782
%!assert (round (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
1783
1784
%!error round ()
1785
%!error round (1, 2)
1786
*/
1787
1788
DEFUN
(roundb, args, ,
1789
"-*- texinfo -*-\n\
1790
@deftypefn {Mapping Function} {} roundb (@var{x})\n\
1791
Return the integer nearest to @var{x}. If there are two nearest\n\
1792
integers, return the even one (banker's rounding). If @var{x} is complex,\n\
1793
return @code{roundb (real (@var{x})) + roundb (imag (@var{x})) * I}.\n\
1794
@seealso{round}\n\
1795
@end deftypefn"
)
1796
{
1797
octave_value
retval;
1798
if
(args.length () == 1)
1799
retval = args(0).
roundb
();
1800
else
1801
print_usage
();
1802
1803
return
retval;
1804
}
1805
1806
/*
1807
%!assert (roundb (1), 1)
1808
%!assert (roundb (1.1), 1)
1809
%!assert (roundb (1.5), 2)
1810
%!assert (roundb (4.5), 4)
1811
%!assert (roundb (i), i)
1812
%!assert (roundb (2.5+3.5i), 2+4i)
1813
%!assert (roundb (-2.6), -3)
1814
%!assert (roundb ([1.1, -2.4; -3.7, 7.1]), [1, -2; -4, 7])
1815
1816
%!assert (roundb (single (1)), single (1))
1817
%!assert (roundb (single (1.1)), single (1))
1818
%!assert (roundb (single (1.5)), single (2))
1819
%!assert (roundb (single (4.5)), single (4))
1820
%!assert (roundb (single (i)), single (i))
1821
%!assert (roundb (single (2.5+3.5i)), single (2+4i))
1822
%!assert (roundb (single (-2.6)), single (-3))
1823
%!assert (roundb (single ([1.1, -2.4; -3.7, 7.1])), single ([1, -2; -4, 7]))
1824
1825
%!error roundb ()
1826
%!error roundb (1, 2)
1827
*/
1828
1829
DEFUN
(sign, args, ,
1830
"-*- texinfo -*-\n\
1831
@deftypefn {Mapping Function} {} sign (@var{x})\n\
1832
Compute the @dfn{signum} function, which is defined as\n\
1833
@tex\n\
1834
$$\n\
1835
{\\rm sign} (@var{x}) = \\cases{1,&$x>0$;\\cr 0,&$x=0$;\\cr -1,&$x<0$.\\cr}\n\
1836
$$\n\
1837
@end tex\n\
1838
@ifnottex\n\
1839
\n\
1840
@example\n\
1841
@group\n\
1842
-1, x < 0;\n\
1843
sign (x) = 0, x = 0;\n\
1844
1, x > 0.\n\
1845
@end group\n\
1846
@end example\n\
1847
\n\
1848
@end ifnottex\n\
1849
\n\
1850
For complex arguments, @code{sign} returns @code{x ./ abs (@var{x})}.\n\
1851
\n\
1852
Note that @code{sign (-0.0)} is 0.\n\
1853
Although IEEE 754 floating point\n\
1854
allows zero to be signed, 0.0 and -0.0 compare equal. If you must test\n\
1855
whether zero is signed, use the @code{signbit} function.\n\
1856
@seealso{signbit}\n\
1857
@end deftypefn"
)
1858
{
1859
octave_value
retval;
1860
if
(args.length () == 1)
1861
retval = args(0).
signum
();
1862
else
1863
print_usage
();
1864
1865
return
retval;
1866
}
1867
1868
/*
1869
%!assert (sign (-2) , -1)
1870
%!assert (sign (0), 0)
1871
%!assert (sign (3), 1)
1872
%!assert (sign ([1, -pi; e, 0]), [1, -1; 1, 0])
1873
1874
%!assert (sign (single (-2)) , single (-1))
1875
%!assert (sign (single (0)), single (0))
1876
%!assert (sign (single (3)), single (1))
1877
%!assert (sign (single ([1, -pi; e, 0])), single ([1, -1; 1, 0]))
1878
1879
%!error sign ()
1880
%!error sign (1, 2)
1881
*/
1882
1883
DEFUNX
(
"signbit"
,
Fsignbit
, args, ,
1884
"-*- texinfo -*-\n\
1885
@deftypefn {Mapping Function} {} signbit (@var{x})\n\
1886
Return logical true if the value of @var{x} has its sign bit set.\n\
1887
Otherwise return logical false. This behavior is consistent with the other\n\
1888
logical functions. See@ref{Logical Values}. The behavior differs from the\n\
1889
C language function which returns non-zero if the sign bit is set.\n\
1890
\n\
1891
This is not the same as @code{x < 0.0}, because IEEE 754 floating point\n\
1892
allows zero to be signed. The comparison @code{-0.0 < 0.0} is false,\n\
1893
but @code{signbit (-0.0)} will return a nonzero value.\n\
1894
@seealso{sign}\n\
1895
@end deftypefn"
)
1896
{
1897
octave_value
retval;
1898
if
(args.length () == 1)
1899
{
1900
retval = args(0).
xsignbit
();
1901
retval = (retval != 0);
1902
}
1903
else
1904
print_usage
();
1905
1906
return
retval;
1907
}
1908
1909
/*
1910
%!assert (signbit (1) == 0)
1911
%!assert (signbit (-2) != 0)
1912
%!assert (signbit (0) == 0)
1913
%!assert (signbit (-0) != 0)
1914
1915
%!assert (signbit (single (1)) == 0)
1916
%!assert (signbit (single (-2)) != 0)
1917
%!assert (signbit (single (0)) == 0)
1918
%!assert (signbit (single (-0)) != 0)
1919
1920
%!error sign ()
1921
%!error sign (1, 2)
1922
*/
1923
1924
DEFUN
(sin, args, ,
1925
"-*- texinfo -*-\n\
1926
@deftypefn {Mapping Function} {} sin (@var{x})\n\
1927
Compute the sine for each element of @var{x} in radians.\n\
1928
@seealso{asin, sind, sinh}\n\
1929
@end deftypefn"
)
1930
{
1931
octave_value
retval;
1932
if
(args.length () == 1)
1933
retval = args(0).
sin
();
1934
else
1935
print_usage
();
1936
1937
return
retval;
1938
}
1939
1940
/*
1941
%!shared rt2, rt3
1942
%! rt2 = sqrt (2);
1943
%! rt3 = sqrt (3);
1944
1945
%!test
1946
%! x = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi];
1947
%! v = [0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0];
1948
%! assert (sin (x), v, sqrt (eps));
1949
1950
%!test
1951
%! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
1952
%! v = single ([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]);
1953
%! assert (sin (x), v, sqrt (eps ("single")));
1954
1955
%!error sin ()
1956
%!error sin (1, 2)
1957
*/
1958
1959
DEFUN
(sinh, args, ,
1960
"-*- texinfo -*-\n\
1961
@deftypefn {Mapping Function} {} sinh (@var{x})\n\
1962
Compute the hyperbolic sine for each element of @var{x}.\n\
1963
@seealso{asinh, cosh, tanh}\n\
1964
@end deftypefn"
)
1965
{
1966
octave_value
retval;
1967
if
(args.length () == 1)
1968
retval = args(0).
sinh
();
1969
else
1970
print_usage
();
1971
1972
return
retval;
1973
}
1974
1975
/*
1976
%!test
1977
%! x = [0, pi/2*i, pi*i, 3*pi/2*i];
1978
%! v = [0, i, 0, -i];
1979
%! assert (sinh (x), v, sqrt (eps));
1980
1981
%!test
1982
%! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]);
1983
%! v = single ([0, i, 0, -i]);
1984
%! assert (sinh (x), v, sqrt (eps ("single")));
1985
1986
%!error sinh ()
1987
%!error sinh (1, 2)
1988
*/
1989
1990
DEFUN
(sqrt, args, ,
1991
"-*- texinfo -*-\n\
1992
@deftypefn {Mapping Function} {} sqrt (@var{x})\n\
1993
Compute the square root of each element of @var{x}. If @var{x} is negative,\n\
1994
a complex result is returned. To compute the matrix square root, see\n\
1995
@ref{Linear Algebra}.\n\
1996
@seealso{realsqrt, nthroot}\n\
1997
@end deftypefn"
)
1998
{
1999
octave_value
retval;
2000
if
(args.length () == 1)
2001
retval = args(0).
sqrt
();
2002
else
2003
print_usage
();
2004
2005
return
retval;
2006
}
2007
2008
/*
2009
%!assert (sqrt (4), 2)
2010
%!assert (sqrt (-1), i)
2011
%!assert (sqrt (1+i), exp (0.5 * log (1+i)), sqrt (eps))
2012
%!assert (sqrt ([4, -4; i, 1-i]), [2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))], sqrt (eps))
2013
2014
%!assert (sqrt (single (4)), single (2))
2015
%!assert (sqrt (single (-1)), single (i))
2016
%!assert (sqrt (single (1+i)), single (exp (0.5 * log (1+i))), sqrt (eps ("single")))
2017
%!assert (sqrt (single ([4, -4; i, 1-i])), single ([2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))]), sqrt (eps ("single")))
2018
2019
%!error sqrt ()
2020
%!error sqrt (1, 2)
2021
*/
2022
2023
DEFUN
(tan, args, ,
2024
"-*- texinfo -*-\n\
2025
@deftypefn {Mapping Function} {} tan (@var{z})\n\
2026
Compute the tangent for each element of @var{x} in radians.\n\
2027
@seealso{atan, tand, tanh}\n\
2028
@end deftypefn"
)
2029
{
2030
octave_value
retval;
2031
if
(args.length () == 1)
2032
retval = args(0).
tan
();
2033
else
2034
print_usage
();
2035
2036
return
retval;
2037
}
2038
2039
/*
2040
%!shared rt2, rt3
2041
%! rt2 = sqrt (2);
2042
%! rt3 = sqrt (3);
2043
2044
%!test
2045
%! x = [0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi];
2046
%! v = [0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0];
2047
%! assert (tan (x), v, sqrt (eps));
2048
2049
%!test
2050
%! x = single ([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]);
2051
%! v = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]);
2052
%! assert (tan (x), v, sqrt (eps ("single")));
2053
2054
%!error tan ()
2055
%!error tan (1, 2)
2056
*/
2057
2058
DEFUN
(tanh, args, ,
2059
"-*- texinfo -*-\n\
2060
@deftypefn {Mapping Function} {} tanh (@var{x})\n\
2061
Compute hyperbolic tangent for each element of @var{x}.\n\
2062
@seealso{atanh, sinh, cosh}\n\
2063
@end deftypefn"
)
2064
{
2065
octave_value
retval;
2066
if
(args.length () == 1)
2067
retval = args(0).
tanh
();
2068
else
2069
print_usage
();
2070
2071
return
retval;
2072
}
2073
2074
/*
2075
%!test
2076
%! x = [0, pi*i];
2077
%! v = [0, 0];
2078
%! assert (tanh (x), v, sqrt (eps));
2079
2080
%!test
2081
%! x = single ([0, pi*i]);
2082
%! v = single ([0, 0]);
2083
%! assert (tanh (x), v, sqrt (eps ("single")));
2084
2085
%!error tanh ()
2086
%!error tanh (1, 2)
2087
*/
2088
2089
DEFUNX
(
"toascii"
,
Ftoascii
, args, ,
2090
"-*- texinfo -*-\n\
2091
@deftypefn {Mapping Function} {} toascii (@var{s})\n\
2092
Return ASCII representation of @var{s} in a matrix. For example:\n\
2093
\n\
2094
@example\n\
2095
@group\n\
2096
toascii (\"ASCII\")\n\
2097
@result{} [ 65, 83, 67, 73, 73 ]\n\
2098
@end group\n\
2099
\n\
2100
@end example\n\
2101
@seealso{char}\n\
2102
@end deftypefn"
)
2103
{
2104
octave_value
retval;
2105
if
(args.length () == 1)
2106
retval = args(0).
xtoascii
();
2107
else
2108
print_usage
();
2109
2110
return
retval;
2111
}
2112
2113
/*
2114
%!assert (toascii (char (0:127)), 0:127)
2115
%!assert (toascii (" ":"@"), 32:64)
2116
%!assert (toascii ("A":"Z"), 65:90)
2117
%!assert (toascii ("[":"`"), 91:96)
2118
%!assert (toascii ("a":"z"), 97:122)
2119
%!assert (toascii ("{":"~"), 123:126)
2120
2121
%!error toascii ()
2122
%!error toascii (1, 2)
2123
*/
2124
2125
DEFUNX
(
"tolower"
,
Ftolower
, args, ,
2126
"-*- texinfo -*-\n\
2127
@deftypefn {Mapping Function} {} tolower (@var{s})\n\
2128
@deftypefnx {Mapping Function} {} lower (@var{s})\n\
2129
Return a copy of the string or cell string @var{s}, with each uppercase\n\
2130
character replaced by the corresponding lowercase one; non-alphabetic\n\
2131
characters are left unchanged. For example:\n\
2132
\n\
2133
@example\n\
2134
@group\n\
2135
tolower (\"MiXeD cAsE 123\")\n\
2136
@result{} \"mixed case 123\"\n\
2137
@end group\n\
2138
@end example\n\
2139
@seealso{toupper}\n\
2140
@end deftypefn"
)
2141
{
2142
octave_value
retval;
2143
if
(args.length () == 1)
2144
retval = args(0).
xtolower
();
2145
else
2146
print_usage
();
2147
2148
return
retval;
2149
}
2150
2151
DEFALIAS
(lower, tolower);
2152
2153
/*
2154
%!assert (tolower ("OCTAVE"), "octave")
2155
%!assert (tolower ("123OCTave!_&"), "123octave!_&")
2156
%!assert (tolower ({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}})
2157
%!assert (tolower (["ABC"; "DEF"]), ["abc"; "def"])
2158
%!assert (tolower ({["ABC"; "DEF"]}), {["abc";"def"]})
2159
%!assert (tolower (68), "d")
2160
%!assert (tolower ({[68, 68; 68, 68]}), {["dd";"dd"]})
2161
%!test
2162
%! a(3,3,3,3) = "D";
2163
%! assert (tolower (a)(3,3,3,3), "d");
2164
2165
%!test
2166
%! charset = char (0:127);
2167
%! result = charset;
2168
%! result (toascii ("A":"Z") + 1) = result (toascii ("a":"z") + 1);
2169
%! assert (tolower (charset), result);
2170
2171
%!error <Invalid call to tolower> lower ()
2172
%!error <Invalid call to tolower> tolower ()
2173
%!error tolower (1, 2)
2174
*/
2175
2176
DEFUNX
(
"toupper"
,
Ftoupper
, args, ,
2177
"-*- texinfo -*-\n\
2178
@deftypefn {Mapping Function} {} toupper (@var{s})\n\
2179
@deftypefnx {Mapping Function} {} upper (@var{s})\n\
2180
Return a copy of the string or cell string @var{s}, with each lowercase\n\
2181
character replaced by the corresponding uppercase one; non-alphabetic\n\
2182
characters are left unchanged. For example:\n\
2183
\n\
2184
@example\n\
2185
@group\n\
2186
toupper (\"MiXeD cAsE 123\")\n\
2187
@result{} \"MIXED CASE 123\"\n\
2188
@end group\n\
2189
@end example\n\
2190
@seealso{tolower}\n\
2191
@end deftypefn"
)
2192
{
2193
octave_value
retval;
2194
if
(args.length () == 1)
2195
retval = args(0).
xtoupper
();
2196
else
2197
print_usage
();
2198
2199
return
retval;
2200
}
2201
2202
DEFALIAS
(upper, toupper);
2203
2204
/*
2205
%!assert (toupper ("octave"), "OCTAVE")
2206
%!assert (toupper ("123OCTave!_&"), "123OCTAVE!_&")
2207
%!assert (toupper ({"abc", "def", {"ghi", {"jkl"}}}), {"ABC", "DEF", {"GHI", {"JKL"}}})
2208
%!assert (toupper (["abc"; "def"]), ["ABC"; "DEF"])
2209
%!assert (toupper ({["abc"; "def"]}), {["ABC";"DEF"]})
2210
%!assert (toupper (100), "D")
2211
%!assert (toupper ({[100, 100; 100, 100]}), {["DD";"DD"]})
2212
%!test
2213
%! a(3,3,3,3) = "d";
2214
%! assert (toupper (a)(3,3,3,3), "D");
2215
%!test
2216
%! charset = char (0:127);
2217
%! result = charset;
2218
%! result (toascii ("a":"z") + 1) = result (toascii ("A":"Z") + 1);
2219
%! assert (toupper (charset), result);
2220
2221
%!error <Invalid call to toupper> toupper ()
2222
%!error <Invalid call to toupper> upper ()
2223
%!error toupper (1, 2)
2224
*/
2225
2226
DEFALIAS
(gammaln, lgamma);
2227
2228
DEFALIAS
(finite, isfinite);
Generated on Mon Dec 30 2013 03:04:27 for GNU Octave by
1.8.1.2