OnLine4-1-Coords.mws

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

1002121940

Outline

This worksheet investigates coordinates.

The basic objectives are:

Visualizing coordinates

First generate a non-standard basis for R^2 .

> v1 := randvector(2,entries=rand(-2..2));
v2 := randvector(2,entries=rand(-2..2));

v1 := vector([0, -2])

v2 := vector([0, -1])

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);

[Maple Plot]

(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);

u1 := vector([0, 6])

u2 := vector([0, 2])

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);

[Maple Plot]

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);

u1g := vector([0, -3])

u2g := vector([0, -1])

[Maple Plot]

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 R^3 .

> w1 := randvector(3,entries=rand(-2..2));
w2 := randvector(3,entries=rand(-2..2));
w3 := randvector(3,entries=rand(-2..2));

w1 := vector([2, 1, 1])

w2 := vector([1, 0, 2])

w3 := vector([-1, 2, -1])

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);

[Maple Plot]

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);

y1 := vector([-2, 1, 0])

y2 := vector([6, -1, 1])

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);

[Maple Plot]

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);

y1g := vector([2, 3, 2])

y2g := vector([0, 3, -2])

[Maple Plot]

>

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 R^3 ):

> PM := augment(w1,w2,w3);

PM := matrix([[2, 1, -1], [1, 0, 2], [1, 2, -1]])

The coordinate matrix is the inverse of the point matrix:

> CM := inverse(PM);

CM := matrix([[4/7, 1/7, -2/7], [-3/7, 1/7, 5/7], [...

Now use this matrix to find the coordinates of, say, [3,-2,5]:

> z := [3,-2,5];
cz := evalm(CM &* z);

z := [3, -2, 5]

cz := vector([0, 2, -1])

Check:

> cz[1]*w1 + cz[2]*w2 + cz[3]*w3;
evalm(cz[1]*w1 + cz[2]*w2 + cz[3]*w3);

2*w2-w3

vector([3, -2, 5])

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]);

OB := [[2, 1, 1], [-1/3, -2/3, 4/3], [-1, 3/2, 1/2]...

Check that these vectors are orthogonal, firstly algebraically:

> dotprod(OB[1],OB[2]);
dotprod(OB[1],OB[3]);
dotprod(OB[2],OB[3]);

0

0

0

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);

[Maple Plot]

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]);

[3, -2, 5]

zc1 := 3/2

zc2 := 3

zc3 := -1

Check:

> zc1*OB[1] + zc2*OB[2] + zc3*OB[3];

[3, -2, 5]

Exercise

4) Find the coordinates of y1 and y2 relative to the orthogonal basis OB using dot products. Check the coordinates by direct computation.

>

>