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 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear 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!