Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Thread::tdlen: Objects of unequal length

746 views
Skip to first unread message

SysInv

unread,
Oct 5, 2011, 4:17:50 AM10/5/11
to
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...

David Reiss

unread,
Oct 6, 2011, 4:21:32 AM10/6/11
to
P.S. If you type "Matrix multiplication" into the Help browser you
will get a link to the tutorial on how to perform matrix operations.

--David


On Oct 5, 4:17 am, SysInv <jo...@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.000 199939,-0.000556137},{0.000211963,-0.000199939,0.00118147,-0.00043913},{

David Reiss

unread,
Oct 6, 2011, 4:22:33 AM10/6/11
to
You want to compute s.t.Transpose[s] rather than s*t*Transpose[s].
An asterisk is multiplication . A dot is matrix multiplication.

--David


On Oct 5, 4:17 am, SysInv <jo...@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.000 199939,-0.000556137},{0.000211963,-0.000199939,0.00118147,-0.00043913},{

Peter Pein

unread,
Oct 6, 2011, 4:21:01 AM10/6/11
to
Am 05.10.2011 10:17, schrieb SysInv:
> 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...
>

1.) wrap curly braces around the sequence of lists in the assignment to t.
2.) use matrix-multiplication

In[5]:= s.t.Transpose[s]
Out[5]= {{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}}

alternatively you can write the input as Dot[s, t, s\[Transpose]], where
\[Transpose] can be entered as <esc>tr<esc>.

Sseziwa Mukasa

unread,
Oct 6, 2011, 4:24:06 AM10/6/11
to
The operator for matrix multiplication is . not *, * is for element by element multiplication.

Incidentally, . actually does tensor multiplication (read the help) so the braces are unnecessary you can do:

{x1,x2,x4,x4}.{{...}}.{x1,x2,x3,x4}

which will result in a scalar, unless you really want a two dimensional 1x1 result in which case s must be two dimensional.

Regards,
Sseziwa

On Oct 5, 2011, at 4:04 AM, SysInv 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}}
>
> =

Heike Gramberg

unread,
Oct 6, 2011, 4:31:58 AM10/6/11
to
First of all, you should use Dot (.) for matrix multiplications;
s*t*Transpose[s] will just multiply s, t, and Transpose[s] element-wise,
but since Length[s] != Length[t] in your example, this fails.

Secondly, in Mathematica lists function both as row-vectors and
column-vectors in matrix multiplications so there is no need for
Transpose. You could simply do

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}};

s.t.s

Heike.

Michael Weyrauch

unread,
Oct 6, 2011, 4:33:01 AM10/6/11
to
For matrix multiplication you must use Dot[].
Then it will work easily.

Michael

DrMajorBob

unread,
Oct 6, 2011, 4:33:32 AM10/6/11
to
No problem here:

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}};
s.t.Transpose@s

{{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}}

Bobby

On Wed, 05 Oct 2011 03:04:36 -0500, SysInv <jo...@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...
>


--
DrMaj...@yahoo.com

A Retey

unread,
Oct 6, 2011, 4:34:34 AM10/6/11
to
Am 05.10.2011 10:17, schrieb SysInv:
Times (*) is element wise multiplication, I guess you want Dot (.):

s.t.Transpose[s]

hth,

albert

Vivek Joshi

unread,
Oct 6, 2011, 4:35:05 AM10/6/11
to
Times is just an element wise multiplication. Are you trying to do a dot
product ?

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}};

Dot[Dot[s, t], Transpose[s]] // Simplify
{{0.0284435 x1^2 + 0.0113862 x2^2 - 0.000399878 x2 x3 +
0.00118147 x3^2 +
x1 (0.00791518 x2 + 0.000423926 x3 + 0.0714806 x4) -
0.00111227 x2 x4 - 0.00087826 x3 x4 + 0.0649449 x4^2}}

Vivek

David Park

unread,
Oct 6, 2011, 4:42:58 AM10/6/11
to
To go straight for the answer:

(svector = {x1, x2, x3, x4}) // MatrixForm
(tmatrix = {{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}
}) // MatrixForm

svector.tmatrix.svector // Expand

The general rules for multiplying (or contracting) arrays of various orders,
with contractions occurring at various levels, are:

The Prime Rule for Products of 'Tensor' Arrays in Mathematica:
S.T dots the lowest level of S with the highest level of T,
or equivalently
S.T dots the last level of S with the first level of T.

The Mathematica Transpose[T,{n1,n2,n3,...}] moves levels {1,2,3,...} to
levels {n1,n2,n3,...}. We will always want to move the contracted level to
the first or last level when doing Dot products and to the first two levels
when doing single array contractions.

If R, S, T,... are Mathematica tensor arrays, then their direct product is
given by Outer[Times,R,S,T,...]. This will produce a single Mathematica
array. The levels are in the same order as the levels in the successive
arrays.

The basic Mathematica command for contraction of the top two levels in a
single array T is Tr[T,Plus,2]. We will have to use Transpose on T to put
the contraction slots in the first two levels. We will have to repeat the
operation if we want to do multiple contractions.

You just have to remain level headed.

David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

Tomas Garza

unread,
Oct 6, 2011, 4:43:30 AM10/6/11
to
As written, t doesn't make sense (it is incomplete). You should wrap the whole thing into {} in order to get a list, i.e. a matrix:
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}}

> Date: Wed, 5 Oct 2011 04:04:36 -0400
> From: jo...@systeminvestors.se
> Subject: Thread::tdlen: Objects of unequal length
> To: math...@smc.vnet.net

Leonid Shifrin

unread,
Oct 6, 2011, 4:44:03 AM10/6/11
to
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 <jo...@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 new messages