Fitting Question
3 次查看(过去 30 天)
显示 更早的评论
Hi guys, I am new to matlab. I was wondering if you can help me with fitting some data. These are my values: x= [0.0 0.5 1.0 2.0 5.0 8.0 10.0 12.0 15.0 18.0 20.0] y= [4.92 7.06 18.88 14.12 76.14 32.92 76.49 47.97 35.75 16.11 17.19]
I would like to obtain the best fit. Can you help me with the syntax?
regards,
0 个评论
回答(4 个)
Oleg Komarov
2011-6-29
If you have the Curve Fitting TB use cftool to fit the data interactively.
Otherwise an example:
x = [0.0 0.5 1.0 2.0 5.0 8.0 10.0 12.0 15.0 18.0 20.0].';
y = [4.92 7.06 18.88 14.12 76.14 32.92 76.49 47.97 35.75 16.11 17.19].';
[b,S] = polyfit(x,y,3);
plot(x,y,'.',0:0.1:20,polyval(b,0:0.1:20),'-r')
ylim([-100,100])
0 个评论
Walter Roberson
2011-6-29
You can get a perfect fit (to within roundoff error) by using polyfit(x,y,length(x))
Unfortunately when you interpolate the function any further, you will very likely decide that the extended values are nonsense. Every polynomial fitting goes to either +infinity or -infinity at the extremes.
If you do not have a model of what the function "should" look like, then there is no way to rank any fitted function as being better or worse than another.
Oleg's suggestion of polyfit() with degree 3 provides (to within roundoff error) the best least-squared degree 3 polynomial over that data. You could keep increasing the polynomial degree until the fitting residue was less than some particular value, but if you do not already have reason to expect a polynomial fit within that degree range, then the solution will be more or less bunk.
0 个评论
Alex Sha
2019-5-28
How about the function below:
y=y0+A*exp(-0.5*((x-xc)/w)^2)+A1*exp(-exp(-(x-xc1)/w1)-(x-xc1)/w1+1);
Root of Mean Square Error (RMSE): 4.08162493636905
Sum of Squared Residual: 183.256283333086
Correlation Coef. (R): 0.985835143591926
R-Square: 0.971870930340914
Adjusted R-Square: 0.964838662926143
Determination Coef. (DC): 0.971870930340914
Chi-Square: 5.73409196786601
F-Statistic: 23.0336076224438
Parameter Best Estimate
---------- -------------
y0 9.50129005851808
a -61.9721900986626
xc 8.00164037070495
w 0.182284401674019
a1 87.8175531846905
xc1 7.19692083049562
w1 3.25672482403779
0 个评论
另请参阅
类别
在 Help Center 和 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!