Fmincon linear contraint doens't work in my case

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 5 Nov 2019
Is there a reason you did not code that A b in terms of lower bound and upper bound parameters?
Wu Ke
Wu Ke on 6 Nov 2019
I tried this as well, but didn't work out. The same results got as the results shown above.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 5 Nov 2019
Edited: Matt J on 5 Nov 2019
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 Comments
Matt J
Matt J on 8 Nov 2019
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!