plotting - How to find and count the points that are elements of ${(x,y)inmathbb{Z}^2:x^2+y^2le16 wedge |y|gt x}$?
I am given the following set:
$\qquad \{(x,y)\in\mathbb{R}^2:x^2+y^2\le16 \wedge |y|\gt x\}$
I want find and count the number of points in this set that have integer coordinates.
I drew this to help me visualize the problem.
ClearAll["Global`*"];
Plot[{y /. Solve[x^2 + y^2 == 16, y], x, -x}, {x, -5, 5},
PlotStyle -> {Solid, Dashed, Dashed},
AspectRatio -> 1,
PlotRange -> {{-5, 5}, {-5, 5}},
PlotTheme -> "Detailed",
GridLines -> {{-4, -3, -2, -1, 0, 1, 2, 3, 4}, {-4, -3, -2, -1, 0, 1, 2, 3, 4}}]
I want to mark all of those points which are inside the set red as well as count them.
What should I do?
Answer
Just solve it:
sol = Solve[x^2 + y^2 <= 16 && Abs[y] > x, {x, y}, Integers];
Get how many:
Length@sol
Make the points (set point size or use Disk
if you want bigger):
gr = Graphics[{Red, Point[{x, y}] /. sol}];
Then show them together:
Show[{Plot[{y /. Solve[x^2 + y^2 == 16, y], x, -x}, {x, -5, 5},
PlotStyle -> {Solid, Dashed, Dashed}, AspectRatio -> 1,
PlotRange -> {{-5, 5}, {-5, 5}}, PlotTheme -> "Detailed",
GridLines -> {{-4, -3, -2, -1, 0, 1, 2, 3, 4}, {-4, -3, -2, -1, 0,
1, 2, 3, 4}}], gr}]
Comments
Post a Comment