MathGroup Archive 1998

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

Search the Archive

Re: Matrix Multiplication


  • To: mathgroup@smc.vnet.net
  • Subject: [mg12288] Re: Matrix Multiplication
  • From: "Stephen P Luttrell" <luttrell@signal.dra.hmg.gb>
  • Date: Thu, 7 May 1998 18:51:24 -0400
  • Organization: Defence Evaluation and Research Agency
  • References: <6imh1a$gu1@smc.vnet.net>

>I'm trying to multiply a 3x1 matrix and a 1x2 matrix.  I should get a
>3x2 matrix, but instead I get an error message:
>
>In: A=Array[a,{3,1}]
>Out: {{a[1,1]},{a[2,1]},{a[3,1]}}
>
>In: B=Array[b,{2}]
>Out: {b[1],b[2]}
>
>In: A.B
>Dot::"dotsh": "Tensors \!\({\({a[\(1, 1\)]}\), \({a[\(2, 1\)]}\),
>\({a[\(3, 1\)]}\)}\) and \!\({\(b[1]\), \(b[2]\)}\) have incompatible
>shapes."
>Out: {{a[1,1]},{a[2,1]},{a[3,1]}}.{b[1],b[2]}
>...

You need to explicitly define B as a 1x2 matrix, rather than a 2 element
vector as you have done.

The following input

A=Array[a,{3,1}]
B=Array[b,{1,2}]
A.B

gives the following output

{{a[1,1]},{a[2,1]},{a[3,1]}}

{{b[1,1],b[1,2]}}

{{a[1,1] b[1,1],a[1,1] b[1,2]},{a[2,1] b[1,1],a[2,1] b[1,2]},{a[3,1]
b[1,1],
    a[3,1] b[1,2]}}

=======================================================

Stephen P Luttrell
luttrell@signal.dra.hmg.gb
Adaptive Systems Theory                           01684-894046 (phone)
Room EX21, DERA                                    01684-894384 (fax)
Malvern, Worcs, WR14 3PS, U.K.
http://www.dra.hmg.gb/cis5pip/Welcome.html




  • Prev by Date: Some basic Help
  • Next by Date: latex and mathematica
  • Prev by thread: Re: Matrix Multiplication
  • Next by thread: Re: Matrix Multiplication