Approximation in 1D using Piecewise Linear Functions

PWL_APROX_1D is a MATLAB library which defines and evaluates a piecewise linear function, using NC "control points", which approximates a set of ND data points (x(i),y(i)).

PWL_APPROX_1D needs access to the R8LIB library. The test code also needs access to the TEST_INTERP_1D library.


The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.


PWL_APPROX_1D is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

BERNSTEIN_POLYNOMIAL, a MATLAB library which evaluates the Bernstein polynomials, useful for uniform approximation of functions;

LAGRANGE_APPROX_1D, a MATLAB library which defines and evaluates the Lagrange polynomial p(x) of degree m which approximates a set of nd data points (x(i),y(i)).

PWL_INTERP_1D, a MATLAB library which interpolates a set of data using a piecewise linear function.

R8LIB, a MATLAB library which contains many utility routines using double precision real (R8) arithmetic.

SPLINE, a MATLAB library which constructs and evaluates spline interpolants and approximants.

TEST_APPROX, a MATLAB library which defines test problems for approximation, provided as a set of (x,y) data.

TEST_INTERP, a MATLAB library which defines a number of test problems for interpolation, provided as a set of (x,y) data.

TEST_INTERP_1D, a MATLAB library which defines test problems for interpolation of data y(x), depending on a 2D argument.

VANDERMONDE_APPROX_1D, a MATLAB library which finds a polynomial approximant to data of a 1D argument by setting up and solving an overdetermined linear system for the polynomial coefficients, involving the Vandermonde matrix.


  1. Kendall Atkinson,
    An Introduction to Numerical Analysis,
    Prentice Hall, 1989,
    ISBN: 0471624896,
    LC: QA297.A94.1989.
  2. Philip Davis,
    Interpolation and Approximation,
    Dover, 1975,
    ISBN: 0-486-62495-1,
    LC: QA221.D33
  3. David Kahaner, Cleve Moler, Steven Nash,
    Numerical Methods and Software,
    Prentice Hall, 1989,
    ISBN: 0-13-627258-4,
    LC: TA345.K34.

Source Code:

Examples and Tests:

The test code requires the test_interp_1d library.

pwl_approx_1d_test01() uses nc evenly spaced control points to approximate a set of nd data values.

You can go up one level to the MATLAB source codes.

Last modified on 18 August 2012.