I have mathematica 11.2 and I'm trying to find the maximum of this function: 3*(1 - 1/3 - y)*3*(-x - 1/3)*(x + y) where -1<x<1, -1<y<1 and xy>0. If I use Maximize I get this warning:

"Warning: there is no maximum in the region in which the objectivefunction is defined and the constraints are satisfied; a result on the boundary will be returned"

and I get {8, {x -> 1, y -> 1}}. I get the same values if I use NMaximize, however if I use FindMaximum I get: {0.0123457, {mf -> -0.444444, tf -> 0.555556}} which looks more reasonable.

However if I try to plot the function using Plot3D[3/1*(1 - 1/3 - y)*3/1*(-x - 1/3)*(x + y), {x, -1, 1}, {y, -1, 1}, AxesLabel -> Automatic, PlotRange -> {{-1, 1}, {-1, 1}, {0, 10}}, MaxRecursion -> 15] I get something very strange. Why is that?

  • 2
    $\begingroup$ I get exactly the same result from Maximize and FindMaximum but perhaps you are using those in a slightly different way from what I am guessing. If you include exactly the code that you are using then perhaps others can exactly reproduce your puzzling results. (Imagine the reader knows NOTHING more than what you have written about what you have done) For your "very strange" plot, your z plot range of {0,10} is cutting off everything below z==0 and I am guessing that is what you are confused by. If you change your z plot range to {-5,10} then you should get a less very strange plot. $\endgroup$ – Bill Apr 6 '18 at 16:46
  • $\begingroup$ Maximize[3*(1 - 1/3 - x)*3*(-x - 1/3)*(x + y), {x, y}] and FindMaximum[{3/1*(1 - 1/3 - y)*3/1*(-x - 1/3)*(x + y)}, {x, y}] is what I used. Maximize says Indeterminate, FindMaximum gives me 2.121756166887642*10^314 $\endgroup$ – Rby Apr 6 '18 at 17:17
  • 2
    $\begingroup$ Why don't you immediately simplify your equation and reduce useless terms? You have two factors of $3$, you have terms like $1 - 1/3$, and so on. At the very least it makes your problem easier to understand. $\endgroup$ – David G. Stork Apr 6 '18 at 17:36
  • 1
    $\begingroup$ Maximize[{3*(1-1/3-x)*3*(-x-1/3)*(x+y),-1<x<1&&-1<y<1&&x*y>0 },{x,y}] and FindMaximum[{3/1*(1-1/3-y)*3/1*(-x-1/3)*(x+y),-1<x<1&&-1<y<1&&x*y>0},{x,y}] enforce your constraints and return exactly the same result, well except for the second one including decimals for an approximate result $\endgroup$ – Bill Apr 6 '18 at 17:44
  • 1
    $\begingroup$ Plotting the function with Plot3D[3*(1 - 1/3 - y)*3*(-x - 1/3)*(x + y), {x, -1, 1}, {y, -1, 1}, PlotRange -> All] clearly shows the maximum occurs at {1,1}, but the surface is still rising which is what your message means by giving you a value on your boundary. $\endgroup$ – Bill Watts Apr 7 '18 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.