Avoid issues with a simple Monte-Carlo problem?

Have a figure: x^4 + y^4 + 62x^2y^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.

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.

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.

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

i had it as tester[{x_,y_ }] with underscore it wont let me do underscore here for some reason.

nothing changed.

you must post code with the code button (second from the upper left) or the text will be altered (missing underscores, etc.)