Polynomial least squares curve fit function. |
||
Syntax |
c,s,f,t = PolyCurveFit(Ind, Dep, Order, Transform) |
|
Arguments |
Name |
Description |
Ind |
A vector of independent data. |
|
Dep |
A vector of dependent data. |
|
Order |
The order of the polynomial to use. A non negative integer. |
|
Transform |
A string set to ‘scaled’ if the independent data is to be scaled to improve the quality of the fit. Otherwise, it should be omitted. |
|
Outputs |
Name |
Description |
c |
A vector of the coefficients in descending power of the independent variable. |
|
s |
A vector of the statistical fit quality. See Comments below. |
|
f |
A vector of a polynomial least squares fit. |
|
t |
When Transform = ‘scaled’, t is a vector containing the mean and standard deviation of Ind, which is used to transform the data. See Comments below. |
|
Example 1 |
For given sets of independent and dependent data, find the best second order polynomial fit. |
|
Syntax |
||
c,s,f = PolyCurveFit([1,2,3,4],[4,8,18,32],2) |
||
Result |
||
c = 2.5 -3.1 4.5 (the polynomial: 2.5x2 – 3.1x + 4.5) s = 0.05 0.99979 f = 3.9 8.3 17.7 32.1 |
||
Example 2 |
For given sets of independent and dependent data, estimate the value of the fitted |
|
Syntax |
||
c,s,f,t = PolyCurveFit(X, Y, 3, 'scaled'); print("y(0) = ", PolyVal(c,(0-t(1))/t(2))) |
||
Result |
||
The result will be as printed out. |
||
Comments |
The output s includes the mean squared error and the correlation coefficient, respectively. Ind and Dep must have the same number of elements. The number of data points must be equal to or greater than Order. The constant coefficient of a polynomial is the value of y when x = 0. If there are no points with x close to 0, then it becomes difficult to estimate the constant coefficient because an internal matrix becomes ill conditioned. If this occurs, a warning will be issued. The problem can often be resolved by setting the Transform argument to ‘scaled’. This shifts the x data by the mean and divides by the standard deviation to produce values closer to 0. The fitted polynomial can be evaluated using the coefficients from the scaled fit using PolyVal(c, (x-t(1))/t(2)). |
|
See Also: |