next up previous index
Next: E105 Function Interpolation Up: CERNLIB Previous: E103 Largest Absolute

E104 Multidimensional Linear Interpolation

Routine ID: E104
Author(s): C. LetertreLibrary: KERNLIB
Submitter: B. SchorrSubmitted: 17.05.1971
Language: FortranRevised: 27.11.1984

Function subprogram FINT uses repeated linear interpolation to evaluate a function f(x1,x2,...,xn ) of n variables which has been tabulated at the nodes of an n-dimensional rectangular grid. It is not necessary that the table arguments corresponding to any coordinate xi be equally spaced.

Structure:

FUNCTION subprogram
User Entry Names: FINT
Files Refernced: Printer
External References: KERMTR (N001), ABEND (Z035)

Usage:

In any arithmetic expression, FINT(N,X,NA,A,F)

has an approximate value of f(X1,X2,...,Xn) .

N
( INTEGER) Number of coordinates n required to define the function f.
X
( REAL) One-dimensional array. X(j), (j=1,2,...,N) , must contain the coordinates of the point at which the interpolation is to be performed.
NA
( INTEGER) One-dimensional array. For j=1,2,...,N, NA(j) must be equal to the number of numerical values of variable xj which are stored in array A.
A
( REAL) One-dimensional array of length not less than the sum of NA(1),...,NA(N) . The first NA(1) elements of A must contain numerical values a11, a12,... of the first variable x1 in strictly increasing order, the next NA(2) elements of A must contain numerical values a21, a22,... of the second variable x2 in strictly increasing order, and so on.
F
( REAL) Multidimensional array with dimensions NA(1), NA(2), ..., NA(N), containing values of the function f at the nodes of the rectangular grid defined by A:
F(i,j,...,m)= f(a1i,a2j,...,anm),(i=1,2,...,NA(1),...;m=1,2,...,NA(N)) .
If any coordinate xi of the given point X lies outside the range of the corresponding table arguments, the interpolation for this coordinate is replaced by an extrapolation based on the two nearest table arguments, with consequent loss of accuracy.

Method:

Repeated linear interpolation with respect to variables x1,x2,... within the grid cell which contains the given point X. For n=2, with (x1,x2) replaced by (x,y) for clarity, the procedure is equivalent to the following:

Let a1,a2,... be the tabulated values of x. Let b1,b2,... be the tabulated values of y.
Let i and j be the subscripts for which ai≤x<ai+1, bj≤y <bj+1 .
Then compute:
t = (x-a)/(ai+1-a),

gj = (1-t)f(ai,bj)+t f(ai+1,bj),

gj+1 = (1-t)f(ai,bj+1+t f(ai+1,bj+1),

u = (y-b)/(bj+1-b),

fappr = (1-u) gj+ u gj+1

Restrictions:

  1. 1≤N ≤5 . FINT is set equal to zero if N is not in this range.
  2. NA(j) ≥1, (j=1,2,...,N).

  3. The table arguments for each variable must be in strictly increasing order.
There is no test for conditions 2 or 3.

Error handling:

E104.1: N<1 or N>5 . FINT is set equal to zero, and a message is printed unless subroutine KERSET (N001) has been called.

Examples:

Given a function of two variables g(x,y) defined by a FUNCTION subprogram G, to construct a table of values of fkm= g(k,logm) for k=1,2,...,10, m=1,2,...,15 , and to interpolate in this table to set GINT equal to an approximate value of g(1.7,2.9) . The program is written in a form which allows generalization to functions of more than two variables.

      PARAMETER (NA1=10,NA2=15)
      DIMENSION X(2),NA(2),A(NA1+NA2),F(NA1,NA2)
      DATA NA/NA1,NA2/
C     STORE ARGUMENT ARRAY
      K1=0
      K2=K1+NA1
      DO 1 J = 1,MAX(NA1,NA2)
        IF (J .LE. NA1) A(J+K1)=SQRT(FLOAT(J))
        IF (J .LE. NA2) A(J+K2)=LOG(FLOAT(J))
    1 CONTINUE
C     STORE FUNCTION ARRAY
      DO 3 J1 = 1,NA1
        DO 2 J2 = 1,NA2
          F(J1,J2)=G(A(J1+K1),A(J2+K2))
    2   CONTINUE
    3 CONTINUE
C     INTERPOLATE IN TABLE
      X(1)=1.7
      X(2)=2.9
      GINT=FINT(2,X,NA,A,F)
      ...

E105



next up previous index
Next: E105 Function Interpolation Up: CERNLIB Previous: E103 Largest Absolute


Janne Saarela
Mon Apr 3 15:06:23 METDST 1995