Using an output from a function as a constraint in an optimisation problem

Hi all, thanks in advance for any help received.
I am using optimtool toolbox and have a function that has 2 outputs. For my optimisation i would like the first output of my function to be less than a value and the second output of my function to be minimised?
How would I go about solving this?
Regards Alim

 采纳的回答

Let's suppose that your function is
[c,fval] = myobj(x)
You want c to be less than 5, say, and fval to be minimized.
Write a nonlinear constraint function
function [c,ceq] = nonlcon(x)
ceq = [];
[c,~] = myobj(x);
c = c - 5;
Your objective function is
function f = fun(x)
[~,f] = myobj(x);
Now this might strike you as wasteful, having to call myobj twice and throwing away half the information each time. To get around this inefficiency, see Objective and Nonlinear Constraints in the Same Function.
Alan Weiss
MATLAB mathematical toolbox documentation

2 个评论

Cool, thanks I did that and it started solving. However, now i'm faced with this message.
'Optimization running. Objective function value: 1270.6042684357653 No feasible solution found.
fmincon stopped because the size of the current step is less than the default value of the step size tolerance but constraints are not satisfied to within the default value of the constraint tolerance. '
What do I do to get around this?
The documentation has suggestions on things to try if the solver cannot find a feasible point. In addition, make sure that you understand what a nonlinear feasible point means to fmincon: it is one where
c(x) <= 0.
(I am assuming that c(x) is your nonlinear constraint function.)
Alan Weiss
MATLAB mathematical toolbox documentation

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by