image thumbnail

Polynomial Curve Fitting

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

492 Downloads

Updated 05 Nov 2012

View License

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 (2022). Polynomial Curve Fitting (https://www.mathworks.com/matlabcentral/fileexchange/38882-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!