Polynomial curve fitting--how to use cubic

I have this code:x=[1.69,1.99,1.99,1.99,1.99,1.99,2.70,2.70,2.70,3.00,3.00,3.00,3.00,3.37,3.37]; plot(x,'r-'); I use the tool "Figure"-"Tools\Basic Fitting"-"cubic" to do the Polynomial curve fitting,but I don't know how to write down the code about "cubic",it's grateful if somebody can help me.

 採用された回答

Matt Fig
Matt Fig 2011 年 3 月 18 日

0 投票

Do you mean, how to get the coefficients from the command line?
PP = polyfit(1:length(x),x,3);
EDIT
To plot the polynomial, use:
hold on
xp = linspace(1,length(x),100);
yp = polyval(PP,xp);
plot(xp,yp,'b-')

5 件のコメント

Tian Lin
Tian Lin 2011 年 3 月 18 日
thank you,I know how to get the coefficients by "polyfit",but I don't know how to write some words to plot the Polynomial curve. I have already tried "polyval",but it did not work very effectivly.
Walter Roberson
Walter Roberson 2011 年 3 月 18 日
xi = 0:.1:length(x);
plot(xi, polyval(PP,xi));
Tian Lin
Tian Lin 2011 年 3 月 18 日
it's ok,I get it,thanks,gays
Jan
Jan 2011 年 3 月 18 日
I'm not a native speaker, but I have the strong impression that there is a difference between "guys" and "gays".
If Matt Fig's answer solves your problem, please accept it.
Tian Lin
Tian Lin 2011 年 3 月 20 日
sorry,man,it's just a cacography.I will accept the answer

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by