4.12. Polynomial Curve Fitting
In case a set of points is known in terms of vectors x and y, then a polynomial can be formed that fits the given points. The following command is used for this purpose:
c = polyfit(x, y, k)
where
x and y specify the vectors of the points for curve fitting, and
k specifies the order of the desired polynomial.
The command returns the coefficients of kth order polynomial that fits the data in descending powers of x, in a least-square sense.
Example 4.18.
Find a polynomial of degree 2 to fit the following data:
Solution: x and y are represented by the following row vectors: x = [0 1 2 4]; y = [1 6 20 100]; To find a polynomial of degree 2 to fit the data given by x and y, the command is c = polyfit(x, ... |
Get MATLAB® and Its Applications in Engineering: [Based on MATLAB 7.5 (R2007b)] now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.