comparison scripts/specfun/expint.m @ 16584:2f766ceeb03e

Add ellipj, ellipke, and expint functions from Octave Forge * ellipj.cc, ellipke.m, expint.m: New files. * libinterp/corefcn/module.mk (COREFCN_SRC): Add ellipj.cc to the list. * scripts/specfun/module.mk (specfun_FCN_FILES): Add ellipke.m and expint.m to the list. * __unimplemented__.m (missing_functions): Remove ellipj, ellipke, and expint from the list. * arith.txi: Include ellipj, ellipke, and expint docstrings. * NEWS: Mention ellipj, ellipke, and expint.
author Mike Miller <mtmiller@ieee.org>
date Wed, 24 Apr 2013 23:22:50 -0400
parents
children 1a3bfb14b5da
comparison
equal deleted inserted replaced
16583:e74ef19d2268 16584:2f766ceeb03e
1 ## Copyright (C) 2006 Sylvain Pelissier <sylvain.pelissier@gmail.com>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{y} =} expint (@var{x})
18 ## Compute the exponential integral,
19 ## @verbatim
20 ## infinity
21 ## /
22 ## expint(x) = | exp(t)/t dt
23 ## /
24 ## x
25 ## @end verbatim
26 ## @seealso{expint_E1, expint_Ei}
27 ## @end deftypefn
28
29 function y = expint(x)
30 if (nargin != 1)
31 print_usage;
32 endif
33 y = expint_E1(x);
34 endfunction
35
36 ## -*- texinfo -*-
37 ## @deftypefn {Function File} {@var{y} =} expint_E1 (@var{x})
38 ## Compute the exponential integral,
39 ## @verbatim
40 ## infinity
41 ## /
42 ## expint(x) = | exp(t)/t dt
43 ## /
44 ## x
45 ## @end verbatim
46 ## @seealso{expint, expint_Ei}
47 ## @end deftypefn
48
49 function y = expint_E1(x)
50 if (nargin != 1)
51 print_usage;
52 endif
53 y = x;
54 y(imag(x) > 0 & imag(x) != 0) = -expint_Ei(-y(imag(x) > 0 & imag(x) != 0)) -i.*pi;
55 y(imag(x) < 0 & imag(x) != 0) = -expint_Ei(-y(imag(x) < 0 & imag(x) != 0)) +i.*pi;
56 y(real(x) >= 0 & imag(x)==0) = -expint_Ei(-y(real(x) >= 0 & imag(x)==0));
57 y(real(x) < 0 & imag(x)==0) = -expint_Ei(-y(real(x) < 0 & imag(x)==0)) -i.*pi;
58 endfunction
59
60 ## -*- texinfo -*-
61 ## @deftypefn {Function File} {@var{y} =} expint_Ei (@var{x})
62 ## Compute the exponential integral,
63 ## @verbatim
64 ## infinity
65 ## /
66 ## expint_Ei(x) = - | exp(t)/t dt
67 ## /
68 ## -x
69 ## @end verbatim
70 ## @seealso{expint, expint_E1}
71 ## @end deftypefn
72
73 function y = expint_Ei(x)
74 if (nargin != 1)
75 print_usage;
76 endif
77 y = zeros(size(x));
78 F = @(x) exp(-x)./x;
79 s = prod(size(x));
80 for t = 1:s;
81 if(x(t)<0 && imag(x(t)) == 0)
82 y(t) = -quad(F,-x(t),Inf);
83 else
84 if(abs(x(t)) > 2 && imag(x(t)) == 0)
85 y(t) = expint_Ei(2) - quad(F,-x(t),-2);
86 else
87 if(abs(x(t)) >= 10)
88 if(imag(x(t)) <= 0)
89 a1 = 4.03640;
90 a2 = 1.15198;
91 b1 = 5.03637;
92 b2 = 4.19160;
93 y(t) = -(x(t).^2 - a1.*x(t) + a2)./((x(t).^2-b1.*x(t)+b2).*(-x(t)).*exp(-x(t)))-i.*pi;
94 else
95 y(t) = conj(expint_Ei(conj(x(t))));
96 endif;
97 ## Serie Expansion
98 else
99 for k = 1:100;
100 y(t) = y(t) + x(t).^k./(k.*factorial(k));
101 endfor
102 y(t) = 0.577215664901532860606512090082402431 + log(x(t)) + y(t);
103 endif
104 endif
105 endif
106 endfor
107 endfunction