Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Row vs. Column Vectors (or Matrices)

2 views
Skip to first unread message

John Resler

unread,
Apr 22, 2002, 1:09:36 AM4/22/02
to
Hi,
I'm new to Mathematica and am doing a little linear algebra. I am
aware of the MatrixForm[m]
function but I know of no way to create a row vector eg. [ 1.0 2.0 3.0
] * [ 1.0

2.0

3.0].

Can someone point me in the right direction? Thanks ahead of time.

-John


Jens-Peer Kuska

unread,
Apr 23, 2002, 7:27:09 AM4/23/02
to
Hi,

how does

MatrixForm[{{a,b,c}}]

look ?

Regards
Jens

BobH...@aol.com

unread,
Apr 23, 2002, 7:32:19 AM4/23/02
to

In a message dated 4/22/02 1:32:59 AM, John-...@kscable.com writes:

>I'm new to Mathematica and am doing a little linear algebra. I am
>aware of the MatrixForm[m]
>function but I know of no way to create a row vector eg. [ 1.0 2.0 3.0
>
>] * [ 1.0
>
>
> 2.0
>
>
> 3.0].
>
>Can someone point me in the right direction? Thanks ahead of time.

{{a1, a2, a3}}.{{b1},{b2},{b3}}

{{a1*b1 + a2*b2 + a3*b3}}


{{a11, a12, a13},{a21,a22,a23}}.{{b1},{b2},{b3}}

{{a11*b1 + a12*b2 + a13*b3}, {a21*b1 + a22*b2 + a23*b3}}


Bob Hanlon
Chantilly, VA USA

Murray Eisenberg

unread,
Apr 23, 2002, 7:35:10 AM4/23/02
to
It's not clear from your message whether you merely want to display a
"row vector" or to create one (these are different issues). Moreover,
the very notion of "row vector" is ambiguous (at least in ordinary
mathematical parlance!).

You can represent an ordinary vector in Mathematica as a list (which is
a one-dimensional creature):

v = {1, 2, 3}

Or you can represent it as a list whose sole element is a list (which is
essentiall a two-dimensional creature):

vRow = {{1, 2, 3}}

Then using MatrixForm[v] will produce a "stacked" column 3-rows high!
But using MatrixForm[vRow] will produce probably what you want to SEE:

(1 2 3)

You wrote " * " for the operation combining these two vectors. Do you
mean "dot product"? If so, then this is abbreviated by " . " in
Mathematica. Thus:

v . w
14

Unfortunately the following creates an error:

vRow . wRow
Dot::"dotsh": "Tensors ({{1, 2, 3})} and ({4, 5, 6})} have incompatible
shapes."

However:

vRow . Transpose[wRow]
{{32}}

And the latter agrees perfectly with the true definition of dot product,
in mathematics, of a 1-by-3 matrix with a 3-by-1 matrix, which yields a
1-by-1 matrix (and NOT a scalar).

You see that ordinary mathematical notation gets a bit sloppy about
these distinctions, whereas an executable notation such as Mathematica
must be very precise.


John Resler wrote:
>
> Hi,


> I'm new to Mathematica and am doing a little linear algebra. I am
> aware of the MatrixForm[m]
> function but I know of no way to create a row vector eg. [ 1.0 2.0 3.0
> ] * [ 1.0
>
> 2.0
>
> 3.0].
>
> Can someone point me in the right direction? Thanks ahead of time.
>

> -John

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street
Amherst, MA 01375

David Park

unread,
Apr 23, 2002, 7:39:14 AM4/23/02
to
John,

Basically, you have to read Section 3.7, Linear Algebra, in the Mathematica
Book. Go to the Help browser, select The Mathematica Book, type 3.7 in GoTo
field and click GoTo. You will probably be especially interested in section
3.7.5 on multiplying matrices and vectors. The subject is slightly tricky in
Mathematica and so it is worthwhile practicing with the examples and
learning the basics.

Here is a sample matrix and vector:

mat = Array[a, {3, 3}]
{{a[1, 1], a[1, 2], a[1, 3]}, {a[2, 1], a[2, 2], a[2, 3]}, {a[3, 1], a[3,
2],
a[3, 3]}}

vec = {1, 2, 3};

vec is neither a row vector nor a column vector. It is just a vector.
Mathematica treats it properly by context. Here it is treated as a column
vector in the usual textbook representation.

mat.vec
{a[1, 1] + 2 a[1, 2] + 3 a[1, 3], a[2, 1] + 2 a[2, 2] + 3 a[2, 3]}

But if we put the vector before the matrix, Mathematica treats it as a row
vector.

vec.mat
{a[1, 1] + 2 a[2, 1] + 3 a[3, 1], a[1, 2] + 2 a[2, 2] + 3 a[3, 2],
a[1, 3] + 2 a[2, 3] + 3 a[3, 3]}

If we want the dot product of the vector with itself, we just write...

vec.vec
14

If we want to convert the vector to a one row matrix we write...

{vec}
{{1, 2, 3}}

If we want to convert the vector to a one column matrix we write...

Transpose[{vec}]
{{1}, {2}, {3}}

We could use matrix multiplication on these to generate a 3x3 matrix.

Transpose[{vec}].{vec}
{{1, 2, 3}, {2, 4, 6}, {3, 6, 9}}

Or obtain the dot product, in a rather silly way, as a 1x1 matrix.

{vec}.Transpose[{vec}]
{{14}}

There are many more little tricks to learn about using and displaying
vectors and matrices. You will probably need them, so study Section 3.7 in
The Book.

David Park
dj...@earthlink.net
http://home.earthlink.net/~djmp/

Adam Smith

unread,
Apr 23, 2002, 7:43:22 AM4/23/02
to
See if the following is what you want

In[1]:=
vector1 = {a,b,c}

Out[1]=
{a,b,c}

In[2]:=
vector2 = {c,d,e}

Out[2]=
{c,d,e}

In[3]:=
Outer[Times,vector1,vector2]

Out[3]=
{{a*c, a*d, a*e}, {b*c, b*d, b*e}, {c^2, c*d, c*e}}


In[4]:=
MatrixForm[Outer[Times,vector1,vector2]]

Note that MatrixForm is such a so-called wrapper that essentially just
changes the way things display on the screen.

It is not necessary to put the 2nd vector in a 1-column format due to
the construction of the Outer[] function.

John Resler <John-...@kscable.com> wrote in message news:<aa05ug$25i$1...@smc.vnet.net>...

Sseziwa Mukasa

unread,
Apr 23, 2002, 7:44:23 AM4/23/02
to

On Monday, April 22, 2002, at 12:57 AM, John Resler wrote:

> Hi,
> I'm new to Mathematica and am doing a little linear algebra. I am
> aware of the MatrixForm[m]
> function but I know of no way to create a row vector eg. [ 1.0 2.0 3.0
> ] * [ 1.0
>
> 2.0
>
> 3.0].
>
> Can someone point me in the right direction? Thanks ahead of time.
>

Mathematica doesn't distinguish between a vector and a 1 by n matrix,
but there is no similar shorthand for a nx1 matrix so enter it using two
levels ie. {{1},{2},{3}}, MatrixForm will then give you your desired
results.

Regards,

Ssezi


Eric L. Strobel

unread,
Apr 24, 2002, 1:33:31 AM4/24/02
to
I think the point was that a Dot product was desired.

And a point of advice... Just remember, due to the way Mathematica deals
with matrices (and particularly column vectors), there are often extra sets
of braces surrounding results. Generally not a problem, until you try to
get at a particular matrix element -- depending upon how one does it, you
may have to 'peel the onion' several layers down.

(Asthetically, I find these artifacts a tiny bit annoying. I don't suppose
there's an automatic way of shedding them, is there?)

At the risk of making this reply too broad, is there any recent progress on
the front of *symbolic* matrix algebra/calculus?? I'm aware of NCAlgebra,
and while it is a workable stopgap I guess, there ought to be something
better, given that this has been a known inadequacy of Mathematica for many
years now.

- Eric.

on 4/23/02 7:14 AM, Adam Smith at adam....@hillsdale.edu wrote:

> See if the following is what you want
>

*** Demonstration of Outer Product removed ***

>
> Note that MatrixForm is such a so-called wrapper that essentially just
> changes the way things display on the screen.
>
> It is not necessary to put the 2nd vector in a 1-column format due to
> the construction of the Outer[] function.
>
> John Resler <John-...@kscable.com> wrote in message
> news:<aa05ug$25i$1...@smc.vnet.net>...

>> Hi,
>> I'm new to Mathematica and am doing a little linear algebra. I am
>> aware of the MatrixForm[m]
>> function but I know of no way to create a row vector eg. [ 1.0 2.0 3.0
>> ] * [ 1.0
>>
>> 2.0
>>
>> 3.0].
>>
>> Can someone point me in the right direction? Thanks ahead of time.
>>

>> -John
>

--

Eric Strobel (fyzycyst@NOSPAM^mailaps.org)

=====================================================================
There is never a single right solution. There are always multiple
wrong ones, though.
=====================================================================


0 new messages