1. Home
  2. INTERPOLATE directive

INTERPOLATE directive

Interpolates values at intermediate points.

Options

CURVE = string token Type of curve to be fitted to calculate the interpolated value (linear, cubic); default line
METHOD = string token Type of interpolation required (interval, value, missing): for METHOD=valu, values are interpolated for each point in the NEWINTERVAL variate and stored in the NEWVALUE variate; for METHOD=inte, points are estimated in the NEWINTERVAL variate for the observations in the NEWVALUE variate; while for METHOD=miss, the NEWVALUE and NEWINTERVAL lists are irrelevant, INTERPOLATE now interpolates for missing values in the OLDVALUE and OLDINTERVAL variates (except those missing in both variates); default inte

Parameters

OLDVALUES = variates Observations from which interpolation is to be done
NEWVALUES = variates Results of each interpolation
OLDINTERVALS = variates Points at which each set of OLDVALUES was observed
NEWINTERVALS = variates Points for each set of NEWVALUES

Description

If you have a set of pairs of observations (x, y), you can use interpolation to estimate either a value y for a value x that need not be in the set, or a value x for a value y that likewise need not be in the set. The simplest way to interpolate is by joining successive pairs of observations by straight lines and reading off the appropriate values in between: then the two cases are called linear interpolation (obtaining y from x) and inverse linear interpolation (obtaining x from y). Genstat can alternatively join the points by cubic functions instead of straight lines. Genstat uses the term values to describe the set of y-values and intervals for the set of x-values, no matter whether you are doing direct or inverse interpolation.

Genstat does the interpolation for each parallel set of variates in the parameter lists. Each variate in the OLDINTERVALS list specifies the x-values of a set of observed points; the corresponding variate in the OLDVALUES list specifies the corresponding y-values. The variates in the NEWINTERVALS and NEWVALUES lists are for the x-values and y-values of the interpolated points.

If you set METHOD=value, Genstat does ordinary interpolation, and you use the NEWINTERVALS variate to specify the x-values for which you require interpolated y-values. Genstat calculates the y-values and stores them in the corresponding NEWVALUES variate; this variate will be declared implicitly if you have not declared it already.

For the interpolation to take place, the x-values must be in either monotonically increasing or decreasing order; thus, if necessary, Genstat takes a copy of the x-values and y-values and sorts these (in parallel) to put the x-values into ascending order.

Assume that wheat plants have been sampled on five occasions and their growth stage (Zadoks) assessed. INTERPOLATE interpolates values, which it stores in variate Nzad, to estimate the growth stage that the plant has reached after 50, 100 and 150 days.

VARIATE [NVALUES=6] Zadoks,Days;\

  VALUES=!(0,15,23,35,65,95),!(0,50,84,119,147,182)

& [NVALUES=3] Nzadoks,Ndays; VALUES=!(25,50,75),!(50,100,150)

INTERPOLATE [METHOD=value] Zadoks; NEWVALUES=Nzad;\

  OLDINTERVALS=Days; NEWINTERVALS=Ndays

Similarly, if you set METHOD=interval, Genstat does inverse interpolation. You must then specify the y-values in the NEWVALUES variate. Genstat calculates the x-values and stores them in the corresponding NEWINTERVALS variate, which will be declared implicitly if necessary. Again the x-values must be in monotonically increasing or decreasing order, and Genstat will produce a sorted copy if necessary. Inverse interpolation is the default.

This statement would use inverse linear interpolation to estimate how long after planting we have to wait for the plant to reach growth stages 25, 50 and 75 Zadoks.

INTERPOLATE [METHOD=interval] Zadoks; NEWVALUES=Nzadoks;\

  OLDINTERVALS=Days; NEWINTERVALS=Nd

If you set METHOD=missing, Genstat ignores the NEWVALUES and NEWINTERVALS parameters; it estimates values for x or y when the other is missing, placing the results in the previously missing position of the OLDVALUES or the OLDINTERVALS variates. Ordinary interpolation is used when the missing value is in y, and inverse interpolation when it is in x. If both the x-value and the y-value are missing for a particular unit, no values can be interpolated for it, and it remains missing. To do linear interpolation requires that both the x-value and the y-value should be non-missing for the point on each side of the unit with the missing value. For cubic interpolation, there must be two non-missing points on each side of the unit.

The CURVE option has two settings, linear and cubic. By default, CURVE=linear, and successive pairs of observations are connected by straight-line segments for linear, or inverse-linear, interpolation. For cubic interpolation you set CURVE=cubic; there must then be at least four values in each of the OLDVALUES and OLDINTERVALS variates.

For linear & inverse linear interpolation between variates you can use the VINTERPOLATE procedure.

Options: CURVE, METHOD.

Parameters: OLDVALUES, NEWVALUES, OLDINTERVALS, NEWINTERVALS.

Action with RESTRICT

Either or both of the OLDVALUES and OLDINTERVALS variates can be restricted to arrange for only a subset of the observed points to be used. Similarly, either or both of the NEWVALUES and NEWINTERVALS variates can be restricted to arrange that values are calculated for only a subset of units of the new variates.

See also

Directives: KRIGE, COKRIGE.

Procedure: VINTERPOLATE.

Commands for: Calculations and manipulation.

Example

CAPTION     'INTERPOLATE Example'; STYLE=meta
DELETE      [REDEFINE=yes] X,Y,iX,iY,pX,pY
VARIATE     [VALUES=0,1,2,4,7,9,11,12,13,16,18,20] X
CALCULATE   Y = (1 + SIN(ABS(X-10)/4))**2 - 1 + (X/4)**2 - (X/9)**3
CALCULATE   iX = !(1...200)/10

"Interpolate Y values using cubic interpolation"
INTERPOLATE [CURVE=cubic; METHOD=VALUE]\ 
            OLDVALUE=Y; OLDINTERVAL=X;\ 
            NEWVALUE=iY; NEWINTERVAL=iX

"Graph Interpolated Function"
PEN         1,2; METHOD=POINT,MONOTONIC; SYMBOL=2,0;\ 
            COLOUR=2,4; CFILL=2,0; THICKNESS=1,3
XAXIS       [RESET=yes] 1; TITLE='X'
XAXIS       [RESET=yes] 1; TITLE='Function'
DGRAPH      [TITLE='Cubic Interpolation'] X=X,iX; Y=Y,iY;\ 
            DESCRIPTION='Function Points','Cubic Interpolation'

"Interpolate X values for given Y values"
VARIATE     [VALUES=1...15] GivenY
INTERPOLATE [CURVE=cubic;METHOD=INTERVAL]\ 
            OLDVALUE=Y;  OLDINTERVAL=X;\ 
            NEWVALUE=GivenY; NEWINTERVAL=PredictedX
PRINT       GivenY,PredictedX; FIELD=8; DECIMALS=0,4
Updated on March 7, 2019

Was this article helpful?