Re: How to mutiply a 3x1 and 1x3 vector
- Subject: [mg3082] Re: [mg3068] How to mutiply a 3x1 and 1x3 vector
- From: rpratt at math.unc.edu (Robert Pratt)
- Date: 31 Jan 1996 04:39:35 -0600
- Approved: usenet@wri.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: Wolfram Research, Inc.
- Sender: daemon at wri.com
I would suggest two equivalent approaches. In either case, you need to
define A and B so that Mathematica recognizes them as matrices (lists of
row vectors, which are themselves lists) rather than just lists of elements.
Method 1:
A={{1, 2, 3}}
B={{3, 4, 5}}
Note that MatrixQ[A] and MatrixQ[B] return True, but MatrixQ[{1, 2, 3}] and
MatrixQ[{3, 4, 5}] return False.
Transpose[A]//MatrixForm
B//MatrixForm
Transpose[A].B//MatrixForm
This last command returns a 3x3 matrix, the desired result.
Here, the //MatrixForm is just for appearance (so that the output looks
like a matrix). You can omit it if you wish.
Method 2:
A={{1}, {2}, {3}}
B={3, 4, 5}
A.B//MatrixForm
Which method you use depends on your preference. Method 1 is better if you
want to define all your vectors in a consistent manner. For example, if
you need to compute both A.B and B.A, you would want to define A and B
similarly (both as row vectors or both as column vectors). You then have to
transpose before multiplying. However, method 2 saves one step in the
calculation since you're performing the transpose "manually" in your
definition of A.
Rob Pratt
Department of Mathematics
The University of North Carolina at Chapel Hill
CB# 3250, 331 Phillips Hall
Chapel Hill, NC 27599-3250
rpratt at math.unc.edu
On Tue, 30 Jan 1996, Stephen Nichols wrote:
>
> Hi,
>
> I have another question that I thought would be simple to to in Mathematica.
> I have two vectors A={1,2,3} and B={3,4,5}. How do I multiple them together
> to get a 3x3 matrix. A . B gives me a scalar result. Mma seems to always
> treat the first one as a row vector and the second as a column vector. I
> need it to do the opposite. Treat the first as a column vector and the second
> as a row vector. Any ideas?
>
> thanks,
>
>
>