Scalar Multiplication
of
Vectors in 2D & 3D

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Special Mathematica Functions used in this NoteBook  (If you said "no" to "evaluate initialization?" you can "evaluate initialization" from the Action menu.  Don't look in here.)

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]];

Notebook Overview

A scalar (or number)  c  times a vector  X = {x,y} or  X = {x,y,z} algebraically is given by

c X = {c x , c y}  or  c X = {c x, c y, c z}

For example,

3 {2,-5} = {3 * 2, 3 * (-5)} = {6, -15}

or

-5 {2,-5,8} = {-5 * 2, (-5) * (-5),-5*8} = {-10,25,-40}

Algebraically, this is a very easy computation.

The geometric meaning is:

When c > 0,  Y = c X points in the direction of  X and has length c times the length of X.
 
When c < 0, Y = c X points opposite  X and has length |c| times the length of X.

Conversely, every position vector that points along the line through  0  and the tip of  X must be a scalar multiple of  X.

References to the Text

Section 15.4

This NoteBook illustrates the algebra and geometry of Section 15.4 of the text.

Scalar Multiples

The following computations use the Arrow[.] and View[.] functions from the Initialization cell to show a vector and a scalar multiple of that vector.

<Enter> them now.

2-D

The next computation shows a vector and 2 times the vector.

X = {3, 4}; Y = 2 X; Print["2", X, " = ", Y]; View2D[{Arrow[X, Navy], 
        Graphics[{Navy, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {X[[1]], 0}, 
                X}]}], Graphics[
          Text[X[[1
              ]], { .5 
                X[[1]],  .1 
                X[[2]]}]], 
        Graphics[
          Text[X[[2
              ]], { .9 
                X[[1]],  .5 
                X[[2]]}]], 
        Arrow[X, Tail -> X, SteelBlue], 
        Graphics[{SteelBlue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{X, {2 X[[1]], 
                  X[[2]]}, 2 X}]}], 
        Graphics[
          Text[X[[1]], {
              (1/2) (1 + 2) X[[1]], 
              1.1 X[[2]]}]], 
        Graphics[
          Text[X[[2
              ]], { .95 2 
                X[[1]], 
              (1/2) (1 + 2) 
                X[[2]]}]], 
        Graphics[{Red, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {0, 
                  2 X[[2]]}, 2 X}]}], 
        Graphics[
          Text[2 X[[1]], {
              1 X[[1]],  .95 2 
                X[[2]]}]], 
        Graphics[
          Text[2 X[[2]], { .1 
                X[[1]], 
              1.  X[[2]]}]]}]; View2D[{Arrow[Y, Red]}];

The next computation shows a vector and 3 times the vector.

X = {3, 4}; Y = 3 X; Print["3", X, " = ", Y]; Print["| X | =", Norm[X], "  & | Y | = ", Norm[Y]]; View2D[{Arrow[X, Navy], Arrow[X, Tail -> X, SteelBlue], 
        Arrow[X, Tail -> 2 X, BlueMedium]}]; View2D[{Arrow[Y, NavyBlue]}];

Practice Exercise

Copy both computations above and modify them to show  X = {-3,5} and (1/2) X.

3-D

The next computation shows a vector and 2 times the vector.

X = {-2, -3, 1}; Y = 2 X; Print["2", X, " = ", Y]; View3D[{Arrow[X, Navy], 
        Graphics3D[{Navy, AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {X[[1]], 0, 
                  0}, {X[[1]], 
                  X[[2]], 0}, X}]}], 
        Arrow[X, Tail -> X, SteelBlue], 
        Graphics3D[{SteelBlue, AbsoluteDashing[{5, 5}], 
            Line[{X, X + {X[[1]], 0, 0}, 
                X + {X[[1]], 
                    X[[2]], 0}, 
                2 X}]}], 
        Graphics3D[{Red, AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {0, Y[[2]], 
                  0}, {0, Y[[2]], 
                  Y[[3]]}, Y}]}]}]; 
    View3D[{Arrow[Y, Red]}];

The next computation shows a vector and 4 times the vector.

X = {1, -2, (1/2)}; Y = 4 X; Print["4", X, " = ", Y]; Print["| X | =", Norm[X], "  & | Y | = ", Norm[Y]]; View3D[{Arrow[X, Navy], Arrow[X, Tail -> X, SteelBlue], 
        Arrow[X, Tail -> 2 X, BlueMedium], 
        Arrow[X, Tail -> 3 X, BlueViolet]}]; View3D[{Arrow[Y, Navy]}];

Exercises

Text Exercise 15.4.1

Copy one of the computations above and modify it to compute and draw  Y =  c X, for

c = 2,  X = {6,4}
c = 3,  X = {-3,1}
c = -1/3,  X = {-3,6}
c = 1,  X = {5,4}
c = 0,  X = {5,4}

Copy one of the computations above and modify it to compute and draw  Y =  c X, for

c = 1/2,  X = {8,5,2}
c = -2,  X = {-4,-6,4}

Text Exercise 15.4.4

a

Draw the vectors  c X for the vectors X and scalars  c  below:

X = {2,3}; c = 1, 3/2, 2, 5/2, 3, 1/2, 1/3, -1/2, -1, -2

Let  X  be a fixed vector.  Give a geometric description of the set of all vectors  of the form  c X, as  c varies thourgh all real numbers.

b

Draw the vectors  c X for the vectors X and scalars  c  below:

X = {3,5,8}; c = 1, 3/2, 2, 5/2, 3, 1/2, 1/3, -1/2, -1, -2

Let  X  be a fixed vector.  Give a geometric description of the set of all vectors  of the form  c X, as  c varies thourgh all real numbers.

Computer Exercise

Draw a vector  X with its tail at  0  and a dashed rectangular box whose edges are parallel to the coordinate axes and so that  X points across the diagonal of the box.  Draw another copy of  X  with its tail at the tip of  X  and another dashed box with this arrow as its diagonal.  Finally, draw a red dashed box with  2 X as its diagonal.  You can see from these boxes that there is a geometric similarity between the boxes, with each red edge twice the corresponding original blue one.