Vector Operations
Using Maple, we can also quickly calculate the dot product, the cross product, and the norm (magnitude) of a vector. In the 'VectorCalculus' package there are three ways to enter the dot product command. They all yield the same result and are exhibited below.
| > | u.r; |
| > | DotProd(u,r); |
| > | DotProduct(u,r); |
Make sure if you use the lengthier version, you don't forget to capitalize the command in the appropriate place.
To calculate the magnitude of a vector, we use the 'Norm' command.
| > | Norm(u); Norm(r); |
This command is also in the 'LinearAlgebra' package, but is slightly different. We'll discuss that later.
Lets use our knowledge to find the angle between u and r. We can do this by combining the previous commands.
| > | theta:=arccos((u.r)/(Norm(u)*Norm(r))); |
| > | evalf(%); |
The answer is given in radians.
If we want to, we can convert the answer to degrees by using the 'convert' command.
| > | convert(%,degrees); |
| > | evalf(%); |
The cross product also has a short form and long forms. In the first statement below, both symbols '&x' comprise the operator.
| > | u &x r; |
| > | CrossProd(u,r); |
| > | CrossProduct(u,r); |
There is another package called the 'LinearAlgebra' package which deals with vectors as well. Some of the commands have the same name as commands in the 'VectorCalculus' package. These commands will take the place of the previously loaded commands.
| > | with(LinearAlgebra); |
Try using the 'Norm' command here on vector r.
| > | Norm(r); |
The result is different from our earlier result. This is because there are many different norms for calculating the magnitude of a vector. When the 'LinearAlgebra' package is loaded, the 'Norm' command defaults to a norm called the infinity norm. This norm returns the absolute value of the component with the largest absolute value. To get the usual Euclidean Norm, we need to enter a second parameter.
| > | Norm(r,2); |
See the help menu for more information on this command. (There is also a command called 'VectorNorm' which has the same syntax as 'Norm'.)
When we wanted to compute the angle between two vectors after loading the 'VectorCalculus' package, we had to enter all the necessary operations. The 'LinearAlgebra' package contains a command called 'VectorAngle' which computes the angle using the same formula.
| > | psi:=VectorAngle(u,r); |
| > | evalf(%); |
| > | psi-theta; |
The above shows that the two methods compute the same angle. But what if you want to use the command, but you've loaded the 'VectorCalculus' package and you don't want to load the 'LinearAlgebra' package? Luckily, there is a way to call the command without loading the package. This is true for every specialized command in Maple. Let's see how to do this.
First, let's unload the 'LinearAlgebra' package by using the 'unwith' command.
| > | unwith(LinearAlgebra); |
Now, try to use the 'VectorAngle' command.
| > | psi:=VectorAngle(u,r); |
Maple doesn't know what you're trying to do, but you haven't entered anything erroneous, so it echos back what you've typed.
To access the command, we need to tell Maple where to find it. This is called using the long form of the command. It's done by entering the name of the package, then the command in brackets, and then the parameters in parentheses. See the example below.
| > | psi:=LinearAlgebra[VectorAngle](u,r); |
For us, this is a better way to access this command. This is the only command in the 'LinearAlgebra' package of which we may want to make regular use. Our usual package will be 'VectorCalculus'.
| > |