I am migrating an excel model to matlab. The orginal model defines decision variables in then constraints. How can I do the same?

1 回表示 (過去 30 日間)
Al Gut
Al Gut 2021 年 9 月 2 日
回答済み: Jaynik 2024 年 4 月 18 日
My aim is to create a code which does the same that the excel one. I want to optimise the function f=x1+2*x2+3*x3 using intlinprog. My problem appears when I arrive to the constraints where one of them is x2>a+c being 'a' & 'c' variables wich value will be suggested by the optimisation. How can I make my program do so?

回答 (1 件)

Jaynik
Jaynik 2024 年 4 月 18 日
Hi Al,
I see that you want to optimize an objective function with additional constraints where x2 > a + c. So the values of 'a' and 'c' would also be needed to be found by the optimization function. Here is a general approach to solve the problem:
% Objective function coefficients
f = [1; 2; 3; 0; 0]; % Coefficients for x1, x2, x3, a, c
% Inequality constraints matrix
A = [0 -1 0 1 1]; % Coefficients for x1, x2, x3, a, c in the constraint x2 - a - c > 0
% RHS for x2 - a - c > 0
b = 0;
lb = [0; 0; 0; 0; 0]; % Lower bounds
ub = [Inf; Inf; Inf; Inf; Inf]; % Upper bounds
intcon = 1:5; % All decision variables are integers
[x,fval,exitflag,output] = intlinprog(f,intcon,A,b,[],[],lb,ub);
You might need to adjust the code depending on the specific details of your problem. For example, if there are any equality constraints, then you need to also give values for the parameters 'Aeq' and 'beq' which are empty in the above case.
Hope this helps!

カテゴリ

Help Center および File ExchangeLinear Programming and Mixed-Integer Linear Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by