Constraint polynomial fit

Version 1.0.0.0 (3.31 KB) by Marc
Polynomial fitting procedure which includes constraints on the desired polynomial degree(s)
367 Downloads
Updated 15 Sep 2014

View License

% POLYFITC allows the user to provide the polynomial fitting
% procedure with constraints regarding the polynomial degree.
% Note, that this function does not provide the centering and scaling
% transformations option as the original polyfit function does.
%
% Usage:
% P = polyfitc(X, Y, N)
% where:
% X : a vector containing the x data
% Y : a vector containing the y data
% N : a vector containing the desired polynomial degrees (see examples)
% Note, that N can only contain unique positive integers
% P : a vector with the resulting coefficients
%
% P = polyfitc(X, Y, N, option)
% where option can be:
% 'raw' {default}: coefficients will be in the order as given in N
% 'asc' : coefficients will be returned in ascending order
% (lowest order first)
% 'desc' : coefficients will be returned in descending order
% (highest order first)
% 'polyval' : coefficients will be returned such that they can be
% used in the MATLAB polyval function
%
% Example:
% Suppose you know that the data you want to fit is purely quadratic in
% nature and may have an offset, but you are sure that there is no linear
% term present in the equation. The regular polyfit function will give you
% a linear term. POLYFITC offers the choice which orders to fit and return
% the result in a vector which can be used in polyval if desired:
%
% X = -9:9;
% Y = -sqrt(1i^1i)*X.^2 + 10; % dummy function
% X = X + rand(1,19) - 0.5; % add some noise to X
% Y = Y + 3*(rand(1,19)-.5); % add some noise to Y
% Pnormal = polyfit(X, Y, 2) % normal MATLAB polyfit result (linear term)
% Pmimic = polyfitc(X, Y, 0:2, 'desc') % mimic the MATLAB polyfit
% Ppolyval = polyfitc(X, Y, [0 2], 'polyval') % force linear term to zero.
%
% (C) M. van Dijk, FOCAL, 2014-09

Cite As

Marc (2024). Constraint polynomial fit (https://www.mathworks.com/matlabcentral/fileexchange/47851-constraint-polynomial-fit), MATLAB Central File Exchange. Retrieved .

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