moba6031
(Joel Nabi)
January 19, 2020, 6:18pm
1
Have a figure: x^4 + y^4 + 62x^2 y^2=1 inside {x,-1,1},{y,-1,1}
want to “estimate” the area of the figure inside using random dots.
dots = RandomReal[{-1, 1}, {1000, 2}];
tester[x_, y_] := x^4 + y^4 + 62*x^2*y^2 <= 1;
infigure = Select[dots, tester];
notinfigure = Complement[dots, infigure];
p1 = ContourPlot[{x^4 + y^4 + 62*x^2*y^2 == 1}, {x, -1, 1}, {y, -1,
1}];
p2 = ListPlot[{infigure, notinfigure}, PlotStyle -> {Green, Blue}];
here I’m getting an error with the plotlist, it generates numbers within -1,1 and then says they are not numbers…
Show[p1,p2]
What am i doing wrong? I did this with the unit circle and it shows fine.
dontdont9
(Bill Nelson)
January 19, 2020, 6:54pm
2
Try changing
tester[x, y] := x^4 + y^4 + 62x^2y^2 <= 1;
to
tester[{x_, y_}] := x^4 + y^4 + 62x^2y^2 <= 1;
and if that works then study that until you understand that change.
There are other ways you could accomplish the same result.
danl
(Daniel Lichtblau)
January 19, 2020, 6:55pm
3
I’m guessing tester[x, y] should instead be tester[x_, y_] .That is to say, pattern variables instead of literal matches to symbols x and y.
neils
(Neil Singer)
January 19, 2020, 7:12pm
4
Joel,
Your bug was identified, but you could also do it with ImplicitRegion (this is a bit faster than the posted approach although the difference is insignificant)
reg=
ImplicitRegion[x^4 + y^4 + 62 x^2 y^2 <= 1, {x, y}];
pts = RandomReal[{-1, 1}, {10000, 2}];
inside = Count[RegionMember[reg, pts], True];
Regards,
Neil
moba6031
(Joel Nabi)
January 19, 2020, 7:16pm
5
i had it as tester[{x_,y_ }] with underscore it wont let me do underscore here for some reason.
nothing changed.
neils
(Neil Singer)
January 19, 2020, 7:27pm
6
you must post code with the code button (second from the upper left) or the text will be altered (missing underscores, etc.)