Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Matrix Multiplication

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13764] Re: Matrix Multiplication
  • From: murray at math.umass.edu (Murray Eisenberg)
  • Date: Mon, 24 Aug 1998 05:07:14 -0400
  • Organization: University of Massachusetts, Amherst
  • References: <6imh1a$gu1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Des Penny (dpenny at iname.com) wrote:

: 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]}

Your B is _not_ a 1-by-2 matrix but rather just a simple list of length
two:

In: B = Array[b, {2}]
Out: {b[1],b[2]}

In: Dimensions[B]
Out: {2}

Hence the last dimension of your A, namely, its number of columns (1),
does not equal the first dimension of your B.

Change B to BB as follows:

In: BB = Array[b, {1, 2}]
Out: {{b[1,1],b[1,2]}}

In: Dimensions[BB]
Out: {1,2}

In: A . BB
Out: {{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]}}

--
  Murray Eisenberg                       Internet: 
murray at math.umass.edu
  Mathematics & Statistics Dept.            Voice:  413-545-2859 (W)
  University of Massachusetts                       413-549-1020 (H)
  Amherst, MA 01003                           Fax:  413-545-1801


  • Prev by Date: Problems with Read[stream,String] after Read[stream,Number]
  • Next by Date: An operator called-- LocalRule
  • Previous by thread: Re: Problems with Read[stream,String] after Read[stream,Number]
  • Next by thread: An operator called-- LocalRule