6
$\begingroup$

I'm making plots of point sets in a plane. My points are generated by a function ranging over two parameters $x$ and $y$ and I want to see all the points where these are integers between $-10$ and $10$. But the function is undefined when $x=y=0$.

Following is a version of my code where I've replaced the function with something simpler, that is also undefined at $x=y=0$.

 ListPlot[Table[{x/(x^2+y^2),y/(x^2+y^2)}, {x, -10, 10, 1}, {y, -10, 10, 1}]]

If you implement that code, you will get the graph but with error messages about the point where it's undefined. (In reality what I'm doing is more complicated and involves a slidable parameter, which compounds the problem because every time you slide the parameter Mathematica hits the undefined point again.)

What is the easiest way to omit the combination $x=y=0$ from the combination of data ranges?

$\endgroup$
  • $\begingroup$ One way: ListPlot[Table[{x/(x^2 + y^2), y/(x^2 + y^2)}, {x, -10.00001, 10, 1}, {y, -10.00001, 10, 1}]] $\endgroup$ – bill s Sep 21 '17 at 0:33
  • $\begingroup$ @bills Okay, but that bugs me because then I'm not really looking at integer values of $x$ and $y$. It may be close enough for the example I used but could cause problems down the road. $\endgroup$ – j0equ1nn Sep 21 '17 at 0:37
  • 1
    $\begingroup$ Then use an If statement and only evaluate when x and y are not zero, e.g., `ListPlot[Table[z = x^2 + y^2; If[z != 0, {x/z, y/z}], {x, -10, 10, 1}, {y, -10, 10, 1}]]' $\endgroup$ – bill s Sep 21 '17 at 0:38
  • $\begingroup$ @bills Thanks, I am still very new to the program so that helps. But it's also very specific to the fake example I put there. I can probably find a way to do something similar for my actual function but ... it seems there should be a more straightforward way. For instance I was just reading about the Exclusions option, which is the right idea but does not seem to work in this context. $\endgroup$ – j0equ1nn Sep 21 '17 at 0:47
5
$\begingroup$

another option is to implement your own region function like for listplot:

(*constraint here*)
f[x_, y_] /; (x^2 + y^2 != 0) := {x/(x^2 + y^2), y/(x^2 + y^2)}

f[x_, y_] := Nothing;  (*what to return for bad region, or other point*)

ListPlot[Table[f[x, y], {x, -10, 10, 1}, {y, -10, 10, 1}]]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Nice, that is more efficient, not just in the code but it's less strain on the hard drive (in my case, when I put in my extra slidable parameter). $\endgroup$ – j0equ1nn Sep 21 '17 at 1:58
3
$\begingroup$

if you dont mind turning off the error messages you can use

Quiet@ListPlot[Table[{x/(x^2+y^2),y/(x^2+y^2)}, {x, -10, 10, 1}, {y, -10, 10, 1}]]

but that doesn't exclude the point (0,0), it just avoid the warnings.

$\endgroup$
  • $\begingroup$ Cool, that does work on my actual example, and is way simpler. I imagine one could encounter problems if one gets in the habit of muting error messages but for my purpose it is just fine. $\endgroup$ – j0equ1nn Sep 21 '17 at 1:30
1
$\begingroup$

This answer is based on the help from @bills (after a slight improvement) but since that occurred in the comments I'm putting it here as an answer, just for completeness.

Use an "If" statement with a dummy variable.

ListPlot[
 Table[
  z = x^2+y^2; 
  If[
   z != 0,
   {x/(x^2 + y^2), y/(x^2 + y^2)}],
  {x, -10, 10, 1}, {y, -10, 10, 1}]]

This way $z$ doesn't occur in the function, is just there to exclude what we want, and the function can be replaced with what we want.

I still feel there should be something more tailored to the problem, e.g. something similar to "Exclusions" but that works in this context. So I'll hold off on accepting my own answer in case anyone has something better.

$\endgroup$
  • $\begingroup$ in this way you omit the combinations (x,0) or (0,y) with x and y different from 0, while in the first post you seems to want to exclude only the case x= y = 0. try x+y. $\endgroup$ – Alucard Sep 21 '17 at 1:25
  • $\begingroup$ @Alucard Good point, I will fix that now. $\endgroup$ – j0equ1nn Sep 21 '17 at 1:26

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.