Re: Thread::tdlen: Objects of unequal length

• To: mathgroup at smc.vnet.net
• Subject: [mg121925] Re: Thread::tdlen: Objects of unequal length
• From: Leonid Shifrin <lshifr at gmail.com>
• Date: Thu, 6 Oct 2011 04:26:51 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <201110050804.EAA07154@smc.vnet.net>

You shouldn't have used the normal multiplication operator (*)  for matrix
multiplication, because
it assumes element-wise multiplication for lists (and therefore matrices,
and generally tensors). A bit more technically, this is due to Times (*)
having Listable attribute. In some other systems, the multiplication
operator for matrices defaults to matrix multiplication, while element-wise
multiplication is a separate operator. Not so in Mathematica, where matrices
are not particularly central to the system's design. In Mathematica, there
is a special-purpose command Dot (.) designed for matrix multiplication. So,

s = {x1, x2, x3, x4}

t = {{0.0284435, 0.00395759, 0.000211963, 0.0357403}, {0.00395759,
0.0113862, -0.000199939, -0.000556137}, {0.000211963, -0.000199939,
0.00118147, -0.00043913}, {0.0357403, -0.000556137, -0.00043913,
0.0649449}}

In[10]:= s.t.s
Out[10]= x2 (0.00395759 x1+0.0113862 x2-0.000199939 x3-0.000556137 x4)+x3
(0.000211963 x1-0.000199939 x2+0.00118147 x3-0.00043913 x4)+x1 (0.0284435
x1+0.00395759 x2+0.000211963 x3+0.0357403 x4)+(0.0357403 x1-0.000556137
x2-0.00043913 x3+0.0649449 x4) x4

You don't need double-list braces for your vector, and neither do you need
to Transpose it.

Cheers,
Leonid

On Wed, Oct 5, 2011 at 12:04 PM, SysInv <johan at systeminvestors.se> wrote:

> This problem is driving me crazy. I'm trying to multiply matrices, where
> one is 1x4 (s) and the other is 4x4 (t) and the multiplication is
> s*t*Transpose[s]
>
> Despite this I get the error message that the objects is of unequal length.
> The matrices are:
>
> s={{x1,x2,x3,x4}}
>
>
> t={0.0284435,0.00395759,0.000211963,0.0357403},{0.00395759,0.0113862,-0.000199939,-0.000556137},{0.000211963,-0.000199939,0.00118147,-0.00043913},{
> 0.0357403,-0.000556137,-0.00043913,0.0649449}
>
> I must use double level in the 1 row matrix, since otherwise Transpose[]
> complains that it needs at least 2 levels. I tried without this as well, but
> I keep getting:
>
> Thread::tdlen : Objects of unequal length in
> {{x1,x2,x3,x4}}{{0.0284435,0.00395759,0.000211963,0.0357403},<<2>>,{<<10>>,<<3>>}}{{x1},{x2},{x3},{x4}}
> cannot be combined. >>
>
> . when I run s*t*Transpose[s].
>
> I've spent hours trying to figure this simple problem out, but without any
> luck. Any pointers guys? It doesn't help if I change the order of the
> transpose...
>

• Prev by Date: Mathematica Hangs on Spurious Dynamic Evaluation
• Next by Date: Re: DynamicModule Pure Function
• Previous by thread: Re: Thread::tdlen: Objects of unequal length
• Next by thread: Re: Thread::tdlen: Objects of unequal length