image thumbnail

Polynomial Curve Fitting

version (1.69 KB) by Khaled Sharif
Will fit two sets of data to a polynomial.


Updated 05 Nov 2012

View License

Polynomial Fitting
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.

Sample Input:

Sample Output:
The best fitting polynomial is of degree

It has average deviation from the points of

(Plot attached)

Cite As

Khaled Sharif (2022). Polynomial Curve Fitting (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!