Next: Matrix Tutorial, Previous: Vector/Matrix Tutorial, Up: Vector/Matrix Tutorial

If you add two vectors, the result is a vector of the sums of the elements, taken pairwise.

1: [1, 2, 3] 2: [1, 2, 3] 1: [8, 8, 3] . 1: [7, 6, 0] . . [1,2,3] s 1 [7 6 0] s 2 +

Note that we can separate the vector elements with either commas or
spaces. This is true whether we are using incomplete vectors or
algebraic entry. The `s 1` and `s 2` commands save these
vectors so we can easily reuse them later.

If you multiply two vectors, the result is the sum of the products of the elements taken pairwise. This is called the dot product of the vectors.

2: [1, 2, 3] 1: 19 1: [7, 6, 0] . . r 1 r 2 *

The dot product of two vectors is equal to the product of their
lengths times the cosine of the angle between them. (Here the vector
is interpreted as a line from the origin ‘`(0,0,0)`’ to the
specified point in three-dimensional space.) The `A`
(absolute value) command can be used to compute the length of a
vector.

3: 19 3: 19 1: 0.550782 1: 56.579 2: [1, 2, 3] 2: 3.741657 . . 1: [7, 6, 0] 1: 9.219544 . . M-<RET> M-2 A * / I C

First we recall the arguments to the dot product command, then we compute the absolute values of the top two stack entries to obtain the lengths of the vectors, then we divide the dot product by the product of the lengths to get the cosine of the angle. The inverse cosine finds that the angle between the vectors is about 56 degrees.

The cross product of two vectors is a vector whose length is the product of the lengths of the inputs times the sine of the angle between them, and whose direction is perpendicular to both input vectors. Unlike the dot product, the cross product is defined only for three-dimensional vectors. Let's double-check our computation of the angle using the cross product.

2: [1, 2, 3] 3: [-18, 21, -8] 1: [-0.52, 0.61, -0.23] 1: 56.579 1: [7, 6, 0] 2: [1, 2, 3] . . . 1: [7, 6, 0] . r 1 r 2 V C s 3 M-<RET> M-2 A * / A I S

First we recall the original vectors and compute their cross product, which we also store for later reference. Now we divide the vector by the product of the lengths of the original vectors. The length of this vector should be the sine of the angle; sure enough, it is!

Vector-related commands generally begin with the `v` prefix key.
Some are uppercase letters and some are lowercase. To make it easier
to type these commands, the shift-`V` prefix key acts the same as
the `v` key. (See General Mode Commands, for a way to make all
prefix keys have this property.)

If we take the dot product of two perpendicular vectors we expect to get zero, since the cosine of 90 degrees is zero. Let's check that the cross product is indeed perpendicular to both inputs:

2: [1, 2, 3] 1: 0 2: [7, 6, 0] 1: 0 1: [-18, 21, -8] . 1: [-18, 21, -8] . . . r 1 r 3 * <DEL> r 2 r 3 *

(•) **Exercise 1.** Given a vector on the top of the
stack, what keystrokes would you use to normalize the
vector, i.e., to reduce its length to one without changing its
direction? See 1. (•)

(•) **Exercise 2.** Suppose a certain particle can be
at any of several positions along a ruler. You have a list of
those positions in the form of a vector, and another list of the
probabilities for the particle to be at the corresponding positions.
Find the average position of the particle.
See 2. (•)