-1

I have a list,

param2 = {
 {-qlim, -qlim},
 {-qlim, qlim},
 {qlim, -qlim},
 {qlim, qlim}
};

and want to get combination of them with,

Flatten[Table[{param2[[i]], param2[[j]]}, {i, 4}, {j, 4}], 2]

But this gives me list which includes sets that have item twice. I want to get

{1,2},{1,3},{1,4},{2,3},{2,4},{3,4}
freezer
  • 123
  • 4
  • 1
    What's the value of qlim? – corey979 Jan 01 '17 at 22:53
  • it is a scalar value like 1 or 3 – freezer Jan 01 '17 at 22:54
  • That's not the answer to my question. I still don't know what do you want to achieve with your code, but the desired output can be obtained with Flatten[Table[{i, j}, {i, 1, 4}, {j, i + 1, 4}], 1]. – corey979 Jan 01 '17 at 22:55
  • Actually ı have written the index inside the list not the actual output. I didn't know that we can use one index inside other. I will try it tomorrow. Thank you. – freezer Jan 01 '17 at 23:07
  • See also: http://mathematica.stackexchange.com/q/86138/121 – Mr.Wizard Jan 01 '17 at 23:16
  • "I didn't know that we can use one index inside other." - it pays to read the docs before asking questions. The second example under "Scope" in the docs for Table[] shows how you could've done it. – J. M.'s missing motivation Jan 02 '17 at 00:09

1 Answers1

0
Subsets[param2, {2}]

{{{-qlim, -qlim}, {-qlim, qlim}},
{{-qlim, -qlim}, {qlim, -qlim}},
{{-qlim, -qlim}, {qlim, qlim}},
{{-qlim, qlim}, {qlim, -qlim}},
{{-qlim, qlim}, {qlim, qlim}},
{{qlim, -qlim}, {qlim, qlim}}}

kglr
  • 394,356
  • 18
  • 477
  • 896
  • Thanks that's what I wanted. What if ı just wanted this point to draw rectangle with these points are corner. – freezer Jan 01 '17 at 23:12
  • @freezer, something like Graphics[{Hue@RandomReal[], Rectangle @@ #}] & /@ (Subsets[ param2, {2}] /. qlim -> 1)? – kglr Jan 01 '17 at 23:23
  • nope @kglr. I think this is not what I asked. I want to get this list {{{-3, -3}, {3, -3}}, {{3, -3}, {3, 3}}, {{3, 3}, {-3, 3}}, {{-3, 3}, {-3, -3}}} as corners of ractangles automatically? Is this possible? – freezer Jan 02 '17 at 23:28
  • @freezer, Rectangle @@@ {{{-3, -3}, {3, -3}}, {{3, -3}, {3, 3}}, {{3, 3}, {-3, 3}}, {{-3, 3}, {-3, -3}}} gives {Rectangle[{-3, -3}, {3, -3}], Rectangle[{3, -3}, {3, 3}], Rectangle[{3, 3}, {-3, 3}], Rectangle[{-3, 3}, {-3, -3}]}. Note that some of these are simply lines (degenerate rectangles). – kglr Jan 02 '17 at 23:40
  • :) I think I couldn't be clear as I need. I need to get that list from possible values of coordinates. Don't want to write manually. – freezer Jan 03 '17 at 00:02
  • @freezer, you mean Rectangle @@@ Subsets[param2, {2}] /. qlim -> 3? – kglr Jan 03 '17 at 00:10
  • no :D. Forget about rectangle function I want to get a list of points where the corner of rectangles are. Which will generate 4 coordinates out of +-some value for corners. This is different question than the main question that I asked here. – freezer Jan 03 '17 at 01:59