Abstract

            The file lagrange\Interpolation.htm contains work done in the 2000 class on Lagrange interplation.

            The best way to fit the data is in sections with a high order Lagrange polynomial.  Since the data is presumed 7 digit accurate, least squares fitting would commonly be considered pointless.  This is implemented in this work.  The Fortran and a copy of H2.TXT are in fortran.zip.  The three codes are TLagrang.for, lagrange.for, and LOCATE.FOR.  The first simply calls the others, POLYL in lagrange.for reads the data on its first call and subsequently interpolates in the saved data.  The main code can be set up to provide the function, its derivatives and all errors on a very tight grid. The out files are organized as r, f(r), err(r).  They are on a very tight grid for easy interpolation. 

Figure 1 Potential going off to -1 V2.OUT

 

Figure 2 Derivative of the potential DERIV.OUT

Figure 3  The second derivative of the potential  DDERIV.OUT

The thick line to the right is where the error first becomes visible. 

 

The Lagrange Polynomial

(1.1)

This is POLYL in lagrange.for

Where

(1.2)

 

This is UELAG in lagrange.for

First derivative of the Lagrange Polynomial

The fixed values f(xm) have no derivatives, but Lm(x) does so the first derivative of P is given by

(1.3)

(1.4)

This is UDLAG in lagrange.for

Second derivative of the Lagrange Polynomial

The fixed values f(xi) have no derivatives, but Li(x) does so the first derivative of P is given by

(1.5)

Where

(1.6)

The inside term is familiar

(1.7)

The entire term is

(1.8)

This is UDLAG in lagrange.for

The error estimate

Each of the routines has an NSKIP coded into it such that if NSKIP is the number of any data point all Lagrange polynomials associated with it are zero.  This point is left out even though it appears in the sum. 

            When FINT=POLYL(NL,X,ERR,DPOLY,ERRD,DDPOLY,ERRDD) is called, the routine locate is used to find the R(nbeg)<=X<=R(nbeg+1)appropriate beginning point to center the point in the interval.  With NL=5, as shown centering is impossible.  The points labeled 1 through 5 are used to estimate P, P’, and P’’ with NSKIP=0

 

Then NSKIP is made to be mbeg+j for j=1,5 as each point is left out in its turn.

            The values of POLY and its derivatives are recalculated and the sum of the differences squared is formed.  This sum is the square of the error introduced by the points.  Five estimates are small, but this is what we have.

 FUN  =        9.000000000000000 +-  3.552713678800500D-015

 FA   =        9.000000000000000

 DFUN =        5.999999999999830

                         +-  5.333346861800590D-013

 DFA  =        6.000000000000000

 DDFUN=        2.000000000002310

                      +-   1.424194235848860D-011

 DDFA =        2.000000000000000

      FUNCTION FUN(X,DA,DDA)

      IMPLICIT REAL*8 (A-H,O-Z)

      DATA X0/7.28754D0/,W0/0.34789D0/

      XT=(X-X0)/W0

      FUN=1/(1+XT*XT)

      DA=-2*XT/(1+XT*XT)**2

      DA=DA/W0

      DDA=-2/(1+XT*XT)**2+8*XT*XT/(1+XT*XT)**3

      DDA=DDA/(W0*W0)

      RETURN

      END

RUN

 ENTER A VALUE FOR NL,X

6,15.7

 FUN  =        0.001707244748255 +-  6.362751777354630D-015

 FA   =        0.001707244748255

 DFUN =  -4.051918377321750D-004 +-  6.278532885081560D-013

 DFA  =  -4.051918377322360D-004

 DDFUN=   1.441681108109410D-004 +-  5.754164671370640D-11

 DDFA =   1.441681109507430D-004

The error is somewhat overestimated here.

 

H2

            The values from your table are input and a high order Lagrange polynomial is used to interpolate and find the derivatives.

RUN

 ENTER A VALUE FOR NL,X

5,1.4

 FUN  =       -1.174475668000000 +-  4.446333333518740D-006

 DFUN =  -3.980700000028050D-004 +-  1.406054057049470D-004

 DDFUN=        0.371363133332935 +-       0.006830586876076

 ENTER A VALUE FOR NL,X

10,1.4

 FUN  =       -1.174475668000000 +-  2.350022620944970D-009

 DFUN =  -4.014638798131910D-004 +-  7.739826802280710D-008

 DDFUN=        0.371368119825176 +-  3.747128135755610D-006

 ENTER A VALUE FOR NL,X

10,1.3

 FUN  =       -1.172347100000000 +-  3.721201013995310D-008

 DFUN =       -0.044692600167176 +-  1.217521003404440D-006

 DDFUN=        0.523068142400540 +-  2.974052154877070D-005

 ENTER A VALUE FOR NL,X

10,1.5

 FUN  =       -1.172855034000000 +-  2.146302913175190D-009

 DFUN =        0.031005907178333 +-  7.824771446983930D-008

 DDFUN=        0.262656461383778 +-  1.996099100769950D-006

 ENTER A VALUE FOR NL,X