Vectors in MapleGreg Warrington - warrings@wfu.edu adapted from worksheets by Mike May, S.J.- maymk@slu.edu and ones on the University of Michigan Math 215 web pageThis worksheet gives examples of working with vectors in Maple. Evaluate the worksheet by hitting the enter key as you move down the page. The only interesting things in the two "Visualizing the ..." sections are the animations at the end.restart to clean things up in case we've already started the worksheet LinearAlgebra lets us manipulate vectors using commands like DotProduct plots gives us the display command which lets us show a whole bunch of pictures we've precomputed plottools lets us plot vectors easilyrestart: with(LinearAlgebra): with(plots): with(plottools):
<Text-field layout="Heading 1" style="Heading 1">Basic operations on vectors</Text-field>Maple distinguishes between "row" vectors and "column" vectors. I use row vectors here because they take up less space.The importance of the two different types doesn't become apparent until a course in linear algebrau := <3|-5|2>; v := <1/2|7|1>; w := <a,b,c>;Simple arithmetic should be written as you think it should.You might get an error if you don't include the appropriate parentheses.3*u + v; The default "Norm" function doesn't give you what you want. It spits out the maximum entry.Norm(v); So, if you want to get the norm of a function, use either of these versions.Norm(v,2); sqrt(add(v[i]^2,i=1..Dimension(v)));There are three different ways you can compute the dot product. The first won't work unless you've used the "with(LinearAlgebra)" command at the beginning of the worksheet.DotProduct(u,v); add( u[i]* v[i], i = 1..Dimension(u)); u . v; There are also at least three was to write the cross product.CrossProduct(u,v); u &x v;This one is sort of cheating, though, as we haven't told maple what the i, j, and k are.Determinant(<<i|j|k>,u,v>);
<Text-field layout="Heading 1" style="Heading 1">Visualizing the dot product</Text-field>nf is the number of frames we'll have in our animation aw, hw, and hh control the shape of the arrow.taw,thw,thh are used for wider arrows. fx and fy give the coordinates of the second vector according to which frame we're atnf:=40: aw := .2: hw := .4: hh := .1: tnf:=40: taw := .4: thw := .8: thh := .2: fx := proc(lt,lnf) cos(2*Pi*lt/lnf) end proc: fy := proc(lt,lnf) sin(2*Pi*lt/lnf) end proc:This vector just stays fixed. u is the actual vector. uarrow is defined just for illustration purposes.u := <3,1,2>: uarrow := arrow([0,0,0],<3,1,2>,aw/2,hw/2,hh/2,color=red):This is the vector that is rotating around.We define it as a sequence of arrows - all in different positions depending on which frame we're in.vseq := display([seq(arrow([0,0,0],<fx(t,nf),fy(t,nf),3>,aw,hw,hh, color=blue),t=0..nf)],insequence=true):normu := u/Norm(u,2): normuarrow := arrow([0,0,0],normu,taw,thw,thh,color=yellow):projvseq := display([seq(arrow([0,0,0],(<fx(t,nf),fy(t,nf),3>.normu)*normu,taw,thw,thh,color=green), t=0..nf)],insequence=true):This animation shows the projection of the blue vector onto the (unit) yellow vector.This projection is illustrated by the green vector.The slider rotates the blue vector around so we get different display({vseq,uarrow,normuarrow,projvseq},scaling=constrained,axes=boxed, labels=[x,y,z],labelfont=[TIMES,ROMAN,18]);
<Text-field layout="Heading 1" style="Heading 1">Visualizing the cross product</Text-field>xyplane:=display({ plot3d([x,y,0], y=-3..3, x=-3..3,color=coral,grid=[7,7],style=wireframe)}):nf is the number of frames we'll have in our animation aw is the arrow width fx and fy give the coordinates of the second vector according to which frame we're atnf:=40: aw := .4: hw := .8: hh := .2: fx := proc(lt,lnf) 2*cos(2*Pi*lt/lnf) end proc: fy := proc(lt,lnf) 2*sin(2*Pi*lt/lnf) end proc:This vector just stays fixedu := arrow([0,0,0],<2,0,0>,aw,hw,hh,color=blue): v := display([seq(arrow([0,0,0],<fx(t,nf),fy(t,nf),0>,aw,hw,hh,color=blue), t=0..nf)], insequence=true): labelu := textplot3d([1,-2/3,0, `U `], align=RIGHT, font = [HELVETICA, BOLD, 10], color=black):This is the sequence of cross products u x vuxv:=display([seq(arrow([0,0,0],<0,0,2*fy(t,nf)>,aw,hw,hh,color=red), t=0..nf)], insequence=true):verts := [[0,0,-.01],[2,0,-.01],[2+fx(t,nf),fy(t,nf),-.01],[fx(t,nf),fy(t,nf),-.01]]: poly := display([seq(polygon(verts,color=green), t=0..nf)],insequence=true):u is the stationary blue vector; v is the moving blue vector. The red vector is the cross product u x v. Notice that the red vector is longer in proportion to the amount of green area enclosed by the parallelogram determined by the two blue vectors. When v is between 180 and 360 degrees counterclockwise of u, the red vector points in the opposite direction.display({labelu,xyplane,poly,u,v,uxv},scaling=constrained,axes=boxed, labels=[x,y,z],labelfont=[TIMES,ROMAN,18]);