Optimization using fmincon with respect to 2 variables
4 views (last 30 days)
Show older comments
Khalil Messaoudi
on 21 Dec 2021
Commented: Alan Weiss
on 2 Mar 2022
Hello, I'm trying to implement this optimization problem by using fmincon in Matlab . I'm struggling to adapt my constrained conditions in the attached figure to parameters A,b,Aeq,beq, lb,ub,nonIcon in fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon). Like you can also notice,my function depends on 2 variables HatAlpha and HatC. Please note that HatAlpha is a (m+1 x 1)vector and HatC is a (m+1 x m+1) matrix. This is why I'm also wondering if I have to create a new function variable that contains both of them for fmincon. Thank you for any tipp
0 Comments
Accepted Answer
Alan Weiss
on 21 Dec 2021
I think that you would find it much easier to use the problem-based approach rather than fmincon directly. The reason is that with fmincon you have to put all of the control variables into one vector, typically called x. This x would contain both HatAlpha and HatC. With the problem-based approach, you are free to use the variables that are most natural for your problem.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
21 Comments
Walter Roberson
on 2 Mar 2022
What would you want the code to do in the case where the constraints could not be satisfied?
- If the lb, ub are inconsisten, or the A, b are inconsistent, or the Aeq, beq are inconsistent ?
- If it has used lb, ub, A, b, Aeq, beq to break down the search space into all polytope subspaces, and it has explored the function value at boundaries and in the centroid of each of the subspaces, and finds no evidence that the nonlinear constraints can be satisfied?
Suppose I define a nonlinear constraint function
c = @(x) 1/2-(x(1)==3432523.353208).*(x(2)==90071992547409.92)
That function has a well-defined global minima: it is -1/2 at (3432523.353208, 90071992547409.92) and it is 1/2 everywhere else. Keeping in mind that fmincon() effectively cannot examine the source code to determine those constants, if you were to tell fmincon not to stop until all the constraints were satisfied, how long would you want fmincon to search until it happened to try the exact combination of that pair of floating point values?
Alan Weiss
on 2 Mar 2022
I stand by my previous comments. It is clear from the exit message that, as far as fmincon is concerned, the constraints are satisfied at the end. If you disagree, it is because you have a different notion of constraint satisfaction.
I told you earlier that your initial constraint function value was extremely large. That has come back to cause you issues now. I suggest again that you rerun the solver from the final point to get your constraint infeasibility to a better value. You culd also scale your constraint infeasibility by, say, taking a nonlinear transformation such as
consval = 1e3*tanh(consval/1e3);
before you return the value.
Alan Weiss
MATLAB mathematical toolbox documentation
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!