Polynomial Curve Fitting
Polynomial Fitting
By Khaled Sharif
Description:
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.
Input:
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.
Output:
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.
Sample Input:
fitting(1:1000,primes(7920),100);
Sample Output:
The best fitting polynomial is of degree
55
It has average deviation from the points of
7.2228
(Plot attached)
Cite As
Khaled Sharif (2024). Polynomial Curve Fitting (https://www.mathworks.com/matlabcentral/fileexchange/38882-polynomial-curve-fitting), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- AI, Data Science, and Statistics > Curve Fitting Toolbox >
- MATLAB > Mathematics > Elementary Math > Polynomials >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.