annotate scripts/specfun/sinint.m @ 27919:1891570abac8

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2020.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 22:29:51 -0500
parents b442ec6dda5c
children bd51beb6205e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
1 ## Copyright (C) 2017-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
5 ##
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
6 ##
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
7 ## This file is part of Octave.
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
8 ##
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
9 ## Octave is free software: you can redistribute it and/or modify it
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
10 ## under the terms of the GNU General Public License as published by
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
11 ## the Free Software Foundation, either version 3 of the License, or
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
12 ## (at your option) any later version.
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
13 ##
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
14 ## Octave is distributed in the hope that it will be useful, but
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
17 ## GNU General Public License for more details.
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
18 ##
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
19 ## You should have received a copy of the GNU General Public License
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
20 ## along with Octave; see the file COPYING. If not, see
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
21 ## <https://www.gnu.org/licenses/>.
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
22
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
23 ## -*- texinfo -*-
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
24 ## @deftypefn {} {} sinint (@var{x})
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
25 ## Compute the sine integral function:
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
26 ## @tex
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
27 ## $$
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
28 ## {\rm Si} (x) = \int_0^x {\sin (t) \over t} dt
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
29 ## $$
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
30 ## @end tex
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
31 ## @ifnottex
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
32 ##
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
33 ## @example
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
34 ## @group
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
35 ## x
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
36 ## /
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
37 ## Si (x) = | sin (t) / t dt
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
38 ## /
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
39 ## 0
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
40 ## @end group
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
41 ## @end example
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
42 ##
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
43 ## @end ifnottex
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
44 ##
25032
a1e391e33004 doc: grammarcheck documentation again ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24996
diff changeset
45 ## Reference:
a1e391e33004 doc: grammarcheck documentation again ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24996
diff changeset
46 ## @nospell{M. Abramowitz and I.A. Stegun},
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
47 ## @cite{Handbook of Mathematical Functions}, 1964.
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
48 ##
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
49 ## @seealso{cosint, expint, sin}
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
50 ## @end deftypefn
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
51
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
52 function y = sinint (x)
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
53
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
54 if (nargin != 1)
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
55 print_usage ();
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
56 endif
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
57
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
58 if (! isnumeric (x))
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
59 error ("sinint: X must be numeric");
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
60 endif
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
61
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
62 ## Convert to floating point if necessary
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
63 if (isinteger (x))
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
64 x = double (x);
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
65 endif
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
66
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
67 ## Convert to column vector
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
68 orig_sz = size (x);
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
69 x = x(:);
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
70 if (iscomplex (x))
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
71 ## Work around reshape which narrows to real (bug #52953)
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
72 x = complex (real (x)(:), imag (x)(:));
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
73 else
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
74 x = x(:);
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
75 end
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
76
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
77 ## Initialize the result
24911
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
78 y = zeros (size (x), class (x));
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
79 tol = eps (class (x));
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
80
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
81 todo = true (size (x));
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
82
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
83 ## Special values
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
84 y(x == 0) = x(x == 0); # correctly signed zero
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
85 y(x == Inf) = pi / 2;
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
86 y(x == - Inf) = - pi / 2;
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
87
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
88 todo = ((todo) & (x != 0) & (x != Inf) & (x != - Inf));
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
89
24910
b98755ef7572 Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24909
diff changeset
90 ## For values large in modulus we use the relation with expint
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
91
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
92 flag_large = abs (x) > 2;
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
93 xx = x(flag_large & todo);
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
94 ii_neg = (real (xx) < 0);
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
95 xx(ii_neg) *= -1;
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
96 ii_conj = (real (xx) == 0) & (imag (xx) < 0);
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
97 xx(ii_conj) = conj (xx(ii_conj));
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
98 yy = -0.5i * (expint (1i * xx) - expint (-1i * xx)) + pi / 2;
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
99 yy(ii_neg) *= -1;
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
100 yy(ii_conj) = conj (yy(ii_conj));
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
101 y(todo & flag_large) = yy;
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
102
24910
b98755ef7572 Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24909
diff changeset
103 ## For values small in modulus we use the series expansion
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
104
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
105 todo = (todo) & (! flag_large);
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
106 xx = x(todo);
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
107 ssum = xx; # First term of the series expansion
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
108 yy = ssum;
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
109 flag_sum = true (nnz (todo), 1);
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
110 it = 0;
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
111 maxit = 300;
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
112 while (any (flag_sum) && (it < maxit))
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
113 ssum .*= - xx .^ 2 * (2 * it + 1) / ((2 * it + 3) ^ 2 * (2 * it + 2));
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
114 yy(flag_sum) += ssum (flag_sum);
24911
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
115 flag_sum = (abs (ssum) >= tol);
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
116 it++;
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
117 endwhile
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
118
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
119 y(todo) = yy;
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
120
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
121 y = reshape (y, orig_sz);
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
122
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
123 endfunction
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
124
24910
b98755ef7572 Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24909
diff changeset
125
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
126 %!assert (sinint (1.1), 1.02868521867373, -5e-15)
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
127
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
128 %!test
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
129 %! x = [2, 3, pi; exp(1), 5, 6];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
130 %! A = sinint (x);
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
131 %! B = [1.60541297680269, 1.84865252799947, 1.85193705198247e+00; ...
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
132 %! 1.82104026914757, 1.54993124494467, 1.42468755128051e+00];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
133 %! assert (A, B, -5e-15);
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
134
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
135 ## Test exceptional values
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
136 %!assert (sinint (0), 0)
24912
08c871c4147b sinint(0) returns correctly signed zero output.
Colin Macdonald <cbm@m.fsf.org>
parents: 24911
diff changeset
137 %!assert (signbit (sinint (-0)))
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
138 %!assert (sinint (Inf), pi/2)
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
139 %!assert (sinint (-Inf), -pi/2)
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
140 %!assert (isnan (sinint (NaN)))
24911
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
141
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
142 ## Check single data type is preserved
24911
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
143 %!assert (class (sinint (single (1))), "single")
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
144
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
145 ## Tests against Maple
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
146 %!assert (sinint (1) , 0.9460830703671830149414, -2*eps)
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
147 %!assert (sinint (-1) , -0.9460830703671830149414, -2*eps)
24996
f80e68529bbf test: relax tolerances on specfun tests to pass on i386 (bug #53437)
Mike Miller <mtmiller@octave.org>
parents: 24927
diff changeset
148 %!assert (sinint (pi) , 1.851937051982466170361, -3*eps)
f80e68529bbf test: relax tolerances on specfun tests to pass on i386 (bug #53437)
Mike Miller <mtmiller@octave.org>
parents: 24927
diff changeset
149 %!assert (sinint (-pi), -1.851937051982466170361, -3*eps)
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
150 %!assert (sinint (300), 1.5708810882137495193, -2*eps)
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
151 %!assert (sinint (1e4), 1.5708915453859619157, -2*eps)
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
152 %!assert (sinint (20i), 1.2807826332028294459e7*1i, -2*eps)
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
153
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
154 %!test
24910
b98755ef7572 Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24909
diff changeset
155 %! x = (0:4)';
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
156 %! y_ex = [0
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
157 %! 0.946083070367183015
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
158 %! 1.60541297680269485
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
159 %! 1.84865252799946826
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
160 %! 1.75820313894905306];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
161 %! assert (sinint (x), y_ex, -4*eps);
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
162
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
163 %!test
24910
b98755ef7572 Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24909
diff changeset
164 %! x = -(0:4)';
24909
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
165 %! y_ex = - [0
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
166 %! 0.946083070367183015
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
167 %! 1.60541297680269485
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
168 %! 1.84865252799946826
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
169 %! 1.75820313894905306];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
170 %! assert (sinint (x), y_ex, -4*eps);
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
171
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
172 %!test
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
173 %! x = 1i * (0:4).';
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
174 %! y_ex = [0
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
175 %! 1.05725087537572851*I
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
176 %! 2.50156743335497564*I
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
177 %! 4.97344047585980680*I
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
178 %! 9.81732691123303446*I];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
179 %! assert (sinint (x), y_ex, -4*eps);
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
180
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
181 %!test
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
182 %! x = - 1i * (0:4).';
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
183 %! y_ex = - [0
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
184 %! 1.05725087537572851*I
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
185 %! 2.50156743335497564*I
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
186 %! 4.97344047585980680*I
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
187 %! 9.81732691123303446*I];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
188 %! assert (sinint (x), y_ex, -4*eps);
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
189
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
190 %!test
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
191 %! % maple:
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
192 %! % > A := [1+2*I, -2 + 5*I, 100, 10*I, -1e-4 + 1e-6*I, -20 + I];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
193 %! % > for a in A do evalf(Si(a)) end do;
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
194 %! x = [1+2i; -2+5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
195 %! A = [ 1.6782404878293681180 + 2.0396845546022061045*1i
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
196 %! -18.154174221650281533 + 1.6146414539230479060*1i
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
197 %! 1.5622254668890562934
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
198 %! 1246.1144901994233444*1i
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
199 %! -0.000099999999944461111128 + 0.99999999833338888972e-6*1i
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
200 %! -1.5386156269726011209 - 0.053969388020443786229*1i ];
4a341330ee15 Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff changeset
201 %! B = sinint (x);
24911
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
202 %! assert (A, B, -3*eps)
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
203 %! B = sinint (single (x));
8d6f3941a118 Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents: 24910
diff changeset
204 %! assert (A, B, -3*eps ("single"))
24927
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
205
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
206 ## FIXME: Need a test for bug #52953
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
207 %#!test <*52953>
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
208
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
209 ## Test input validation
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
210 %!error sinint ()
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
211 %!error sinint (1,2)
c280560d9c96 Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents: 24923
diff changeset
212 %!error <X must be numeric> sinint ("1")