Free-knot spline approximation

Least squares approximation of 1D data using free-knots spline
Updated 24 Feb 2022
The purpose of this function is to provide a flexible and robust fit to one-dimensional data using free-knot splines. The knots are free and able to cope with rapid change in the underlying model. Knot removal strategy is used to fit with only a small number of knots.
Optional L2-regularization on the derivative of the spline function can be used to enforce the smoothness.
Shape preserving approximation can be enforced by specifying the lower and upper bounds of the derivative(s) of the spline function on sub-intervals. Furthermore specific values of the spline function and its derivative can be specified on a set of discrete data points.
I did not test QUADPROG engine, but I have implemented it. Any feedback is welcome.

Cite As

Bruno Luong (2024). Free-knot spline approximation (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

See release notes for this release on GitHub:

quadprog is functioning (blind codding before)
Add regularization to make quadprog more robust. This is important change for those who use QUADPROG as engine.
Fix a bug when checking for knot collision

Fix the bug when starting knots are provided

Fix the bug for continuous regularization

Fix a small bug (eigs with 'sa' option requires true symmetric matrix, which is now always the case by symmetrizing)

A more robust conversion in pp form is implemented

Remove some redundant code, modify test program

New feature: Periodic spline

fix a bug with parsing k and nknots
Spline order can be as low as k=1 (piecewise constant fit)

fixed small bug when calling QP engine minqdef

Correct a bug in UpdateConstraints that did not update the knot positions. Precasting data to double. Update more frequently the scaling matrix. Reduce the Lagrange's tolerance to detect active set of QPC solver

Singular constraints will issue a warning (instead of an error). Refine the Gauss-Newton direction. Fix few minor bugs.

Change the description.

Correct another bug in the Jacobian calculation (constrained case)

Point-wise constraints. Discover an error of the Jacobian formula in [Schutze/Schwetlick 97] paper, modify the calculation accordingly. This concern only the constrained fitting.

A major enhancement with shape preserving splines

Change title and description

Remove NaN data before fitting, change TRY/CATCH ME syntax for better compatibility (tested under 2006B), estimate automatic of the noise standard deviation

Update description, more options added to control the fit, discrete regularization

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.