# How do we extract exact constraint function values from FindMinimum?

When we use optimization command such as e.g. FindMinimum, we minimize a function subject to the given constraints and seek to find the optimal solution where these constraints are satisfied. Now I would like to know the exact values of the constraint functions. How do we extract this information from the FindMinimum command? For example,

sol=FindMinimum[{x^2+y^2, 0.00211 <= x+1 <= 0.00274, 0.703 <= x-y <= 0.963},{,x,y}]


I would like to extract the exact values of x+1 and x-y directly from the sol but not by again writing another few of lines to find those values from defining sol[[2,1]] etc.. The above given code is arbitrary and need not have a solution.

• Try: {x + 1, x - y} /. FindMinimum[{x^2 + y^2, 0.00211 <= x + 1 <= 0.00274, 0.703 <= x - y <= 0.963}, {x, y}][[2]] Sep 3, 2022 at 7:05
• but not by again writing another few of lines to find those values from defining sol[[2,1]] etc.. The above given code is arbitrary and need not have a solution. Since the x and y are returned in the solution, is the issue then how to check that FindMinimum was successful or not before extracting these? If not, what exactly is the problem? As Daniel showed above, you can just read these from the result returned. All what you have to do, is check that it did find a minimum. Right? Is there any other issue? Sep 3, 2022 at 7:20
• {x + 1, x - y} /. sol[[2]] Sep 3, 2022 at 8:37
• @Nasser The actual code has many constraints and in some variations of the problem that I have, I get a solution only when some constraints are excluded. I need to find the value of that excluded constraint function for the obtained solution. Sep 3, 2022 at 9:04

sol = FindMinimum[{x^2 + y^2, 0.00211 <= x + 1 == v <= 0.00274,