How to find y in polyfit(x,y,n) ??
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a set of points against time and I want to see what degree of polynomial best fits my data set.For this I am using the polyfit function, but how should I define function "y" ?? Is it taken intuitively from shape of time plot or should it be given in the problem set. I am new to matlab ,please help me with this.
0 Commenti
Risposte (1)
John D'Errico
il 27 Gen 2015
Modificato: John D'Errico
il 27 Gen 2015
Well, the easy answer is to not do this, at least, don't use a polynomial. People inevitably use too high an order polynomial, since that is what gives the "best" fit. Higher orders are always "better" in terms of error. And then what always happens is they have numerical problems. In fact, I've seen many people having serious numerical problems fitting something as low an order as a cubic polynomial to their data.
As well, higher order polynomials, while they fit the data best, tend to do nasty things between the data points.
And, most of the time, when people use polynomials, it is because they do not know of a better solution. After all, you can represent pretty much any function with a Taylor series, right? So a polynomial model must be a good idea. Easy to do, fast, efficient, etc.
If you insist on the use of a polynomial model, then you can evaluate the function using polyval, but I'm not sure what you mean about taking something intuitively. So I have no idea what you are asking there.
Anyway, a far better idea in general is to use my SLM toolbox for curve fits, if you just want a curve that fits your data. You are given a great deal of control over the resulting shape, and it is designed to fit robustly, avoiding all of those numerical problems I alluded to above.
You can download SLM from the file exchange. The only downside to SLM is it will use the optimization toolbox for many fits.
You evaluate the function using slmeval once it has been fit.
There are other tools you can use too. For simple interpolation, interp1 offers a simple set of spline fits.
2 Commenti
John D'Errico
il 27 Gen 2015
But that is why you are looking to use a tool like polyfit, or better, SLM to fit your data. It builds a model that approximates your data. The value of SLM is it helps you to build that intuitive knowledge about your curve into the model.
Vedere anche
Categorie
Scopri di più su Linear and Nonlinear Regression 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!