Contents Previous Next Subchapters

Piecewise Linear Interpolation In One Dimension
Syntax ynew = interp1(yoldxnew)
ynew = interp1(xoldyoldxnew)
See Also interp

Piecewise linear interpolation of the row vector valued function of a scalar argument.

Let m be the number of rows in the integer, real, double-precision or complex matrix yold. (If yold is a row vector, m is the length of yold). The argument xold is an integer, real, or double-precision vector of length m that is monotone increasing or decreasing. If the argument xold is not present, the column vector
     (1, 2, ... , m)
is used in its place. The integer, real, or double-precision vector xnew specifies the values at which to interpolate the values of the function.

If yold is not a row vector, and ijk are positive integers such that
     xold   <= xnew   <= xold
         k         i         k+1
and 1 <= j <= m,
           xnew - xold                 xold  - xnew 
               i      k                    k+1     i
ynew    =  ------------  yold      +   -------------   yold
    i,j    xold  - xold      k+1,j      xold  - xold       k,j
               k+1     k                    k+1     k

If yold is a row vector, and ik are positive integers such that
     xold   <= xnew   <= xold
         k         i         k+1

           xnew - xold                 xold  - xnew 
               i      k                    k+1     i
ynew    =  ------------  yold     +    -------------   yold
    i      xold  - xold      k+1        xold  - xold       k
               k+1     k                    k+1     k

If all the arguments are real, the return value is real. If y is complex, the return value is complex. Otherwise the return value is double-precision.

If yold is a row vector, the return value ynew has the same dimension as xnew. Otherwise it is a matrix with row dimension equal to the length of xnew and with the same number of columns as yold.

If you enter
     xold = {1., 2., 3.,  4.}
     yold = {2., 4., 6.,  8.}
     xnew = {1.5, 2.5, 3.5}
     ynew = interp1(xold, yold, xnew)
     print ynew

O-Matrix will reply

Note that if an element of xnew is outside the range of the elements of xold, the values in the corresponding row of ynew is not defined.