5
$\begingroup$

Hello and thanks for your time in advance.

The problem I'm having is that I can't figure out how to make a list of elements from the following expression:

(x-h)^2 + (y-k)^2 == r^2

What I'm trying to do is generate a list with a definite set of values for h and k with a fixed value of r, to get something like this:

{(-1 + x)^2 + (-1 + y)^2 == 1, (-2 + x)^2 + (-2 + y)^2 == 1, (-3 + x)^2 + (-3 + y)^2 == 1}

The code I'm using is the following:

(-h + x)^2 + (-k + y)^2 == r^2 /. {h :> Range[1, 3], k :> Range[1, 3],r -> 1}

And from that I'm getting this:

   {(-1 + x)^2 + (-1 + y)^2, (-2 + x)^2 + (-2 + y)^2, (-3 + x)^2 + (-3 + y)^2} == 1

I'm looking for any pointers on what I'm doing wrong because I can't figure it out.

Again thanks for any pointers, help or comments that could help me to figure out what to do.

$\endgroup$
  • 1
    $\begingroup$ How about using Table? $\endgroup$ – mikado Sep 17 '16 at 22:42
5
$\begingroup$

Just an example...

Flatten[Table[(x - h)^2 + (y - k)^2 == r^2, {h, 1, 3}, {k, 1, 3}]]

results in...

{(-1 + x)^2 + (-1 + y)^2 == r^2, (-1 + x)^2 + (-2 + y)^2 == r^2, (-1 + x)^2 + (-3 + y)^2 == r^2, (-2 + x)^2 + (-1 + y)^2 == r^2, (-2 + x)^2 + (-2 + y)^2 == r^2, (-2 + x)^2 + (-3 + y)^2 == r^2, (-3 + x)^2 + (-1 + y)^2 == r^2, (-3 + x)^2 + (-2 + y)^2 == r^2, (-3 + x)^2 + (-3 + y)^2 == r^2}

Isn“t that what you are looking for ?

Taking your comments into account, I would rewrite that as...

Table[(x - h)^2 + (y - h)^2 == r^2, {h, 1, 3}]

And you can do away with Flatten as well.

$\endgroup$
  • $\begingroup$ Hello FACamargo, something like that but how you stop the permutations between h and k. Because like i was trying to explain im looking to get this {(-1 + x)^2 + (-1 + y)^2 == 1, (-2 + x)^2 + (-2 + y)^2 == 1, (-3 + x)^2 + (-3 + y)^2 == 1}, thats why i use RuleDelayed (:>) in the example i show in my initial post. But really thanks for your ideas. $\endgroup$ – Leothan Sep 17 '16 at 23:59
  • $\begingroup$ What about making h = k, and having just one iterator? It would produce exactly what you asked for... $\endgroup$ – FACamargo Sep 18 '16 at 0:02
  • $\begingroup$ Awesome thats it thanks man, i feel dumb now lol. Thanks alot :D $\endgroup$ – Leothan Sep 18 '16 at 0:37
  • $\begingroup$ Don't worry, I know the feeling... We are both neophytes here :) $\endgroup$ – FACamargo Sep 18 '16 at 0:43

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.