Contents Previous Next Subchapters Current Chapters-> interp interp1 lagrange polyfit smospl cubespl cubeval interp2 mlmode_interp2 snewton brent linlsq linlsqb nlsq dnlsq nlsqbox dnlsqb conjdir neldermead conjgrad minline lemke Qpos Qbox Qpro sqp relative fordiff cendiff autodiff testder testgrad testhess Parent Chapters-> Omatrix6 fit interp1 Search Tools-> contents reference index search

Piecewise Linear Interpolation In One Dimension
 Syntax ynew` = interp1(`yold`, `xnew`)` ynew` = interp1(`xold`, `yold`, `xnew`)` See Also interp

Description
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 ```                     T      (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 `i, j, k` 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 `i, k` 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.

Example
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 ```      {      3      5      7      } ```
Reference
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.