compute the interpolated value for a set of spline coefficients and either a scalar x or an array of x values
Definition at line 1031 of file C2Functions.py. 01031 : 01032 """returns the interpolated from from the spline 01033 x can either be a scalar or a listable item, in which case a Numeric Float array will be 01034 returned and the multiple interpolations will be done somewhat more efficiently. 01035 If derivs is not False, return y, y', y'' instead of just y.""" 01036 if not operator.isSequenceType(x): 01037 x=float(x) #this will throw an exception if x is an array! 01038 if (x<xa[0] or x>xa[-1]): 01039 raise RangeError, "%f not in range (%f, %f) in splint()" % (x, xa[0], xa[-1]) 01040 01041 khi=max(_numeric.searchsorted(xa,x),1) 01042 klo=khi-1 01043 #convert everything which came out of an array to a float, since numpy arrays return numpy scalars, rather than native scalars 01044 #this speeds things up, and makes sure numbers coming back from here are native 01045 h=float(xa[khi]-xa[klo]) 01046 a=float(xa[khi]-x)/h; b=1.0-a 01047 ylo=float(ya[klo]); yhi=float(ya[khi]); y2lo=float(y2a[klo]); y2hi=float(y2a[khi]) 01048 else: 01049 #if we got here, we are processing a list, and should do so more efficiently 01050 if (min(x)<xa[0] or max(x)>xa[-1]): 01051 raise RangeError, "(%f, %f) not in range (%f, %f) in splint()" % (min(x), max(x), xa[0], xa[-1]) 01052 01053 npoints=len(x) 01054 khi=_numeric.clip(_numeric.searchsorted(xa,_numeric.asarray(x)),1,len(xa)) 01055 01056 klo=khi-1 01057 xhi=_numeric.take(xa, khi) 01058 xlo=_numeric.take(xa, klo) 01059 yhi=_numeric.take(ya, khi) 01060 ylo=_numeric.take(ya, klo) 01061 y2hi=_numeric.take(y2a, khi) 01062 y2lo=_numeric.take(y2a, klo) 01063 01064 h=(xhi-xlo).astype(_numeric_float) 01065 a=(xhi-x)/h 01066 b=1.0-a 01067 01068 y=a*ylo+b*yhi+((a*a*a-a)*y2lo+(b*b*b-b)*y2hi)*(h*h)/6.0 01069 if derivs: 01070 return y, (yhi-ylo)/h+((3*b*b-1)*y2hi-(3*a*a-1)*y2lo)*h/6.0, b*y2hi+a*y2lo 01071 else: 01072 return y ##
|