非线性回归
对经验公式: y=2*(exp(a*b*X/2.)-1)/(a*x)中的参数 a,b 进行非线性回归,讨论它的收敛域。观测次数43 ,回归时, ab可作为一个参数。观察值如下:
y=2060.,2140.,2240.,2340.,2440.,2490.,2550.,2630.,2720.,2800.,2880.,2940.,3010.,3080.,3140.,3200.,3240.,3280.,3330.,3380.,3420.,3460.,3510.,3550.,3600.,3640.,3680.,3720.,3750.,3800.,3850.,3900.,3940.,3980.,4020.,4060.,4110.,4150.,4180.,4210.,4230.,4250.,4280.
t=0.3,0.4,0.5,0.6,0.7,… 4.2,4.3,4.4,4.5。
(从0.3始,间隔0.1,至4.5)
参数优化
[ 本帖最后由 zsp1983 于 2006-12-22 12:00 编辑 ] 先提出自己的见解
然后大家讨论:handshake a = 0.000212580362810155
b = 2406.95837364732
我的
:@( :@( :@)function F = fun(x, data);
F=2*exp(x(1)*x(2)*xdata./2)./(x(1)*x.)-2/(x(1)*xdata.)
xdata = ;
ydata = ;
x0 =[.2e-3, 2000]; % Starting guess
= lsqcurvefit(@fun,x0,xdata,ydata)
Warning: See help sprintf for valid escape sequences.
In optim\private\lsqncommon at 126
In lsqcurvefit at 165
??? Error using ==> optim\private\lsqncommon
User supplied function ==> fun
failed with the following error:
Error: File: C:
Error in ==> lsqcurvefit at 165
= ...
回复
这种最基本的拟合看看帮助就能解决.提示:明显地,代码中拟合函数写得不正确.
注意"点"运算; 且x,y数据长度要一样.
[ 本帖最后由 xjzuo 于 2006-12-30 15:59 编辑 ]
回复 #6 xjzuo 的帖子
我现在是 用的nlinfit命令进行回归,M文件
function ydata = myfun(beta0, xdata);
m=beta0(1);n=beta0(2);
ydata=2.*exp(m*xdata/2.)/(n*xdata)-2./(n*xdata)
脚本文件
xdata=;
ydata=;
beta0=;
=nlinfit(xdata,ydata,'myfun',beta0)
可老出不了结果,我已经就此花费了好几天,回归公式的表达式应该没错,可就是出现这样的警告信息:
Error using ==> nlinfit>checkFunVals
MODELFUN has returned Inf or NaN values.
294 error('stats:nlinfit:NonFiniteFunOutput', ...
function checkFunVals(v)
if any(~isfinite(v))
error('stats:nlinfit:NonFiniteFunOutput', ...
'MODELFUN has returned Inf or NaN values.');
end
高手指教一二
[ 本帖最后由 zsp1983 于 2007-1-3 17:11 编辑 ] function F = fun(x, xdata)
F= 2 * ( exp ( x(1) * x(2) * xdata ./ 2.0 ) - 1 ) ./ ( x(1) * xdata );
xdata = ;
ydata = ;
x0 =[.2e-3, 2000]'; % Starting guess
= lsqcurvefit(@fun,x0,xdata,ydata)
Optimization terminated: relative function value
changing by less than OPTIONS.TolFun.
x =
1.0e+003 *
0.000000219793658
2.379757677454140
resnorm =
1.060806784813972e+006 function F = fun(x, xdata)
F= 2 * ( exp ( x(1) * x(2) * xdata ./ 2.0 ) - 1 ) ./ ( x(1) * xdata );
xdata = ;
ydata = ;
x0 =[.2e-3, 2000]'; % Starting guess
=nlinfit(xdata,ydata,'fun',x0)
betafit =
1.0e+003 *
0.000000219796786
2.379747492551644
回复 #9 happy 的帖子
谢谢这位大哥!!:victory:回复 #9 zsp1983 的帖子
有多元回归的例子吗?
页:
[1]