Least square polynomial fit

3 Ansichten (letzte 30 Tage)
Pranab Bhuyan
Pranab Bhuyan am 21 Jan. 2012
Kommentiert: B am 22 Nov. 2017
I have two arrays x(i) ,y(i). I need to do a least square polynomial fitting for y(i). After the polynomial fit is done, I need to find the maximum of y(i), say y(n) and then corresponding to that find the value of x(n). Can you please suggest, how shall I proceed? What are the math functions involved?

Akzeptierte Antwort

John D'Errico
John D'Errico am 21 Jan. 2012
Learn to use matlab. By this, I mean learn how to look for the tools you need. So you want to find a polynomial model. A good idea is to learn the lookfor function.
lookfor polynomial
If you do this, you will find a tool for polynomial fitting - polyfit. It will also show you polyder, an important thing since you are looking for a maximum. A stationary point on a curve will come at a root of the derivative. Finally, you might notice roots.
So much to glean from a simple lookfor command.
I will add that the best programmatic solution is to use a better tool than a polynomial fit anyway. Polynomials are terribly poor tools for curve fitting. Instead, use a tool designed to do the job.
x = rand(1,50);
y = sin(pi*x) + randn(size(x))/100;
slm = slmengine(x,y,'knots',8,'plot','on');
[maxfun,maxloc] = slmpar(slm,'maxfun')
maxfun =
0.99971
maxloc =
0.50241
Here, I used my slm tools (it is on the file exchange) to do the curve fitting. It includes a tool that will determine various parameters from the resulting model, one of which is the maximum value of the function, and the location thereof.
  2 Kommentare
Matt J
Matt J am 10 Mai 2015
Looks like the OP forgot to accept this one.
B
B am 22 Nov. 2017
How would I use this process to find the polynomial equation if I know points on the curve?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Dr. Seis
Dr. Seis am 21 Jan. 2012
Check out "polyfit", "polyval" and "max"
- polyfit will give you the polynomial coefficients for an n-order polynomial
- polyval will give you new y-values when you supply it new x-values and the polynomial coefficients found in polyfit
- max will give you the max value associated with you new y-values, it can also supply you the index of the max value so you can determine its corresponding value from your new x-values

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by