# How to define and plot a maximum function?

Define a function $g$ as follows:

f = 2/((x1 + Sqrt x2)^2 + (y1 + Sqrt y2)^2)
X = vx1^2*D[D[f, x1], x1] + vx2^2*D[D[f, x2], x2] + 2 vx1*vx2*D[D[f, x1], x2]
Y= vx1*D[f, x1] + vx2*D[f, x2]
g=X+Y^2


The function $g$ is clearly a function in 6 variables ($vx1,vx2,x1,x2,y1,y2$).

Now I want to define a function in two variables $max$ as the maximum of $g$ for $x1,x2,y1,y2$ which vary in the following hypersurface

H = ImplicitRegion[{3 (-x1^2 - y1^2 + x2^2 + y2^2) +
2 Sqrt (x1*x2 + y1*y2) == 0}, {x1, y1, x2, y2}]


So I want to (but I don't know how to) define the function $max:\mathbb{R}^2\rightarrow \mathbb{R}$ as follows:

$$max(vx1,vx2)=\max\limits_{(x1,x2,y1,y2)\in H}g(vx1,vx2,x1,x2,y1,y2)$$

All I could think of is the command

FindMaximum[{g, {x1, y1, x2, y2} ∈ H}, {x1, y1, x2, y2}]


but this doesn't define a function, it just gives the maximum of $g$ for specific values of $vx1,vx2$.

How can I define the function $max$? It's important to me to define it as a function because I need to

• derive it in its smooth points

• plot it

• define other functions which involve $max$ in their definition

How can I do it?

EDIT: I followed the suggestions of user Corey979 and defined the function max[vx1,vx2], but with FindMaximum substitued by MaxValue, since I'm interested in the maximum value (as I thought was clear in my definition). But then I'm not able to do any operation with the function max:

Any of these operations

D[max[vx1, vx2], vx1]

Plot3D[max[vx1, vx2], {vx1, -10, 10}, {vx2, -10, 10}]

FindMaximum[{max[vx1, vx2]}, {vx1, vx2}]


Will require an extremely long computational time and will give no output. Which is strange, since with my old code

f = 2/((x1 + Sqrt x2)^2 + (y1 + Sqrt y2)^2)
X = vx1^2*D[D[f, x1], x1] + vx2^2*D[D[f, x2], x2] + 2 vx1*vx2*D[D[f, x1], x2]
Y= vx1*D[f, x1] + vx2*D[f, x2]
g=X+Y^2
H = ImplicitRegion[{3 (-x1^2 - y1^2 + x2^2 + y2^2) +
2 Sqrt (x1*x2 + y1*y2) == 0}, {x1, y1, x2, y2}]
FindMaximum[{g, {x1, y1, x2, y2} ∈ H}, {vx1,vx2,x1, y1, x2, y2}]


I was able to get the answer

{2.39111, {vx1 -> 1.55608, vx2 -> 1.96316, x1 -> 0.810245, y1 -> -0.236216, x2 -> 1.34919, y2 -> -0.463331}}


Is there a better way to define max in such a way that it will be possible to perform operations with it?

• What are some typical values of vx1 and vx2? – corey979 Jan 17 '17 at 10:38
• Let's just assume that the domain of $h$ is $\mathbb{R}^2$ – User28341 Jan 17 '17 at 12:21
• The underscore Blank (_) is used when defining functions, like f[x_]:=x^2; then you call it normally with f[x]. You can't have them in expressions like D[max[vx1_, vx2_], vx1] or FindMaximum[{max[vx1_, vx2_]}, {vx1, vx2}]. That's a simple syntax error. – corey979 Jan 17 '17 at 12:22
• Also, you should read the docs of FindMaximum as you misunderstand its output - with my def of max, FindMaximum[{max[vx1, vx2]}, {vx1, vx2}] makes no sense. – corey979 Jan 17 '17 at 12:28
• I corrected the $_$ error. As I wrote in the definition of $h$, $h$ is defined as the maximum value of g. should I substitute FindMaximum with MaxValue in your code? If yes, then I'm not able to do any computation with max function, because the computational time is too long – User28341 Jan 17 '17 at 12:41

f[x1_, x2_, y1_, y2_] :=
2/((x1 + Sqrt x2)^2 + (y1 + Sqrt y2)^2)

X[vx1_, vx2_, x1_, x2_, y1_, y2_] :=
vx1^2*D[D[f[x1, x2, y1, y2], x1], x1] +
vx2^2*D[D[f[x1, x2, y1, y2], x2], x2] +
2 vx1*vx2*D[D[f[x1, x2, y1, y2], x1], x2]

Y[vx1_, vx2_, x1_, x2_, y1_, y2_] :=
vx1*D[f[x1, x2, y1, y2], x1] + vx2*D[f[x1, x2, y1, y2], x2]

g[vx1_, vx2_, x1_, x2_, y1_, y2_] :=
X[vx1, vx2, x1, x2, y1, y2] + Y[vx1, vx2, x1, x2, y1, y2]^2

H = ImplicitRegion[{3 (-x1^2 - y1^2 + x2^2 + y2^2) + 2 Sqrt (x1*x2 + y1*y2) == 0}, {x1, y1, x2, y2}]


Define the max as a function:

max[vx1_, vx2_] :=
FindMaximum[{g[vx1, vx2, x1, x2, y1,
y2], {x1, y1, x2, y2} ∈ H}, {x1, y1, x2, y2}]


Then

m = max[1000., 1000.] (The value of the maximum is a numerical zero; you might want to incorporate Chop in max.) Verify that the solution is in H:

m[[2, All, 2]] ∈ H


True

• thank you for your answer, but doing as you said I then encountered some problems trying to do operations with function max. I edited my question because it took too long to explain the problems in comments, I hope it's all right. – User28341 Jan 17 '17 at 12:18