MatLab POLYFIT function - Computer Science
Curve Fitting with MATLAB
Curve fitting is a useful tool for representing a data set in a linear or quadratic fashion. MATLAB has two functions, polyfit and polyval, which can quickly and easily fit a polynimial to a set of data points. A first order polynomial is the linear equation that best fits the data. A polynomial can also be used to fit the data in a quadratic sense. As a reminder, the general formula for a polynomial is:
[pic]
The degree of a polynomial is equal to the largest value of the exponents of the independent variable, x.
For example:
[pic]
Polyfit and Polyval
"Polyfit" is a MATLAB function that computes a least squares polynomial for a given set of data. Polyfit actually generates the coefficients of the polynomial (which can be used to simulate a curve to fit the data) according to the degree specified.
"Polyval" evaluates a polynomial for a given set of x values. So, polyval actually generates a curve to fit the data based on the coefficients found using polyfit.
MATLAB's explanation of polyfit and polyval are:
POLYFIT- Polynomial curve fitting
POLYFIT(x,y,n) finds the coefficients of a polynomial p(x) of degree n that fits the data, p(x(i)) is approximately equal to y(i), in a least-squares sense.
POLYVAL - Polynomial evaluation
If V is a vector whose elements are the coefficients of a polynomial, then POLYVAL(V,s) is the value of the polynomial evaluated at s. If s is a matrix or vector, the polynomial is evaluated at all points in s.
The following is an example MATLAB curve fit sequence using polyfit and polyval.
[pic]
Here is the plot reflecting our first try at fitting the data with a first degree polynomial (or a straight line).
[pic]
The coefficients given by MATLAB yield the following equation for the line:
[pic]
Trying a higher polynomial:
[pic]
Here is the plot of the curve generated from the 5th order polynomial. This curve fits the data perfectly.
[pic]
The coefficients given by MATLAB for the curve yield the following equation:
[pic]
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- participation in che 435l unit operations laboratory
- university of utah
- matlab polyfit function computer science
- exercise 14 power sources and matlab
- matlab gmu college of science
- paper title use style paper title ijariit
- 1 university of illinois at urbana champaign
- curve fitting
- lab 1 introduction to matlab
Related searches
- igcse computer science workbooks pdf
- igcse computer science workbook
- igcse computer science workbook answer
- igcse computer science coursebook pdf
- computer science people
- what is computer science like
- computer science revision
- igcse computer science revision notes
- college computer science project ideas
- ideas for computer science project
- computer science projects for students
- computer science final project