How can I write summationn constraints for an optimization problem?
Show older comments
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 Comment
Ricardo López
on 29 Sep 2020
Accepted Answer
More Answers (1)
Ameer Hamza
on 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
Categories
Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!