manu87 发表于 2014-3-25 10:39:04

如何用MATLAB最小二乘法得出回归方程系数?

各位高手,求大家帮帮忙,万分感谢!!!回归方程模型如下:C=a*(x^m/y^n)+b*y^p

如何运用Matlab工程软件,采用最小二乘法分别求指数数a,b,m,n,p?具体程序是怎样的?
回归方程显著性检验如何进行?具体程序是什么?

实验数据如下:




XYC
1100.2157.661.8
1157.8857.791.7
1272.8558.031.67
1330.3458.221.67
138957.691.7
159057.011.67
182055.421.6
204959.351.5
230858.321.56
259657.281.6
271157.131.368
282655.611.33
288354.791.315
294053.781.325
300154.411.3
311755.931.2495
329157.151.28
337758.051.25
352258.411.31
372557.611.31
389953.551.195
401551.221.178
418850.891.185


ljelly 发表于 2014-3-25 14:34:22

用lsqcurvefit函数来做,也可以用regress函数,具体你可以找例程
或者仔细研究一下这两个函数的用法

liuyalong008 发表于 2014-3-30 00:05:17


data:Dat=[1100.21        57.66        1.8
1157.88        57.79        1.7
1272.85        58.03        1.67
1330.34        58.22        1.67
1389        57.69        1.7
1590        57.01        1.67
1820        55.42        1.6
2049        59.35        1.5
2308        58.32        1.56
2596        57.28        1.6
2711        57.13        1.368
2826        55.61        1.33
2883        54.79        1.315
2940        53.78        1.325
3001        54.41        1.3
3117        55.93        1.2495
3291        57.15        1.28
3377        58.05        1.25
3522        58.41        1.31
3725        57.61        1.31
3899        53.55        1.195
4015        51.22        1.178
4188        50.89        1.185]fitg = fittype( @(a, b,m, n,p, x,y) a.*(x.^m./y.^n)+b.*y.^p,...
    'independent', {'x', 'y'},'dependent', 'z' )
= fit( Dat(:,1:2),Dat(:,3), g);
plot(fitobject, Dat(:,1:2),Dat(:,3))
errors = feval(fitobject,Dat(:,1:2))-Dat(:,3)
lsqcurvefitf =@(x, xdata ) x(1).*(xdata(:,1).^x(3)./xdata(:,2).^x(4))+x(2).*xdata(:,2).^x(5)
= lsqcurvefit(f,rand(5,1), Dat(:,1:2), Dat(:,3));
nlinfitf =@(beta, xdata ) beta(1).*(xdata(:,1).^beta(3)./xdata(:,2).^beta(4))+beta(2).*xdata(:,2).^beta(5)
= nlinfit(Dat(:,1:2),Dat(:,3),f,rand(5,1) )

shenhaijingling 发表于 2014-4-2 19:15:55

liuyalong008 发表于 2014-3-30 00:05
data:fitlsqcurvefitnlinfit

版主你好:
能请教下这个公式怎么拟合吗?
公式 z=(A+B*x^n)*(1+C*lny)          z,x,y已知
赋给初值后总是没有结果返回
谢谢!

mwg 发表于 2022-6-23 09:05:55

本帖最后由 mwg 于 2022-6-23 09:25 编辑

其实本人也是刚刚在学习,感谢楼主提供了相关的数据也就刚好有机会练一下手。
拟合结果可以自动给出的:如附图中所示。General model:
   f(x,y) = a*(x^m/y^n)   +b*y^p
Coefficients (with 95% confidence bounds):
       a =   6.107e-10(-3.607e-08, 3.729e-08)
       b =         1(1, 1)
       m =   0.03267(-3.707, 3.772)
       n =       1.538(-93.96, 97.04)
       p =         1(1, 1)

Goodness of fit:
SSE: 3.787e-18
R-square: 1
Adjusted R-square: 1
RMSE: 4.587e-10


页: [1]
查看完整版本: 如何用MATLAB最小二乘法得出回归方程系数?