Which Class Should I Use?

Most users only need to answer one question first: are you interpolating exact data, or fitting noisy data?

If the data should be matched exactly, start with InterpolatingSpline. If the data are noisy, or if you need robust fitting or constraints, start with ConstrainedSpline.

The short version

Problem Class MATLAB analogue Why start there
Build or inspect a 1D spline basis directly BSpline none directly You work with knots, coefficients, basis matrices, roots, and transforms explicitly.
Interpolate exact 1D data InterpolatingSpline interp1, spline Returns a reusable spline object rather than only values.
Interpolate exact data on a rectilinear grid InterpolatingSpline griddedInterpolant Uses the same spline object model as the rest of the package.
Fit noisy 1D or rectilinear-grid data ConstrainedSpline polyfit for simple 1D least-squares fits Extends naturally to splines, robust fitting, and constraints.
Fit a planar trajectory with shared parameter t TrajectorySpline none directly Keeps x(t), y(t), u(t), and v(t) together in one persisted object.
Add local value or derivative constraints ConstrainedSpline with PointConstraint none directly Constrain the fitted spline at specific points.
Add global positivity or monotonicity constraints ConstrainedSpline with GlobalConstraint none directly Constrain the fit over the whole model domain.
Work with tensor-product spline objects directly TensorSpline none directly Lower-level tensor basis, evaluation, and transforms.

Exact interpolation

InterpolatingSpline is for exact interpolation. In one dimension, it chooses canonical spline knots from the sample locations and solves for coefficients so that the spline matches the supplied values exactly.

t = sort(rand(20,1));
x = sin(2*pi*t);
f = InterpolatingSpline.fromGriddedValues(t, x, S=3);

For rectilinear grids, pass one grid vector per dimension:

F = InterpolatingSpline.fromGriddedValues({x, y}, V, S=[3 3]);
Vq = F(Xq, Yq);

Noisy fitting and constraints

ConstrainedSpline uses the same spline family for noisy-data fitting. This is where robust fitting, local point constraints, and global shape constraints enter the workflow.

t = sort(rand(50,1));
x = exp(t) + 0.05*randn(size(t));
fit = ConstrainedSpline.fromData(t, x, S=3, splineDOF=12);

In higher dimensions, use ConstrainedSpline.fromGriddedValues({x, y}, values, ...) for rectilinear grids.

If you usually think in terms of polyfit, the direct alignment is:

  • polyfit(t, x, N-1) corresponds to ConstrainedSpline.fromData(t, x, S=N-1, splineDOF=N)

Planar trajectories

TrajectorySpline is a thin planar wrapper for paired component splines that share the same parameter t. Use it when you want x(t), y(t), and their first derivatives to stay together in one object and persist cleanly to file.

t = linspace(0, 1, 40)';
x = cos(2*pi*t);
y = sin(2*pi*t);

trajectory = TrajectorySpline.fromData(t, x, y, S=3);
u = trajectory.u(t);
v = trajectory.v(t);

Low-level spline work

Use BSpline in 1D and TensorSpline in higher dimensions when you want direct access to basis matrices, knot vectors, coefficients, or transform operations.

That is usually the right choice for custom regression, inverse problems, or when you want to work with the spline representation itself rather than starting from a high-level interpolation or fitting workflow.

Where to go next