int gauss(dvec& x, dvec& w) { int n = x.size(); double dist = 1; double tol = 1e-15; int iter = 0; // Use Chebyshev-Gauss nodes and initial guess initguess(x); // chebnodes(x); dvec x0(x); dvec L(n,0.0); dvec Lp(n,0.0); dvec a(n,0.0); dvec b(n,0.0); rec_legendre(a,b); // Iteratively correct nodes with Newton's method while(dist>tol) { newton_step(a,b,x,L,Lp); dist = dist_max(x,x0); ++iter; x0 = x; } // Compute Weights for(int i=0;i<n;++i){ w[i] = 2.0/((1-x[i]*x[i])*(Lp[i]*Lp[i])); } return iter; }
/* * Routine: DistSizeToShiftWidth(char *szDist) * Purpose: Determine the number of bits required to select a member of the distribution * Algorithm: * Data Structures: * * Params: * Returns: * Called By: * Calls: * Assumptions: * Side Effects: * TODO: None */ int DistSizeToShiftWidth(char *szDist, int nWeightSet) { int nBits = 1, nTotal = 2, nMax; d_idx_t *d; d = find_dist(szDist); nMax = dist_max(d->dist, nWeightSet); while (nTotal < nMax) { nBits += 1; nTotal <<= 1; } return(nBits); }