annotate general/numerical/scalar/hzeta.c @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents cb249ba61e9e
children
rev   line source
samer@17 1 /*=================================================================
samer@17 2 * hzeta.c
samer@17 3 *
samer@17 4 * Wrapper function for gsl_sf_hzeta_e
samer@17 5 *
samer@17 6 * This MEX function computes the Hurwitz-zeta-function by calling
samer@17 7 * the function gsl_sf_hzeta_e from the GNU Scientific Library. For
samer@17 8 * x>1 and a>=0 the Hurwitz-zeta-function is defined as
samer@17 9 *
samer@17 10 * oo
samer@17 11 * -----
samer@17 12 * \ 1
samer@17 13 * hzeta(x, a) = ) -------- .
samer@17 14 * / x
samer@17 15 * ----- (i + a)
samer@17 16 * i = 0
samer@17 17 *
samer@17 18 * The MEX function takes two arguments, x and a. If both arguments
samer@17 19 * are matrices of the same size, then the MEX function will compute
samer@17 20 * the Hurwitz-zeta-function elementwise and the result of the MEX
samer@17 21 * function will be a matrix of the same size as the inputs. If one
samer@17 22 * input argument is a scalar s, then the function behaves as if this
samer@17 23 * argument would be a matrix filled with the value s of the same
samer@17 24 * size as the other argument.
samer@17 25 *
samer@17 26 * Compile this MEX function with "mex hzeta.c -lgsl". See Matlab
samer@17 27 * documentation for additional information on compiling MEX functions.
samer@17 28 *
samer@17 29 * (C) by Heiko Bauke, 2007, heiko.bauke@physics.ox.ac.uk
samer@17 30 *
samer@17 31 * This program is free software; you can redistribute it and/or
samer@17 32 * modify it under the terms of the GNU General Public License in
samer@17 33 * version 2 as published by the Free Software Foundation.
samer@17 34 *
samer@17 35 * This program is distributed in the hope that it will be useful, but
samer@17 36 * WITHOUT ANY WARRANTY; without even the implied warranty of
samer@17 37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
samer@17 38 * General Public License for more details.
samer@17 39 *
samer@17 40 * You should have received a copy of the GNU General Public License
samer@17 41 * along with this program; if not, write to the Free Software
samer@17 42 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
samer@17 43 * 02111-1307, USA.
samer@17 44 *
samer@17 45 *=================================================================*/
samer@17 46
samer@17 47 #include "mex.h"
samer@17 48 #include <gsl/gsl_errno.h>
samer@17 49 #include <gsl/gsl_math.h>
samer@17 50 #include <gsl/gsl_sf_zeta.h>
samer@17 51
samer@17 52 void mexFunction(int nlhs, mxArray *plhs[],
samer@17 53 int nrhs, const mxArray *prhs[]) {
samer@17 54 double *x, *y, *a;
samer@17 55 int nrows_x, ncols_x, i_x,
samer@17 56 nrows_a, ncols_a, i_a,
samer@17 57 nrows_y, ncols_y, i_y,
samer@17 58 status;
samer@17 59 gsl_sf_result result;
samer@17 60
samer@17 61 /* check input arguments */
samer@17 62 if (nrhs!=2)
samer@17 63 mexErrMsgTxt("Two input arguments required.\n");
samer@17 64 if (!mxIsDouble(prhs[0]))
samer@17 65 mexErrMsgTxt("1st argument not a matrix of double.");
samer@17 66 nrows_x=mxGetM(prhs[0]);
samer@17 67 ncols_x=mxGetN(prhs[0]);
samer@17 68 if (!mxIsDouble(prhs[1]))
samer@17 69 mexErrMsgTxt("2nd argument not a matrix of double.");
samer@17 70 nrows_a=mxGetM(prhs[1]);
samer@17 71 ncols_a=mxGetN(prhs[1]);
samer@17 72 if (!( (nrows_a==nrows_x && ncols_a==ncols_x) ||
samer@17 73 (nrows_x==1 && ncols_x==1) ||
samer@17 74 (nrows_a==1 && ncols_a==1) ) )
samer@17 75 mexErrMsgTxt("arguments must be matrices of the same size or scalars.");
samer@17 76 /* create matrix for the return argument */
samer@17 77 nrows_y=nrows_x>nrows_a ? nrows_x : nrows_a;
samer@17 78 ncols_y=ncols_x>ncols_a ? ncols_x : ncols_a;
samer@17 79 plhs[0]=mxCreateDoubleMatrix(nrows_y, ncols_y, mxREAL);
samer@17 80 /* assign pointers to each input and output */
samer@17 81 x=mxGetPr(prhs[0]);
samer@17 82 a=mxGetPr(prhs[1]);
samer@17 83 y=mxGetPr(plhs[0]);
samer@17 84 /* compute zeta function */
samer@17 85 gsl_set_error_handler_off();
samer@17 86 for (i_x=i_a=i_y=0; i_y<nrows_y*ncols_y; ++i_y) {
samer@17 87 if (gsl_sf_hzeta_e(x[i_x], a[i_a], &result)==GSL_SUCCESS)
samer@17 88 y[i_y]=result.val;
samer@17 89 else
samer@17 90 y[i_y]=GSL_NAN;
samer@17 91 if (!(nrows_x==1 && ncols_x==1))
samer@17 92 ++i_x;
samer@17 93 if (!(nrows_a==1 && ncols_a==1))
samer@17 94 ++i_a;
samer@17 95 }
samer@17 96 }