最小二乘法拟合指数函数,Matlab polyfit线性拟合问题
拟合函数形式为:y=c(1-exp(at));t=[1.52752.08173.32674.20885.03765.72815.72815.72815.72817.983...
拟合函数形式为:y=c(1-exp(at));
t=[1.5275 2.0817 3.3267 4.2088 5.0376 5.7281 5.7281 5.7281 5.7281 7.9832 10.5347 11.5058 13.0526 14.3302 15.4550 16.0434 17.1287 18.0409 18.0409 18.6259 2.8636 4.5765 5.4087 5.7281 5.7281 5.7281 5.7281 9.3960],
y=[ 0.3408 0.6278 0.3790 0.7242 0.8386 0.7113 0.7113 0.7113 0.7113 0.6627 0.6625 0.6563 0.8832 1.1014 1.0155 0.9698 0.9823 0.9294 0.9294 0.9149 0.4343 0.9054 0.7805 0.7113 0.7113 0.7113 0.7113 0.6555] 展开
t=[1.5275 2.0817 3.3267 4.2088 5.0376 5.7281 5.7281 5.7281 5.7281 7.9832 10.5347 11.5058 13.0526 14.3302 15.4550 16.0434 17.1287 18.0409 18.0409 18.6259 2.8636 4.5765 5.4087 5.7281 5.7281 5.7281 5.7281 9.3960],
y=[ 0.3408 0.6278 0.3790 0.7242 0.8386 0.7113 0.7113 0.7113 0.7113 0.6627 0.6625 0.6563 0.8832 1.1014 1.0155 0.9698 0.9823 0.9294 0.9294 0.9149 0.4343 0.9054 0.7805 0.7113 0.7113 0.7113 0.7113 0.6555] 展开
1个回答
展开全部
%方法一
y=[50 40 30 20 10 ]; t=[55 63 73 100 121];
yp=log(y);
p = polyfit(t,yp,1);
b=-p(1)
a=exp(p(2))
yf=a*exp(-b*t);
yf-y
plot(t,y,'r+',t,yf,'b-')
legend('原始点','拟合线')
%方法二
%% Fit: 'exp1'.
[xData, yData] = prepareCurveData( t, y );
% Set up fittype and options.
ft = fittype( 'exp1' );
opts = fitoptions( ft );
opts.StartPoint = [145.2 -0.3];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. t', 'exp1', 'Location', 'NorthEast' );
% Label axes
xlabel( 't' );
ylabel( 'y' );
fitresult
gof
%方法三
y=[50 40 30 20 10 ]';
yp=log(y);
t=[55 63 73 100 121]';
tl=ones(size(t));
t1=[tl t];
p=t1\yp;
b=-p(2)
a=exp(p(1))
yf=a*exp(-b*t);
yf-y
plot(t,y,'r+',t,yf,'b-')
legend('原始点','拟合线')
%方法四
regress
y=[50 40 30 20 10 ]; t=[55 63 73 100 121];
yp=log(y);
p = polyfit(t,yp,1);
b=-p(1)
a=exp(p(2))
yf=a*exp(-b*t);
yf-y
plot(t,y,'r+',t,yf,'b-')
legend('原始点','拟合线')
%方法二
%% Fit: 'exp1'.
[xData, yData] = prepareCurveData( t, y );
% Set up fittype and options.
ft = fittype( 'exp1' );
opts = fitoptions( ft );
opts.StartPoint = [145.2 -0.3];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. t', 'exp1', 'Location', 'NorthEast' );
% Label axes
xlabel( 't' );
ylabel( 'y' );
fitresult
gof
%方法三
y=[50 40 30 20 10 ]';
yp=log(y);
t=[55 63 73 100 121]';
tl=ones(size(t));
t1=[tl t];
p=t1\yp;
b=-p(2)
a=exp(p(1))
yf=a*exp(-b*t);
yf-y
plot(t,y,'r+',t,yf,'b-')
legend('原始点','拟合线')
%方法四
regress
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |