Calculus: The Language of Change

Exercise Set 15.4
Computer Exercise: #1
Geometry of Vector Addition

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

In each example below a vector X and a scalar c are given.

Compute:
(1) Y=cX
(2) |Y|
(3) |X|
(4) |c||X|
(5) Sketch X, Y and a unit vector in the same direction as X.

(a) X=(({{6}, {4}})), c=2

Part (1):  When we multiply a scalar times any vector, the resulting vector is a multiple of the old one.  Therefore, to get the appropriate vector result, we multiply each component of the old vector times the scalar.  <Enter> below to see how this is accomplished by Mathematica:

\(Clear[X, Y, c]; 
c = 2; 
X = {6, \ 4}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):  This has notation has two meanings which are extremely important to know.  If we want the length of a vector, as in this part, the notation |Y| means, "Give me the length of the vector Y."  If we have a scalar, Y, the notation |Y| means, "Give me the absolute value of the scalar Y."  In this case we want the previous of the two definitions.  <Enter> below to see the length of vector Y:

Print["| Y | = ",  Norm[Y]]

Part (3):  This part is easy now that we know how to compute |Y|.  Use the same technique to derive |X|.

Print["| X | = ",  Norm[X]]

Part (4): This is a combination of the definitions I discussed in Part (2).  Now they are placed together to get a new answer.  <Enter> below to check your work with mine:

\(\(Print["|c||X| = ", \ Norm[2  X]]
\)\)

Part (5): Now we want to put all of our data together geometrically.  But first we need to remember what a unit vector is.  A unit vector is a vector with unit length (ie length=1) pointing in the same direction as the given vector it was made from.  Look below to see how this is accomplished with Mathematica:

\(Unit\  = \ X/Norm[X]; 

    View2D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)

Notice all three vectors are on top of each other.  This is what is suppose to happen.  Also notice the lengths of all three vectors:  Yellow (vector Y) is twice the length of X and Black (vector Unit) is length 1; just as we suspected.

Now apply these 5 steps to the rest of the problems.  Below is my work; check yours with it.

(b) X=(({{-3}, {1}})), c=3

Part (1):

\(Clear[X, Y, c]; 
c = 3; 
X = {\(-3\), \ 1}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):

Print["| Y | = ",  Norm[Y]]

Part (3):

Print["| X | = ",  Norm[X]]

Part (4):

\(\(Print["|c||X| = ", \ Norm[c*X]]
\)\)

Part (5):

\(Unit\  = \ X/Norm[X]; 

    View2D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)

(c) X=(({{-3}, {6}})), c=-(1/3)

Part (1):

\(Clear[X, Y, c]; 
c = \(-1\)/3; 
X = {\(-3\), \ 6}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):

Print["| Y | = ",  Norm[Y]]

Part (3):

Print["| X | = ",  Norm[X]]

Part (4):

\(\(Print["|c||X| = ", \ Norm[c*X]]
\)\)

Part (5):

\(Unit\  = \ X/Norm[X]; 

    View2D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)

(d) X=(({{5}, {4}})), c=1

Part (1):

\(Clear[X, Y, c]; 
c = 1; 
X = {5, \ 4}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):

Print["| Y | = ",  Norm[Y]]

Part (3):

Print["| X | = ",  Norm[X]]

Part (4):

\(\(Print["|c||X| = ", \ Norm[c*X]]
\)\)

Part (5):

\(Unit\  = \ X/Norm[X]; 

    View2D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)

(e) X=(({{5}, {4}})), c=0

Part (1):

\(Clear[X, Y, c]; 
c = 0; 
X = {5, \ 4}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):

Print["| Y | = ",  Norm[Y]]

Part (3):

Print["| X | = ",  Norm[X]]

Part (4):

\(\(Print["|c||X| = ", \ Norm[c*X]]
\)\)

Part (5):

\(Unit\  = \ X/Norm[X]; 

    View2D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)

(f) X=(({{5}, {4}})), c=-1

Part (1):

\(Clear[X, Y, c]; 
c = \(-1\); 
X = {5, \ 4}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):

Print["| Y | = ",  Norm[Y]]

Part (3):

Print["| X | = ",  Norm[X]]

Part (4):

\(\(Print["|c||X| = ", \ Norm[c*X]]
\)\)

Part (5):

\(Unit\  = \ X/Norm[X]; 

    View2D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)

(g) X=(({{8}, {5}, {2}})), c=-2

Part (1):

\(Clear[X, Y, c]; 
c = \(-2\); 
X = {8, \ 5, \ 2}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):

Print["| Y | = ",  Norm[Y]]

Part (3):

Print["| X | = ",  Norm[X]]

Part (4):

\(\(Print["|c||X| = ", \ Norm[c*X]]
\)\)

Part (5):

\(Unit\  = \ X/Norm[X]; 

    View3D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)

(h) X=(({{8}, {5}, {2}})), c = 1/2

Part (1):

\(Clear[X, Y, c]; 
c = 1/2; 
X = {8, \ 5, 2}; 
Y = c*X; 

    Print[c, X, \ "=", \ Y]\)

Part (2):

Print["| Y | = ",  Norm[Y]]

Part (3):

Print["| X | = ",  Norm[X]]

Part (4):

\(\(Print["|c||X| = ", \ Norm[c*X]]
\)\)

Part (5):

\(Unit\  = \ X/Norm[X]; 

    View3D[{Arrow[X, Red], \ Arrow[Y, \ Yellow], \ Arrow[Unit, \ Black]}]\)