5
$\begingroup$

I have a list of xi,yi points. I want to remove any points from the list where x^2+y^2<1. I probably have to write a for loop of some sorts, not sure how to begin.

Subscript[x, i] = -2 + 0.2 m;
m = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20};
Print[Subscript[x, i]];
Subscript[y, i] = .2 q;
q = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Print[Subscript[y, i]]
a = {-1.8, -1.6, -1.4, -1.2, -1., -0.8, -0.6, -0.4, -0.2, 0., 0.2, 
0.4, 0.6, 0.8, 1., 1.2, 1.4, 1.6, 1.8, 2.};
b = {0.2, 0.4, 0.6, 0.8, 1., 1.2, 1.4, 1.6, 1.8, 2.};
Tuples[{a, b}];
pnts = {{-1.8, 0.2}, {-1.8, 0.4}, {-1.8, 0.6}, {-1.8, 0.8}, {-1.8, 
1.}, {-1.8, 1.2}, {-1.8, 1.4}, {-1.8, 1.6}, {-1.8, 1.8}, {-1.8, 
2.}, {-1.6, 0.2}, {-1.6, 0.4}, {-1.6, 0.6}, {-1.6, 0.8}, {-1.6, 
1.}, {-1.6, 1.2}, {-1.6, 1.4}, {-1.6, 1.6}, {-1.6, 1.8}, {-1.6, 
2.}, {-1.4, 0.2}, {-1.4, 0.4}, {-1.4, 0.6}, {-1.4, 0.8}, {-1.4, 
1.}, {-1.4, 1.2}, {-1.4, 1.4}, {-1.4, 1.6}, {-1.4, 1.8}, {-1.4, 
2.}, {-1.2, 0.2}, {-1.2, 0.4}, {-1.2, 0.6}, {-1.2, 0.8}, {-1.2, 
1.}, {-1.2, 1.2}, {-1.2, 1.4}, {-1.2, 1.6}, {-1.2, 1.8}, {-1.2, 
2.}, {-1., 0.2}, {-1., 0.4}, {-1., 0.6}, {-1., 0.8}, {-1., 
1.}, {-1., 1.2}, {-1., 1.4}, {-1., 1.6}, {-1., 1.8}, {-1., 
2.}, {-0.8, 0.2}, {-0.8, 0.4}, {-0.8, 0.6}, {-0.8, 0.8}, {-0.8, 
1.}, {-0.8, 1.2}, {-0.8, 1.4}, {-0.8, 1.6}, {-0.8, 1.8}, {-0.8, 
2.}, {-0.6, 0.2}, {-0.6, 0.4}, {-0.6, 0.6}, {-0.6, 0.8}, {-0.6, 
1.}, {-0.6, 1.2}, {-0.6, 1.4}, {-0.6, 1.6}, {-0.6, 1.8}, {-0.6, 
2.}, {-0.4, 0.2}, {-0.4, 0.4}, {-0.4, 0.6}, {-0.4, 0.8}, {-0.4, 
1.}, {-0.4, 1.2}, {-0.4, 1.4}, {-0.4, 1.6}, {-0.4, 1.8}, {-0.4, 
2.}, {-0.2, 0.2}, {-0.2, 0.4}, {-0.2, 0.6}, {-0.2, 0.8}, {-0.2, 
1.}, {-0.2, 1.2}, {-0.2, 1.4}, {-0.2, 1.6}, {-0.2, 1.8}, {-0.2, 
2.}, {0., 0.2}, {0., 0.4}, {0., 0.6}, {0., 0.8}, {0., 1.}, {0., 
1.2}, {0., 1.4}, {0., 1.6}, {0., 1.8}, {0., 2.}, {0.2, 0.2}, {0.2,
 0.4}, {0.2, 0.6}, {0.2, 0.8}, {0.2, 1.}, {0.2, 1.2}, {0.2, 
1.4}, {0.2, 1.6}, {0.2, 1.8}, {0.2, 2.}, {0.4, 0.2}, {0.4, 
0.4}, {0.4, 0.6}, {0.4, 0.8}, {0.4, 1.}, {0.4, 1.2}, {0.4, 
1.4}, {0.4, 1.6}, {0.4, 1.8}, {0.4, 2.}, {0.6, 0.2}, {0.6, 
0.4}, {0.6, 0.6}, {0.6, 0.8}, {0.6, 1.}, {0.6, 1.2}, {0.6, 
1.4}, {0.6, 1.6}, {0.6, 1.8}, {0.6, 2.}, {0.8, 0.2}, {0.8, 
0.4}, {0.8, 0.6}, {0.8, 0.8}, {0.8, 1.}, {0.8, 1.2}, {0.8, 
1.4}, {0.8, 1.6}, {0.8, 1.8}, {0.8, 2.}, {1., 0.2}, {1., 
0.4}, {1., 0.6}, {1., 0.8}, {1., 1.}, {1., 1.2}, {1., 1.4}, {1., 
1.6}, {1., 1.8}, {1., 2.}, {1.2, 0.2}, {1.2, 0.4}, {1.2, 
0.6}, {1.2, 0.8}, {1.2, 1.}, {1.2, 1.2}, {1.2, 1.4}, {1.2, 
1.6}, {1.2, 1.8}, {1.2, 2.}, {1.4, 0.2}, {1.4, 0.4}, {1.4, 
0.6}, {1.4, 0.8}, {1.4, 1.}, {1.4, 1.2}, {1.4, 1.4}, {1.4, 
1.6}, {1.4, 1.8}, {1.4, 2.}, {1.6, 0.2}, {1.6, 0.4}, {1.6, 
0.6}, {1.6, 0.8}, {1.6, 1.}, {1.6, 1.2}, {1.6, 1.4}, {1.6, 
1.6}, {1.6, 1.8}, {1.6, 2.}, {1.8, 0.2}, {1.8, 0.4}, {1.8, 
0.6}, {1.8, 0.8}, {1.8, 1.}, {1.8, 1.2}, {1.8, 1.4}, {1.8, 
1.6}, {1.8, 1.8}, {1.8, 2.}, {2., 0.2}, {2., 0.4}, {2., 0.6}, {2.,
 0.8}, {2., 1.}, {2., 1.2}, {2., 1.4}, {2., 1.6}, {2., 1.8}, {2., 
2.}};

I have included how I arrived to these set of points as a reference as well, incase it would be easier to include that directly into the loop as well, I took a more manual way to getting the specific list of points.

$\endgroup$
7
$\begingroup$

I would say the previous answers are better for your specific case of $x^2 + y^2 < 1$, but in the more general case I would use:

Select[pnts, #[[1]]^2 + #[[2]]^2 >= 1 &]

or

Select[pnts, !#[[1]]^2 + #[[2]]^2 < 1 &]

where #[[1]] means the first element and #[[2]] means the second element in each pair of numbers (your x and y). I find that this syntax allows me to construct fairly complex selection criteria.

The two definitions I gave are equivalent, it just depends on which syntax makes the most sense to you - either take the opposite sign (>= instead of <) to get elements that are greater than or equal to, or simply ask for those elements that are "not lesser than".

$\endgroup$
7
$\begingroup$

Use Select which will give you a list of points which satisfy your condition

pnts={...};
Select[pnts, Norm[#]>=1&]
$\endgroup$
7
$\begingroup$

Use RegionMember:

Pick[pnts, RegionMember[Disk[{0, 0}, 1]][pnts], False] // Short

{{-1.8,0.2},{-1.8,0.4},{-1.8,0.6},<<159>>,{2.,1.6},{2.,1.8},{2.,2.}}

$\endgroup$
  • $\begingroup$ @BobHanlon Thanks! $\endgroup$ – Carl Woll Nov 26 '19 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.