1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2018 - 2020 - Samuel GOUGEON
4 // This file is hereby licensed under the terms of the GNU GPL v2.0,
5 // pursuant to article 5.3.4 of the CeCILL v.2.1.
6 // This file was originally licensed under the terms of the CeCILL v2.1,
7 // and continues to be available under such terms.
8 // For more information, see the COPYING file which you should have received
9 // along with this program.
11 function y = %s_gamma(varargin)
12 // call for complex numbers or/and for hypermatrix of reals
13 // or/and for incomplete integral
14 // gamma(a) // with a complex or real hypermat
15 // gamma(x, a) // with real x >= 0
17 // gamma(x,.., option) // "upper": complementary integral
19 msg = _("%s: Function not defined for the given argument type.\n Check arguments or define function %s for overloading.\n")
21 a = varargin(min(2,rhs))
25 // gamma(..) with complex numbers (all cases: complete, uncomplete, hypermat)
26 // -------------------------------
27 if or(type(a)==[1 5]) & ~isreal(a,0)
28 if isdef("%s_gamma_user") & type(%s_gamma_user)==13
29 y = %s_gamma_user(varargin(:));
30 // Note: the overload must be able to process hypermatrices
33 error(msprintf(msg, "%s_gamma", "%s_gamma_user()"))
41 // gamma(a) with hypermatrix of real numbers
42 // -----------------------------------------
44 y = matrix(gamma(a(:)), sa)
48 // gamma(x,a,..) : uncomplete gamma (all cases with real numbers)
51 if type(x)<>1 | ~isreal(x,0) then
52 msg = _("%s: Argument #%d: Decimal numbers expected.\n")
53 error(msprintf(msg, "gamma", 1))
60 msg = _("%s: Argument #%d: Must be > %d.\n")
61 error(msprintf(msg, "gamma", 1, 0))
63 if ~isscalar(x) & ~isscalar(a) & or(size(x)<>size(a)) then
64 msg = _("%s: Arguments #%d and #%d: Same sizes expected.\n")
65 error(msprintf(msg, "gamma", 1, 2))
76 if convstr(u(1))<>"upper" then
77 msg = _("%s: Argument #%d: ''%s'' expected .\n")
78 error(msprintf(msg, "gamma", rhs, "upper"))
84 if length(varargin) > 2 then
86 if type(b)<>1 | ~isreal(b,0) then
87 msg = _("%s: Argument #%d: Decimal numbers expected.\n")
88 error(msprintf(msg, "gamma", 3))
92 msg = _("%s: Argument #%d: Must be > %d.\n")
93 error(msprintf(msg, "gamma", 3, 0))
95 if ~isscalar(a) & ~isscalar(b) & or(size(a)<>size(b)) then
96 msg = _("%s: Arguments #%d and #%d: Same sizes expected.\n")
97 error(msprintf(msg, "gamma", 2, 3))
114 [x, a, b] = (x(:), a(:), b(:))
120 [?,y] = cdfgam("PQ", x, a, b)
122 y = cdfgam("PQ", x, a, b)