Fmincon linear contraint doens't work in my case
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi there,
I am solving a nonlinear optimization problem. The code shows as follows in which I have 54 unknowns.
A = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1];
b = [0.015;-0.005;0.015;-0.005;0.08;-0.02;0.08;-0.02];
% 0.005<=x(51)<=0.015;
% 0.005<=x(52)<=0.015;
% 0.02<=x(53)<=0.08;
% 0.02<=x(54)<=0.08;
Aeq = [];
beq = [];
x0= 0.001*rand(54,1);
lb= -200*ones(54,1);
ub= +200*ones(54,1);
options = optimoptions('fmincon','Display','iter','MaxFunctionEvaluations', 10000,'ConstraintTolerance',1e-10);
[x,y,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]=fmincon('fun1',x0,A,b,Aeq,beq,lb,ub,'fun3',options);
fun1:
f=(x(49))^2;
fun3:
(I have got a lot of nonlinear and linear equations here and some inequality contraints here. Altogether around 80 constraints.
Thoes equations have no bugs or errors as they can run successfully under fsolve function if the 4 unknowns are given.)
The idea is to optimize the last four unknowns within their ranges shown above(A,b).
Sometimes, fmincon can give some 'good' results saying local minimal value found. However, when I trace back to the values of the last 4 unknowns, there are not actually within the ranges set in the code.
I was wondering if anyone could help me with this?
My email address is ke.wu@ucdconnect.ie. Contact me if you want to look into the case.
Thanks in advance,
Ke
댓글 수: 2
Walter Roberson
2019년 11월 5일
Is there a reason you did not code that A b in terms of lower bound and upper bound parameters?
채택된 답변
Matt J
2019년 11월 5일
편집: Matt J
2019년 11월 5일
You should check the EXITFLAG output to see if fmincon believes it converged. If it did converge, the ranges should be satisfied to within the ConstraintTolerance parameter that you set.
As Walter alluded, it would really be better for you to express the desired ranges using the lb, ub inputs. That is their purpose. Moreover, under default settings, the lb, ub constraints will be ideally satisfied (no violation of the bounds is tolerated).
댓글 수: 10
Matt J
2019년 11월 8일
It is not possible that you got exitflag=2 or 3 but violated the bounds. I suggest you post your latest code and also the x0 that leads to exitflag 2 or 3 so that we can try to reproduce it.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!