How can I write summationn constraints for an optimization problem?
Afficher commentaires plus anciens
Good morning,
I would like to optimize the following equation:
min
with the following contraints:
x>0
Where
is a known set of values,
is equal to a [288x1] vector and
is also known as a [288x1] vector.
How can I add those constraints? I am trying to use x=fmincon(fun,x0,A,b,Aeq,beq);
Thanks!
1 commentaire
Ricardo López
le 29 Sep 2020
Réponse acceptée
Plus de réponses (1)
Ameer Hamza
le 29 Sep 2020
Something like this
price = rand(288, 1); % example value
c = rand(288, 1); % example value
sum_c = sum(c);
x0 = rand(288, 1); % initial guess
fmincon(@(x) price.'*x, x0, [], [], [], [], [], [], @(x) nlcon(x, sum_c)) % price.'*x is same as sum(price.*x)
function [cneq, ceq] = nlcon(x, sum_c)
cneq = [];
ceq = sum(x) - sum_c;
end
Catégories
En savoir plus sur Choose a Solver dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!