Exemplo n.º 1
0
def hermite_gauss_integral(m, n, x0, x1, stepsize=0.01):
	"compute integral(h[m](x}*h[n](x)*exp(-x^2),{x,x0,x1})"
	if m>n:
		m,n = n,m #always make m<=n
	xmax=max(abs(x0), abs(x1))
	if not integral_cache.has_key((m,n)) or integral_cache[(m,n)][0] < xmax:
		#just use Simpson's rule for this
		#first, load up cache
		hermite_gauss(m,xmax)
		hermite_gauss(n,xmax)
		xm, xa1, ya1, y2a1 = hermite_cache[m]
		xm, xa2, ya2, y2a2 = hermite_cache[n]

		stepcount=int(2.0*xmax/stepsize)
		if stepcount%2==0:
			stepcount=stepcount+1 #always odd for Simpson
		stepsize=2*xmax/(stepcount-1) #exact step size
		xlist=Numeric.array(range(stepcount),Numeric.Float)*stepsize - xmax
		y=spline.splint(xa1, ya1, y2a1, xlist)*spline.splint(xa2, ya2, y2a2, xlist)
		hmn2=spline.spline(xlist, y)
		yint=Numeric.cumsum(y[0:-2:2]+y[2::2]+4.0*y[1::2])*(stepsize/3.0)
		yint=Numeric.concatenate( ( (0,), yint )) #first element of integral is 0
		yi2=spline.spline(xlist[::2], yint)
		integral_cache[(m,n)]=(xmax, xlist[::2], yint, yi2, stepsize, xlist, y, hmn2)

	xmax, xa, ya, y2a, stepjunk, xjunk, yjunk, hmn2junk=integral_cache[(m,n)]
	iv1, iv2=spline.splint(xa, ya, y2a, (x0, x1) )
	return iv2-iv1
Exemplo n.º 2
0
def hermite_gauss_integral(m, n, x0, x1, stepsize=0.01):
	"compute integral(h[m](x}*h[n](x)*exp(-x^2),{x,x0,x1})"
	if m>n:
		m,n = n,m #always make m<=n
	xmax=max(abs(x0), abs(x1))
	if not integral_cache.has_key((m,n)) or integral_cache[(m,n)][0] < xmax:
		#just use Simpson's rule for this
		#first, load up cache
		hermite_gauss(m,xmax)
		hermite_gauss(n,xmax)
		xm, xa1, ya1, y2a1 = hermite_cache[m]
		xm, xa2, ya2, y2a2 = hermite_cache[n]

		stepcount=int(2.0*xmax/stepsize)
		if stepcount%2==0:
			stepcount=stepcount+1 #always odd for Simpson
		stepsize=2*xmax/(stepcount-1) #exact step size
		xlist=Numeric.array(range(stepcount),Numeric.Float)*stepsize - xmax
		y=spline.splint(xa1, ya1, y2a1, xlist)*spline.splint(xa2, ya2, y2a2, xlist)
		hmn2=spline.spline(xlist, y)
		yint=Numeric.cumsum(y[0:-2:2]+y[2::2]+4.0*y[1::2])*(stepsize/3.0)
		yint=Numeric.concatenate( ( (0,), yint )) #first element of integral is 0
		yi2=spline.spline(xlist[::2], yint)
		integral_cache[(m,n)]=(xmax, xlist[::2], yint, yi2, stepsize, xlist, y, hmn2)

	xmax, xa, ya, y2a, stepjunk, xjunk, yjunk, hmn2junk=integral_cache[(m,n)]
	iv1, iv2=spline.splint(xa, ya, y2a, (x0, x1) )
	return iv2-iv1
Exemplo n.º 3
0
    def interpolate(self, actuators, width, int_act):
        self.calls = self.calls + 1
        n_act = numpy.shape(actuators)[0]

        xinterp = numpy.zeros((width, n_act))
        yinterp = numpy.zeros((width, width))

        x = numpy.arange(n_act)
        xint = numpy.arange(0, width) / float(int_act)
        for row in range(0, n_act):
            y = actuators[:, row]
            xinterp[:, row] = spline.splint(x, y, xint)


# splint is Python coding of a Numerical Recipies function
        x = numpy.arange(n_act)
        xint = numpy.arange(0, width) / float(int_act)
        for col in range(0, width):
            y = xinterp[col, :]
            yinterp[col, :] = spline.splint(x, y, xint)

        return yinterp
Exemplo n.º 4
0
def hermite_gauss_matrix_element(m, n, x0, x1, f, stepsize=0.01):
	"compute integral(h[m](x}*h[n](x)*exp(-x^2)*f(x),{x,x0,x1}) : f should be able to be evaluated with a vector x"
	if m>n:
		m,n = n,m #always make m<=n
	xmax=max(abs(x0), abs(x1))
	if not integral_cache.has_key((m,n)) or integral_cache[(m,n)][0] < xmax:
		hermite_gauss_integral(m,n,x0,x1) #preload cache with raw data

	jxmax, jxa, jya, jy2a, jstepsize, xa, hmn, hmn2=integral_cache[(m,n)]
	
	stepcount=int((x1-x0)/stepsize)
	if stepcount%2==0:
		stepcount=stepcount+1 #always odd for Simpson
	stepsize=(x1-x0)/(stepcount-1) #exact step size
	xlist=Numeric.array(range(stepcount),Numeric.Float)*stepsize + x0
	y=spline.splint(xa, hmn, hmn2, xlist)*f(xlist)
	yint=Numeric.sum(y[0:-2:2]+y[2::2]+4.0*y[1::2])*(stepsize/3.0)
	return yint
Exemplo n.º 5
0
def hermite_gauss_matrix_element(m, n, x0, x1, f, stepsize=0.01):
	"compute integral(h[m](x}*h[n](x)*exp(-x^2)*f(x),{x,x0,x1}) : f should be able to be evaluated with a vector x"
	if m>n:
		m,n = n,m #always make m<=n
	xmax=max(abs(x0), abs(x1))
	if not integral_cache.has_key((m,n)) or integral_cache[(m,n)][0] < xmax:
		hermite_gauss_integral(m,n,x0,x1) #preload cache with raw data

	jxmax, jxa, jya, jy2a, jstepsize, xa, hmn, hmn2=integral_cache[(m,n)]
	
	stepcount=int((x1-x0)/stepsize)
	if stepcount%2==0:
		stepcount=stepcount+1 #always odd for Simpson
	stepsize=(x1-x0)/(stepcount-1) #exact step size
	xlist=Numeric.array(range(stepcount),Numeric.Float)*stepsize + x0
	y=spline.splint(xa, hmn, hmn2, xlist)*f(xlist)
	yint=Numeric.sum(y[0:-2:2]+y[2::2]+4.0*y[1::2])*(stepsize/3.0)
	return yint
Exemplo n.º 6
0
def hermite_gauss(order,x, cache_key=None):
	"compute h[order](x)*exp(-x^2/2).  x may be an array, and cache_key should be a unique identifier for x if cacheing is desired."
	if type(x) is not type(1.0):
		xmax=max(abs(x))
	else:
		xmax=abs(x)
		
	if (not hermite_cache.has_key(order)) or hermite_cache[order][0] < xmax:
		q=generate_table(order, max(1.5*xmax, hermite_x_bound))
		hermite_cache[order]=q
	
	if cache_key and hermite_cache.has_key((order, cache_key)):
		hermite_cache[(order, cache_key)][0]=time.time() #update time stamp
		return hermite_cache[(order, cache_key)][1]
	else:
		xmax, xa, ya, y2a=hermite_cache[order]
		y= spline.splint(xa, ya, y2a, x)
		if cache_key:
			hermite_cache[(order,cache_key)]=[time.time(), y]
		return y
Exemplo n.º 7
0
def hermite_gauss(order,x, cache_key=None):
	"compute h[order](x)*exp(-x^2/2).  x may be an array, and cache_key should be a unique identifier for x if cacheing is desired."
	if type(x) is not type(1.0):
		xmax=max(abs(x))
	else:
		xmax=abs(x)
		
	if (not hermite_cache.has_key(order)) or hermite_cache[order][0] < xmax:
		q=generate_table(order, max(1.5*xmax, hermite_x_bound))
		hermite_cache[order]=q
	
	if cache_key and hermite_cache.has_key((order, cache_key)):
		hermite_cache[(order, cache_key)][0]=time.time() #update time stamp
		return hermite_cache[(order, cache_key)][1]
	else:
		xmax, xa, ya, y2a=hermite_cache[order]
		y= spline.splint(xa, ya, y2a, x)
		if cache_key:
			hermite_cache[(order,cache_key)]=[time.time(), y]
		return y