UC SCI 111, vM+.
Notebook 9

Needs["Graphics`Colors`"];
<< Graphics`Arrow`
Off[General::spell1];

Mathematica: plotting curves.

Parametric plots.

We have seen before that plotting functions can be done by using Mathematica's command Plot. But sometimes one wants to make a picture of a curve that is not a function, that is, there is not a unique correspondence between points in the domain and in the range.  A famous example of a curve that's not a function is the circle. When, however, you know a parametrization of the curve, you can make a picture by using the command ParametricPlot. We will only consider curves that are depending on one parameter, say t. You can think of t as time, that is, the parametrization tells you where you are in the plane or in three-space at moment t.

Exercise 6.
a) Draw a circle with ParametricPlot.
b) Draw the line y=x with ParametricPlot.Is your parametrization the only one that gives the line y=x?

Geometrically defined mappings: projections, rotations and spirals.

Projection.

\(projection[x_, u_]\  := \ 
      Module[
		
		{lw, \ o, y, pr, domb, \ dome, \ rangeb, \ 
          rangee}, 
\ 
		Print["## original vector: ", 
          x]; 
		Print["## line defining vector u: ", 
          u]; 
		lw\  = \ 
          Thickness[ .006]; 
		o\  = \ {0, 
            0}; 
		pr\  = \ \((x . u/
                u . u)\)\ u; 
		Print["## projected vector: ", 
          pr]; 
		
		If[
          x[\([1]\)]\  < \ 
            0\ , 
\ \ 			domb\  = \ \ Min[x[\([1]\)], 
              pr[\([1]\)]]; 
			\ \ dome\  = \ \ Max[pr[\([1]\)], 
              0], 
			\ \ domb\  = \ \ Min[0, 
              pr[\([1]\)]]; 
		\ \ \ \ dome\  = \ \ Max[\ x[\([1]\)], 
              pr[\([1]\)]];	
		]\ ; 
		
		If[
          x[\([2]\)]\  < \ 
            0, 
\ \ 			rangeb\  = \ \ Max[0, \ 
              pr[\([2]\)]]; 
\ \ 			rangee\  = \ \ Min[x[\([2]\)], 
              pr[\([2]\)]], 
		\ \ \ \ rangeb\  = \ \ Min[0, \ 
              pr[\([2]\)]\ ]; 
		\ \ \ \ rangee\  = \ \ Max[x[\([2]\)], \ 
              pr[\([2]\)]\ ];
	]; 
	
	
        If[\ u[\([1]\)]\  == \ 
            0, 
			{Show[\ 
              Graphics[{lw, Black, Line[{o, {0, 3/2\ pr[\([2]\)]}}], \ Red, 	
                  Arrow[o, x, HeadWidth\  -> \  .8], \ 
                  Blue, 
\ \ \ \ 					Arrow[o, pr, HeadWidth\  ->  .8], 
                  Black, 
\ \ \ \ 					Dashing[{0.03, 
                      0.03}], 
\ \ \ \ 					Arrow[x, 
                    pr]\ }], 
				\ \ \ \ \ \ Axes\  -> \ True], 
            pr}, 

	
          Plot[\ \((u[\([2]\)]/u[\([1]\)])\)\ y, \ {y, 3/2  domb, 
              3/2  dome}, 
\ \ 			PlotStyle\  -> \ {lw}, 
\ \ 			PlotRange\  -> \ 3/2 {rangeb, \ rangee}, 
\ \ 			Epilog\  -> \ {lw, 
                Red, 
\ \ \ \ 					Arrow[o, x, HeadWidth\  -> \  .8], \ 
                Blue, 
\ \ \ \ 					Arrow[o, pr, HeadWidth\  ->  .8], 
                Black, 
\ \ \ \ 					Dashing[{0.03, 
                    0.03}], 
\ \ \ \ 					Arrow[x, 
                  pr]\ }, 
		\ AspectRatio\  -> \ 
              Automatic]
		]		
]\)

The module projection[x_,u_]draws the projection of the vector x on the line defined by the vector u. To spare our own imagination, let's  generate random integers to get different vectors.

r  := Random[Integer, {-10, 10}];

projection[{r, 
          r}, {r, r}];

Exercise 7.
a) What does your answer in ex. 2.(v) mean with respect to the pictures created by projection? More precisely, can you point out the null space and the range in the pictures?

Let M be a (2 x 2)-matrix and α an angle such that 0 ≤ α < π.
Define (Subscript[α, M]) as 

	(Subscript[α, M]) = angle( M · (({{cos α}, {sin α}})) ),		0 ⩽ (Subscript[α, M]) < π

b) Write a procedure mapangle[matrix_,alpha_]that returns (Subscript[α, M])  when matrix denotes M and alpha denotes α.
c) Determine (Subscript[M, p]), the projection matrix for the projection on the line that contains the vector p= (({{1}, {1}})).
d) Plot in one picture the line that contains p  and mapangle[(Subscript[M, p]),α] considered as a function of α.
e) Explain what information your picture yields.
f) Can you point out the angle of the eigenvector in the picture?

Rotation.

\(rotation[alpha_, x_]\  := \ 
      Module[
		
		{length, \ angle, \ \ o, \ m, arc, \ 
          mx}, 
\ 
		Print["Vector: ", x]; 
		Print["Angle: ", 
          alpha]; 
		length\  = \ Sqrt[x . x]; 
		angle\  = \ 
          ArcCos[x[\([1]\)]/length]; 
		If[
          x[\([2]\)] < \ 
            0, 
			\(angle\  = \ 
              2\ Pi\  - \ 
                angle;\)
		]; 
\ 	\ \ \ \ \ \ \ \ \ o\  = \ {0, 
            0}; 
		lw\  = \ 
          Thickness[ .003]; 
	\ \ \ \ \ \ \ \ \ m\  = \ {{Cos[
                alpha], \ \(-Sin[
                  alpha]\)}, 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {Sin[alpha], Cos[alpha]}}; 
		arc\  = \ {angle, \ 
            angle\  + \ alpha}; 
		If[
          angle\  > \ 
            angle\  + \ 
              alpha, 
			\(arc\  = \ {arc[\([2]\)], 
                arc[\([1]\)]\ };\)
		]; 

		Show[
          Graphics[{lw, Blue, Arrow[o, x], Red, 
				Arrow[o, m . x], \ 
              Black, 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Circle[o, 1/5\ length, \ arc], 
				Disk[1/5\ m . x, 
                1/100\ length]}, 
				AspectRatio\  -> \ Automatic, \ 
            Axes\  -> \ True]]
]\)

The module rotation[alpha_,x_]rotates the vector x over an angle α.We use our random vectors of above and rotate them over a random angle an.

an:=2 Pi/ Random[Integer,  {-12,  12}];

rotation[an, {r, r}];

Suppose we are given the vector (Subscript[e, 1]) := (1, 0). We want to rotate (Subscript[e, 1])in counter clockwise direction over an angle α.

Exercise 8.
a) Show that the image of (Subscript[e, 1]) is given by the vector (cos α, sin α )^T.

In a similar way we can show that the image of (Subscript[e, 2]) := (((0,1))^T) is given by the vector (((-sin α, cos α))^T). We conclude that the rotation matrix (Subscript[R,  α]) is given by
 	
 	(Subscript[R,  α])   := (({{ cos α, -sin α }, { sin α, cos α }}))  ,		α ∈ [ 0, 2 π)

b) What is the inverse of a rotation over an angle α?
c) Show that

		\(TraditionalForm\`\((\ R\_\(\(\ \)\(α\)\(\ \)\))\)\^\(\(\ \)\(n\)\)\)   := (({{ cos nα, -sin nα }, { sin nα, cos nα }}))  
		
Hint: see Exercise 9.1.5. 
d)  Fix α = π/6. Again draw a picture with mapangle, but now choose for M the rotation matrix  (Subscript[R,  α]). 
e) Why is there no eigenvector?

Combination of rotation and multiplication.

When we combine a rotation over an angle α with a scalar multiplication with the number c, we get the following matrix

	 (Subscript[R,  α, c])   := (({{c cos α, -c sin α }, {c sin α, c cos α }})),		α ∈ [ 0, 2 π);	c ∈ ℝ

Exercise 9.
a) Show that (Subscript[R,  α, c]) = c ·(Subscript[R,  α]).
b) Write a procedure multrot that multiplies a vector x with c and rotates it over an angle α.  
Hint: you only have to adapt the procedure rotation slightly!

Reflection.

Exercise 10.
a) Use the projection procedure to find the reflection of the vector (3, 2) in the x-axis, the y-axis and the line y=x.  
b) Write down the reflection matrix for a reflection in the line y = a x.
c) Draw pictures with mapangle for different values of a.
d) What is the eigenspace of the reflection map?

Combination of rotation and reflection.

Exercise 11.
Let R be the matrix that rotates a vector over an angle of (π/2). Let M be the matrix that reflects a vector in the x-axis.
a) Determine R and M.
b) Does R·M=M·R hold?
c) Find all different combinations of R and M. By this we mean repeated application of R and/or M in any order.
Now consider a square with coordinates (1,1), (-1,1), (-1,-1)  and (1,-1). 
d) Describe the geometric action of every different combination on this square.

In fact you have just found the group of symmetries of the rectangle. We will study groups in more detail in chapter 14.

Curves.

Substitute α = π/2·t in the rotation matrix (Subscript[R,  α]). Starting with a vector (((1,  0))^T) we rotate it anticlockwise with `velocity' π/2. We get 

	(({{(Subscript[x, 1])(t)}, {(Subscript[x, 2])(t)}}))=  (({{ cos π/2·t, -sin π/2·t  }, { sin  π/2·t, cos  π/2·t}}))  (({{1}, {0}}))

Exercise 12.
a) Sketch the resulting curve in the ((Subscript[x, 1]),(Subscript[x, 2])) plane, for t=0,..,4, using ParametricPlot.

Now substitute α = π/2 and c = (2^t) in the matrix (Subscript[R,  α, c]). (What was c in  part a. of the Notebook exercise?) Think of a rotation together with a centrifugal force. Again vary t from 0 to 4.

b) Sketch the curve that one gets when one starts with the vector (1,0). How would you describe the result?
c) The same question but now with c = (((1/2))^t).
d) Give a description of the curves in terms of polar coordinates: write both r as a function of φ and φ as a function of r.

Spirals.

When we want to analyze movements in (ℝ^3), we have to specify what happens with the z-coordinate of an object  in the xyz-space as well. Consider as an example the rotation of a point around the z-axis. We can represent this rotation via the matrix

	(Subscript[R, z - axis])( α)   =   (({{ cos α t, -sin α t, 0}, {sin α t,  cos α t, 0}, {0, 0, 1}}))		  (13.1)	
	
which represents a circular movement around the z-axis with velocity α. Let's for example start with the point p = (0,1,1). We can specify what happens with every coordinate when we perform the multiplication R·p. For the moment we take α=1.

We start by performing the multiplication R·p.

rp = (({{ Cos [t], -Sin[ t], 0}, {Sin [ t],  Cos [ t], 0}, {0, 0, 1}})) .(({{0}, {1}, {1}}))

We use the answer, slightly adapted to get a nice picture, as an argument for Mathematica's function ParametricPlot3D.

ParametricPlot3D[{{-Sin[2  Pi t], Cos[2 Pi t], 1}, {0, 
            0, 3  Abs[Sin[t]]}},  {t, 0, 3/4}, 
        Ticks  ->  {{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 
              1}}];

Exercise 13.
a) What is the form of the curve (0,0,2 |cos t | )?
b) What adaption in (-sin(2π t), cos(2π t),1) is needed to get the following picture?

c) We continue with adaptions. In part b) the curve gains height with constant speed. Change  (-sin(2π t), cos(2π t),1) in such a way that this speed increases when t increases.

d) Until now, the radius with respect to the z-axis is equal to 1. Make also this radius r dependent on the time, that is, the picture should change in something similar to this.

This exercise shows that you can control a spiral with three parameters r, s and α.

({{r,   Expansion speed in the xy-plane}, {s, Speed with respect to the z-axis}, {α,     Speed of rotation in the xy-plane }})

e) Finally adapt matrix (13.1) in such a way that it incorporates these three tunable effects.