作业帮 > 综合 > 作业

matlab拟合二个未知变量.已知A=x-10*y*lgB;

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/15 12:48:16
matlab拟合二个未知变量.已知A=x-10*y*lgB;
其中A=[1,2,3,4,5,6,7,8,9,10]; B=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
求拟合的最优x和y值.
A=[1,2,3,4,5,6,7,8,9,10]; B=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
>> fun=inline('x(1)-10*x(2)*log10(B)','x','B'); %log10(B),10为底的常用对数
>> [x,resnorm,residual,exitflag]=lsqcurvefit(fun,[0.1 1],B,A)
Local minimum found.
Optimization completed because the size of the gradient is less thanthe default value of the function tolerance.

x =
8.6137 -0.9051
resnorm =
7.7829
residual =
Columns 1 through 7
-1.4371 0.2875 0.8812 1.0120 0.8891 0.6058 0.2117
Columns 8 through 10
-0.2634 -0.8005 -1.3863
exitflag =
1


%exitflag =1,最优解
拟合的最优x和y值:x= 8.6137 y=-0.9051
再问: 您好,我的方法算的y和你的y差个负号,宁能帮忙看看哪里不对吗?最佳给您! clc; A=[1;2;3;4;5;6;7;8;9;10]; B=[0.1;0.2;0.3;0.4;0.5;0.6;0.7;0.8;0.9;1]; B=10*log10(B); X=[ones(10,1),B]; [b,bint,r,rint,stats]=regress(A,X) fprintf('经验公式中的系数x,y分别为%f,%f\n',b(1),b(2)); 经验公式中的系数x,y分别为8.613684,0.905078
再答: 用Matlab的工具箱,得到的结果与上面的的结果是一样的。 General model: f(B) = a-10*b*log10(B) Coefficients (with 95% confidence bounds): a = 8.614 (7.523, 9.704) b = -0.9051 (-1.143, -0.6669) Goodness of fit: SSE: 7.783 R-square: 0.9057 Adjusted R-square: 0.8939 RMSE: 0.9863