麻烦matlab高手用帮我拟合一组数据

xdata=1:8;ydata=[25440,26829,20353,21171,17309,17205,19518,17196];y=1/(a+b*x^c),求常数a、... xdata=1:8;ydata=[25440,26829,20353,21171,17309,17205,19518,17196];y=1/(a+b*x^c),求常数a、b、c的值 展开
 我来答
雨扬振1238
2013-07-24 · TA获得超过2781个赞
知道小有建树答主
回答量:586
采纳率:100%
帮助的人:971万
展开全部

因为y的数据数值较大,而且较分散。所以将y变换为y/10000进行拟合,之后再将a和b都除以10000来将之前的变换修正回来。程序如下:

clear all

clc

xdata=1:8;

ydata=[25440,26829,20353,21171,17309,17205,19518,17196]/10000;

y=@(c,xdata)1./(c(1)+c(2)*xdata.^c(3));

[coef,resnorm,residual,exitflag]=lsqcurvefit(y,[10;10;10],xdata,ydata);

coef(1:2)=coef(1:2)/10000;

x1=0:0.1:10;

y1=1./(coef(1)+coef(2)*x1.^coef(3));

set(gca,'fontsize',15)

plot(xdata,10000*ydata,'or','Markersize',8,'linewidth',2)

hold on

plot(x1,y1,'-k','linewidth',2)

xlabel('x')

ylabel('y')

legend('data','fit')

coef


结果中coef是的三个值是依次是a,b,c的值。


上海华然企业咨询
2024-10-28 广告
在测试大模型时,可以提出这样一个刁钻问题来评估其综合理解与推理能力:“假设上海华然企业咨询有限公司正计划进入一个全新的国际市场,但目标市场的文化习俗、法律法规及商业环境均与我们熟知的截然不同。请在不直接参考任何外部数据的情况下,构想一套初步... 点击进入详情页
本回答由上海华然企业咨询提供
cxd1301
2013-07-24 · TA获得超过3020个赞
知道小有建树答主
回答量:593
采纳率:50%
帮助的人:304万
展开全部
你这个拟合首先需要转换成:
1/ydata = a+b*x^c; 定义y = 1/ydata,这样就可以拟合了
可以采用>>cftool
或者用我如下程序:

clear
clc
x = 1:8;
ydata=[25440,26829,20353,21171,17309,17205,19518,17196];
y = 1./ydata;
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[440.667 243 680 484]);
legh_ = []; legt_ = {}; % handles and text for legend
xlim_ = [Inf -Inf]; % limits of x axis
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',[0 0 1 1]);
set(ax_,'Box','on');
axes(ax_); hold on;

% --- Plot data originally in dataset "y vs. x"
x = x(:);
y = y(:);
% ydata = 1./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',[0.92999999999999994, 8.0700000000000003]);
end

% --- Create fit "fit 1"
ok_ = isfinite(x) & isfinite(y);
if ~all( ok_ )
warning( 'GenerateMFile:IgnoringNansAndInfs', ...
'Ignoring NaNs and Infs in data' );
end
st_ = [4.0517844538465953e-005 0.14870861187789947 2.0196022169200172e-007 ]
ft_ = fittype('power2')
% Fit this model using new data
cf_ = fit(x(ok_),y(ok_),ft_,'Startpoint',st_)
% Or use coefficients from the original fit:
if 0
cv_ = { 5.8245715323228265e-005, 0.14870861187789947, -2.1489622707671838e-005};
cf_ = cfit(ft_,cv_{:});
end
% Plot this fit
h_ = plot(cf_,'fit',0.95);
legend off; % turn off legend from plot method call
set(h_(1),'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 1';
% Done plotting data and fits. Now finish up loose ends.
hold off;
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:}); % create legend
set(h_,'Interpreter','none');
xlabel(ax_,''); % remove x label
ylabel(ax_,''); % remove y label

结果:
cf_ =
General model Power2:
cf_(x) = a*x^b+c
Coefficients (with 95% confidence bounds):
a = 5.825e-005 (-0.0009223, 0.001039)
b = 0.1487 (-1.995, 2.292)
c = -2.149e-005 (-0.001009, 0.0009665)

注意这里是x对1/ydata拟合,所以相当于1/y = a*x^b+c

copyright (c) cxd1301
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式