Vectors

Drawing a Vector

We need a little module to draw a vector in Mathematica:

Arrow3D[{x1_,y1_,z1_},{x2_,y2_,z2_},color_]:=Module[{line,head,headsize},
headsize=0.015*(Sqrt[(((x1-x2))^2)+(((y1-y2))^2)+(((z1-z2))^2)]);
head=Sphere[{x2,y2,z2},headsize];
line=Line[{{x1,y1,z1},{x2,y2,z2}}];
Return[Graphics3D[{color,Thick,line,head}]];
]

Here is the vector from p to q:

p={1,0,3}
q={-1,4,5}

plot1=Show[Arrow3D[p,q,Blue],Axes->True,AxesLabel->{"x","y","z"}]

I am using a small sphere at the head of the vector--for some reason, Mathematica is not very good at drawing vectors in (ℝ^3)!

Standard Position

Standard position moves the tail of the vector to the origin, but the vector has the same length and is parallel to the original vector.

p={1,0,3}
q={-1,4,5}
q-p

Show[plot1,Arrow3D[{0,0,0},q-p,Red],Axes->True,AxesLabel->{"x","y","z"}]

Notice the red vector has it's tail at the origin, but it has the same length and is parallel to the original blue vector.

Because of this, we can instead use a module that always draws the vector in the standard position:

plotvector3D[{x_,y_,z_},color_,opts_]:=Module[{line,head,headsize},
headsize=0.015*(Sqrt[(x^2)+(y^2)+(z^2)]);
head=Sphere[{x,y,z},headsize];
line=Line[{{0,0,0},{x,y,z}}];
Return[Graphics3D[{color,opts,line,head}]];
]

Show[plotvector3D[q-p,Blue,Thick],Axes->True,AxesLabel->{"x","y","z"}]

Vector Addition

Vector addition is accomplished by creating a parallelogram from two vectors, and the sum of the two vectors is the diagonal of the parallelogram.

u={-1,3,1}
v={4,7,0}
Show[plotvector3D[u,Blue,Thick],plotvector3D[v,Blue,Thick],plotvector3D[u+v,Red,Thick],Axes->True,AxesLabel->{"x","y","z"}]

Notice that if you rotate the diagram you can make all the vectors line up in one plane.

Vector Subtraction

u={-1,3,1}
v={4,7,0}
Show[plotvector3D[u,Blue,Thick],plotvector3D[v,Blue,Thick],plotvector3D[-v,Green,Thick],plotvector3D[u-v,Red,Thick],Axes->True,AxesLabel->{"x","y","z"}]

Scalar Multiplication of a Vector

u={-1,3,1}
Show[plotvector3D[u,Blue,Thick],plotvector3D[1/2u,Red,Thickness[0.015]],Axes->True,AxesLabel->{"x","y","z"}]

u={-1,3,1}
Show[plotvector3D[u,Blue,Thick],plotvector3D[-1/2u,Red,Thickness[0.015]],Axes->True,AxesLabel->{"x","y","z"}]

Unit Vectors

A unit vector is a vector that has length 1. So for any vector we can calculate the unit vector by dividing by the magnitude of the vector (provided the vector does not equal the zero vector):

The component of a vector can be accessed in Mathematica using square brackets.

w={34,4,-π}

w[[1]]
w[[2]]
w[[3]]

u={-1,3,1}
unitu=(u/(Sqrt[((u[[1]])^2)+((u[[2]])^2)+((u[[3]])^2)]))
Show[plotvector3D[u,Blue,Thick],plotvector3D[unitu,Red,Thickness[0.015]],Axes->True,AxesLabel->{"x","y","z"}]

Standard Unit Vectors

i={1,0,0};
j={0,1,0};
k={0,0,1};

unitvectors=Show[plotvector3D[i,Darker[Green],Thick],plotvector3D[j,Darker[Green],Thick],plotvector3D[k,Darker[Green],Thick],Axes->True,AxesLabel->{"x","y","z"}]

We can write any vector in terms of the standard unit vectors, for example:

w=i+2*j+1/2*k
Show[unitvectors,plotvector3D[w,Blue,Thick],Axes->True,AxesLabel->{"x","y","z"}]

We can do this because the standard unit vectors form a basis for vectors in (ℝ^3)(basis is an idea you see in linear algebra). This means that any vector can be written as linear combination of the vectors i, j, k.  We shall see later (when we look at spherical and cylindrical coordinates) that other sets of vectors can be used as a basis for vectors in (ℝ^3).