# Imposing constraints to NMinimize/NMaximize leads to wrong function values [closed]

I wrote a function that uses NMaximize to find certain parameters (using NelderMead simplex algorithm). My objective functional $J({x_i})$ is real-valued and its values can only be between 0 and 1, i.e. $0 \leq J({x_i}) \leq 1 \quad \forall i$.

If I start the bare NelderMead algorithm without constraints on my parameters everything works fine, although the obtained parameters sometimes are not feasible for the underlying model. That is why I am imposing constraints on the parameters. For that, I call NMinimize as follows:

nbr=0;
NMinimize[
{objective[vars], constraints},
vars,
EvaluationMonitor :> {nbr += 1; If[Mod[nbr, steps] == 0, Print["Step: ", nbr, " ; Current error: ", objective[vars], vars], Print]}];


where constraints looks like -1<=x1<=1&&-2<=x2<=2 for example. The problem now is that I see from the EvaluationMonitor of NMaximize that I get values larger than 1. Plugging the parameters for which I obtain the "wrong" results into my model shows that the value for those parameters vars is NOT larger than 1. So, how can it be that NMaximize produces wrong values during the algorithm if I impose constraints?

## closed as off-topic by MarcoB, march, happy fish, Wjx, m_goldbergOct 6 '16 at 14:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, march, happy fish, Wjx, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

• Can you post your objective function and constraints? Without them it's hard to test/repeat your problem. – dr.blochwave Apr 5 '15 at 15:31
• As that involves solving a system of differential equations and a few functions, I will move all relevant things into a notebook and post a link to that here to maintain readability. I will do that within the next 1-2 hours. – Lukas Apr 5 '15 at 15:34
• Can you provide a simple objective function that exhibits the behavior that concerns you? – bbgodfrey Apr 5 '15 at 16:05
• While reducing my code I must have introduced some error. So most certainly it will take longer than announced to upload and post the code here. Sorry for that! – Lukas Apr 5 '15 at 16:43
• NMinimize works by imposing penalties on some types of constraint violations. So it is common to have constraint violations at intermediate stages. That said, rectangular inequality constraints should not be violated (unless some variables are eliminated from equality constraints, which does not seem to be the case here). – Daniel Lichtblau Apr 5 '15 at 17:20