Fit Polynomial to Data with Constraints

essentially polyfit with many added features
1.4K Downloads
Updated 6 Nov 2012

View License

P=MMPOLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of degree N that fits the data Y in a least-squares sense. P is a row vector of length N+1 containing the polynomial coefficients in descending order,
P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1).
This matches POLYFIT. The number of elements in X and Y must be equal and greater than N.
MMPOLYFIT(X,Y,N,'Param1',PValue1,...) sets selected options based on pairs of parameters and associated values as described below.
MMPOLYFIT(X,Y,N,D) sets options based on the options structure D, whose fieldnames are parameters names and whose contents are associated values.
D=MMPOLYFIT('Param1',PValue1,...) returns an options structure D using the given input parameter names and parameter values that can be used for calls to MMPOLYFIT. Dnew=MMPOLYFIT(Dold,'Param1',PValue1,...) returns an options structure Dnew that is a copy of the existing options structure Dold altered by the added parameters and associated parameter values.

Parameter VALUE and DESCRIPTION

Weight A vector having NUMEL(X) real positive weights. Solution found is the weighted least squares solution. Default value is ONES(SIZE(X)), i.e., no weighting. The equation for the i(th) data point is scaled by the square root of the i(th) weight.

ZeroCoef A vector containing the powers of x whose coefficients must be zero, e.g., [1 3 0] sets the x^1, x^3 and x^0 coefficients to zero.

Point A p-by-2 matrix containing p points that the resulting polynomial must pass through. The i(th) row contains the i(th) data pair [x(i) y(i)].

Slope An s-by-2 matrix containing s points that the slope of the polynomial must pass through. The i(th) row contains the(i)th data pair [x(i) dy(i)/dx].

Equal A k-by-(N+2) matrix containing k equality constraints on the N+1 coefficients. The structure of this matrix is [B d] where B is k-by-N+1, d is k-by 1, and the constraints are given by B*P' = d where P is the row vector solution
containing the polynomial coefficients.

Cite As

Duane Hanselman (2024). Fit Polynomial to Data with Constraints (https://www.mathworks.com/matlabcentral/fileexchange/38926-fit-polynomial-to-data-with-constraints), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP3
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
1.0.0.0