马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
非线性拟合也是一优化问题,即残差平方和最小,Lingo因而可用于曲线拟合。Lingo也不需要赋初值。
拟合数据:- X = [0.25,0.5,0.75,1,1.5,2,2.5,3,3.5,4,4.5,5,6,7,8,9,10,11,12,13,14,15,16],
- Y = [30,68,75,82,82,77,68,68,58,51,50,41,38,35,28,25,18,15,12,10,7,7,4];
- 拟合公式:
- y = A1*(Exp(-A2*X)-Exp(-A3*X))
- Lingo代码:
- Model:
- Sets:
- BAC/R1..R23/:X,Y;
- EndSets
- Data:
- X = 0.25,0.5,0.75,1,1.5,2,2.5,3,3.5,4,4.5,5,6,7,8,9,10,11,12,13,14,15,16;
- Y = 30,68,75,82,82,77,68,68,58,51,50,41,38,35,28,25,18,15,12,10,7,7,4;
- EndData
- Min = @Sum(BAC: A1*(@Exp(-A2*X)-@Exp(-A3*X))-y)^2);
- End
复制代码 1stOpt代码:- Constant X = [0.25,0.5,0.75,1,1.5,2,2.5,3,3.5,4,4.5,5,6,7,8,9,10,11,12,13,14,15,16],
- Y = [30,68,75,82,82,77,68,68,58,51,50,41,38,35,28,25,18,15,12,10,7,7,4];
- MinFunction Sum(i=1:23,X,Y)((A1*(Exp(-A2*X)-Exp(-A3*X))-y)^2);
复制代码 Lingo不需初值,成功率不是很高(有兴趣可自己试试),还有如果想赋初值,在Lingo里不知如何设定。1stOpt也不需初值,本题成功率为100%。有兴趣者也可用其它数学工具练练手,对比一下。
来自:simwe--shamohu |