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,
Outer[Times,A,B]
: A . B gives me a scalar result.
This is an Inner or Dot product.
It seem to me that the best way to distinguish between row and column vectors is to write
them explicitly in matrix form.
{{a}, {b}, {c}} is a column vector.
{{x, y, z}} is a row vector.
{{a}, {b}, {c}}.{{x, y, z}} is a 3x3 matrix:
{{x, y, z}}.{{a}, {b}, {c}} is 1x1 matrix (as oppose to a scalar).
In[1]:= vector = {{a}, {b}, {c}}
Out[1]= {{a}, {b}, {c}}
In[2]:= MatrixForm[vector]
Out[2]//MatrixForm= a
b
c
In[3]:= covector = {{x, y, z}}
Out[3]= {{x, y, z}}
In[4]:= MatrixForm[covector]
Out[4]//MatrixForm= x y z
In[5]:= vector.covector
Out[5]= {{a x, a y, a z}, {b x, b y, b z}, {c x, c y, c z}}
In[6]:= MatrixForm[%]
Out[6]//MatrixForm= a x a y a z
b x b y b z
c x c y c z
In[7]:= covector.vector
Out[7]= {{a x + b y + c z}}
In[8]:= MatrixForm[%]
Out[8]//MatrixForm= a x + b y + c z
There is no problem to transfer lists into vectors or covectors. Here are obvious
micro-utilities.
ToVector[l_List]:= List /@ l
ToCovector[l_List]:= {l}
Greetings,
Leszek
Express your column vector as a 3x1 matrix, and your row vector as
a 1x3 matrix:
In[1]:=
{{1},{2},{3}}.{{3,4,5}}
Out[1]=
{{3, 4, 5}, {6, 8, 10}, {9, 12, 15}}
Dave Wagner
Principia Consulting
(303) 786-8371
dbwa...@princon.com
http://www.princon.com/princon
-Fernando f...@usl.edu