I have data of 10000 points of nonlinear fit. I want to have an equation that gives me the trend of that data.
2 ビュー (過去 30 日間)
古いコメントを表示
Equation that gives the trend of the data.
回答 (2 件)
the cyclist
2014 年 10 月 9 日
編集済み: the cyclist
2014 年 10 月 9 日
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 日
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 件のコメント
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.
参考
カテゴリ
Help Center および File Exchange で Least Squares についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!