0

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

在此处输入图像描述

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]);
4

1 回答 1

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'})

数据和拟合图

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

于 2013-10-19T15:53:54.347 回答