Message Boards Message Boards

0
|
3662 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Isolate integers in a pair from a table?

Posted 4 years ago

Evening,

I am trying to isolate the whole numbers/integers from a pair of numbers within a range. This is the function I am currently using:

Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}]

I want to find out which of the Sqrt(1+5k^2) is a square number itself, so a whole number. I am currently having to try a range and read through all my results. What I would like to to use a command, or a different command to the above, to just show those results that give me whole numbers.

I hope I have explained that well enough and am asking in the right place. Thank you in advance.

POSTED BY: Emily Larkin
4 Replies
Posted 4 years ago

Another variant:

Cases[Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}], {_Integer, _}]
POSTED BY: Hans Milton
Posted 4 years ago

There is usually more than one way to solve problems, this is another.

Cases[Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}], {a_, b_} /; 
  IntegerQ[a]]
POSTED BY: Paul Cleary
Posted 4 years ago

Yes!! Yes that is exactly it thank you! I was scouring Google for hours earlier today. Thank you so much!

POSTED BY: Emily Larkin
Posted 4 years ago

Hi Emily,

Is this what you mean?

Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}] // Select[IntegerQ@First@# &]
(* {{1, 0}, {9, 4}, {161, 72}} *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract