I try too find out the solution but is not work. Please help!
-
$\begingroup$ Tangentially related: (55352) $\endgroup$– Mr.WizardNov 10, 2019 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]}]]
-
1
-
1$\begingroup$ @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. :) $\endgroup$– ubpdqnNov 10, 2019 at 7:12
-
1$\begingroup$ Just for fun:
Pick[mesh, Last@*Ordering@*Through /@ {f, g, h} @@@ mesh, 1]
$\endgroup$ Nov 10, 2019 at 7:31 -
$\begingroup$ @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:) $\endgroup$– ubpdqnNov 10, 2019 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|> *)