int main() { double xmin[3] = {-2,-2,-2}, xmax[3] = {2,2,2}, sigma = 0.5, val, err; hcubature(1, f, &sigma, 3, xmin, xmax, 0, 0, 1e-4, ERROR_INDIVIDUAL, &val, &err); //hcubature_v(1, f2, &sigma, 3, xmin, xmax, 0, 0, 1e-4, ERROR_INDIVIDUAL, &val, &err); printf("Computed integral = %0.10g +/- %g\n", val, err); cout << "finished algMosaic: " << clock()*1e-6 << endl; return 0; }
void integrateVector( int n, double * y, double kappa, int m, double * vertices, double tol, int fdim, double * result ) { double * val = new double[fdim]; double * err = new double[fdim]; double * xmin = new double[n ]; double * xmax = new double[n ]; for (int i = 0; i < n ; i++ ) { xmin[i] = 0; xmax[i] = 1; } double * fdata = new double[1 + 1 + n + m]; fdata[0] = kappa; fdata[1] = detA( vertices, n ); memcpy( fdata + 2, y, n * sizeof(double) ); memcpy( fdata + 2 + n, vertices, m * sizeof(double) ); hcubature( fdim, //unsigned fdim FUNCTION_NAME, //integrand f - need to replace this line, ow won't compile!! fdata, //void *fdata n, //unsigned dim xmin, //const double *xmin xmax, //const double *xmax 0, //size_t maxEval tol, //double reqAbsError tol, //double reqRelError ERROR_INDIVIDUAL, //error_norm norm val, //double *valx err ); //double *err for (int i = 0; i < fdim ; i++ ) { result[i] = result[i] + val[i]; if isnan( val[i] ) { printf( "NaN! Vertices = \n" ); printData( fdata, 2 ); } } delete[] fdata; delete[] val; delete[] err; delete[] xmin; delete[] xmax; }
virtual int exec(double* integral,double* error){ cubature_integrand_wrapper c; c.params = params; c.integrand = integrand; double xl[ndim]; double xu[ndim]; std::fill(xl,xl+ndim,0.); // unit cube! std::fill(xu,xu+ndim,1.); // unit cube! return hcubature(ncomp,cubature_integrand_wrapper::f,(void*) &c, ndim,xl,xu,maxEval,epsabs,epsrel,err_norm,integral,error); }
int c_magnus3sint(double wa, double wb, double *res){ const unsigned ndim=2; const unsigned fdim=2; const double xmin[2]={-1.0,-1.0}; const double xmax[2]={1.0,1.0}; double val[fdim]; double error[fdim]; double ws[2]={wa,wb}; const double maxEval=MAX_EVAL_INT; const double reqAbsError=REQ_ABS_ERROR; const double reqRelError=REQ_REL_ERROR; hcubature(fdim,c_magnus3s,ws,ndim,xmin,xmax,(size_t)maxEval,reqAbsError,reqRelError,ERROR_L2,val,error); res[0]=val[0]; res[1]=error[0]; res[2]=val[1]; res[3]=error[1]; return 0; }
int c_magnus3int(double wa, double wb, double *res){ const unsigned ndim=4; const unsigned fdim=2; double xmin[4]={0.0,0.0,-1.0,-1.0}; double xmax[4]={1.0,1.0,1.0,1.0}; double val[fdim]; double error[fdim]; double ws[2]; ws[0]=wa; ws[1]=wb; const double maxEval=MAX_EVAL_INT; const double reqAbsError=REQ_ABS_ERROR; const double reqRelError=REQ_REL_ERROR; hcubature(fdim,c_magnus3,ws,ndim,xmin,xmax,(size_t)maxEval,reqAbsError,reqRelError,ERROR_L2,val,error); //HERE IMPORTANT this is the prefactor of 3 in the definition of the integrals. res[0]=val[0]; res[1]=error[0]; res[2]=val[1]; res[3]=error[1]; return 0; }
scalar SASFITqrombIQdR(Tcl_Interp *interp, int *dF_dpar, scalar l[], scalar s[], scalar Q, scalar a[], sasfit_function* SD, sasfit_function* FF, sasfit_function* SQ, int distr, scalar Len_start, scalar Len_end, bool *error) { scalar *aw, res,err; scalar cubxmin[1], cubxmax[1], fval[1], ferr[1]; gsl_integration_workspace * w; gsl_integration_cquad_workspace * wcquad; gsl_integration_glfixed_table * wglfixed; gsl_function F; size_t neval; int lenaw=4000; sasfit_param4int param4int; param4int.dF_dpar=dF_dpar; param4int.l=l; param4int.s=s; param4int.Q=Q; param4int.a=a; param4int.SD=SD; param4int.FF=FF; param4int.SQ=SQ; param4int.distr=distr; param4int.error=error; switch(sasfit_get_int_strategy()) { case OOURA_DOUBLE_EXP_QUADRATURE: { aw = (scalar *)malloc((lenaw)*sizeof(scalar)); sasfit_intdeini(lenaw, GSL_DBL_MIN, sasfit_eps_get_nriq(), aw); sasfit_intde(&IQ_IntdLen, Len_start,Len_end, aw, &res, &err,¶m4int); free(aw); break; } case OOURA_CLENSHAW_CURTIS_QUADRATURE: { aw = (scalar *)malloc((lenaw+1)*sizeof(scalar)); sasfit_intccini(lenaw, aw); sasfit_intcc(&IQ_IntdLen, Len_start,Len_end, sasfit_eps_get_nriq(), lenaw, aw, &res, &err,¶m4int); free(aw); break; } case GSL_CQUAD: { wcquad = gsl_integration_cquad_workspace_alloc(lenaw); F.function=&IQ_IntdLen; F.params = ¶m4int; gsl_integration_cquad (&F, Len_start, Len_end, 0, sasfit_eps_get_nriq(), wcquad, &res, &err,&neval); gsl_integration_cquad_workspace_free(wcquad); break; } case GSL_QAG: { w = gsl_integration_workspace_alloc(lenaw); F.function=&IQ_IntdLen; F.params = ¶m4int; gsl_integration_qag (&F, Len_start, Len_end, 0, sasfit_eps_get_nriq(), lenaw, 3, w, &res, &err); gsl_integration_workspace_free (w); break; } case H_CUBATURE: { param4int.function=&IQ_IntdLen; cubxmin[0]=Len_start; cubxmax[0]=Len_end; hcubature(1, &f1D_cubature,¶m4int,1, cubxmin, cubxmax, 10000, 0.0, sasfit_eps_get_nriq(), ERROR_INDIVIDUAL, fval, ferr); res = fval[0]; break; } case P_CUBATURE: { param4int.function=&IQ_IntdLen; cubxmin[0]=Len_start; cubxmax[0]=Len_end; pcubature(1, &f1D_cubature, ¶m4int,1, cubxmin, cubxmax, 10000,0.0, sasfit_eps_get_nriq(), ERROR_INDIVIDUAL, fval, ferr); res = fval[0]; break; } case NR_QROMB: { res = SASFITqrombIQdR_old(interp,dF_dpar,l,s,Q,a, SD,FF,SQ, distr,Len_start, Len_end,error); break; } default: { sasfit_err("Unknown integration strategy\n"); break; } } if (err < 0) { sasfit_err("Integration Int[N(R)I(Q,R),R=0,Infty] did not converged for Q=%lf",Q); } return res; }