std::vector<double> get_exps_legendre(const gsl_vector *v, int Nf) { arma::vec A(v->size); for(size_t i=0;i<v->size;i++) A(i)=gsl_vector_get(v,i); arma::vec z=legendre_set(A,Nf); return arma::conv_to< std::vector<double> >::from(z); }
void legendre_3d_set ( double a[], double b[], int nx, int ny, int nz, double x[], double y[], double z[], double w[] ) /******************************************************************************/ /* Purpose: LEGENDRE_3D_SET: set a 3D Gauss-Legendre quadrature rule. Discussion: The integral: integral ( z1 <= z <= z2 ) ( y1 <= y <= y2 ) ( x1 <= x <= x2 ) f(x,y,z) dx dy dz The quadrature rule: sum ( 1 <= i <= n ) w(i) * f ( x(i),y(i),z(i) ) where n = nx * ny * nz. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 August 2014 Author: John Burkardt Parameters: Input, double A[3], B[3], the lower and upper integration limits. Input, int NX, NY, NZ, the orders in the X and Y directions. These orders must be between 1 and 10. Output, double X[N], Y[N], Z[N], the abscissas. Output, double W[N], the weights. */ { int i; int j; int k; int l; double *wx; double *wy; double *wz; double *xx; double *yy; double *zz; /* Get the rules for [-1,+1]. */ xx = ( double * ) malloc ( nx * sizeof ( double ) ); wx = ( double * ) malloc ( nx * sizeof ( double ) ); legendre_set ( nx, xx, wx ); yy = ( double * ) malloc ( ny * sizeof ( double ) ); wy = ( double * ) malloc ( ny * sizeof ( double ) ); legendre_set ( ny, yy, wy ); zz = ( double * ) malloc ( nz * sizeof ( double ) ); wz = ( double * ) malloc ( nz * sizeof ( double ) ); legendre_set ( nz, zz, wz ); /* Adjust from [-1,+1] to [A,B]. */ for ( i = 0; i < nx; i++ ) { xx[i] = ( ( 1.0 - xx[i] ) * a[0] + ( 1.0 + xx[i] ) * b[0] ) / 2.0; wx[i] = wx[i] * ( b[0] - a[0] ) / 2.0; } for ( j = 0; j < ny; j++ ) { yy[j] = ( ( 1.0 - yy[j] ) * a[1] + ( 1.0 + yy[j] ) * b[1] ) / 2.0; wy[j] = wy[j] * ( b[1] - a[1] ) / 2.0; } for ( k = 0; k < nz; k++ ) { zz[k] = ( ( 1.0 - zz[k] ) * a[2] + ( 1.0 + zz[k] ) * b[2] ) / 2.0; wz[k] = wz[k] * ( b[2] - a[2] ) / 2.0; } /* Compute the product rule. */ l = 0; for ( k = 0; k < nz; k++ ) { for ( j = 0; j < ny; j++ ) { for ( i = 0; i < nx; i++ ) { x[l] = xx[i]; y[l] = yy[j]; z[l] = zz[k]; w[l] = wx[i] * wy[j] * wz[k]; l = l + 1; } } } free ( wx ); free ( wy ); free ( wz ); free ( xx ); free ( yy ); free ( zz ); return; }