# At how many of these points is f(x,y) (strictly) greater than both g(x,y) and h(x,y)? and

I try too find out the solution but is not work. Please help!

This what I wrote:

• Tangentially related: (55352) – Mr.Wizard Nov 10 '19 at 7:36

## 3 Answers

First, define functions.

Next, use Outer to get the function values as matrices..

Matrices can be compared elementwise.

Posting code rather than images helps people providing answers.

There are syntax errors in the image of the code. sin should be Sin.

Here is an approach defining functions (as suggested by @Alan) and using Tuples, though Outer and matrices could be used.

The solution to the first question can be plotted to confirm result. I leave the second question to OP. I hope this is instructive:

f[x_, y_] := x^3 + y^2 - 30 x y - 2
g[x_, y_] := x Sin[x + y] + 6 y
h[x_, y_] := (x^3 + y^3)/(x^2 + Exp[y/100])
mesh = Tuples[Range[-1, 1, 0.1], 2];
fm = f @@@ mesh;
gm = g @@@ mesh;
hm = h @@@ mesh;
fg = Sign[fm - gm] /. -1 -> 0;
fh = Sign[fm - hm] /. -1 -> 0;
pos = Position[fg fh, 1] ;
ans = Extract[mesh, pos]
Length[ans]/Length[mesh]
Show[Plot3D[{f[x, y], g[x, y], h[x, y]}, {x, -1, 1}, {y, -1, 1},
Mesh -> None, PlotRange -> Full, PlotLegends -> "Expressions"],
Graphics3D[{Red, Point[{#1, #2, f[#1, #2]} & @@@ ans]}]]


• Consider ans = Pick[mesh, fg fh, 1]; – Mr.Wizard Nov 10 '19 at 7:10
• @Mr.Wizard thank you. I must admit I did not spend much time on this but Pick is much nicer way to extract flat list. Appreciate the feedback. :) – ubpdqn Nov 10 '19 at 7:12
• Just for fun: Pick[mesh, Last@*Ordering@*Through /@ {f, g, h} @@@ mesh, 1] – Mr.Wizard Nov 10 '19 at 7:31
• @Mr.Wizard love the use of left composition and Ordering. I continue to enjoy the creativity even if I have not been around as much. Thanks for the comments:) – ubpdqn Nov 10 '19 at 7:34

Another option

f[x_, y_] := x^3 + y^2 - 30*x*y - 2;
g[x_, y_] := x*Sin[x + y] + 6*y
h[x_, y_] := (x^3 + y^3)/(x^2 + Exp[y/100]);

pointsf = Table[f[x, y], {x, -1, 1, 0.1}, {y, -1, 1, 0.1}] // Flatten;
pointsg = Table[g[x, y], {x, -1, 1, 0.1}, {y, -1, 1, 0.1}] // Flatten;
pointsh = Table[h[x, y], {x, -1, 1, 0.1}, {y, -1, 1, 0.1}] // Flatten;

pointsf // MapIndexed[(# > pointsg[[First@#2]] && # > pointsh[[First@#2]]) &] // Counts

(* <|False -> 289, True -> 152|> *)