2
$\begingroup$

Mathematica makes no distinction between columns and rows. Yet, that is a BIG deal in the classroom. Does anyone have a source that explains how Mathematica manages to make every vector a list and every list a vector regardless of whether they are columns or rows? I have searched for this a lot with no success.

$\endgroup$
3
  • 7
    $\begingroup$ Maybe the following answer by @Szabolcs suffices? $\endgroup$
    – Carl Woll
    Commented Jun 17, 2019 at 18:57
  • $\begingroup$ Very helpful. I see I need to brush up on Tensors. Thanks. $\endgroup$
    – Rogo
    Commented Jun 17, 2019 at 19:58
  • $\begingroup$ I just write my vectors as 1 x n Or n x 1 matrices as appropriate, to enforce expected behavior. The only real burp comes when you take the inner product of a row and column. The result is a 1 x 1 matrix rather than a hoped for scalar. $\endgroup$
    – MikeY
    Commented Jun 19, 2019 at 12:12

2 Answers 2

2
$\begingroup$

When you're teaching I recommend connecting vector representations explicitly to the underlying linear-algebra concepts.

A vector is an abstract concept: it is an element of a vector space. To represent it in a computer, we must define a basis set and express the vector as a linear combination of the basis-set elements. The list of coefficients in this linear combination is what Mathematica uses to represent the vector. The vector itself cannot be represented directly in a computer (except for some symbolic tensors).

Such a linear-combination expression in terms of a basis set can be done for any vector in any finite-dimensional vector space (FDVS). In this sense, vectors of any FDVS as well as vectors of its dual space (which is a FDVS as well) can all be represented as linear combinations of basis vectors. There is no intrinsic difference between how vectors of a FDVS and those of its dual space are represented.

Mathematica represents both FDVS elements and dual-space elements as lists of coefficients for the corresponding basis set. In other circumstances, vectors and dual-space vectors are written distinctly:

  • MATLAB writes vectors as columns ($n\times1$ matrices) and dual-space vectors as rows ($1\times n$ matrices). This helps to distinguish them and to calculate their scalar products as matrix multiplications.
  • The Dirac notation of quantum physics writes vectors as kets $\lvert\psi\rangle$ and dual-space vectors as bras $\langle\psi\rvert$. This helps to recognize their identities and scalar products more easily.

Further reading: chapter 2 of my book Using Mathematica for Quantum Mechanics: A Student's Manual

$\endgroup$
4
  • $\begingroup$ I think this may be obfuscating the issue here. For a given positive integer n, the set of all n-tuples of real numbers is a vector space (with respect to the usual operations), and each element of this set may be represented in Mathematica as a simple (unnested) list. $\endgroup$
    – murray
    Commented Jun 18, 2019 at 15:18
  • $\begingroup$ @murray In your comment you choose a particularly simple example where the tacitly assumed basis is the set of Kronecker $n$-tuples $\{\{1,0,0,\ldots,0\}, \{0,1,0,\ldots,0\}, \ldots, \{0,0,0,\ldots,1\}\}$, and so the correspondence between an $n$-tuple and an $n$-list-of-coefficients looks trivial. I agree that in this simple case what I say borders on obfuscation. Yet in only slightly more complex cases it's crucial to remember the linear-algebra underpinning, and to remember that objects (vectors) and representations (lists) are in different categories. $\endgroup$
    – Roman
    Commented Jun 18, 2019 at 15:39
  • $\begingroup$ By definition, a vector space consists of a set provided with an internal operation and an external operation satisfying the usual axioms. I made no assumption whatsoever about a basis! I just stated the simple, trivial-to-prove, fact that, with respect to the usual operations of addition and multiplication by scalars, the set of all n-tuples of reals is a vector space. One immediately deduces that the n-tuples you list do form a basis of this vector space. (I do, though, understand the distinctions needed in geometry among points, vectors, and covectors.) $\endgroup$
    – murray
    Commented Jun 18, 2019 at 16:30
  • $\begingroup$ @murray I think we agree in practice and are splitting hairs over a quasi-religious difference: is an $n$-tuple the same thing as its representation in a list of numbers inside the computer, or is there a trivial bijection involved? I don't mean the hair-splitting over double-precision representations vs. true real numbers; but rather the distinction between the abstract and the concrete. I am not versed enough in modern math and philosophy to stake any claims here, please take all I said with a grain of salt. $\endgroup$
    – Roman
    Commented Jun 18, 2019 at 17:42
1
$\begingroup$

Presumably "column vector" means a matrix having 1 column.

But what is meant by "row vector" ? If it means a matrix having 1 row, then it's easy to make the distinction between row vectors and column vectors in Mathematica:

    lis = {5, -9, 7/3};

    rowvec = {lis}
(*  {{5, -9, 7/3}}  *)

    colvec = Partition[lis, 1]
(*  {{5}, {-9}, {7/3}}  *)

    Dimensions[lis]
(*  {3}  *)

    Dimensions[rowvec]
(*  {1, 3}  *)

    Dimensions[colvec]
(*  {3, 1}  *)

Note that a "row vector" such as rowvec, above, is not considered as a "vector" by Mathematica!

    VectorQ[rowvec]
(*  False  *)
    VectorQ[lis]
(*  True  *)

A trouble with many linear algebra textbooks is the failure to make a clear distinction between a simple list, on the one hand, and a row vector (as a 1-row matrix), on the other hand.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.