当前位置: 首页 > 有奖问答 >matlab 非线性拟合 数据拟合

matlab 非线性拟合 数据拟合

作者 闲人与懒猫
来源: 小木虫 150 3 举报帖子
+关注

我在做一个动力学的方程拟合,用的是最小二乘法,下面是程序,不知道哪里有问题,结果偏差很大,求各位大神帮助!
原方程 K=k0*exp(-E/T)*PH^a*PS^b*P,知K T PH PS P,求 k0 E a b
function nihe
global T0 PH0 PS0 P0 K0
T0=[5014.5891 5014.5891 5014.5891 5180.8691 5180.8691 5180.8691 5347.1491 5347.1491 5347.1491];
PH0=[788732.39 592592.59 396039.6 790123.46 394366.19 594059.41 792079.21 591549.29 395061.73];
PS0=[20.19 13.28 7.1 17.71 10.1 10.65 14.2 15.15 8.85];
P0=[24220.91 29411.10 20587.77 20587.77 29411.10 24220.91 29411.10 20587.77 24220.91];
K0=[1047 1122 1233 1188 1225 1148 1815 1185 1125];
y=log(K0);
x1=T0
x2=log(PH0);
x3=log(PS0);
x4=log(P0);
y=y';
X=[ones(size(y)) x1' x2' x3' x4'];
[b bint]=regress(y,X,0.1);
k=exp(b(1));
E=b(2)
a=b(3);
c=b(4);
beta0=[k E a c];
lb=[];ub=[];
[beta,resnorm,resid,exitflag,output,lambda,jacobian] = ...
     lsqnonlin(@ObjFunc,beta0,lb,ub);
ci=nlparci(beta,resid,jacobian)

% 残差关于拟合值的残差图
K0c = Rate(beta,PH0,PS0,T0,P0);
plot(K0c,resid,'*')
xlabel('反应速率拟合值, torr s^-^1')
ylabel('残差R, torr s^-^1')
refline(0,0)

% 参数辨识结果
fprintf('Estimated Parameters:\n')
fprintf('\tk = %.4f ± %.4f\n',beta(1),ci(1,2)-beta(1))
fprintf('\tE = %.2f ± %.2f\n',beta(2),ci(2,2)-beta(2))
fprintf('\ta = %.2f ± %.2f\n',beta(3),ci(3,2)-beta(3))
fprintf('\tc = %.2f ± %.2f\n',beta(3),ci(3,2)-beta(3))
fprintf('\tThe sum of the squares is: %.1e\n\n',resnorm)
% ----------------------------------------------------------------
function f=ObjFunc(beta)
global T0 PH0 PS0 P0 K0
f=K0-Rate(beta,T0,PH0,PS0,P0);
% ------------------------------------------------------------------
function K=Rate(beta,T,PH,PS,P)
K=beta(1).*exp(-beta(2)./T).*PH.^beta(3).*PS.^beta(4).*P;



运行结果如下
ci =

  1.0e+004 *

   -0.0000    0.0000
   -2.4270    3.5058
   -0.0000    0.0002
   -0.0002    0.0001

Estimated Parameters:
        k = 0.0001 ± 0.0015
        E = 5393.89 ± 29664.08
        a = 0.64 ± 1.05
        c = 0.64 ± 1.05
        The sum of the squares is: 2.2e+005 返回小木虫查看更多

今日热帖
  • 精华评论
  • dingd

    均方差(RMSE):145.616909851711
    残差平方和(SSE):190838.559912851
    相关系数(R): 0.808436694770782
    相关系数之平方(R^2): 0.653569889451906
    确定系数(DC): 0.533303922309213
    卡方系数(Chi-Square): 84.1949588985453
    F统计(F-Statistic): 3.57120350124504

    参数        最佳估算
    ----------        -------------
    a        0.000908846493918729
    b        15363.6309483451
    c        0.613132584682165
    d        -0.466403903584844

    ====== 结果输出 ======

    No        实测值y        计算值y
    1        1047        1044.65871777826
    2        1122        1294.24697276882
    3        1233        947.632511671439
    4        1188        1042.59182404487
    5        1225        1263.95133737708
    6        1148        1305.46096405217
    7        1815        1813.28448120857
    8        1185        1029.71059671882
    9        1125        1215.31618898618,

  • 闲人与懒猫

    引用回帖:
    2楼: Originally posted by dingd at 2015-01-29 20:07:38
    均方差(RMSE):145.616909851711
    残差平方和(SSE):190838.559912851
    相关系数(R): 0.808436694770782
    相关系数之平方(R^2): 0.653569889451906
    确定系数(DC): 0.533303922309213
    卡方系数(Chi-Square): 84.1949 ...

    谢谢大神,我用1stopt 1.5做了一下,就是这个结果,但是不是想要的数值,忽然发现有个单位是错的,还不知道影响大不大,我再算算。

  • 闲人与懒猫

    单位基本没影响,求助matlab大神。。!

猜你喜欢
下载小木虫APP
与700万科研达人随时交流
  • 二维码
  • IOS
  • 安卓