0
$\begingroup$

how can I only show the integers values of this Table data? Like I don't want to see all the other imaginary values displayed even.

Table[Sqrt[(x + y)], {x, -20, 20}, {y, -20, 20}]

Also: You know how the data is displayed in arrays {{},{},{},...{}} which goes through x=-20 with All of y, then x=-19 with all of y again ...etc....x=20 with all of y. Can the actual x and y elements be displayed also (besides the actual final values)?

Thanks, Steve

$\endgroup$
  • 4
    $\begingroup$ Does Flatten[Table[Block[{t = x + y, s}, If[t >= 0, s = Sqrt[t]; If[IntegerQ[s], {{x, y}, s}, Nothing], Nothing]], {x, -20, 20}, {y, -20, 20}], 1] do what you want? $\endgroup$ – J. M.'s technical difficulties Jan 25 at 23:03
  • 2
    $\begingroup$ sol = SortBy[{x, y, s} /. Solve[s == Sqrt[(x + y)] && -20 <= x <= 20 && -20 <= y <= 20, {x, y, s}, Integers], Last] $\endgroup$ – Bob Hanlon Jan 26 at 0:29
  • $\begingroup$ Nice, wow! this is exactly what I wanted! Thanks so much! But just note seems like the second solution is missing the value for (-19,20) which is actually a 1. But second one skips it. And likely skips a few others too. I wanted to send a screenshot of what I am saying but seems like I cannot attach screenshot to a reply? $\endgroup$ – Steve237 Jan 26 at 4:48
  • $\begingroup$ Damn, never mind! Apologies, I just saw -19,20 but it was sorted differently and tucked in the middle! Seems like both complete! Thx $\endgroup$ – Steve237 Jan 26 at 4:54
1
$\begingroup$

modified answer(27.01.2020)

Try

Table[If[IntegerQ[#], {x, y, #}, Nothing] &[Sqrt[x + y]], {x,  -20,20}, {y,  
-20, 20}] // Flatten[#, 1] &

(* {{-20, 20, 0}, {-19, 19, 0}, {-19, 20, 1}, {-18, 18, 0}, {-18, 19,1}
, {-17, 17, 0}, {-17, 18, 1}, {-16, 16, 0}, {-16, 17, 1}, {-16,20, 2}
, {-15, 15, 0}, {-15, 16, 1},...}*)  
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! this looks concise too - by the way I expanded your range from -20 to 20 here. However, now this makes me fully confused when i look at the new outputs, you know why? your new expression now correctly contains all +/- variations of {20, 15, 25} which is totally valid, which is NOT present in the first 2 solutions provided above! however, both their solutions contained +/- variations of {-19, 19, 0}, which is NOT contained in yours! So now all 3 solutions appear incomplete? Please let me know if anyone can see an error anywhere. $\endgroup$ – Steve237 Jan 26 at 19:48
  • $\begingroup$ I would like to have an ultimate solution which has all values included. Also:can we show a count of all the elements at the end? So I can see a total number of sets? Thanks! $\endgroup$ – Steve237 Jan 26 at 19:48
  • $\begingroup$ In Addition: Is there a way to bypass the zero elements where x=0 OR y=0? like can the range be split into 2 ranges or exclude those zeros? Since there are many obvious ones there that distort the answer (However good to see both, but 1 more expression to exclude those)? Thx $\endgroup$ – Steve237 Jan 26 at 19:55
  • $\begingroup$ LOL never mind - you subtly rearranged my original equation to Sqrt[x^2+y^2] whereas the original one was Sqrt[x+y] which is why your answers differed from others. Ok so seems like ALL complete! Thx....P.S. see if you can help with my other question is zero-excludes! OR where the OUTOUT is zero, for instance, if there is a way to exclude either inputs or outputs. $\endgroup$ – Steve237 Jan 26 at 20:00
  • $\begingroup$ x + y == 0 is probably not interesting either. So If[x != 0 && y != 0 && x + y != 0 && IntegerQ[#], {x, y, #}, Nothing] & $\endgroup$ – Rohit Namjoshi Jan 27 at 0:09

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.