필터 지우기
필터 지우기

curve of best fit from a few points

조회 수: 10 (최근 30일)
Tom
Tom 2013년 3월 6일
댓글: Ghada Bakaraki 2021년 1월 3일
I have these points: -
x=[1 1.5 2 2.5 3];
y=[19.74 14.26 12.34 11.45 10.97];
and I know I can do a very rough approximation of a curve of best fit simply by "joining the dots" using: -
plot(x,y)
but is there a way to get MATLAB to join them using a curve of best fit?
I'm not sure exactly how to define 'curve of best fit', but I suppose an example might be if one had a string of x-values (+ & -) and each one had a corresponding y-value that was just x^2, then a curve of best fit for those points would show the get close to showing the curve y=x^2.
I obviously don't know the equation of my curve, which I guess is one of the issues that requires a certain method to be adopted over another.
  댓글 수: 3
Tom
Tom 2013년 3월 6일
Well I suppose some assumptions need to be made, i.e. guessing at the nature of the curve. My curve looks like it might be a hyperbola (it's similar to a positive section of y=1/x). If I assumed that then how would I proceed from there?
amberly hadden
amberly hadden 2014년 6월 16일
I would suggest you in put your data in terms of x and y. next type cftool. you will get a new window which will ask you to input x and y. then creat data and next step go to fitting option and click new fitting you will see lots of curves. Fit them one by one and see which one is best fit for your data.You will get equation as well.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 6일
편집: Azzi Abdelmalek 2013년 3월 6일
x=[1 1.5 2 2.5 3];
y=[19.74 14.26 12.34 11.45 10.97];
xi=1:0.2:3
method='spline'
yi=interp1(x,y,xi,method)
plot(xi,yi)
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 6일
If you have a curve fiting toolbox, you can use fit function
Ghada Bakaraki
Ghada Bakaraki 2021년 1월 3일
this method can be used with any set of points?or only with the given set of points in the question?

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

추가 답변 (3개)

Daniel Shub
Daniel Shub 2013년 3월 6일
The title of your question says line, bu the body of the question says curve. If you really interested in a straight line, then lsline will do the job.
x=[1 1.5 2 2.5 3];
y=[19.74 14.26 12.34 11.45 10.97];
plot(x,y, '*')
lsline
The source of lsline is available:
type lsline
and you can see it does all the work with polyfit, so it should be possible to create a enhanced version that fits higher order polynomials or your own custom curve.
  댓글 수: 3
Daniel Shub
Daniel Shub 2013년 3월 6일
Please edit the question to explain how you are defining the curve of best fit.
Tom
Tom 2013년 3월 6일
Okay - done that.

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


Shashank Rayaprolu
Shashank Rayaprolu 2017년 10월 21일
I took the points and formed a curve using spline function (using spline method and interpl command). But now I want to get the equation of the curve generated.
How should I go about that???

Alex Sha
Alex Sha 2019년 10월 20일
The equation below is good enough:
y = p1+p2/(p3-x)^2;
Root of Mean Square Error (RMSE): 0.000924797017843405
Sum of Squared Residual: 4.27624762106028E-6
Correlation Coef. (R): 0.999999958196234
R-Square: 0.999999916392469
Adjusted R-Square: 0.999999832784938
Determination Coef. (DC): 0.999999916392469
Chi-Square: 1.87530479087576E-7
F-Statistic: 11960644.0637016
Parameter Best Estimate
---------- -------------
p1 9.87104884862438
p2 9.88400654611518
p3 -0.000758647151949232
f1.jpg
  댓글 수: 1
JoaquinB
JoaquinB 2019년 11월 15일
How did you do that? Curve Fitting Toolbox?

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

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by