How can I write summationn constraints for an optimization problem?
古いコメントを表示
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 件)
Ameer Hamza
2020 年 9 月 29 日
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
カテゴリ
ヘルプ センター および File Exchange で Choose a Solver についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!