1

I have this table of values, how do I find the maximum value? i.e. find $z_{max}(x,y)$

tt1 = Table[Solve[z^2 == x^2 y - z, z, Method -> Reduce], {x, 0, 5, 1}, {y, 0, 
    5, 1}] 

By visual inspection, clearly max $z$ occurs at the most bottom right element in matrix, $z = \frac{1}{2}(-1 + \sqrt{501}) $

How do I get Mathematica to read out the position and value of maximum z?

I tried using:

Max[tt1]

but it didn't work..

user44840
  • 421
  • 3
  • 13

3 Answers3

3

We can adapt Sjoerd's solution to the question, Table - find index of the maximum element. Other methods may be found here: List manipulation: position & max value combination.

tt1 = Flatten[
   Table[Thread@{x, y, z /. Solve[z^2 == x^2 y - z, z, Method -> Reduce]},
    {x, 0, 5, 1}, {y, 0, 5, 1}],
   2];

Then this yields {x, y, max}:

tt1 ~Part~ Last @ Ordering @ tt1[[All, 3]]
(*
  {5, 5, 1/2 (-1 + Sqrt[501])}
*)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
1

Because of this comment the following becomes too long to be just a comment so here you go:

tt1 = Table[
   z /. Solve[z^2 == x^2 y - z, z, Method -> Reduce], {x, 0, 5,1}, {y, 0, 5, 1}];
Max[tt1]
Table[{x, y}, {x, 0, 5, 1}, {y, 0, 5, 1}][[Sequence @@ (First@Position[tt1, Max[tt1]])[[;; 2]]]]
1/2 (-1 + Sqrt[501])
{5, 5}
Öskå
  • 8,587
  • 4
  • 30
  • 49
1

Too long for a comment but... For your specific setup this can be a way with a v10 function:

tt1 = Table[Solve[z^2 == x^2 y - z, z, Method -> Reduce], {x, 0, 5, 1}, {y, 0, 5, 1}]
With[{v = z /. tt1}, With[{m = Max[v]}, {m, Most@FirstPosition[v, m]}]]

But... Why don't you solve analitically the problem? The command

z /. Solve[z^2 == x^2 y - z, z]

gives

{1/2 (-1 - Sqrt[1 + 4 x^2 y]), 1/2 (-1 + Sqrt[1 + 4 x^2 y])}

so it's not surprising the maximum is located at lower-right corner of the matrix, where $x=y=5$, and here

%[[2]] /. {x -> 5, y -> 5}

gives:

1/2 (-1 + Sqrt[501])
unlikely
  • 7,103
  • 20
  • 52