Maximize a bivariate function in Maple

203 Views Asked by At

I have the following function ($\theta$ is a parameter with known value, e.g. $\theta=1$): $$ f:=\frac{xy}{1+\theta (1-x)(1-y)} $$ and I want to maximize its second-order partial derivative in Maple for $x,y\in [0,1]$. My code was as follows:

$$ fxy:=\frac{\partial^2}{\partial x \partial y}f $$

I use "maximize()" as follows, but it gives me the wrong answer:

Optimization:-Maximize(fxy, x = 0 .. 1, y = 0 .. 1)

I would appreciate it if anyone could help me.

1

There are 1 best solutions below

0
On BEST ANSWER

Note that Maple's Optimization package offers only local solvers for nonconvex multivariate problems. So the initial point can matter.

Forcing a more fortuitous initial point, or another method, can help. Eg,

restart;
f := x*y/(1+theta*(1-x)*(1-y)):
fxy := diff(eval(f,theta=1),x,y):

Optimization:-Maximize(fxy, x = 0 .. 1, y = 0 .. 1,
                       method=modifiednewton);

                 [2., [x = 0., y = 1.]]

Optimization:-Maximize(fxy, x = 0 .. 1, y = 0 .. 1,
                       method=sqp, initialpoint=[x=0.51,y=0.49]);

                 [2., [x = 1., y = 0.]]

Unfortunately, with this particular choice of range the default method appears to be returning a saddle point (likely using an initial point of [0.5,0.5]).

# uses method=sqp here
sad := Optimization:-Maximize(fxy, x = 0 .. 1, y = 0 .. 1);

      sad := [1.03521665624990256,
             [x = 0.552786404455194, y = 0.552786404455196]]

eval(diff(fxy,x),sad[2]), eval(diff(fxy,y),sad[2]);

                            -10                     -10
         1.93439708695564 10   , 1.93446592078317 10   

plots:-display(
  plots:-pointplot3d([[eval([x,y],sad[2])[],sad[1]]],
                     color=red,symbolsize=30,symbol=solidsphere),
  plot3d(fxy, x=0..1, y=0..1)
);

enter image description here

Using a global solver can make this easier. Below I'll use the 3rd party add-on DirectSearch package.

DirectSearch:-GlobalSearch(fxy, [x=0..1, y=0..1], maximize);

 [[1.99999999774906, [x = 0.999999999969016, y = 0.1063501190*10^(-8)], 68],
  [1.99999999741613, [x = 0.7116227275*10^(-9), y = 0.999999999709843], 65]])

In recent Maple versions (eg, Maple 2017 and newer) you can install that add-on package directly from Maple itself, via the MapleCloud sign-in (top right of the main menu icon bar). Or by downloading from its site on the MapleCloud.

In version Maple 2016, etc, the DirectSearch ver.2 package can still be downloaded for installation from the Application Center.