![]() |
求助,fmincon函数报错
各位前辈,本人初次接触matlab,在使用fmincon函数后报告如下错误:
??? Error using ==> fmincon The constraint function mycon must return two outputs: the nonlinear inequality constraints and the nonlinear equality constraints. 意思是说我的那个非线性约束函数必须有两个输出值,但是在我的mycon函数里已经有了c和ceq了 为什么还报错呢 请前辈们指教,谢谢了 |
回复: 求助,fmincon函数报错
约束处理不正确 把约束的方程给出来 以及你写的约束和调用程序。
|
回复: 求助,fmincon函数报错
谢谢楼上,我的约束函数如下:
function [c,ceq]=mycon(x) x1=x(1); x2=x(2); x3=x(3); x4=x(4); x5=x(5); x6=x(6); x7=x(7); x8=x(8); c=[x6+x7+x8+asin((x5-x4*sin(alpha+x6+x7))/x3)-150*pi/180; asin(x1*sin(x6+x8)-(x1+x2)*sin(x6))-50*pi/180; x1/x2-0.9; 0.7-x1/x2; 45-sqrt(x1*x1+x4*x4-2*x1*x2*cos(x7)); x5-x4*sin(x6+x7)+x3; x4*sin(x6+x7)+x1*sin(80*pi/180)-x5; (275-x4*sin(x6+x7))^2-x3^2;(275-x4*sin(x6+x7+x8))^2-x3^2; (x1*sin(x7+x8)-(x1+x2)*sin(x7))^2-x2^2]; ceq=[]; 调用程序如下: OPT=optimset;OPT.LargeScale='off'; OPT.TolFun=1e-30;OPT.TolX=1e-15;OPT.Tolcon=1e-20; x0=[260,370,93.6,173.9,160,0.07152,0.32098,1.8125]; A=[];B=[];Aeq=[];Beq=[]; lb=[0,0,290,0,0,3*pi/180,15*pi/180,90*pi/180]; ub=[290,1e5,1e5,297.5,290,5*pi/180,25*pi/180,110*pi/180]; >> [x,fval,exitflag,output]=fmincon(@fun1,x0,A,B,Aeq,Beq,lb,ub,@mycon,OPT) |
回复: 求助,fmincon函数报错
我发现好像是alpha没有定义。现在的问题是运行以后不出结果一直busy
|
回复: 求助,fmincon函数报错
[QUOTE=zj201;39997]我发现好像是alpha没有定义。现在的问题是运行以后不出结果一直busy[/QUOTE]
是的 需要有数值才行 busy是因为没有找到最优解 可修改初始数值 或者采用其他优化算法 比如遗传粒子群等试验 |
回复: 求助,fmincon函数报错
好的,我大概明白了,非常感谢:)。
|
所有时间均为北京时间。现在的时间是 16:05。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.