home *** CD-ROM | disk | FTP | other *** search
- #
- # Routine for polynomial interpolation from "Numerical Recipes in C",
- # by Press et. al.
- #
- # This routine is used by qromb.ic
- #
- # mws, 7/92
- #
-
- #
- # polint
- #
- # Given arrays xa[1..n] and ya[1..n], and given a value x, this routine
- # returns a value y, and an error estimate dy. If P(x) is the polynomial of
- # degree n-1 s.t. P(xa[j]) = ya[j] for j = 1..n, then the returned value is
- # y = P(x).
- #
- array polint_c[1] # will be resized as required
- array polint_d[1]
- #
- func polint(@xa,@ya,n,x,*y,*dy) = {
- local ii,m,den,dif,dift,ho,hp,w,ns
-
- ns = 1
- dif=abs(x-xa[1])
-
- resize(polint_c,n)
- resize(polint_d,n)
-
- for (ii=1;ii<=n;ii+=1) {
- if ( (dift=abs(x-xa[ii])) < dif) {
- ns=ii
- dif=dift
- }
- polint_c[ii]=ya[ii]
- polint_d[ii]=ya[ii]
- }
- y=ya[ns]
- ns -= 1
- for (m=1;m<n;m+=1) {
- for (ii=1;ii<=n-m;ii+=1) {
- ho=xa[ii]-x
- hp=xa[ii+m]-x
- w=polint_c[ii+1]-polint_d[ii]
- # error can occur only if two input xa's are identical
- if ( (den=ho-hp) == 0) error(0)
- den=w/den
- polint_d[ii]=hp*den
- polint_c[ii]=ho*den
- }
- if (2*ns < (n-m)) dy = polint_c[ns+1] else {
- dy = polint_d[ns]
- ns -= 1
- }
- y += dy
- }
- }
-