a better explanation of polyfit please

4 Ansichten (letzte 30 Tage)
Savanna
Savanna am 28 Feb. 2015
Kommentiert: Star Strider am 28 Feb. 2015
My teacher wants us to use polyfit and gave us a little bit of information on how to use it, but what he gave us makes no sense and I've looked on this website for an explanation and that didn't help me. I know that the form is polyfit(x,y,n) but I'm not sure what the n stands for or how to figure it out from a set of data. Thanks in advance.

Akzeptierte Antwort

Star Strider
Star Strider am 28 Feb. 2015
The ‘n’ is the degree of the polynomial. The degree can be considered to be the highest power of the independent variable, x. So a first-degree polynomial is p(1)*x + p(2), a second-degree p(1)*x^2 + p(2)*x + p(3), and so forth.
  2 Kommentare
Savanna
Savanna am 28 Feb. 2015
ahhh. So a follow-up question to your explanation is that I have this large row array and an equation that is to the 4th power(so 4th dregree), but when i use polyfit i only get NaN as the answers. why is that?
Star Strider
Star Strider am 28 Feb. 2015
I don’t have your data or your code, so I can’t say why you are getting the NaN values.
If you have numbers in both your x and y vectors that have at least 6 elements in each and the same number of elements in both, none of which are NaN, and you fit them with a 4th-degree polynomial with polyfit, for instance:
p = polyfit(x, y, 4);
you should get numeric values for all elements of ‘p’, none of which are NaN.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by