Maple & Vectors

advertisement
Maple & Vectors
Recall that the linalg package contains many commands useful for linear algebra. Similarly, the plots package
contains particular commands that are needed for specialised types of plots or pictures. Both of these packages
can be loaded using the command with.
Vectors can be created and stored in Maple in a similar manner to matrices.
> with(linalg):
u:=vector([1,2]);
v:=vector([-2,3]);
u:=[1, 2]
v:=[-2, 3]
Note that Maple writes the components horizontally to conserve space. However, the presence of the comma
between the components indicates that u is in fact a 21 vector/matrix and not a 12 vector/matrix.
As 2-dimensional vectors can be regarded as 21 matrices, the familiar commands can be used to operate on
them.
> matadd(u,v);
scalarmul(u,5);
[-1, 5]
[5, 10]
To find the length or magnitude of a vector the command norm is used with the option frobenius. (In more
advanced linear algebra, different types of norms can be defined for vectors–thus, it is important to specify in
Maple the type of norm required, so that the result is the length of the vector in the plane.)
> norm(u, frobenius);
5
The angle between two vectors can be computed using the command angle as follows:
> angle(u,v);
 4

5
13 
arcos 
 65

It may be necessary to use the evalf command to find the numerical value of the result: note that the angle is
measured in radians and not degrees.
> angle(u,v);
evalf(%);
 4

5
13 
arcos 
 65

1.051650212
Finally, in order to represent vectors diagrammatically, we use the arrow command from the plots package.
By default, Maple locates all vectors at the origin (i.e. the initial point of every vector is (0,0)). The following
gives a simple plot of the vector u:
> with(plots):
arrow(u);
To refine the plot, various options can be used. For instance, to plot the vector more neatly in red on a
diagram where the same scale is used on both axes, use the following command:
> arrow(u, shape=arrow, colour=red, scaling=constrained);
In order to locate a vector at a point other than the origin, for instance, (0,1), this point must be specified along
with the vector to be plotted, in the following way:
> arrow({[ [0,1], u]}, shape=arrow, colour=red, scaling=constrained);
Thus, we can plot several representations of the vector u located at different points. For instance,
> arrow( { [[0,0], u], [[0,1], u], [[-2,3], u], [[4,-2], u] }, shape=arrow, colour=green, scaling=constrained);
This is also useful when illustrating how the sum of vectors can be interpreted geometrically. The following
code gives a plot of the vectors u and v positioned tail to tip to start. The second plot then shows these vectors
again and their sum u+v:
> w:=matadd(u,v);
p1:=arrow({ [[0,0], u], [[1,2], v] }, shape=arrow, colour=red, scaling=constrained);
display(p1);
p2:= arrow({ [[0,0], w] }, shape=arrow, colour=green, scaling=constrained);
display(p1,p2);
Exercises:
1. Use the command ?linalg to access the help page on the linalg package. From the list of commands
shown, choose the one you think will compute the dot product (scalar product) of two vectors.
(i) Having read the information on how to use this command, compute the dot product of the vectors u
and v above.
  2
(ii) Compute the dot product of the vector u with r =   . What can you say about the vectors u and r?
 1 
(iii) Use Maple to compute the angle between u and r.
2. Using the vectors u and v above,
(i) compute ||u|| and ||v|| to verify the triangle inequality: ||u+v||  ||u|| + ||v||,
(ii) verify the following relationship between the norm of a vector and the dot product of a vector with
itself: u.u=||u||2.
3. Compute the scalar k=(u.v)/||v||2. Now find p=kv and plot u, v and p on the same set of axes (positioning
each with initial point at the origin).
Can you give a geometrical interpretation of the vector p?
4. For each of the following, illustrate the vectors given on the same plot using different colours:
(i) u, 2u, 7u, -3/5u;
(ii) u, r, u+r, u-r.
Download