ppfit(varargin)

Fit a piecewise polynomal, i.e. ppform, to points (x,y) using fixed breaks
451 Downloads
Updated 6 Dec 2016

View License

This file makes a piecewise polynomal that fits given points such that the least square error is minimized. In many ways "ppfit" is similar to "splinefit", but "ppfit" may use different order for each of the polynomals and it may give different continuity properties at each break point.
The help text is:
ppfit Fit a piecewise polynomal, i.e. ppform, to points (x,y)
The points will be approximated by N polynomials, given in
the pp-form (piecewise polynomial). ex: fnplt(pp); % to plot results

pp = ppfit(x, y, breaks);
pp = ppfit(x, y, breaks, ord, [], 'v');
pp = ppfit(x, y, breaks, ord, cprop, fixval);
pp = ppfit(x, y ,breaks, ord, cprop, fixval, 'p', 'v');
pp = ppfit(x, y ,breaks, ord, cprop, fixval, 'p', 'v', weight);
--------------------------------------------------------------------------
arguments:
x - the x values of which the function is given, size Lx1
y - the function value for the corresponding x, size Lx1
breaks - break sequence (knots), the start and end points for
the N polynomials as a vector of length (N+1).
Values of x should be within range of breaks:
min(breaks) <= x(i) <= max(breaks)
A scalar N may be given to set the number of polynomials.
ord - order of each polynomial, a vector of length N or a scalar
1 (constant), 2 (linear), 3 (quadratic), 4 (cubic) (default)
cprop - continuity properties, a vector of length (N-1) or N or a
scalar. Note that cprop(i) gives continuity at end of piece
i, at breaks(i+1).
0 - no continuity for breaks(i+1)
1 - continuity (default),
2 - also continuious first derivate,
3 - also continuious second derivate.
argument 6 and onward may be in any order, they may be:
fixval, numeric and size Kx3, gives fixed values for pp
fixval(k,1) is the x-value, must be within range of breaks.
fixval(k,2) the y-value (or the value of the derivate), and
fixval(k,3) is the type or derivate degree, i.e. 0 for value
1 for first derivate, 2 for second derivate.
if this variable is omitted no fixed values is assumed
weight, numeric and size Lx1
If this is given what is minimized is the weighted SSE;
i.e. SSEw = sum( (weight.*error).^2 );
where error = y - ppval(pp, x);
'p' for periodic, need cprop(N) > 0 to have any effect
'v' for verbose, default display only errors/warnings
include fields 'input' and 'fitProp' in output struct
--------------------------------------------------------------------------
ex: res = ppfit('test'); % special test (demo) examples

Cite As

Karl Skretting (2024). ppfit(varargin) (https://www.mathworks.com/matlabcentral/fileexchange/55024-ppfit-varargin), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Polynomials in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
2.5.0.0

Ver 2.5 A minor error was corrected.

2.4.0.0

Version 2.4: a missing function included
firstge.m was missing, It is replaced by local function thisFirstge(.)

2.3.0.0