Command for basic fitting

조회 수: 48 (최근 30일)
Yün Han
Yün Han 2011년 9월 26일
Hi,
I know we can use Tools -> Basic Fitting from the menu bar in the plot to generate linear or higher order equations for relationships between x and y. But it is a graphic way, if I want to draw the fitting curve by using m-script, which command should I use?
Thanks.
Y-L

채택된 답변

Grzegorz Knor
Grzegorz Knor 2011년 9월 26일
To find the coefficients of a polynomial of degree n use polyfit function.
Alternatively use the option: File -> Generate M-file, to preview the source code.
  댓글 수: 1
Yün Han
Yün Han 2011년 9월 26일
Thanks. I know that polyfit could be used to calculate the coefficients of polynomials but what I want is after those coefficients are found out by polyfit, I want to use scripts to plot the fitting curve on the plot, just like using basic fitting. Any further ideas?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

UJJWAL
UJJWAL 2011년 9월 26일
Gregorz is right. Here is a bit of an example :
a= 1:0.1:10;
p = polyfit(a,exp(a),5); % Fits a fifth degree polynomial to exp(a) in the Least squares sense
v = polyval(p,a);
plot(a,v,a,exp(a)) % You will see the difference.
Happy To help
  댓글 수: 1
Yün Han
Yün Han 2011년 9월 26일
Thanks. polyval command is really what I want. :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by