# Problem with constraints of NMaximize

I am using NMaximize to solve the following problem.

Mh = 95.;
MH = 125.18;
v = 246.22;
l1[a_, b_,M12_] := (Sin[a]^2 MH^2+Cos[a]^2 Mh^2 - (M12) Tan[b])/(Cos[b]^2 v^2);
l2[a_, b_,M12_] := (Cos[a]^2 Mh^2+Sin[a]^2 MH^2 - ((M12)/Tan[b]))/(Sin[b]^2 v^2);
l3[a_, b_, MC_,M12_] := ((Sin[2. a]) (Mh^2 - MH^2) + 2. (M12)+2. (MC^2) Sin[2. b])/(Sin[2. b] v^2);
l4[b_, MC_, MA_,M12_] := (MA^2 - 2. (MC^2) - (2 (M12)/Sin[2b]))/(v^2);
l5[b_, MA_, M12_] := ((2. (M12)/Sin[2. b]) - MA^2)/v^2;

Pert[a_, b_, MC_, MA_, M12_] := Abs[l1[a, b, M12]] <= 4.*N[Pi, 4] && Abs[l2[a, b, M12]] <= 4.*N[Pi, 4] && Abs[l3[a, b, MC, M12]] <= 4.*N[Pi, 4] && Abs[l4[b, MC, MA, M12]] <= 4.*N[Pi, 4] &&
Abs[l5[b, MA, M12]] <= 4.*N[Pi, 4]

Mct[a_, b_, MC_, MA_, M12_] := MC + 0*(a + b + MC + MA + M12)
NMaximize[{Mct[a, b, MC, MA, M12],Pert[a, b, MC, MA, M12]}, {a, b, MC, MA, M12}]


The result is:

{628.097, {a -> 453.086, b -> 427.368, MC -> 628.097, MA -> -589.965, M12 -> 254.967}}


which seems like there is no problem.

Then, I put the result back into the constraint Pert. It shows:

Pert[453.08648222747297, 427.368470714907, 628.097417629226,-589.965030031508, 254.96714952092478]
False


That means the result doesn't obey the constraint. Is there anything wrong with my code?

• Not the real problem, but you should better replace Beta by another symbol; Beta is the built-in symbol for the Euler beta function. – Henrik Schumacher Jan 31 '19 at 8:11
• Please check your code, I can't reproduce your results. In your constraint Pert I found <...4.*N[Pi, 4]. What 's your intention reducing the accuracy? Better substitute <...4Pi. one last remark: If you check your constraint by substituting the result there might be rounding effects causing False. Try Pert[Alpha, Beta, MC, MA, M12] /.LessEqual->Subtract – Ulrich Neumann Jan 31 '19 at 8:17
• Hi. I change Beta to b and Alpha to a. The result show different value but checking with the constraint still returns False. Also tried Pert[Alpha, Beta, MC, MA, M12] /.LessEqual->Subtract – Panithi Nakkhruea Jan 31 '19 at 8:26
• ...and Pert[Alpha, Beta, MC, MA, M12] /.LessEqual->Subtract  gives a list of small negative numbers? – Ulrich Neumann Jan 31 '19 at 9:03
• @UlrichNeumann No. It returns False – Panithi Nakkhruea Jan 31 '19 at 9:20

If you name the result of NMaximize opt you can check the constraints as follows:

Pert[a, b, MC, MA, M12] /. LessEqual -> Subtract /. opt[[2]]
(*-12.3711 && -8.19684*10^-10 && 1.31202*10^-11 && -1.26459 &&-10.8498*)


Every constraint is negativ! Second and third are very small and cause the False in

Pert[a, b, MC, MA, M12] /. opt[[2]]
(* False *)
Pert[a, b, MC, MA, M12] /. And -> List /. opt[[2]]
(*{True, True, False, True, True}*)

• So, how can I fix this? And what does the very small value mean? – Panithi Nakkhruea Jan 31 '19 at 14:20
• You don't have to fix it! It is a numerical accuracy issue. – Ulrich Neumann Jan 31 '19 at 15:17
• Could you explain me what the result of Pert[a, b, MC, MA, M12] /. LessEqual -> Subtract /. opt[[2]] means? – Panithi Nakkhruea Jan 31 '19 at 15:31
• That means the inequalitis a<=b is changed to a-b. – Ulrich Neumann Jan 31 '19 at 15:51
• Ok, I see. That means it should show only negative value or zero. The third value is very small (approaching zero), so this makes it return False, right? Could you edit your answer and add the explanation on it? Thank you so much for your help. – Panithi Nakkhruea Jan 31 '19 at 16:16