I have problems with some applications for finding convergence - below is one example of failure for {x=0.35,y=0.35,z=0.3}, but it works fine for {x=0.3,y=0.3,z=0.4}.
How can I increase the iterations or change the precision in this structure?
Clear["Global`*"]
SetDirectory[NotebookDirectory[]]
f[a_, b_, c_, x1_, x2_, x3_, y1_, y2_, y3_, z1_, z2_, z3_] := (a*x1)/(
a*x1 + b*y1 + c*z1) + (a*x2)/(a*x2 + b*y2 + c*z2) + (a*x3)/(
a*x3 + b*y3 + c*z3)
x = 0.35
y = 0.35
z = 0.3
g1[x1_, x2_, x3_] := x1 + x2 + x3 - 3*x
g2[y1_, y2_, y3_] := y1 + y2 + y3 - 3*y
g3[z1_, z2_, z3_] := z1 + z2 + z3 - 3*z
g4[x1_, y1_, z1_] := x1 + y1 + z1 - 1
g5[x2_, y2_, z2_] := x2 + y2 + z2 - 1
g6[x3_, y3_, z3_] := x3 + y3 + z3 - 1
inputs = {
{1, 5, 1},
{3, 5, 1},
{5, 5, 1},
{7, 5, 1},
{10, 5, 1},
{1, 5, 3},
{3, 5, 3},
{5, 5, 3},
{7, 5, 3},
{10, 5, 3},
{1, 5, 5},
{3, 5, 5},
{5, 5, 5},
{7, 5, 5},
{10, 5, 7},
{1, 5, 7},
{3, 5, 7},
{5, 5, 7},
{7, 5, 7},
{10, 5, 7},
{1, 5, 10},
{3, 5, 10},
{5, 5, 10},
{7, 5, 10},
{10, 5, 10}
} // Rationalize;
(table =
Prepend[Flatten[{#, {#[[1]], Values[#[[2]]]} &@
Maximize[{f[#[[1]], #[[2]], #[[3]], x1, x2, x3, y1, y2, y3, z1, z2, z3],
g1[x1, x2, x3] == 0, g2[y1, y2, y3] == 0, g3[z1, z2, z3] == 0,
g4[x1, y1, z1] == 0, g5[x2, y2, z2] == 0, g6[x3, y3, z3] == 0,
x1 >= 0, x2 >= 0, x3 >= 0, y1 >= 0, y2 >= 0, y3 >= 0,
z1 >= 0, z2 >= 0, z3 >= 0, x1 <= 1, x2 <= 1, x3 <= 1,
y1 <= 1, y2 <= 1, y3 <= 1, z1 <= 1, z2 <= 1, z3 <= 1},
{x1, y1, z1, x2, y2, z2, x3, y3, z3}, Reals]}]
& /@ inputs, {"a", "b", "c", "f", "x1", "y1", "z1",
"x2", "y2", "z2", "x3", "y3", "z3"}]) //
Grid[#, Frame -> All] &
Export["Output/table.xls", table /. r_Rational :> N[r, 2], "xls"]
Error message -- NMaximize: Failed to converge the requested accuracy or precision within 100 iterations.
Thank you!
MaxIterations->10^3
and see if that helps. You can also change your decimal constants (which are limited to MachinePrecision) to rationals (which have infinite precision) which will allow you to insert something likeWorkingPrecision->64
and see if that helps. Bump these up or down a little at a time, not thinking a billion iterations should be better or a million digits of precision should be better $\endgroup$