0
$\begingroup$

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.

Thank you in advance.

$\endgroup$
4
  • 1
    $\begingroup$ 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]] $\endgroup$ Commented Sep 3, 2022 at 7:05
  • $\begingroup$ 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? $\endgroup$
    – Nasser
    Commented Sep 3, 2022 at 7:20
  • 2
    $\begingroup$ {x + 1, x - y} /. sol[[2]] $\endgroup$
    – cvgmt
    Commented Sep 3, 2022 at 8:37
  • $\begingroup$ @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. $\endgroup$
    – user31694
    Commented Sep 3, 2022 at 9:04

1 Answer 1

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

(*   {3.88541, {x -> -0.99726, y -> -1.70026, v -> 0.00274, w -> 0.703}}   *)
$\endgroup$
1
  • $\begingroup$ Redefining with another variable really worked. Thank you. But I have constraint functions that are non-linear functions of the solution set. The functions are like eigenvalues that satisfy some constraints and the solution is the matrix elements I need to find. So in that case, I need not define with another equality in the FindMinimum command and when I include that function like you did with the solution set, the program is showing errors. Anyhow I am able to obtain what I wanted. $\endgroup$
    – user31694
    Commented Sep 4, 2022 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.