I have data of 10000 points of nonlinear fit. I want to have an equation that gives me the trend of that data.
이전 댓글 표시
답변 (2개)
the cyclist
2014년 10월 9일
편집: the cyclist
2014년 10월 9일
1 개 추천
With the complete lack of detail you offer us, I can only give a generic response, which is to perhaps try the function nlinfit from the Statistics Toolbox.
Chad Greene
2014년 10월 9일
0 개 추천
p = polyfit(x,y,n) will give you that equation. If n=1, p will have a slope and a y-intercept value. If n=2, the first value in p will be coefficient for the squared term, the second value in p is the slope, and the third value in p is the y-intercept. Choose a value of n that gives you the best balance of fit versus simplicity.
댓글 수: 3
Sruthi Mantri
2014년 10월 9일
Chad Greene
2014년 10월 9일
The polyfit documentation explains it pretty well. Here's an example using 100 data points instead of your 10000, but it works the same.
xdata = 1:100;
ydata = 0.1*xdata.^2 + 4*xdata - 4000 + 200*rand(size(xdata));
plot(xdata,ydata,'ko')
hold on
linearFit = polyfit(xdata,ydata,1);
xfit = 0:5:100;
yfitLinear = linearFit(1)*xfit + linearFit(2);
plot(xfit,yfitLinear,'b')
secondOrderFit = polyfit(xdata,ydata,2);
yfitSecondOrder = secondOrderFit(1)*xfit.^2 + secondOrderFit(2)*xfit + secondOrderFit(3);
plot(xfit,yfitSecondOrder,'r')
legend('original data','linear fit','second order fit','location','northwest')
legend boxoff
box off

the cyclist
2014년 10월 9일
Chad, this is very nice, and helpful.
Sruthi, you have still given only a tiny amount of information about your problem. You should add a lot more detail in your question.
I encourage you to be very careful about what you mean by a "nonlinear fit". Usually, the word "linear" in "linear fit" refers to the parameters, NOT the variables. polyfit() actually does a linear fit (in the parameters).
So,
y = A + B1 * x + B2 * x.^2
which is what polyfit() does, is a linear fit.
But if you mean something like
y = A ./ (1 + exp(-B * x))
then that is a nonlinear fit (because the parameters do not come in linearly).
If that is more like what you have, then you will need nlinfit.
카테고리
도움말 센터 및 File 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!