samer@17: /*================================================================= samer@17: * hzeta.c samer@17: * samer@17: * Wrapper function for gsl_sf_hzeta_e samer@17: * samer@17: * This MEX function computes the Hurwitz-zeta-function by calling samer@17: * the function gsl_sf_hzeta_e from the GNU Scientific Library. For samer@17: * x>1 and a>=0 the Hurwitz-zeta-function is defined as samer@17: * samer@17: * oo samer@17: * ----- samer@17: * \ 1 samer@17: * hzeta(x, a) = ) -------- . samer@17: * / x samer@17: * ----- (i + a) samer@17: * i = 0 samer@17: * samer@17: * The MEX function takes two arguments, x and a. If both arguments samer@17: * are matrices of the same size, then the MEX function will compute samer@17: * the Hurwitz-zeta-function elementwise and the result of the MEX samer@17: * function will be a matrix of the same size as the inputs. If one samer@17: * input argument is a scalar s, then the function behaves as if this samer@17: * argument would be a matrix filled with the value s of the same samer@17: * size as the other argument. samer@17: * samer@17: * Compile this MEX function with "mex hzeta.c -lgsl". See Matlab samer@17: * documentation for additional information on compiling MEX functions. samer@17: * samer@17: * (C) by Heiko Bauke, 2007, heiko.bauke@physics.ox.ac.uk samer@17: * samer@17: * This program is free software; you can redistribute it and/or samer@17: * modify it under the terms of the GNU General Public License in samer@17: * version 2 as published by the Free Software Foundation. samer@17: * samer@17: * This program is distributed in the hope that it will be useful, but samer@17: * WITHOUT ANY WARRANTY; without even the implied warranty of samer@17: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU samer@17: * General Public License for more details. samer@17: * samer@17: * You should have received a copy of the GNU General Public License samer@17: * along with this program; if not, write to the Free Software samer@17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA samer@17: * 02111-1307, USA. samer@17: * samer@17: *=================================================================*/ samer@17: samer@17: #include "mex.h" samer@17: #include samer@17: #include samer@17: #include samer@17: samer@17: void mexFunction(int nlhs, mxArray *plhs[], samer@17: int nrhs, const mxArray *prhs[]) { samer@17: double *x, *y, *a; samer@17: int nrows_x, ncols_x, i_x, samer@17: nrows_a, ncols_a, i_a, samer@17: nrows_y, ncols_y, i_y, samer@17: status; samer@17: gsl_sf_result result; samer@17: samer@17: /* check input arguments */ samer@17: if (nrhs!=2) samer@17: mexErrMsgTxt("Two input arguments required.\n"); samer@17: if (!mxIsDouble(prhs[0])) samer@17: mexErrMsgTxt("1st argument not a matrix of double."); samer@17: nrows_x=mxGetM(prhs[0]); samer@17: ncols_x=mxGetN(prhs[0]); samer@17: if (!mxIsDouble(prhs[1])) samer@17: mexErrMsgTxt("2nd argument not a matrix of double."); samer@17: nrows_a=mxGetM(prhs[1]); samer@17: ncols_a=mxGetN(prhs[1]); samer@17: if (!( (nrows_a==nrows_x && ncols_a==ncols_x) || samer@17: (nrows_x==1 && ncols_x==1) || samer@17: (nrows_a==1 && ncols_a==1) ) ) samer@17: mexErrMsgTxt("arguments must be matrices of the same size or scalars."); samer@17: /* create matrix for the return argument */ samer@17: nrows_y=nrows_x>nrows_a ? nrows_x : nrows_a; samer@17: ncols_y=ncols_x>ncols_a ? ncols_x : ncols_a; samer@17: plhs[0]=mxCreateDoubleMatrix(nrows_y, ncols_y, mxREAL); samer@17: /* assign pointers to each input and output */ samer@17: x=mxGetPr(prhs[0]); samer@17: a=mxGetPr(prhs[1]); samer@17: y=mxGetPr(plhs[0]); samer@17: /* compute zeta function */ samer@17: gsl_set_error_handler_off(); samer@17: for (i_x=i_a=i_y=0; i_y