MathGroup Archive 1998

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

Search the Archive

Re: Matrix Multiplication



Des,

I checked that 
In: A=Array[a,{3,1}]
>Out: {{a[1,1]},{a[2,1]},{a[3,1]}}
>In: B=Array[b,{1,2}]
                ^
gives :
>Out: {{b[1],b[2]}}
       ^         ^

and that then A.B does work ok.

wouter.
**************************************   


At 03:29 05.05.98 -0400, you wrote:
>Hi Folks:
>
>I ran into the following little problem that has me puzzled.
>
>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]}
>
>Of course I can get what I want by:
>
>In: A1=Flatten[A]
>Out: {a[1,1],a[2,1],a[3,1]}
>
>In:  Outer[Times, A1, B]
>Out: {{a[1,1] b[1],a[1,1] b[2]},{a[2,1] b[1],a[2,1] b[2]},{a[3,1]
>b[1],a[3,1] b[2]}}
>
>
>I don't seem to have trouble with any other dimensions e.g.
>
>In: A=Array[a,{3,2}]
>Out: {{a[1,1],a[1,2]},{a[2,1],a[2,2]},{a[3,1],a[3,2]}}
>
>In: B=Array[b,{2,4}]
>Out: {{b[1,1],b[1,2],b[1,3],b[1,4]},{b[2,1],b[2,2],b[2,3],b[2,4]}}
>
>In: A.B
>Out: {{a[1,1] b[1,1]+a[1,2] b[2,1],a[1,1] b[1,2]+a[1,2] b[2,2],a[1,1]
>b[1,3]+a[1,2] b[2,3],a[1,1] b[1,4]+a[1,2] b[2,4]},{a[2,1] b[1,1]+a[2,2]
>b[2,1],a[2,1] b[1,2]+a[2,2] b[2,2],a[2,1] b[1,3]+a[2,2] b[2,3],a[2,1]
>b[1,4]+a[2,2] b[2,4]},{a[3,1] b[1,1]+a[3,2] b[2,1],a[3,1] b[1,2]+a[3,2]
>b[2,2],a[3,1] b[1,3]+a[3,2] b[2,3],a[3,1] b[1,4]+a[3,2] b[2,4]}}
>
>Can anyone explain what's going on?
>Thanks for your help.
>
>Cheers,
>
>Des Penny
>penny@suu.edu
>
>
>
>

NV Vandemoortele Coordination Center Oils & Fats Applied Research
Prins Albertlaan 79
Postbus 40
B-8870 Izegem (Belgium)
Tel: +/32/51/33 21 11
Fax: +/32/51/33 21 75
vdmcc@vandemoortele.be




  • Prev by Date: Re: Matrix Multiplication
  • Next by Date: EPS printing problems
  • Prev by thread: Re: Matrix Multiplication
  • Next by thread: Re: Matrix Multiplication