Mercurial > forge
changeset 8879:bfacc6ba256e octave-forge
psi: use print_usage, help text using texinfo, replace lgamma by gammaln
author | carandraug |
---|---|
date | Fri, 11 Nov 2011 11:32:45 +0000 |
parents | c2511f9f8f9a |
children | 95429496c68c |
files | main/specfun/inst/psi.m |
diffstat | 1 files changed, 23 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/main/specfun/inst/psi.m Fri Nov 11 11:07:50 2011 +0000 +++ b/main/specfun/inst/psi.m Fri Nov 11 11:32:45 2011 +0000 @@ -13,26 +13,31 @@ ## You should have received a copy of the GNU General Public License ## along with this program; If not, see <http://www.gnu.org/licenses/>. -## PSI compute the psi function, -## +## -*- texinfo -*- +## @deftypefn {Function File} {@var{y} = } psi (@var{x}) +## Compute the psi function, for each value of @var{x}. ## -## -## d +## @verbatim +## d ## psi(x) = __ log(gamma(x)) ## dx +## @end verbatim ## +## @seealso{gamma, gammainc, gammaln} +## @end deftypefn + +function [y] = psi (x) -function [y] = psi(x) - if (nargin != 1) - usage ("psi(x)"); - endif - if(imag(x) != zeros(size(x))) - error('unable to handle complex arguments'); - else - h = 1e-9; - y = x; - y(x == 0) = -Inf; - y(x>0) = (lgamma(y(x>0)+h)-lgamma(y(x>0)-h))./(2.*h); - y(x<0) = (lgamma((1-y(x<0))+h)-lgamma((1-y(x<0))-h))./(2.*h) + pi.*cot(pi.*(1-y(x<0))); - endif -endfunction \ No newline at end of file + if (nargin != 1) + print_usage; + elseif (imag(x) != zeros(size(x))) + error("unable to handle complex arguments"); + endif + + h = 1e-9; + y = x; + y(x == 0) = -Inf; + y(x>0) = (gammaln(y(x>0)+h)-gammaln(y(x>0)-h))./(2.*h); + y(x<0) = (gammaln((1-y(x<0))+h)-gammaln((1-y(x<0))-h))./(2.*h) + pi.*cot(pi.*(1-y(x<0))); + +endfunction