Math 236  •  5 February 2001

Vectors

Name (s):

Representing vectors as lists

Officially, an n-vector—that is, a member of (ℝ^n)—is a matrix with n rows and just one column.  So that's why an n-vector is referred to as a column vector.  For example, the vector (({{1}, {2}, {3}})) ∈ (ℝ^3) is a 3 × 1 matrix, that is, a matrix with three rows and one column.  To represent this vector in Mathematica then, form  a list consisting of of the three lists {1} and {2} and {3}.  Thus the Mathematica representation is:

colvec  =  { {1},  {2},  {3} }

Sometimes it's handy to think of an n-vector in either of two other ways:
(i)  as an ordered list, or
(ii) as a one-row matrix—a 1 × n matrix—in other words, as a row vector.
The corresponding representations in Mathematica are (i) a list of n entries,  and (ii) a one-entry list whose single entry is a list of n entries.  For example:

vec  =  {1,  2,  3}
rowvec  =  { {1,  2,  3} }

Check the number of dimensions of each of the preceding three representatations of a vector:

Dimensions[vec]
Dimensions[rowvec]
Dimensions[colvec]

Now find the lengths of the three representations:

Length[vec]
Length[rowvec]
Length[colvec]

Predict the results of the following expressions before evaluating them:

Dimensions[Dimensions[vec]]
Dimensions[Dimensions[rowvec]]
Dimensions[Dimensions[colvec]]

Task 1

Create in Mathematica a vector representation v for which Dimensions[Dimensions[v]] is {2} and Length[v] is 5.  
Does v represent the ordered list, row vector, or column vector form of a mathematical vector?
Execute an expression that extracts the third entry in the vector.

Repeat the preceding but for a vector w with Dimensions[Dimensions[w]] being {1} and Length[w] being 5.

Displaying vectors in MatrixForm

The MatrixForm function displays a vector (or matrix) in a traditional two-dimensional mathematical format rather than in the form of a Mathematica list:

MatrixForm[vec]
MatrixForm[rowvec]
MatrixForm[colvec]

Try adding the various forms of the original vector:

vec  +  vec
rowvec  +  rowvec
colvec  +  colvec
vec  +  rowvec
rowvec  +  colvec
vec  +  colvec

Task 2

Some of those sums did not give a resultant vector.  Explain why not in each such case.

Symbolic vectors and proofs

Mathematica's Array function allows you to create symbolic vectors, matrices, and others arrays.  For example:

Clear[u,  x]
u  =  Array[x,  3]

Clear[v,  y]
v  =  Array[y,  3]

⚠  Caution:  If you try something like x = Array[x, 3], where the symbol x apprears on both sides of the assignment operator = , you'll get into big trouble.  If you don't believe that, just try it—but be sure you've saved your work first!  (You'll need to choose Abort Evaluation from the Kernel menu to get out of the hole you've dug for yourself.)

Clear[z] 
z  =  Array[z,  3]

Add the two vectors in both possible orders:

u  +  v
v  +  u

Observe that Mathematica already simplified the form of v + u.  The next cell and its result provide a proof of the commutative law for addition of n-vectors, just in dimension n = 3:

u  +  v  ==  v  +  u

Task 3

Use Mathematica as above to demonstrate the following two vector laws in dimension n = 5 (five):
	\(TraditionalForm\`c\ \((\(u\& -> \)\  + \ \(v\& -> \))\)\  = \ c\ \(u\& -> \)\  + \ c\ \(v\& -> \)\)
\(TraditionalForm\`\(w\& -> \)\  + \ \((\(-\ \(w\& -> \)\))\)\  = \ \(0\& -> \)\)
(Hint:  You may need to apply Simplify to force Mathematica to use its usual rules for simplifying scalar algebraic expressions.)

Plotting vectors in the plane

Drawing line segments

Mathematica automatically knows how to plot a line segment.  For example:

Show[Graphics[Line[{{0,  0},  {3,  1}}]]]

Here's what's happening.  First, Line gives a primitive graphics object that is cannot be further evaluated by itself:

Line[{{0,  0},  {3,  1}}]

Next, wrapping the Graphics function around that produces a graphics object as result—but no display of graphics as a side-effect:

Graphics[Line[{{0,  0},  {3,  1}}]]

Finally, applying the Show function actually displays the line segment:

Show[Graphics[Line[{{0,  0},  {3,  1}}]]]

Drawing directed line segments (arrows)

For the geometric representation of vectors as directed line segments, however, we want to use arrows.  The function Arrow to create a line segment with an arrowhead is not, however, built into the kernel.  Instead, it is in one of the standard add-on packages.  Documentation about standard packages is available in the Help Browser.  Find it there now!

To read in any standard (or other) package you need to know the name of the package as well as its "context path" (which reflects the directory or folder structure on the hard disk where the Mathematica program files are stored).  In our case, the package is also named Arrow, and the folder containing it is named Graphics, so the full context name is Graphics`Arrow`.  The symbol ` here is the backquote, not the ordinary single quote found on the same key as the double quote.  Notice the trailing backquote, too.  (You'll learn more about contexts and context paths later.)

The command to read in the package is:

Needs["Graphics`Arrow`"]

Be sure to evaluate the preceding input cell before proceeding any further in this notebook!

Once a package is read in, all the objects defined in it may be used as if they had been built into Mathematica as primitives.

origin  =  {0,  0}; 
p  =  {3,  1};  q  =  {2,  4};

Show[Graphics[{Arrow[origin,  p],  Arrow[origin,  q]}]];

The picture you just produced is qualitatively correct but quantitatively misleading and incomplete.  To force equal scales in the two directions, include the option AspectRatio -> Automatic; to indicate the quantitative extent of the vectors, include the option Axes -> True :

Show[Graphics[{Arrow[origin,  p],  Arrow[origin,  q]}],  
      AspectRatio  ->  Automatic,  
      Axes  ->  True];

To save some typing later, make a definition:

showit[grfstuff_]  :=  
      Show[Graphics[grfstuff],  AspectRatio  ->  Automatic,  
        Axes  ->  True]

Use it like this:

showit[{Arrow[origin,  p],  Arrow[origin,  q]}];

Task 4

For the vectors p and q defined above, use Mathematica to check that
	p + (q - p) = q.                             (*)
(Remember to use a double equal == for equality!)  Also, use the eight fundamental properties of vector algebra to explain why, in general, the identity (*) is true for all n-vectors p and q.

Use showit and Arrow to draw a figure showing the vectors p and q and their difference q - p; do not use the standard representation (tail at origin) for q - p, but rather a representation in which the three arrows representing p, q, and q - p form a triangle.  By hand label the three arrows with the vectors they represent.

Use the identity (*) to check that the arrow representing q - p in your figure has the correct direction.  Explain how you can tell on the basis of (*) that the direction is correct.

End of Vectors.nb