Linear Algebra Powertool
Working with and plotting vectors
On Line 1.2
Worksheet by Michael K. May, S.J., revised by Russell Blyth.
> restart: with(linalg): with(plots): with(plottools):
Warning, the protected names norm and trace have been redefined and unprotected
Warning, the name changecoords has been redefined
Warning, the name arrow has been redefined
Outline
This worksheet works through the problems covered in the On Line 1.2 section, pages 28 - 31.
The basic objectives are:
Vectors in
and
:
The easiest way to enter a vector in
and
is as a list. In Maple you separate the coordinates with commas and surround the list with square brackets.
>
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:
> v1 + w1;
Error, adding lists of different length
We can also enter vectors in Maple with the vector command, which is part of the linalg package. When we have used the vector command to enter the vectors, we need to use the evalm (for evaluate matrix) command to see the coordinates of a linear combination.
>
a1 := vector([1,1]); a2 := vector([1,3]);
a1 + a2; 3*a1;
evalm(a1+a2); evalm(3*a1);
Exercises:
1) Use the first 4 digits of your student id number to create two vectors, u1 and u2. 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
. Use Maple to compute 1.0*z1 + 2.0*z2. Compare this to z1+2*z2.
>
Plotting lists of Points
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 a list of points, 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.
>
pointplot({v1+v2,v2-2*v1},view = [-5..5,-5..5]);
pointplot({evalm(a1-2*a2),evalm(a1+a2)},view = [-5..5,-5..5]);
If the vectors are in
instead of
, we use the command pointplot3d.
> pointplot3d({w1,w2},color=blue, symbol=circle, 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=circle, symbolsize=15);
Click on the graph and rotate the plot to get a good idea of the location of the two points.
Exercises:
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.
>
Random number generators and long lists
The last part of the On Line section of the text (page 29) deals with using MATLAB to produce a random number between 0 and 1. The syntax in Maple is a bit different. 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]);
Exercise:
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
, 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. q gives the angle of view in degrees in the xy-plane around from the positive x-axis, while f gives the view angle down from vertical. The default view orientation is q = 45 and f = 45. Trial and error rotations of the figure above show that an orientation of [ q , f ] = [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.
>
Exercise:
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.
>
>
>