作业帮 > 综合 > 作业

用matlab最小二乘法拟合曲线

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/29 00:39:38
用matlab最小二乘法拟合曲线
y=[0 0.06 0.11 0.17 0.23 0.28 0.34 0.40 0.46 0.52 0.59 0.65 0.72 0.80 0.87 0.96 1.05 1.16 1.31 1.55];
x=[20.02 18.95 17.79 17.00 16.12 14.97 13.96 13.01 12.10 11.07 10.11 8.95 7.99 6.93 5.99 5.03 4.04 3.02 2.01 1.01];
方程为y=[(x0-x)+a*ln(x0/x)]/b
其中x0就是第一个x值,即20.02
要求出a,b,麻烦给出源程序!
用matlab最小二乘法拟合曲线
y=[0 0.06 0.11 0.17 0.23 0.28 0.34 0.40 0.46 0.52 0.59 0.65 0.72 0.80 0.87 0.96 1.05 1.16 1.31 1.55]';
x=[20.02 18.95 17.79 17.00 16.12 14.97 13.96 13.01 12.10 11.07 10.11 8.95 7.99 6.93 5.99 5.03 4.04 3.02 2.01 1.01]';
st_ = [0.5 0.5];
ft_ = fittype('((20.02-x)+a*log(20.02/x))/b' ,...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a', 'b'});
[cf,good]= fit(x,y,ft_ ,'Startpoint',st_)
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);
hold on,plot(x,y,'*')
cf =
General model:
cf(x) = ((20.02-x)+a*log(20.02/x))/b
Coefficients (with 95% confidence bounds):
a = 6.326 (5.824, 6.829)
b = 24.7 (23.9, 25.49)
good =
sse: 0.00138633303036586
rsquare: 0.999617990625558
dfe: 18
adjrsquare: 0.999596767882533
rmse: 0.00877601855552917