I am migrating an excel model to matlab. The orginal model defines decision variables in then constraints. How can I do the same?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Jaynik
el 18 de Abr. de 2024
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 comentarios
Ver también
Categorías
Más información sobre Linear Programming and Mixed-Integer Linear Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!