View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Fit Polynomial to Data with Constraints

5.0 | 1 rating Rate this file 16 Downloads (last 30 days) File Size: 3.73 KB File ID: #38926 Version: 1.0

Fit Polynomial to Data with Constraints



essentially polyfit with many added features

| Watch this File

File Information

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.


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.

Required Products MATLAB
MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
25 Nov 2016 Robert

Robert (view profile)

Figured it out, thanks!

Comment only
25 Nov 2016 Robert

Robert (view profile)

Could you provide an example on how to obtain the options structure D? I'd like to force a 2nd-order polynomial through 2 points.

Contact us