# Maximize this function

For the following matrix

$$M = \begin{pmatrix} f1[x,y,z] & f2[x,y,z]\\ g1[x,y,z] & g2[x,y,z]\\ h1[x,y,z] & h2[x,y,z] \end{pmatrix}$$

with

f1[x_,y_,z_] := E^(-E^(2 Im[x]) Abs[y Sqrt[1 - z] + 0.1 Sqrt[z]]^2)
g1[x_,y_,z_] := E^(-E^(2 Im[x]) Abs[y Sqrt[1 - z] + 0.1 I Sqrt[z]]^2)
h1[x_,y_,z_] := E^(-E^(2 Im[x]) Abs[y Sqrt[1 - z] + Sqrt[z]]^2)

f2[x_,y_,z_] := E^(-E^(2 Im[x]) Abs[y Sqrt[1 - z]])
g2[x_,y_,z_] := E^(-E^(2 Im[x]) Abs[y Sqrt[1 - x]])
h2[x_,y_,z_] := E^(-E^(2 Im[x]) Abs[y Sqrt[1 - y]])


Now I want to optimise the value of:

P = f1[x,y,z] pos + f2[x,y,z] pos


where pos[j] returns the row corresponding to the highest value in column j . However, I don't know how to define pos[j]. I currently have

MWE

pos = Position[{f1[x,y,z], g1[x,y,z], h1[x,y,z]]}, Max[f1[x,y,z], g1[x,y,z], h1[x,y,z]]]

pos = Position[{f2[x,y,z], g2[x,y,z], h2[x,y,z]]}, Max[f2[x,y,z], g2[x,y,z], h2[x,y,z]]]

Poptimized = Maximize[P, {x, y, z}]

But this is not working. This is since pos and pos return empty lists. I thought that wrapping it inside the Maximize would have it evaluate. I want something structured as follows:

Maximize[f1[x,y,z] pos + f2[x,y,z] pos,{x,y,z}]


where pos and pos both also depend on x,y,z and so need to be optimised too.

• Shouldn't you use f1[x_,y_,z_] := ...? Dec 4 '19 at 19:18
• Yes, that was a typo ...
– Sid
Dec 4 '19 at 19:20
• f2=g2=h2?.... Dec 4 '19 at 19:36
• Does ArgMax do what you want? Dec 4 '19 at 19:50
• $x\in Reals$ why do you need Im[x]=0 and so f1[x_,y_,z_] := E^(-E^(2 Im[x]) Abs[y Sqrt[1 - z] + 0.1 Sqrt[z]]^2)= f1[x_,y_,z_] := E^(-Abs[y Sqrt[1 - z] + 0.1 Sqrt[z]]^2) Dec 4 '19 at 20:00

Not a complete answer but try this. Since all function has the same max value, how do you decide which function you choose? Mathematica chose the last one.

M = {{-x - y^2 - 2 z , x - y^2 + 2 z },
{-x - y - z^2, x + 2 y + z^2},
{-x - y - z^3, 2 x - y + z}};


$$M=\left( \begin{array}{cc} -x-y^2-2 z & x-y^2+2 z \\ -x-y-z^2 & x+2 y+z^2 \\ -x-y-z^3 & 2 x-y+z \\ \end{array} \right)$$

pos1 = First@Ordering[MaxValue[#, {x, y, z}] & /@ M[[All, 1]], -1]
pos2 = First@Ordering[MaxValue[#, {x, y, z}] & /@ M[[All, 2]], -1]

P = NMaximize[M[[1,1]] pos1 + M[[1,2]] pos2,{x, y, z}]

• You are correct that each row has two columns. However, I am trying to find the maximum values in each column. Hence, for the above example, pos looks for the row corresponding to the max value in column 1. That is pos=Ordering[MaxValue[#, {x, y, z}] & /@ func, -1].
– Sid
Dec 6 '19 at 18:06
• I want to then determine the optimised value for P = f1[x,y,z] pos + f2[x,y,z] pos, where f1[x,y,z] = x + y^2 + 2z and f2[x,y,z] = x + y + z^2. Can I use your above code inside the Maximize function?
– Sid
Dec 6 '19 at 18:12
• I want something structured as follows: Maximize[f1[x,y,z] pos + f2[x,y,z] pos,{x,y,z}]. How can I define pos[j] such that it it takes performs the optimisation and returns the row position as described in the question?
– Sid
Dec 6 '19 at 18:43
• These functions are unbounded above f1[x,y,z] = x + y^2 + 2z and f2[x,y,z] = x + y + z^2 Can you edit the question with your real problem if it is not too complicated. Dec 6 '19 at 20:24
• The actual functions i'm using are very lengthy. However x, y, z are all finite. Can you describe how pos1 is defined please? It's correctly looking at column 1, but how is it looking for the MaxValue? (i.e. what values for x,y,z is it using to determine which is largest)
– Sid
Dec 6 '19 at 22:57