作业帮 > 综合 > 作业

用matlab拟合函数,将这两组数据给拟合,算出xy的关系式.这个数据应该是指数函数,谢

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/18 00:51:41
用matlab拟合函数,将这两组数据给拟合,算出xy的关系式.这个数据应该是指数函数,谢
x=[98 103 117 142 186 232 291 363 435 526 615 1114 1639 2161 2720 3250 3816 4288 4914 5445 5962 6423 6950 7404 7884 8326 8765 9185 9529 10259 11087 11883 12612 13128 13644 15651 18337 19697 19823 21409 22783 23748 24659 25272 25476 28235 29239 33436 36964 39890 54312 58625 59597 60278 63175 63544 64136 64889 65214 65491];
y=[0.3 0.5 0.7 1 1.3 1.7 2.1 2.5 3 3.5 4 6.3 9 11.7 14.5 17.2 19.8 22.5 25.2 27.8 30.5 33.1 35.5 37.9 40.4 42.7 44.9 47.1 49.1 53 57.5 61.5 65.5 68.5 72.2 85.4 101.2 114 121 123 132 140 148 152 157 187 193 240 282 329 568 786 818 879 1127 1192 1245 1347 1401 1465];
谢谢qibbxxt的提供,但是我没有fittype这个函数,请问还有什么好办法吗?
function createFit(x,y)
%CREATEFIT Create plot of data sets and fits
% CREATEFIT(X,Y)
% Creates a plot,similar to the plot in the main Curve Fitting Tool,
% using the data that you provide as input.You can
% use this function with the same data you used with CFTOOL
% or with different data.You may want to edit the function to
% customize the code and this help message.
%
% Number of data sets:1
% Number of fits:1
% Data from data set "y vs.x":
% X = x:
% Y = y:
% Unweighted
% Auto-generated by MATLAB on 01-Dec-2010 17:24:25
if nargin==0
x=[98 103 117 142 186 232 291 363 435 526 615 1114 1639 2161 2720 3250 3816 4288 4914 5445 5962 6423 6950 7404 7884 8326 8765 9185 9529 10259 11087 11883 12612 13128 13644 15651 18337 19697 19823 21409 22783 23748 24659 25272 25476 28235 29239 33436 36964 39890 54312 58625 59597 60278 63175 63544 64136 64889 65214 65491];
y=[0.3 0.5 0.7 1 1.3 1.7 2.1 2.5 3 3.5 4 6.3 9 11.7 14.5 17.2 19.8 22.5 25.2 27.8 30.5 33.1 35.5 37.9 40.4 42.7 44.9 47.1 49.1 53 57.5 61.5 65.5 68.5 72.2 85.4 101.2 114 121 123 132 140 148 152 157 187 193 240 282 329 568 786 818 879 1127 1192 1245 1347 1401 1465];
end
% Set up figure to receive data sets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[578 254 688 485]);
% Line handles and text for the legend.
legh_ = [];
legt_ = {};
% Limits of the x-axis.
xlim_ = [Inf -Inf];
% Axes for the plot.
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',[0 0 1 1]);
set(ax_,'Box','on');
axes(ax_);
hold on;
% --- Plot data that was originally in data set "y vs.x"
x = x(:);
y = y(:);
h_ = line(x,y,'Parent',ax_,'Color',[0.333333 0 0.666667],...
'LineStyle','none','LineWidth',1,...
'Marker','.','MarkerSize',12);
xlim_(1) = min(xlim_(1),min(x));
xlim_(2) = max(xlim_(2),max(x));
legh_(end+1) = h_;
legt_{end+1} = 'y vs.x';
% Nudge axis limits beyond data limits
if all(isfinite(xlim_))
xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
set(ax_,'XLim',xlim_)
else
set(ax_,'XLim',[-555.93000000000006,66144.929999999993]);
end
% --- Create fit "fit 1"
ok_ = isfinite(x) & isfinite(y);
if all( ok_ )
warning( 'GenerateMFile:IgnoringNansAndInfs',...
'Ignoring NaNs and Infs in data.' );
end
st_ = [35.773947240380622 5.3684112100804791e-005 ];
ft_ = fittype('exp1');
% Fit this model using new data
cf_ = fit(x(ok_),y(ok_),ft_,'Startpoint',st_);
% Alternatively uncomment the following lines to use coefficients from the
% original fit.You can use this choice to plot the original fit against new
% data.
% cv_ = { 23.933534662859728,6.1528631198640689e-005};
% cf_ = cfit(ft_,cv_{:});
% Plot this fit
h_ = plot(cf_,'fit',0.95);
set(h_(1),'Color',[1 0 0],...
'LineStyle','-','LineWidth',2,...
'Marker','none','MarkerSize',6);
% Turn off legend created by plot method.
legend off;
% Store line handle and fit name for legend.
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 1';
% --- Finished fitting and plotting data.Clean up.
hold off;
% Display legend
leginfo_ = {'Orientation','vertical','Location','NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:});
set(h_,'Interpreter','none');
% Remove labels from x- and y-axes.
xlabel(ax_,'');
ylabel(ax_,'');