菜鸟1stopt代码求助
刚接触该软件,很多地方都不明白,按照手册上介绍,编写了如下代码,但是没有运行结果,也没提示错误麻烦高手帮忙解决下,谢谢了
Title "Torfactor2";
Parameters a,b,c,d,e,f;
Constant L=44;
Constant n=17;
Variable X, Y, Z;
DataSet;
X,Y,Z=
0.95286646053 7.31174393 45.90818274
1.0675890636 7.74423607 44.88095647
1.2070326551 8.708188311 56.666422786
1.2891664894 9.45328306 69.870900159
1.371300061 10.309441311 72.423575922
1.5246342784 11.00918745 77.923426956
1.7982441944 12.63134323 87.625605046
2.0530550486 14.22717859 96.124313224
2.4533315015 17.82962177 115.26023012
2.6266643202 18.226344191 119.23084942
2.856667018 19.9127711 132.53090467
3.0838023283 21.3538607 136.76386882
3.6142052724 24.92344013 161.35438276
3.987415716 27.120747051 176.52416388
4.8679566752 33.00078812 220.1193594
5.9622115035 40.50833169 283.81985361
6.9308234511 45.90868196 335.91465167
EndDataSet;
MinFunctionSum(i=1:n)(-Y+(L*a+b)*X+c)^2+
Sum(i=1:n)(-Z+(2*L*c+d)*X+e*X^2+f*a^2*X^3+2*b^2)^2;
回复 楼主 sophio 的帖子
我一运行,就出错了呀!??? Error: File: Untitled2.m Line: 6 Column: 7
Expression or statement is incomplete or incorrect. 那是因为公式里的X,Y,Z后面都有方括号i的,我一复制就变成斜体字,显示不出来了 改动如下试试,3.0运行是没问题的,以前的版本不敢保证。
Title "Torfactor2";
Parameters a,b,c,d,e,f;
Constant L=44;
Constant n=17;
DataSet;
X,Y,Z=
0.95286646053 7.31174393 45.90818274
1.0675890636 7.74423607 44.88095647
1.2070326551 8.708188311 56.666422786
1.2891664894 9.45328306 69.870900159
1.371300061 10.309441311 72.423575922
1.5246342784 11.00918745 77.923426956
1.7982441944 12.63134323 87.625605046
2.0530550486 14.22717859 96.124313224
2.4533315015 17.82962177 115.26023012
2.6266643202 18.226344191 119.23084942
2.856667018 19.9127711 132.53090467
3.0838023283 21.3538607 136.76386882
3.6142052724 24.92344013 161.35438276
3.987415716 27.120747051 176.52416388
4.8679566752 33.00078812 220.1193594
5.9622115035 40.50833169 283.81985361
6.9308234511 45.90868196 335.91465167
EndDataSet;
MinFunctionSum(x,y,z)((-Y+(L*a+b)*X+c)^2)+
Sum(x,y,z)((-Z+(2*L*c+d)*X+e*X^2+f*a^2*X^3+2*b^2)^2); 非常谢谢楼上的答复,可能不是3.0的原因,还是没反应呢,我去下载个3.0再试试看 3.0的似乎没有可以下载的。。我的是1.5版本的
这个例子里,有三个变量,我之前用matlab尝试过用lsqnonlin函数拟合,matlab也不太会呢,似乎运行不对的
function F=Torfac(d,Data)
d=1:6;
L=44; %cm
Data=[0.95286646053 7.31174393 45.90818274
1.0675890636 7.74423607 44.88095647
1.2070326551 8.708188311 56.666422786
1.2891664894 9.45328306 69.870900159
1.371300061 10.309441311 72.423575922
1.5246342784 11.00918745 77.923426956
1.7982441944 12.63134323 87.625605046
2.0530550486 14.22717859 96.124313224
2.4533315015 17.82962177 115.26023012
2.6266643202 18.226344191 119.23084942
2.856667018 19.9127711 132.53090467
3.0838023283 21.3538607 136.76386882
3.6142052724 24.92344013 161.35438276
3.987415716 27.120747051 176.52416388
4.8679566752 33.00078812 220.1193594
5.9622115035 40.50833169 283.81985361
6.9308234511 45.90868196 335.91465167];
xdata=Data(:,1);ydata=Data(:,2);zdata=Data(:,3);
d0=;
for i=1:length(xdata)
M(i)=((-ydata(i)+(L*d(1)+d(2))*xdata(i)+d(3))^2)+((-zdata(i)+(2*L*d(3)+d(4))*xdata(i)+d(5)*xdata(i)^2+d(6)*d(1)^2*xdata(i)^3+2*d(2)^2)^2);
i=i+1;
end
F=sum(M);
options=optimset('LargeScale','off');
options=optimset(options,'MaxFunEvals',300);
options=optimset(options,'LevenbergMarquardt','off');
options=optimset(options,'LineSearch','cubicpoly');
d=lsqnonlin('Torfac',d0,[],[],options,Data);
[ 本帖最后由 sophio 于 2009-5-17 11:01 编辑 ]
页:
[1]