Linear Algebra Powertool
Coordinates
OnLine 4.1
Worksheet by Russell Blyth.
>
restart: with(linalg): with(plots): with(plottools):
randomize();
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 investigates coordinates.
The basic objectives are:
Visualizing coordinates
First generate a non-standard basis for
.
>
v1 := randvector(2,entries=rand(-2..2));
v2 := randvector(2,entries=rand(-2..2));
Check to see that v1 and v2 are independent - if not, execute the previous line again to obtain a basis.
Plot the vectors as line segments:
>
v1l := line([0,0],convert(v1,list),color=blue,thickness=2):
v2l := line([0,0],convert(v2,list),color=navy,thickness=2):
display([v1l,v2l],scaling=constrained);
(If any of the vectors are not visible, perhaps they lie along an axis. Click on the graph, and then on the icon that removes the axes in the menu bar)
Next have Maple generate two vectors that are linear combinations of v1 and v2, with integer coefficients.
>
u1 := evalm(rand(-3..3)()*v1+rand(-3..3)()*v2);
u2 := evalm(rand(-3..3)()*v1+rand(-3..3)()*v2);
If either of these is zero, recompute! Plot these new vectors:
>
u1l := line([0,0],convert(u1,list),color=red,thickness=2):
u2l := line([0,0],convert(u2,list),color=green,thickness=2):
display([v1l,v2l,u1l,u2l],scaling=constrained);
Exercise:
1) Your task is to find the coordinates of u1 and of u2 relative to the ordered basis {v1, v2}. Do this by experimentally finding the linear combinations of v1 and v2 that give u1 and u2, respectively. You need to provide the coefficients of v1 and v2 in the following code. Your "guess" linear combinations appear as dashed lines.
>
u1g := evalm(1*v1 + 1*v2);
u2g := evalm(1*v1 + (-1)*v2);
u1gl := line([0,0],convert(u1g,list),color=red,thickness=2,linestyle=3):
u2gl := line([0,0],convert(u2g,list),color=green,thickness=2,linestyle=3):
display([v1l,v2l,u1l,u2l,u1gl,u2gl],scaling=constrained);
Conclusion: The coordinate vector of u1 relative to the ordered basis {v1, v2} is:
The coordinate vector of u2 relative to the ordered basis {v1,v2} is:
>
On to Three Dimensions!
We repeat the above exercise in three dimensions. First, we generate a "random" basis for
.
>
w1 := randvector(3,entries=rand(-2..2));
w2 := randvector(3,entries=rand(-2..2));
w3 := randvector(3,entries=rand(-2..2));
Check that these vectors form a basis by visually checking the span. If the plot is a plane or a line, execute the commands above to generate another set of vectors! (If you just don't like the look of the basis, go back and generate another set of vectors!)
>
w1l := line([0,0,0],convert(w1,list),color=blue,thickness=2):
w2l := line([0,0,0],convert(w2,list),color=navy,thickness=2):
w3l := line([0,0,0],convert(w3,list),color=cyan,thickness=2):
spanpoints := pointplot3d({seq(evalm(rand(-2..2)()*w1+rand(-2..2)()*w2+rand(-2..2)()*w3),i=1..200)} minus {0},color=black):
display([w1l,w2l,w3l,spanpoints],scaling=constrained,axes=normal);
Now have Maple pick two "random" vectors in the span:
>
y1 := evalm(rand(-3..3)()*w1+rand(-3..3)()*w2+rand(-3..3)()*w3);
y2 := evalm(rand(-3..3)()*w1+rand(-3..3)()*w2+rand(-3..3)()*w3);
If either of these vectors is zero, recompute! Plot these new vectors:
>
y1l := line([0,0,0],convert(y1,list),color=red,thickness=2):
y2l := line([0,0,0],convert(y2,list),color=green,thickness=2):
display([w1l,w2l,w3l,y1l,y2l],scaling=constrained,axes=normal);
Exercise:
2) Your task now is to find the coordinates of y1 and of y2 relative to the ordered basis {w1, w2, w3}. Same as in Exercise 1, the coefficients are all integers between -3 and 3. (If you wish to remove the axes, click on the graph and then on the right-most button on the menu bar that appears - or replace "axes = normal' with "axes = none")
>
y1g := evalm(1*w1 + 1*w2 + 1*w3);
y2g := evalm(1*w1 + (-1)*w2 + 1*w3);
y1gl := line([0,0,0],convert(y1g,list),color=red,thickness=2,linestyle=3):
y2gl := line([0,0,0],convert(y2g,list),color=green,thickness=2,linestyle=3):
display([w1l,w2l,w3l,y1l,y2l,y1gl,y2gl],scaling=constrained,axes=normal);
>
Conclusion: The coordinate vector of y1 relative to the ordered basis {w1, w2, w3} is:
The coordinate vector of y2 relative to the ordered basis {w1, w2, w3} is:
The Point Matrix and the Coordinate Matrix
Now we find a matrix which computes coordinates for us. The text says to create the point matrix by making columns from the elements of the new basis (do this for our basis for
):
> PM := augment(w1,w2,w3);
The coordinate matrix is the inverse of the point matrix:
> CM := inverse(PM);
Now use this matrix to find the coordinates of, say, [3,-2,5]:
>
z := [3,-2,5];
cz := evalm(CM &* z);
Check:
>
cz[1]*w1 + cz[2]*w2 + cz[3]*w3;
evalm(cz[1]*w1 + cz[2]*w2 + cz[3]*w3);
Exercise
3) Use the coordinate matrix to compute the coordinates of y1 and y2 with respect to the basis {w1, w2, w3}. You ought to get the same answers you got in Exercise 2!
>
Computing Coordinates in Orthogonal Bases
Computing coordinates with respect to an orthogonal basis is less difficult. First let's use "magic" to find an orthogonal basis starting from the basis {w1, w2, w3}:
> OB := GramSchmidt([w1, w2, w3]);
Check that these vectors are orthogonal, firstly algebraically:
>
dotprod(OB[1],OB[2]);
dotprod(OB[1],OB[3]);
dotprod(OB[2],OB[3]);
Then graphically:
>
OB1l := line([0,0,0],convert(OB[1],list),color=blue,thickness=2):
OB2l := line([0,0,0],convert(OB[2],list),color=navy,thickness=2):
OB3l := line([0,0,0],convert(OB[3],list),color=cyan,thickness=2):
display([OB1l,OB2l,OB3l],scaling=constrained,axes=normal);
Rotate the plot to check that the vectors appear to be mutually orthogonal
Now the coordinates for any vector are simply computed using dot products:
>
z;
zc1 := dotprod(z,OB[1])/dotprod(OB[1],OB[1]);
zc2 := dotprod(z,OB[2])/dotprod(OB[2],OB[2]);
zc3 := dotprod(z,OB[3])/dotprod(OB[3],OB[3]);
Check:
>
zc1*OB[1] + zc2*OB[2] + zc3*OB[3];
Exercise
4) Find the coordinates of y1 and y2 relative to the orthogonal basis OB using dot products. Check the coordinates by direct computation.
>
>