By Khaled Sharif
This function will take two sets of data of equal length and attempt to fit them to polynomials using the polyfit function varying the degree of polynomials from 1 to 100 and choosing the one that gives the least average deviation from the points. It will also display a plot of the original points against the new fitted polynomial line to give an idea of the fit.
The function takes two sets X and Y that contain the data where each point in Y corresponds to F(X). It takes a third argument specifying the maximum degree of the polynomial.
The function will output the degree of the best fitting polynomial, the average deviation from the points, and a plot of two lines: one represents the original data and the second represents the new polynomial fit.
The best fitting polynomial is of degree
It has average deviation from the points of
Khaled Sharif (2022). Polynomial Curve Fitting (https://www.mathworks.com/matlabcentral/fileexchange/38882-polynomial-curve-fitting), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!