与Polyfit更合身

时间:2013-10-19 09:26:07

标签: matlab curve-fitting

我正在尝试拟合一些数据但是使用多项式我找不到一个好的解决方案。那么,我如何画出像黑色曲线一样的曲线(知道曲线的类型)?

enter image description here

figure('Units', 'pixels', 'Position', [100 100 500 375]);
hold on;

ydata_s = [1.0e-03 0.5804 0.3916 0.2234 0.1527 0.0697 0];
ydata_m = [0.2765 0.2760 0.2758 0.2757 0.2755 0.2754];
xdata_m = [1 2.5 5 10 50 100];

% Fit with a line.
coeffs = polyfit(xdata_m, ydata_m, 2)
% Define the range where we want the line
xFitting = (0:1:100); 
yFitted = polyval(coeffs, xFitting);

hFit = line(xFitting, yFitted);
hE   = errorbar(xdata_m, ydata_m, ydata_s);


set(hFit                          , ...
  'Color'           , [0 .2 .6]    );
set(hE                            , ...
  'LineStyle'       , 'none'      , ...
  'Marker'          , '.'         , ...
  'Color'           , [.8 .3 .3]  );

hTitle  = title ('Precisione / Velocità');
hXLabel = xlabel('Campionamnto [%]');
hYLabel = ylabel('Funzione Obiettivo [€/P]');

xlim([0 100]);

hLegend = legend( ...
  [hE, hFit], ...
  'Data (\mu \pm \sigma)' , ...
  'Fit (\it{x^3})'      , ...
  'location', 'NorthEast' );

set(gca,'XTick',[1 2.5 5 10 50 100]);

1 个答案:

答案 0 :(得分:1)

如果您有曲线拟合工具箱

,这是相对论
x = [1 2.5 5 10 50 100];
y = [0.2765 0.2760 0.2758 0.2757 0.2755 0.2754];
plot(x, y, '*');
hold('on');
plot(fit(x', y', 'exp2'));
legend({'Data', 'Fit'})

Figure of data and fit

两项指数拟合的r ^ 2为0.96