# polyfit

75 visualizzazioni (ultimi 30 giorni)
12ar.af il 27 Set 2011
Commentato: Gabriela il 28 Set 2023
Hi guys, i have a question on polyfit. i have a set of data from a profile a picture, so know i want to use polyfit from 3rd degree to tenth degree to find which degree best fits the data so that it looks similar to the picture. can somebody help me pliz...
##### 2 CommentiMostra NessunoNascondi Nessuno
Jan il 27 Set 2011
Please explain, what the problem is. Just try the different degrees and compare them with the original data. Then decide for a method to define "more similar": minimal sum of differences, minimal maximal difference, minimal difference of sum of position and 1st derivative, etc.
12ar.af il 30 Set 2011
can i use spline?

Accedi per commentare.

### Risposte (2)

UJJWAL il 27 Set 2011
Hi,
Kindly go to MATLAB and open the curve fitting toolbox. there select the data you want to fit and then clicking on the fitting button select a polynomial function and click on apply to fit the data Hope it helps. For details mail back
HAPPY TO HELP
UJJWAL
##### 2 CommentiMostra NessunoNascondi Nessuno
UJJWAL il 27 Set 2011
The Method is like this
a) Open the curve Fitting toolbox.
b)click on DATA...
c) Select the variables in the workspace that represtn the x and y-axis data and then click on create new data set.
d) Now Click on Ok and then click on Fitting... which is next to Data...
e) In the Type of Fit combo box select Custom Equations and then click on New.
f)A New window will open and there select the tab corresponding to General Equations.
g) Corresponding to the dependent variable y type the equation like cos(a*x+b).
h) As you will write the constants like a and b they will appear in the table below. You can also modify their starting points and their upper and lower limits. If you have any idea of these quantities depennding upon the nature of your program and your requirements then change them accordingly or let MATLAB handle the issue. It will just take some extra time.
Now CLick ok to go back to the previous window.
i) Click on Apply. MATLAB will compute the appropriate values of the constants and display them in the same wiundow under the title results. It will show the values of the constants you have provided computed in the least squares sense.
Gabriela il 28 Set 2023
Hello! Thanks you this is so helpful! Do you know how I can get the equation to remain on the plot? Once I switch to different data or if i close the fitting toolbox it dissapears.

Accedi per commentare.

Walter Roberson il 30 Set 2011
Sure you can use spline, but you specifically asked about polynomial fitting over the whole data (which is what polyfit does). Spline is defined through piecewise polynomials -- a different polynomial is used at every original point. Splines are pleasing to the eye, but useless at fitting a single function to the entire set of data, and seldom useful at extrapolating to points to the left or right of the given dataset.
There are an infinite number of different possible functions that precisely fit any finite set of data. That is infinite as in "uncountably large number", not just as an exaggeration for "a very large but fundamentally computable number". And if you say that there might be measurement error in the data such as from being limited to 53 bits of precision, then the only reason you do not have "more" polynomials to content with is that infinity times billions is still infinity.
Fundamentally fitting any particular function form (such as a polynomial) to a finite set of data is a more or less worthless thing to do unless you have prior knowledge that the data was generated by a process that has the characteristics of that function form. You have a better chance of picking the winning numbers in a major lottery than you have of picking the right function form for data created by an unknown process.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Interpolation in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by