Solving equation problem with constrains using the Optimization Toolbox

I have a problem with handful of variables and constrains, it look a lot like this one:
However, instead of finding the minimum cost like the problem above, I already have a target cost, but find the variables that fits this target cost. So I look at the equation problems:
But it seems that the equation problem wouldn't allow me to add constrains, what should I do?

 Respuesta aceptada

Matt J
Matt J el 12 de Nov. de 2021
Editada: Matt J el 12 de Nov. de 2021
Use your first approach except specify a least squares objective, like below.
x=optimvar('x','lower',0);
y=optimvar('y','lower',0);
target=10; %target cost
con(1)=x>=y;
con(2)=x+y>=1;
solve( optimproblem('Objective', (x+2*y-target).^2,'Constraints',con) )
Solving problem using lsqlin. Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
ans = struct with fields:
x: 3.8238 y: 3.0881
Be mindful, however, that the solution will probably be non-unique. For example, another solution to the example problem above is x=10, y=0.

7 comentarios

Thank you for your help! But how can I get all the possible solution, not just one, maybe in the form of plot?
Is it a 2D problem? You can't plot a 4+ dimensional polygon.
It is acutally a 3D problem.
Are all of the variables integer constrained? If so often to get "all" the solutions, using exhaustive search can be the easiest way -- construct all of the potential combinations of the variables, filter out the combinations that do not meet constraints, evaluate the function at each remaining combination.
Matt J
Matt J el 12 de Nov. de 2021
Editada: Matt J el 12 de Nov. de 2021
All points meeting the target cost satisfy the equation
dot(f,x)=targetCost
which is a line in 2D and a plane in 3D. The set of solutions will be the intersection of this line/plane with the convex region specified by your other constraints. You can compute the vertices of this intersection using intersectionHull() in this FEX package:
For example, applying this to the toy 2D problem above,
Aineq=[-1,1;
-1 -1;
-eye(2)]; bineq=[0;-1; 0 ;0]; %inequality constraints
f=[1 2];
targetCost=10;
I=intersectionHull('lcon',Aineq,bineq,[],[],'lcon',[],[],f,targetCost);
I.vert, %vertices
ans =
10.0000 0
3.3333 3.3333
In other words, the set of solutions are all points on the line segment from (x,y)=[3.33,3.33] to (x,y)=[10,0]. In 3D, if you had only inequality constraints, you would get vertices of a polygon floating in the plane dot(f,x)=targetCost. If you wanted to plot this region, you could feed the vertices to patch(), similar to the figure below.
If the set of solutions is all points on a particular line or particular plane, then you cannot return them all -- not unless you want to iterate over each distinguishable floating point number in the range.
That is why I was suggesting that the system needed to be integer constrained variables: for those it is possible to list all of the solutions (but it might need a lot of memory if the set of points is large enough.)
If the set of solutions is all points on a particular line or particular plane, then you cannot return them all
No, you can't, but it will be a convex polyhedral region and, if bounded, you can use its vertices both to plot the region and to sample an arbitrary number of points from its interior.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Quadratic Programming and Cone Programming en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Preguntada:

el 12 de Nov. de 2021

Comentada:

el 12 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by