2
$\begingroup$

I have been using mathematica for a while, but I have problem wrapping my head around list manipulation functions. I would appreciate any suggestions. Here is what I want to do.

ListV is a list of vectors:

ListV= {{x1,y1,z1},{x2,y2,z2},...}= {V1,V2,...}

ListU is also a list of vectors :

ListU={{a1,b1,c1},{a2,b2,c2},...}= {U1,U2,...}

ListU and ListV may have unequal lengths.

I want to make a new list (ListUV) which would contain all the new positions generated by the sum of all vectors in ListU and ListV. Mathematically, that would be

ListUV= {V1+U1, V2+U1, ..., V2+U1, V2+U2, ... }.

Thanks for any suggestions.

$\endgroup$
  • 4
    $\begingroup$ Is it what you want? Flatten[Outer[Plus, ListV, ListU], 1] $\endgroup$ – Yi Wang Feb 19 '14 at 13:19
  • $\begingroup$ You say V2+U1, ... V2+U1, V2+U2. Do you mean V2+U1, ... V3+U1, V3+U2 ? $\endgroup$ – Jacob Akkerboom Feb 19 '14 at 14:23
  • $\begingroup$ 'Partition[Flatten[Outer[Plus, UnitCellPositions, LatticePositions, 1]], 3]' does exactly what I need. Thank you Yi Wang for the solution. $\endgroup$ – user3328102 Feb 19 '14 at 16:50
  • $\begingroup$ Thank you PlatoManiac for edited the formatting. $\endgroup$ – user3328102 Feb 19 '14 at 16:54
  • $\begingroup$ @YiWang Please consider posting an answer :) $\endgroup$ – Kuba Apr 24 '14 at 17:43
2
$\begingroup$

Two lists were created using only letters

listV = {{a, b, c}, {d, e, f}, {g, h, i}}

$\left( \begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \\ \end{array} \right)$

listU = {{j, k, l}, {m, n, o}, {p, q, r}}

$\left( \begin{array}{ccc} j & k & l \\ m & n & o \\ p & q & r \\ \end{array} \right)$

With this command it is possible to create all the possibilities of sum of vectors (Modified)

allVectors = Flatten[Outer[Plus, listV, listU], 2]

$\left( \begin{array}{ccc} a+j & a+k & a+l \\ a+m & a+n & a+o \\ a+p & a+q & a+r \\ b+j & b+k & b+l \\ b+m & b+n & b+o \\ b+p & b+q & b+r \\ c+j & c+k & c+l \\ c+m & c+n & c+o \\ c+p & c+q & c+r \\ d+j & d+k & d+l \\ d+m & d+n & d+o \\ d+p & d+q & d+r \\ e+j & e+k & e+l \\ e+m & e+n & e+o \\ e+p & e+q & e+r \\ f+j & f+k & f+l \\ f+m & f+n & f+o \\ f+p & f+q & f+r \\ g+j & g+k & g+l \\ g+m & g+n & g+o \\ g+p & g+q & g+r \\ h+j & h+k & h+l \\ h+m & h+n & h+o \\ h+p & h+q & h+r \\ i+j & i+k & i+l \\ i+m & i+n & i+o \\ i+p & i+q & i+r \\ \end{array} \right)$

Now the same previous information applying values ​​to the vectors

numericListV = {{1, 2, 0}, {0, 2, 4}, {5, 8, 10}}

$\left( \begin{array}{ccc} 1 & 2 & 0 \\ 0 & 2 & 4 \\ 5 & 8 & 10 \\ \end{array} \right)$

Graphics3D[{Red, 

MapThread[Arrow, {{{0, 0, 0}, #}} & /@ numericListV // Transpose]}]

Im1

numericListU = {{1, 4, 5}, {3, 5, 7}, {8, 8, 9}}

$\left( \begin{array}{ccc} 1 & 4 & 5 \\ 3 & 5 & 7 \\ 8 & 8 & 9 \\ \end{array} \right)$

Graphics3D[{Blue, 

MapThread[Arrow, {{{0, 0, 0}, #}} & /@ numericListU // Transpose]}]

Im2

allVectorsNumeric = 

Flatten[Outer[Plus, numericListV, numericListU], 2]

$\left( \begin{array}{ccc} 2 & 5 & 6 \\ 4 & 6 & 8 \\ 9 & 9 & 10 \\ 3 & 6 & 7 \\ 5 & 7 & 9 \\ 10 & 10 & 11 \\ 1 & 4 & 5 \\ 3 & 5 & 7 \\ 8 & 8 & 9 \\ 1 & 4 & 5 \\ 3 & 5 & 7 \\ 8 & 8 & 9 \\ 3 & 6 & 7 \\ 5 & 7 & 9 \\ 10 & 10 & 11 \\ 5 & 8 & 9 \\ 7 & 9 & 11 \\ 12 & 12 & 13 \\ 6 & 9 & 10 \\ 8 & 10 & 12 \\ 13 & 13 & 14 \\ 9 & 12 & 13 \\ 11 & 13 & 15 \\ 16 & 16 & 17 \\ 11 & 14 & 15 \\ 13 & 15 & 17 \\ 18 & 18 & 19 \\ \end{array} \right)$

Graphics3D[{Green, 

MapThread[ Arrow, {{{0, 0, 0}, #}} & /@ allVectorsNumeric // Transpose]}]

enter image description here

$\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.