主题:fsolve函数的应用问题
heheempire
[专家分:0] 发布于 2007-08-08 16:00:00
F(v,t,s,a,b,c)=a*e^(2cs+bt)-(a+bv+cv^2),其中,v, t, s有n组数据,如何利用matlab最优化工具箱中的fsolve函数求解方程中的系数a, b, c
回复列表 (共4个回复)
沙发
Guassfans [专家分:4090] 发布于 2007-08-08 17:53:00
用fsolve不太好吧!
n>3组数据将形成超定方程
建议用lsqcurvefit 或 nlinfit 拟合参数
板凳
Guassfans [专家分:4090] 发布于 2007-08-08 18:06:00
用nlinfit 做线性回归:
function y=myfun(beta,x)
%F(v,t,s,a,b,c)=a*e^(2cs+bt)-(a+bv+cv^2),
y=beta(1)*exp(2*beta(3)*x(3)+beta(2)*x(2))-(beta(1)+beta(2)*x(1)+beta(3)*x(1).^2)
%beta=[a b c] x=[v t s]
X=[v s t]
Y=[]
%F(v,t,s,a,b,c)=Y
beta=[a0 b0 c0]
[beta,r,j]=nlinfit(X,Y,'myfun',beta0)
3 楼
heheempire [专家分:0] 发布于 2007-08-08 23:05:00
怎么会出现这样的现象:
[color=FF0000]??? Strings passed to EVAL cannot contain function declarations.[/color]
4 楼
happyhearo [专家分:0] 发布于 2007-11-13 11:25:00
上上楼主,按照你的思路,我做了程序,可总是报错?哪里错了呢?求助!
function y=sta67_8m(beta,x)
%Rs=beta(1);
%Rsh=beta(2);
%Il=beta(3);
%I0=beta(4);
K=1.38e-23;T=300;q=1.6e-19;
y=(beta(3).*beta(2)-(beta(4).*beta(2)).*(exp((x(2).*beta(1)-x(1)).*q./K./T)-1)+x(1))./(beta(2)+beta(1))-x(2);
x1=[8.00 8.00 10.00 10.00 10.00 10.00 12.00 12.00 12.00 14.00 14.00 14.00...
16.00 16.00 16.00 18.00 18.00 20.00 20.00 20.00 20.00 22.00 22.00 24.00...
24.00 24.00 26.00 26.00 26.00 28.00 28.00 30.00 30.00 30.00 32.00 32.00...
34.00 36.00 36.00 38.00 38.00 40.00 42.00]';
x2=[0.49 0.49 0.48 0.47 0.48 0.47 0.46 0.46 0.45 0.43 0.45 0.43 0.43 0.44 0.43...
0.43 0.46 0.42 0.42 0.43 0.41 0.41 0.40 0.42 0.40 0.40 0.41 0.40 0.41 0.41...
0.40 0.40 0.40 0.38 0.41 0.40 0.40 0.41 0.38 0.40 0.40 0.39 0.39]';
X=[x1 x2];
Y=x2*0;
beta0=[0.30 0.20 0.2 0.2];
[beta,r,j]=nlinfit(X,Y,'sta67_8m',beta0)
总是出错:
??? Error using ==> nlinfit
MODELFUN should return a vector of fitted values the same length as Y.
怎么回事啊?感谢帮助!
我来回复