1
$\begingroup$

I need to make a list by evaluating

{1, x, y, x*y}

on a sequence of points

{-10,10},{10,10},{10,-10},{-10, -10}

Neither

Table[{1, x, y, x*y}, {y, 10, -10, -20}, {x, -10, 10, 20}]

nor

Table[{1, x, y, x*y}, {y, {10, 10, -10, -10}}, {x, {-10, 10, 10, -10}}]

gave me the desired result.

I expect the result to be:

{{1, -10, 10, -100}, {1, 10, 10, 100}, {1, 10, -10, 100}, {1, -10, -10, -100}}

Is there a way to do it with Table? Thanks.

$\endgroup$
  • $\begingroup$ ricecakebear, thinking that it is a typo, I changed {-10,10} in the last entry of your set of points to {-10, -10}. If it is not a typo and it should stay {-10,10} please let me know, I will roll back my edit. $\endgroup$ – kglr Sep 11 '17 at 6:33
  • $\begingroup$ @kglr Yeah, it's a typo. Thanks for correction. $\endgroup$ – ricecakebear Sep 11 '17 at 6:49
0
$\begingroup$
ClearAll[f]
f[{x_, y_}] := {1, x, y, x*y}

f /@ {{-10, 10}, {10, 10}, {10, -10}, {-10, -10}}

{{1, -10, 10, -100}, {1, 10, 10, 100}, {1, 10, -10, -100}, {1, -10, -10, -100}}

Table[f[i], {i, {{-10, 10}, {10, 10}, {10, -10}, {-10, -10}}}]

{{1, -10, 10, -100}, {1, 10, 10, 100}, {1, 10, -10, -100}, {1, -10, -10, -100}}

Or

Table[{1, i[[1]], i[[2]], i[[1]] i[[2]]}, 
    {i, {{-10, 10}, {10, 10}, {10, -10}, {-10, -10}}}]

{{1, -10, 10, -100}, {1, 10, 10, 100}, {1, 10, -10, -100}, {1, -10, -10, -100}}

$\endgroup$

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.