Maple Syntax for Vectors and Gradients. Vectors are entered in Maple using the command vector . For example, to define the vector v=2 i +3 j -4 k in three-dimensional space, use the syntax
Most commands to manipulate vectors are contained in the linalg package ("linalg" for "linear algebra"). Let's load the linalg package. If you are curious about its content, replace the colon by a semicolon on the line below before re-executing it.
The "2" within the norm command stands for the root of order two in our definition of the magnitude.
The useful command normalize returns a unit vector with the same direction as a given vector. In other words, divides a nonzero vector by its magnitude. For example:
Another handy command is angle . The command calculates the angle between two vectors.
The value of the angle is returned in radians.The very important command grad that calculates the gradient of a given function of two or more variables is also contained in the linalg package. Remember that:
If F is a function of two variables x and y, the gradient of F is the vector function whose first component is the partial derivative of F with respect to x and whose second component is the partial derivative of F with respect to y.
Notice that the gradient vector of a function of two variables is itself a function of two variables. In fact, it's a function which takes two variables, x and y , as input, and which outputs a vector.
Let us plot our function f(x,y)
|>||plot3d(f(x,y), x=-1..1, y=-1..1, axes=BOX, scaling=constrained);|
|>||fcount:=contourplot(f(x,y), x=-32..32, y=-32..32, contours=30,filled=true,coloring=[white,yellow],scaling=constrained):|
|>||ffiledp:=fieldplot([4*x^3,4*y^3], x=-32..32, y=-32..32, color=BLACK, arrows=THICK):|
The gradient vector points in direction of greatest increase of "f" , which is away from the origin. As x and y increase, the gradient vector increases in length. The contour lines show paths in the plane along which the function is constant, so the direction of greatest increase of a function should be directly away from the contour lines. The length of the gradient vector indicates the steepness of the graph of "f", which increases as (x,y) moves away from the origin.
For any unit vector u=[u1, u2] , the directional derivative of "f" at (a,b) in the direction u , f_u(a, b) , represents the rate of change of f in the direction u , and is given as the dot product of the vector u with the gradient gradf(a,b), that is:
Example 2. Plot a level surface and the field of gradients for the function
Display both its contour diagram and its field of gradients on the same plot. Comment on the direction in which you should move from a point (x,y) to obtain the maximum and minimum rates of change of f.
Match each of the sets of gradient vectors plotted below with the graph of a function
|>||plot3d(sin(x)+2*sin(y), x=-6..6, y=-6..6, axes=boxed,scaling=constrained);|
|>||plot3d(y^2-y^4-x^2, x=-1..1, y=-1..1, axes=boxed, scaling=constrained);|
|>||plot3d((x^2-y^2), x=-2..2, y=-2..2, axes=boxed, scaling=constrained);|