Working with and plotting vectorsWorksheet by Michael K. May, S.J., revised by Russell Blyth.restart: with(LinearAlgebra): with(plots): with(plottools):
<Text-field layout="Heading 1" style="Heading 1">Outline</Text-field>The basic objectives are:1) Learn the basic mechanics of entering vectors, and producing linear combinations with either addition or scalar multiplication.2) Learn to plot a set of vectors in R2 and R3.3) Using a random number generator, see what typical linear combinations of a pair of vectors look like.
<Text-field layout="Heading 1" style="Heading 1">Vectors in R<Font subscript="false" superscript="true">2</Font> and R<Font subscript="false" superscript="true">3</Font><Font subscript="false" superscript="false">:</Font></Text-field>The easiest way to enter a vector in R2 and R3 is as a list with angle brackets. In Maple you separate the coordinates with commas for a column vector, and with vertical bars ( | ) for a row vector. The whole vector is surrounded the with angle brackets ( < and >).v1 := <1, 1>; v2 := <1, 3>; w1 := <1| 1| 1>; w2 := <-1| 3| 2>;When vectors are entered this way we use normal mathematics notation to add two vectors or to multiply by a scalar.2*v1; v1+v2; 2*w1+3*w2;Notice that vectors need to have the same length before we can add them:<1,2> + <3,4,5>;We can also enter vectors in Maple with the Vector command, which is part of the LinearAlgebra package. a1 := Vector([1,1]); a2 := Vector([1,3]); a1 + a2; 3*a1;
<Text-field layout="Heading 2" style="Heading 2">Exercises:</Text-field>1) Use the first 4 digits of your student id number to create two vectors u1 and u2 in R2. Use Maple to compute the linear combination 2*u1 + 3*u2. (Be sure to label answers to all exercises. You can either add a comment like "The answer is ..." to the Maple worksheet, or write a comment on your printout.)2) Pick six integers from -10 to 10 (repetitions are allowed) to create two distinct nonzero vectors z1 and z2 in R3. Use Maple to compute 1.0*z1 + 2.0*z2. Compare this to z1+2*z2.
<Text-field layout="Heading 1" style="Heading 1">Plotting Lists of Points:</Text-field>We plot points representing vectors with the command pointplot, which is part of the plot package. pointplot({v1,v2}); pointplot([a1,a2]);Notice that we can plot either a set of points (sets are enclosed in curly braces and are unordered) or a list of points (lists are ordered and enclosed in square brackets). When plotting, you may want to use the view option to specify the viewing window of the plot. For the two plots above, letting x and y both range from -5 to 5 is convenient. You can also specify a symbolsize to make the points easier to see.pointplot({v1+v2,v2-2*v1},view = [-5..5,-5..5], symbolsize=15); pointplot({(a1-2*a2),(a1+a2)},view = [-5..5,-5..5], symbolsize=15);If the vectors are in R3 instead of R2, we use the command pointplot3d.pointplot3d({w1,w2},color=blue, symbol=diamond, symbolsize=15);Unfortunately, the default option for 3-dimensional plots in Maple is to hide the axes. This can be fixed by either clicking once on the 3-D plot above and then clicking on the icon for normal axes or by using the axes=normal option. Once again there is a view option for these graphs.pointplot3d({w1,w2},axes=normal,view = [-5..5, -5..5, -5..5],color=blue, symbol=diamond, symbolsize=15); Click on the graph and rotate the plot to get a good idea of the location of the two points.
<Text-field layout="Heading 2" style="Heading 2">Exercises:</Text-field>3) Plot the points [1, 1], [2, -2], [-3, 3], and [4, -4] all on the same graph.4) Using the points z1 and z2 you defined in Exercise 2 above, plot z1, z2, z1 + z2, and 2*z1 - z2 all on the same graph.
<Text-field layout="Heading 1" style="Heading 1">Random Number Generators and Long Lists:</Text-field>It is useful to be able to generate random vectors and matrices. The rand function in Maple returns random integers in a specified range. We can use rand to create functions that produce random 3 digit numbers either from 0 to 1 or from -1 to 1.rand0to1 := rand(0..1000)/1000.0: randneg1to1 := rand(-1000..1000)/1000.0:With the first of these functions it is easy to produce a list of 10 random linear combinations of the form A*v1+B*v2, where A and B are both between 0 and 1.setofpoints := {seq(rand0to1()*v1+rand0to1()*v2,i=1..10)}; pointplot(setofpoints,view=[-5..5,-5..5]);
<Text-field layout="Heading 2" style="Heading 2">Exercise:</Text-field>5) Use the rand0to1 function to create a list of 500 random linear combinations of v1 and v2. (You probably want to end the command with a colon rather than a semicolon so the list is not printed out.) Plot the points in the list and describe the geometric figure that they make. Include the coordinates of the vertices in your description.
When we try the same trick with vectors in R3, we find that the points all lie in a plane. To see this, rotate the figure below in such a way that the plane is viewed edge-on - that is, so that it appears to be a line.setofpoints := {seq(rand0to1()*w1+rand0to1()*w2,i=1..500)}: pointplot3d(setofpoints,view=[-1..1,0..4,0..3], axes=normal);When a 3-D plot is active, you see the present orientation in the second menu bar. NiNJJnRoZXRhRzYi gives the angle of view in degrees in the xy-plane around from the positive x-axis, while NiNJJHBoaUc2Ig== gives the view angle down from vertical. The default view orientation is NiNJJnRoZXRhRzYi = 45 and NiNJJHBoaUc2Ig== = 45. Trial and error rotations of the figure above show that an orientation of [NiNJJnRoZXRhRzYi, NiNJJHBoaUc2Ig==] = [17,65] views the plane containing all the points on edge, while an orientation of [-11, 17] looks at that plane from the top so that the set of points looks like a figure in a plane.
<Text-field layout="Heading 2" style="Heading 2">Exercise:</Text-field>6) Use the rand0to1 function to create a list of 500 random linear combinations of the vectors z1 and z2 that you created in exercise 2 above. Plot the list and find an orientation that looks at the plane from the edge and an orientation that looks at the plane from the top.