MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: lists of lists, tensor products and stuff like that..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44987] Re: [mg44976] lists of lists, tensor products and stuff like that..
  • From: "Sseziwa Mukasa,,(978) 536-2359" <mukasa at jeol.com>
  • Date: Fri, 12 Dec 2003 04:41:25 -0500 (EST)
  • References: <200312111028.FAA13145@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Dec 11, 2003, at 5:28 AM, allan wrote:

> hi, i want to work with a data structure which is basically a tensor
> product or matrix of matrixes of vectors.  so for instance, i'd like
> to do operations like taking an i x j matrix of 3 vectors and an n x n
> matrix of 3 vectors, and form the (i x j) x (n x n) matrix of dot
> products.
>
> it would appear that Outer, Flatten, List etc are exactly set up to do
> this sort of thing but i can't seem to get the hang of it.  is there a
> good introduction, or overview (rather than function by function)
> documentation, or illustrative examples of this?
>
> thanks in advance!

Your problem looks like you have an ixj matrix and want the direct 
product of that with an nxn matrix where the elements of the matrices 
are 3 vectors and the operation is the scalar product.  Outer computes 
the direct product, but since a 3 vector looks like a list if you write 
Outer[Dot,a,b] where a is you ixj object and b your nxn matrix it will 
treat a as an ixjx3 object and b as an nxnx3 object which isn't what 
you want.  There is another form of Outer where you can specify that 
you only want to treat the previous arguments as lists to a certain 
depth.  However in playing around with that function I found that if 
the subobjects were lists this form doesn't work as expected.  For 
example compare the results of:

Outer[z, {{v[a, b, c], v[d, e, f]}}, {{v[g, h, i], v[j, k, l]}, {v[m, n,
    o], v[p, q, r]}}]

and

Outer[z,{{{a, b, c}, {d, e, f}}}, {{{g, h, i}, {j, k, l}}, {{m, n,
    o}, {p, q, r}}},2]

which I would have expected to be the same except the arguments to z 
from the first expression have the head v and the arguments in the 
second expression have the head List.  This isn't the case and I don't 
understand why.  However it does give one a clue as to how to solve you 
problem: simply change the head of the vectors and remove the change 
later ie,

Outer[Dot[List @@ #, List @@ #2] &, Apply[v, {{{a, b, c}, {d, e,
    f}}}, {2}], Apply[
     v, {{{g, h, i}, {j, k, l}}, {{m, n, o}, {p, q, r}}}, {2}]]

returns the results you want.  Obviously I skipped a few steps in how I 
arrived at this expression, but I think you should be able to see how I 
came up with it.

Regards,

Ssezi


  • Prev by Date: Efficient Monte Carlo code
  • Next by Date: Immediate or Delayed Definitions in NDSolve?
  • Previous by thread: lists of lists, tensor products and stuff like that..
  • Next by thread: Re: lists of lists, tensor products and stuff like that..