Message Boards Message Boards


Row vs column vectors?

Posted 6 months ago
5 Replies
1 Total Likes

I am 73 years old and retired. I failed Calculus in college. I am working my way through Linear Algebra (with Mathematica in the Cloud) and am perplexed by how Mathematica represents column vectors.

Wolfram U’s “Introduction to Linear Algebra” has a section in chapter 4 on Vector Equations in which the numbers in column vectors are moved into an augmented matrix. The example is simple and so the conversion to a matrix is done manually. I succeeded in doing the conversion in Mathematica:

v1= {1,2,3} // MatrixForm
v2 = {5,-13,3} // MatrixForm
b= {-3, 8, 2} // MatrixForm

The column vectors look like row vectors until you display them with "// MatrixForm." They are displayed quite differently using MatrixForm[ ]. Such differences lead me to the attached PDF and to the question why Mathematica doesn't CLEARLY distinguish between row and column vector. Any comments (however critical) would be appreciated.

5 Replies
Posted 6 months ago

I'm sure you'll get responses from those with more expertise, but I wanted to point out a few things first. I haven't actually watched the intro to linear algebra video (doesn't seem to want to load for me right now), so some comments might be off base.

Be very careful with any Mathematica function that has "Form" in the name: MatricForm, TableForm, etc. You should think of these as special display-only functions. The basically wrap what you give them in a special "box" that causes the front end to apply special display rules. That special "box" will usually interfere with "normal" operations you might want to perform on your data. As soon as you apply MatrixForm, you no longer have a nice, simple matrix. You have a matrix hidden inside a "box", and that "box" doesn't understand arithmetic.

So, for example, for your vector v1, when you did this,

v1= {1,2,3} // MatrixForm

what you actually did was assign a special "box" to the variable v1. Inside that "box" is your vector, but anything you do directly to v1 will likely not be what you want. If you want to see v1 in matrix form, do the assignment first and then the display, like this:

v1= {1,2,3}; v1 // MatrixForm

Not sure how familiar you are with Mathematica, so I'll just note that you can put things on different lines or in different cells. Also, // is just a pretty way to apply a head to an expression, so you could do

v1= {1,2,3};
POSTED BY: Eric Rimbey
Posted 6 months ago

As for row vectors versus column vectors, that's really just a convenient way to think about vectors so that the definitions of matrix multiplication extend to vectors. It's a representational choice, but it's not all that substantive from a semantic point of view. A vector of three elements means the same thing whether it's represented as a row vector or a column vector. Mathematica just dispenses with all of that. The List construct is probably the most common thing in Mathematica, and it is used for vectors and matrices. To do matrix multiplication as you see in textbooks, you should use Dot.

v1 = {1, 2, 3};
m1 = {{10, 11, 12}, {20, 21, 22}};
m1 . v1
(* outputs {68, 128} *)

or alternatively

Dot[m1, v1]

This is just a representational choice. There is no distinction in Mathematica between row vector and column vector, so there is no reason to provide a visual distinction between them.

POSTED BY: Eric Rimbey
Posted 6 months ago

To be concrete, in your pdf, let's start with the left column. Transpose[trueRowVector] actually didn't do anything. There aren't enough dimensions for transpose to actually have an effect. When you wrapped it in MatrixForm, you just added that special box I mentioned.

In the second column, you did the wrapping as part of the assignment, so pseudoColVector isn't actually a vector at all. It's a vector hidden inside the fancy box. So, everything you do after that is suspect.

In the third column, trueColVector actually has two dimensions, so it's really a matrix. That one you can, indeed, apply Transpose to.

Side note, as you've no doubt noticed, MatrixForm displays 1-dimensional vectors vertically by default. That's just a choice. It so happens that there are options to control this. Try

MatrixForm[{a, b, c}, TableDirections -> Row]

to see a different orientation.

POSTED BY: Eric Rimbey

In Mathematica:

  1. A vector is a list. Example: v = {3, 4, -1, 2}. It has "rank" 1: Part works with 1 index and no more. So v[[2]] is good and v[[2, 1]] gives an error. Also Dimensions[v] is a list of length equal to the rank of v, namely, the list {4} of length 1.

  2. A matrix is a list of lists all of the same length. Example: m = {{1, 2}, {3, 4}, {5, 6}}. It has "rank" 2: Part works with 1 or 2 indices and no more. So m[[2]] is good, m[[2, 1]] is good, but m[[2, 2, 1]] gives an error. Also Dimensions[m] is a list of length equal to the rank of m, namely, the list {3, 2} of length 2.

  3. We can go on to higher ranks, a list of lists of lists, etc. and the pattern continues. But this would take us away from introductory linear algebra. Such objects are called "tensors." A vector is a rank-1 tensor and a matrix is a rank-2 tensor. I mention it only because some messages in Mathematica refer to vectors and matrices as tensors, and it will be good to be able to understand what such messages are trying to tell you.

Consequently, vectors are not distinguished as row or column vectors. In some languages and in some linear algebra courses, a row vector is a matrix with one row, and similarly, a column vector is a matrix with one column. In Mathematica, you could construct such matrices, but usually you can deal with just vectors. For instance, {{1, 2, 3}} is a row vector, and its transpose {{1}, {2}, {3}} is a column vector, according to the convention I proposed. The following tells how to treat a Mathematica vector as a row or column vector in matrix multiplication:

  • For instance m.v multiplies a matrix m and vector v, treating v as a column matrix, assuming you pick a matrix whose number of columns equals the length of the vector.

  • And v.m multiplies a matrix m and vector v, treating v as a row matrix, assuming you pick a matrix whose number of row equals the length of the vector.

Finally, if v is a rank-1 vector, then to convert it to a matrix vector you can use ArrayReshape:

rowVector = ArrayReshape[v, {1, Length[v]}]
colVector = ArrayReshape[v, {Length[v], 1}]

The following is another way to convert it:

rowVector = {v}
colVector = List /@ v
POSTED BY: Michael Rogers

Rather than writing:

V1 = {1, 2, 3} // MatrixForm


MatrixForm[V1 = {1, 2, 3}]

Such that V1 is not assigned any MatrixForm, but it is displayed when printed.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract