Calculus: The Language of Change

Exercise Set 15.2
Computer Exercise: #1
Position Vectors

solutions by David Theobald

Special Mathematica Functions used in this NoteBook

We told you not to look.  This horrible stuff sets various defaults and defines some functions needed to draw the geometric side of the lexicon.  Ignore the details here and go on to the lesson.

Off[General::spell];
Off[General::spell1];
Off[ParametricPlot3D::ppcom]
Needs["Graphics`Colors`"]

SetOptions[Graphics,Axes->False,AxesOrigin->{0,0},AspectRatio->Automatic];
SetOptions[Graphics3D,ViewPoint->{5,2,1},Boxed->False,AspectRatio->Automatic];
SetOptions[ParametricPlot3D,ViewPoint->{5,2,1},AspectRatio->Automatic];
SetOptions[Plot3D,ViewPoint->{5,2,1},AspectRatio->Automatic];
SetOptions[ParametricPlot,AspectRatio->Automatic];
SetOptions[Plot,AspectRatio->Automatic];

colorQ[a_]:=(Head[a]===RGBColor);
grayQ[a_]:=(Head[a]===GrayLevel);
thickQ[a_]:=(Head[a]===Thickness);
absthickQ[a_]:=(Head[a]===AbsoluteThickness);
notruleQ[u_] := !(Head[u]===Rule);
ruleQ[u_] := (Head[u]===Rule);

Norm::usage = "Norm[expr] returns the Euclidean length of the
		vector, 'expr'.";

Norm[a_?VectorQ] := Sqrt[a.a];

Angle[a_?VectorQ,b_?VectorQ] := ArcCos[(a.b)/(Norm[a] Norm[b])]

Proj[a_?VectorQ,b_?VectorQ] := ((a.b)/(b.b))b

tol = .5*10^-6;

OrthUp[a_?VectorQ] :=
	Module[{b,c,d,f},
		d = N[a/Norm[a]];
		If[Chop[d[[3]]^2 - 1,tol] == 0, b={1,0,0} ,
		b = {0,0,1} - d[[3]] d; b = b/Norm[b];];
	Return[b]];
	
OrthSet[a_?VectorQ] :=
	Module[{b,c,d},
		d = N[a/Norm[a]];
		If[Chop[d[[1]],tol]==0,b={1,0,0},
			 If[Chop[d[[2]],tol]==0,b={0,1,0},
			  b={-d[[2]],d[[1]],0}]];
			b=b/Norm[b];c = Cross[d,b];
	Return[{b,c/Norm[c],d}]];

				
Rotate[a_?VectorQ,theta_] :=
	Module[{u,v,r},
		u = OrthSet[a];
		v = Transpose[u];
		r = N[{{Cos[theta],-Sin[theta],0},{Sin[theta],Cos[theta],0},{0,0,1}}];
	Return[v.r.u]];

Vector2D[tail_,tip_,opts___]:=
	Module[{ntail,ntip,sopts,Punit,up,arrow},
	ntail = N[tail];
	ntip = N[tip];
	
	sopts = Join[Select[{opts},colorQ],Select[{opts},
				thickQ],Select[{opts},absthickQ],Select[{opts},grayQ]];

If[Chop[ntail.ntail+ntip.ntip,tol] == 0,
			(*too small to plot or not number*)
			Return[Graphics[Point[{0,0}]]];
	,						
If[Chop[(ntip-ntail).(ntip-ntail),tol] == 0,
		Return[Graphics[{Join[sopts,{Line[{ntail,ntip}]}]}]];
	,
	Punit = (.075 Norm[ntip-ntail]/Norm[ntip-ntail]) (ntip-ntail) ;
	up = 0.15 {-Punit[[2]],Punit[[1]]};
	arrow = Line[{ntail,ntip,ntip-Punit+up,ntip,ntip-Punit-up}];
	]];
Return[Graphics[{Join[{AbsoluteThickness[2]},Join[sopts,{arrow}]]}]];
];

Vector3D[tail_,tip_,opts___]:=
	Module[{ntail,ntip,sopts,Punit,up,u2,u3,u4,rotmat,arrow},
	ntail = N[tail];
	ntip = N[tip];
	
	sopts = Join[Select[{opts},colorQ],Select[{opts},
				thickQ],Select[{opts},absthickQ],Select[{opts},grayQ]];

If[Chop[ntail.ntail+ntip.ntip,tol] == 0,
			(*too small to plot or not number*)
			Return[Graphics3D[Point[{0,0,0}]]];					
	,		
If[Chop[(ntip-ntail).(ntip-ntail),tol] == 0,
		Return[Graphics3D[{Join[sopts,{Line[{ntail,ntip}]}]}]];
	,
	Punit = (ntip-ntail);
	rotmat = Rotate[Punit,N[Pi/2]];
	up = OrthUp[Punit];
	Punit = .075 Punit;
	up = .15 Norm[Punit] up;
	u2 = rotmat.up;
	u3 = rotmat.u2;
	u4 = rotmat.u3;
	arrow = Line[{ntail,ntip,
				ntip - Punit + up,ntip,
				ntip - Punit + u2,ntip,
				ntip - Punit + u3,ntip,
				ntip - Punit + u4}];
	]];
Return[Graphics3D[{Join[{AbsoluteThickness[2]},Join[sopts,{arrow}]]}]];
];

aRCtAN[y_,x_] := Module[{v},
	If[ Chop[N[x],tol] == 0 ,If[ N[y] < 0, v = -N[Pi/2], v = N[Pi/2]],
		v = N[ArcTan[y/x]];
		If[ x < 0 && y < 0, v = N[Pi -  v],v]];
	Return[v]];

Arc2D[X_,Y_,opts___] := Graphics[{opts,
		Disk[{0,0},1,{Min[
							aRCtAN[
						N[X[[2]]],N[X[[1]]]
								]
							,
							aRCtAN[
							N[Y[[2]]],N[Y[[1]]]
								]
						]
						,
					Max[
							aRCtAN[
						N[X[[2]]],N[X[[1]]]
								]
							,
							aRCtAN[
							N[Y[[2]]],N[Y[[1]]]
								]
						]}
				]}
				];
Arc3D[X_,Y_] := 
	Module[{t,U,V},
		U[V_]:= N[(1/Sqrt[V.V]) V];
		Return[Graphics3D[
		Polygon[Append[Table[U[t X + (1-t) Y],{t,0,1,0.1}],{0,0,0}]]
				]
		]
	];

(*Zero Arrow causes trouble. Put in Vector?*)

Vector[tail_,tip_,opts___]:=
	If[Length[N[tail]]==2,Return[Vector2D[tail,tip,opts]],
		Return[Vector3D[tail,tip,opts]]];
		
Arrow[vec_,opts___]:= 
	Module[{a,b},
				If[Length[N[vec]]==2,
				a=ToExpression["Tail"]/.Select[{opts},ruleQ]/.
					{ToExpression["Tail"]->{0,0}};
				Return[Vector2D[a,a+vec,opts]],
				a=ToExpression["Tail"]/.Select[{opts},ruleQ]/.
					{ToExpression["Tail"]->{0,0,0}};
				Return[Vector3D[a,a+vec,opts]]]
				];

Frame2D[delta_] := 
      Graphics[{
            {Green,Line[{{-delta/4,0},{delta,0}}]},
                    Text["x",{1.01 delta,0}],
            {Green,Line[{{0,-delta/4},{0,delta}}]},
                    Text["y",{0, 1.01 delta}]}];

Frame3D[delta_] := 
      Graphics3D[{
            {Green,Line[{{-delta/4,0,0},{delta,0,0}}]},
                    Text["x",{1.01 delta,0,0}],
            {Green,Line[{{0,-delta/4,0},{0,delta,0}}]},
                    Text["y",{0, 1.01 delta,0}],
            {Green,Line[{{0,0,-delta/4},{0,0,delta}}]},
                    Text["z",{0,0,1.01 delta}]}];

View2D[stuff_] := Show[stuff,Frame2D[1]];
View3D[stuff_] := Show[stuff,Frame3D[1]];

\(
\)

Exercise 1

Here is some practice with position vectors.

1-D

Graph the following position vectors and compute their lengths.

These are pretty straight forward number lines with the tail of the vector at the origin and the head at the x value.

a) A(-3)  Vector A has the tail dot on the origin and points to the negative (left) direction ending on -3

b) B(6)  Vector B has the tail dot on the origin and points to the positive (right) direction ending on 6

c) C(5.333)  Vector C has the tail dot on the origin and points to the positive (right) direction ending on 5.333

2-D

Graph the following position vectors and compute their lengths.

These are a little more work that the 1-D vectors in the previous part, but not too bad.  <Enter> in the input cell below to see the graph of the vector A.
a) A(3, 4)

\(A = {3, \ 4}; 

    View2D[{Arrow[A, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {A[[1]], 0}, 
                A}]}], Graphics[
          Text[A[[1
              ]], { .6\ 
                A[[1]],  .1\ 
                A[[2]]}]], 
        Graphics[
          Text[A[[2
              ]], { .9\ 
                A[[1]],  .5\ 
                A[[2]]}]]}]; \)

And now the length of vector A.  Another name for the geometric length is "norm."  We use this name for our geometric length function, because "Length[ X ]" is used by Mathematica  for the number of elements in the list.  Norm[.]  is defined in the Initialization Cell at the begining of this NoteBook in a compact form.    In 2-D the definition is equivalent to:

Norm[ X_ ] := \(TraditionalForm
      \`\@\(\((x\_\(1
	\))\)\^2 + \ \((x\_\(2
\))\)\^2\)\)

NOTE:  TO GET THE CORRECT LENGTH OPEN THE PICTURE FIRST BEFORE OPENING THE NORM COMMAND!!!
<Enter> below to get the length of vector A:

Norm[A]

The same process is done for the other parts of this problem as shown below:

b) B(-3, -2)

\(B = {\(-3\), \(-2\)}; 

    View2D[{Arrow[X, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {B[[1]], 0}, 
                B}]}], Graphics[
          Text[B[[1
              ]], { .6\ 
                B[[1]],  .1\ 
                B[[2]]}]], 
        Graphics[
          Text[B[[2
              ]], { .9\ 
                B[[1]],  .5\ 
                B[[2]]}]]}]; \)

And the length of vector B:

Norm[B]

c) C(-2, 6)

\(c = {\(-2\), \ 6}; 

    View2D[{Arrow[c, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {c[[1]], 0}, 
                c}]}], Graphics[
          Text[c[[1
              ]], { .6\ 
                c[[1]],  .1\ 
                c[[2]]}]], 
        Graphics[
          Text[c[[2
              ]], { .9\ 
                c[[1]],  .5\ 
                c[[2]]}]]}]; \)

And The length of Vector c:

Norm[c]

d) D(5, -3)

\(d = {5, \ \(-3\)}; 

    View2D[{Arrow[d, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {d[[1]], 0}, 
                d}]}], Graphics[
          Text[d[[1
              ]], { .6  d[[1
                  ]],  .1\ 
                d[[2]]}]], 
        Graphics[
          Text[d[[2
              ]], { .9\ 
                d[[1]],  .5\ 
                d[[2]]}]]}]; \)

And The length of Vector d:

Norm[d]

e) E(4.1, 2.7)

\(e = {4.1, \ 2.7}; 

    View2D[{Arrow[e, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {e[[1]], 0}, 
                e}]}], Graphics[
          Text[e[[1
              ]], { .6  e[[1
                  ]],  .1\ 
                e[[2]]}]], 
        Graphics[
          Text[e[[2
              ]], { .9\ 
                e[[1]],  .5\ 
                e[[2]]}]]}]; \)

And The length of Vector e:

Norm[e]

f) F(-3.5, 1)

\(f = {\(-3.5\), \ 1}; 

    View2D[{Arrow[f, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {f[[1]], 0}, 
                f}]}], Graphics[
          Text[f[[1
              ]], { .6  f[[1
                  ]],  .1\ 
                f[[2]]}]], 
        Graphics[
          Text[f[[2
              ]], { .9\ 
                f[[1]],  .5\ 
                f[[2]]}]]}]; \)

And The length of Vector f:

Norm[f]

3-D

Graph the following position vectors and compute their lengths.

These are very similar to the previous 2-D drawings, however, now a third direction has been added to the vector's coordinates.  <Enter> below to see the graph of vector A in three-dimensions.

a)  A(2, 1, 5)

\(a = {2, 1, 5}; 

    View3D[{Arrow[a, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {a[[1]], 0, 
                  0}, {a[[1]], 
                  a[[2]], 0}, a}]}], 
        Graphics3D[
          Text[a[[1
              ]], { .5\ 
                a[[1]],  .1\ 
                a[[2]], 
              0\ a[[3]]}]], 
        Graphics3D[
          Text[a[[2
              ]], { .8\ 
                a[[1]],  .5\ 
                a[[2]], 
              0\ a[[3]]}]], 
        Graphics3D[
          Text[a[[3
              ]], { .8\ 
                a[[1]],  .8\ 
                a[[2]],  .5\ 
                a[[3]]}]]}]; \)

Previously the norm was defined in terms of (Subscript[x, 1]) and (Subscript[x, 2]) only.  Now in 3-D, the norm will need to add in the (Subscript[x, 3]) term as well:

Norm[ X_ ] := \(TraditionalForm
      \`\@\(\((x\_\(1
	\))\)\^2 + \ \((x\_\(2
\))\)\^2 + \ 
          \((x\_3)\)\^2\)\)

NOTE:  TO GET THE CORRECT LENGTH OPEN THE PICTURE FIRST BEFORE OPENING THE NORM COMMAND!!!
<Enter> below to get the length of vector A:

Norm[a]

The same process is done for the other parts of this problem as shown below:

b) B(-3, 4, 2)

\(b = {\(-3\), 4, 2}; 

    View3D[{Arrow[b, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {b[[1]], 0, 
                  0}, {b[[1]], 
                  b[[2]], 0}, b}]}], 
        Graphics3D[
          Text[b[[1
              ]], { .5\ 
                b[[1]],  .1\ 
                b[[2]], 
              0\ b[[3]]}]], 
        Graphics3D[
          Text[b[[2
              ]], { .8\ 
                b[[1]],  .5\ 
                b[[2]], 
              0\ b[[3]]}]], 
        Graphics3D[
          Text[b[[3
              ]], { .8\ 
                b[[1]],  .8\ 
                b[[2]],  .5\ 
                b[[3]]}]]}]; \)

And the length of vector B:

Norm[b]

c)  C(-2, -4, -1)

\(c = {\(-2\), \(-4\), \(-1\)}; 

    View3D[{Arrow[c, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {c[[1]], 0, 
                  0}, {c[[1]], 
                  c[[2]], 0}, c}]}], 
        Graphics3D[
          Text[c[[1
              ]], { .5\ 
                c[[1]],  .1\ 
                c[[2]], 
              0\ c[[3]]}]], 
        Graphics3D[
          Text[c[[2
              ]], { .8\ 
                c[[1]],  .5\ 
                c[[2]], 
              0\ c[[3]]}]], 
        Graphics3D[
          Text[c[[3
              ]], { .8\ 
                c[[1]],  .8\ 
                c[[2]],  .5\ 
                c[[3]]}]]}]; \)

And the length of vector C:

\(\(Norm[c]
\)\)

d)  D(3, -2, -5)

\(d = {3, \(-2\), \(-5\)}; 

    View3D[{Arrow[d, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {d[[1]], 0, 
                  0}, {d[[1]], 
                  d[[2]], 0}, d}]}], 
        Graphics3D[
          Text[d[[1
              ]], { .5\ 
                d[[1]],  .1\ 
                d[[2]], 
              0\ d[[3]]}]], 
        Graphics3D[
          Text[d[[2
              ]], { .8\ 
                d[[1]],  .5\ 
                d[[2]], 
              0\ d[[3]]}]], 
        Graphics3D[
          Text[d[[3
              ]], { .8\ 
                d[[1]],  .8\ 
                d[[2]],  .5\ 
                d[[3]]}]]}]; \)

And the length of vector D:

\(\(Norm[d]
\)\)

e)  E(3.25,  2.1, -6.5)

\(e = {3.25, 2.1, \(-6.5\)}; 

    View3D[{Arrow[e, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {e[[1]], 0, 
                  0}, {e[[1]], 
                  e[[2]], 0}, e}]}], 
        Graphics3D[
          Text[e[[1
              ]], { .5\ 
                e[[1]],  .1\ 
                e[[2]], 
              0\ e[[3]]}]], 
        Graphics3D[
          Text[e[[2
              ]], { .8\ 
                e[[1]],  .5\ 
                e[[2]], 
              0\ e[[3]]}]], 
        Graphics3D[
          Text[e[[3
              ]], { .8\ 
                e[[1]],  .8\ 
                e[[2]],  .5\ 
                e[[3]]}]]}]; \)

And the length of vector E:

\(\(Norm[e]
\)\)

f)  F(8.3,  0, 7)

\(f = {8.3, 0, 7}; 

    View3D[{Arrow[f, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {f[[1]], 0, 
                  0}, {f[[1]], 
                  f[[2]], 0}, f}]}], 
        Graphics3D[
          Text[f[[1
              ]], { .5\ 
                f[[1]],  .1\ 
                f[[2]], 
              0\ f[[3]]}]], 
        Graphics3D[
          Text[f[[2
              ]], { .8\ 
                f[[1]],  .5\ 
                f[[2]], 
              0\ f[[3]]}]], 
        Graphics3D[
          Text[f[[3
              ]], { .8\ 
                f[[1]],  .8\ 
                f[[2]],  .5\ 
                f[[3]]}]]}]; \)

And the length of vector F:

\(\(Norm[f]
\)\)