How do I minimize one output and constrain the value of another?

2 views (last 30 days)
Hello,
I have a function which takes in a vector v and gives two outputs p and q. I wish to minimize output p while keeping output q at a certain value i choose. Is there any way I can do this with ga ?
Thank you.

Accepted Answer

Ameer Hamza
Ameer Hamza on 22 Sep 2020
Yes, it is possible. However, it might be better of you divide it into two different functions to avoid redundant calculations. However, if speed is not a concern, then you can do something like this.
function [p q] = myObjective(v)
% calculates p and q
end
Then call ga() like this
v_sol = ga(@myObjective, 2, [], [], [], [], [], [], @nlcon)
function [c ceq] = nlcon(v)
q_ = 1; % suppose you want the value of q to be 1.
[~, q] = myObjective(v)
ceq = q - q_;
c = []
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!