def tst_gauss_legendre_engine(): for n in range(2,95): gle = sm.gauss_legendre_engine(n) x_this = gle.x() step=1e-5 # check AMS pg 919. nodes for n=96 are allways more then stpe away from each other for ix in range( x_this.size() ): f = gle.f( x_this[ix] )[0] assert approx_equal(f,0,eps=1e-5) # check the uniqueness of each point for jj in range( x_this.size() ): if jj != ix: assert ( math.fabs(x_this[ix]-x_this[jj]) >= step )
def tst_gauss_legendre_engine(): for n in range(2, 95): gle = sm.gauss_legendre_engine(n) x_this = gle.x() step = 1e-5 # check AMS pg 919. nodes for n=96 are allways more then stpe away from each other for ix in range(x_this.size()): f = gle.f(x_this[ix])[0] assert approx_equal(f, 0, eps=1e-5) # check the uniqueness of each point for jj in range(x_this.size()): if jj != ix: assert (math.fabs(x_this[ix] - x_this[jj]) >= step)
def examples(): # an illustration of Hermite Gauss quadrature # we will try to integrate # Exp[-x^2-x] {x,-inf, inf} # The true answer is Exp[0.25] Sqrt[Pi] # f_theory = math.exp(0.25)*math.sqrt( math.pi ) for ii in xrange(6,10): ghq = sm.gauss_hermite_engine(ii) w = ghq.w() x = ghq.x() f = flex.sum( (flex.exp( -x ))*w ) assert approx_equal(f,f_theory, eps=1e-5) # an example of Gauss-Legendre integration # we integrate exp(-x) between -1 and 1 f_theory = math.exp(1) - math.exp(-1) for ii in xrange(5,90): glq = sm.gauss_legendre_engine(ii) w = glq.w() x = glq.x() f = flex.sum( (flex.exp( -x ))*w )
def examples(): # an illustration of Hermite Gauss quadrature # we will try to integrate # Exp[-x^2-x] {x,-inf, inf} # The true answer is Exp[0.25] Sqrt[Pi] # f_theory = math.exp(0.25) * math.sqrt(math.pi) for ii in xrange(6, 10): ghq = sm.gauss_hermite_engine(ii) w = ghq.w() x = ghq.x() f = flex.sum((flex.exp(-x)) * w) assert approx_equal(f, f_theory, eps=1e-5) # an example of Gauss-Legendre integration # we integrate exp(-x) between -1 and 1 f_theory = math.exp(1) - math.exp(-1) for ii in xrange(5, 90): glq = sm.gauss_legendre_engine(ii) w = glq.w() x = glq.x() f = flex.sum((flex.exp(-x)) * w)