Function minimization with equality constraints in Mathematica 8
Asked Answered
D

3

7

When using constraints with simple equality in Mathematica 8, minimization doesn't work. E.g.

FindMinimum[{x^2 + y^2,  y == 1}, {x, y}]

works ok in Mathematica 6, but gives errors in version 8. Can anyone else confirm (or explain) this? Looks like fixing one of the parameters with a constraint confuses version 8. Putting xy==1 is OK, also any inequality.

Any simple workaround on this? I have tried changing the Method, no luck. I would like to keep all the parameters in the parameter list, but hold some of them with simple constraint instead of removing the parameter name from the list. I have a working code in version 6, which does not work anymore in 8.

Discursive answered 20/5, 2011 at 11:52 Comment(1)
This seems like a bug to me; consider reporting it to Wolfram.Removal
M
2

Your syntax appears to be incorrect:

FindMinimum[{x^2 + y^2,  y == 1}, {x, y}]

which asks to start x with a value of y. This doesn't make much sense to me.

Perhaps you are attempting to do:

Minimize[{x^2 + y^2, y == 1}, {x, y}]
  Out:  {1, {x -> 0, y -> 1}}

Apparently your syntax is valid. Consider Minimize as shown above to be a possible work-around for your problem.

Mccleary answered 20/5, 2011 at 12:26 Comment(5)
The documentation suggests that his syntax is reasonable. Here's an example: FindMinimum[{x + y, x + 2 y >= 3 && x >= 0 && y >= 0 && y [Element] Integers}, {x, y}]Removal
@Removal to my surprise you're right! I have never used FindMinimum that way. I still don't know that it makes sense. I guess there is another problem at work here, but I don't have time to search for it.Mccleary
I was equally surprised; from the syntax coloring, it seems that the Mathematica front-end is also surprised (notice the funny combination of green for x and blue for y).Removal
I was trying to make a "simplest example". I actually use the notation with starting points, but it does not change the fact, that the code, that used to work in 6 is broken in 8. I'll check if the Minimize is a good replacement, thanks for the tip. I suspect more and more that this is a bug in Mathematica 8.Discursive
@Boocko, as a point of reference, I use Mathematica 7 and I also get errors and no output for your test case.Mccleary
G
3

Another workaround would be to use version 9.

In[1]:= FindMinimum[{x^2 + y^2, y == 1}, {x, y}]
Out[1]= {1., {x -> 0., y -> 1.}}

Which is to say, what you show above is a bug that has kindly fixed itself for a future release.

Daniel Lichtblau Wolfram Research

Gorge answered 20/5, 2011 at 14:5 Comment(2)
Thanks,Daniel Lichtblau. Would you please help me test the following optimization code in version 9? a = ((x - 50)^2 + (y - 50)^2)^(1/2) + E; f = Sin[a]/a + 1; NMinimize[{f, 0 <= x <= 100, 0 <= y <= 100}, {x, y}]Hyalo
Do you suggest the v9 release is nearby then?Spurrier
M
2

Your syntax appears to be incorrect:

FindMinimum[{x^2 + y^2,  y == 1}, {x, y}]

which asks to start x with a value of y. This doesn't make much sense to me.

Perhaps you are attempting to do:

Minimize[{x^2 + y^2, y == 1}, {x, y}]
  Out:  {1, {x -> 0, y -> 1}}

Apparently your syntax is valid. Consider Minimize as shown above to be a possible work-around for your problem.

Mccleary answered 20/5, 2011 at 12:26 Comment(5)
The documentation suggests that his syntax is reasonable. Here's an example: FindMinimum[{x + y, x + 2 y >= 3 && x >= 0 && y >= 0 && y [Element] Integers}, {x, y}]Removal
@Removal to my surprise you're right! I have never used FindMinimum that way. I still don't know that it makes sense. I guess there is another problem at work here, but I don't have time to search for it.Mccleary
I was equally surprised; from the syntax coloring, it seems that the Mathematica front-end is also surprised (notice the funny combination of green for x and blue for y).Removal
I was trying to make a "simplest example". I actually use the notation with starting points, but it does not change the fact, that the code, that used to work in 6 is broken in 8. I'll check if the Minimize is a good replacement, thanks for the tip. I suspect more and more that this is a bug in Mathematica 8.Discursive
@Boocko, as a point of reference, I use Mathematica 7 and I also get errors and no output for your test case.Mccleary
H
1
In[31]:= NMinimize[{x^2 + y^2, y == 1}, {x, y}]

Out[31]= {1., {x -> -3.20865*10^-9, y -> 1.}}

In[32]:= FindMinimum[{x^2 + y^2, 1 - 10^-10 <= y <= 1 + 10^-10}, {x, y}]

Out[32]= {1., {x -> 0., y -> 1.}}

However, I wonder how to force mma to keep on searching even if it encounters a infinite expression? Can anybody share your idea?

thanks ^_^

Hyalo answered 20/5, 2011 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.