Tutorial 2

advertisement
Tutorial 2
(version 1/22/03)
In this tutorial we want to introduce some new functions that will be useful to visualize different
problems in linear algebra. We start with the simple problem of understanding (visually and
analytically) a system of two linear equations in two unknowns.
Before we describe the system we instruct Maple to load the LinearAlgebra package as well as the
plots package that we will use later to produce some graphs.
> with(LinearAlgebra):
> with(plots):
Warning, the name changecoords has been redefined
Next we define the system of equations by giving its coefficient matrix (A) and the constant terms (b)
> A:=<<1,2>|<1,-1>>;
> b:=<1,0>;
 1
1

A := 

 2
-1
 1

b := 

 0
We use LinearSolve to find the solutions:
> LinearSolve(A,b);
 1 


 3 






 2 


 3 
Therefore there is a unique solution.
Now we want to visualize the system: remember that each equation represents, in this case, a line in
R^2. For example, the first equation x+y=1 corresponds to the explicit line y=-x+1. We can graph this
line as
> plot(-x+1,x=-2..2);
3
2
1
–2
–1
0
–1
Alternatively, without solving for y:
> implicitplot(x+y=1,x=-2..2,y=-2..2);
1
x
2
2
1.5
y
1
0.5
–1
–0.5
0.5
1
x
1.5
2
–0.5
–1
When we consider the second equation, 2*x-y=0, we are imposing the additional condition that the
solution must be in both lines simultaneously. Graphically
> plot([-x+1,2*x],x=-2..2,color=[red,blue],scaling=constrained);
4
2
–2
–1
1
x
2
–2
–4
Notice the use of the scaling=constrained option to force Maple to use the same scale on both axes.
See what happens if you don’t use this option.
We can produce the same graph as above but, rather than viewing it on the screen, we can save it for
later use:
> lines:=plot([-x+1,2*x],x=-2..2,color=[red,blue],scaling=constraine
d):
We can finally add the intersection point to the graph:
> P:=pointplot([1/3,2/3]):
To see the lines and intersection point on the same graph we use
> display(lines,P);
4
2
–2
–1
1
x
2
–2
–4
Problem: Repeat the same analysis for the linear system 3*x+y=1 and x-y=1.
Problem: Repeat the same analysis for the system x+2*y=1 and x/2+y=2.
Our next step is to consider systems of linear equations with three unknowns. We start with the
simplest case: only one equation: x+2*y+z=1. The solutions of this equation describe a plane in R^3.
We can see the plane by, for instance, solving for z: z=-x-2*y+1
> plot3d(-x-2*y+1,x=-2..2,y=-2..2,axes=normal);
6
4
–2
2
–1
0
y
1
2
–2
–1
–2
–4
1
x
2
Try rotating the graph in order to better understand the location of the plane in space!!!
Next we add a second equation to the system, which then becomes: x+2*y+z=1 and x+z=1. Solving
for z in the new equation (z=-x-1) we plot both planes together:
> plot3d({-x-2*y+1,-x+1},x=-2..2,y=-2..2,axes=normal,scaling=constra
ined);
6
4
2
–2 –1
–2
x y
–2
2
–4
We immediately see that the solution of our system of equations (the intersection of the two planes)
consists of a line. How can we find that line?
> LinearSolve(<<1,1>|<2,0>|<1,1>>,<1,1>);
1 − _t03




 0 






 _t0 

3 
That is, the solution consists of the points of the form (t,0,-t+1). We plot this solution with the
command spacecurve.
> spacecurve([1-t,0,t],t=-2..2,axes=normal,labels=["x","y","z"],thic
kness=2,color=brown,scaling=constrained);
2
–1
x
2
3
1
y
0 z
1
1
–1
–2
Finally, we put together the two planes and the intersection line:
> planes:=plot3d({-x-2*y+1,-x+1},x=-2..2,y=-2..2,axes=normal):
> line:=spacecurve([t,0,-t+1],t=-2..2,axes=normal,labels=["x","y","z
"],thickness=2,color=brown):
> display(planes,line);
6
4
2
–2
2
–2
–1
–1
1y
x 1
–2
2
–4
Problem: add a third equation (y+z=2) to the system that we have been considering so far and see how
this new plane intersects the other two. Find analytically and graphically the intersection.
Problem: Analyse completely the system x+y+2*z=1, x+z=0 and y+z=0.
Our next goal is to visualize the action of some linear transformations in the plane. For that we will
start by introducing a new way of producing (planar) graphs: using a list of points.
> listOfPoints:=[[1,1],[2,0],[1,2]];
listOfPoints := [[1, 1 ], [2, 0 ], [1, 2 ]]
> listplot(listOfPoints);
2
1.5
1
0.5
0 1
1.2
1.4
1.6
1.8
2
This type of plot joins the given points by line segments. If we just want the points we can use
> listplot(listOfPoints,style=POINT);
2
1.5
1
0.5
0 1
1.2
1.4
1.6
1.8
2
Notice that each point in listOfPoints is not a Vector. We can go from a list to a Vector
> convert([1,2],Vector);
 1




 2
as well as produce a list from a Vector:
> convert(<1,2>,list);
[1, 2 ]
There are some ways to automatically produce lists. For example,
> listLine:=seq([t/50,t/50],t=0..100);
1 1 1 1 3 3 2 2 1 1 3 3 7 7 4 4
listLine := [0, 0 ],  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 9 9   1 1   11 11   6 6   13 13   7 7   3 3   8 8   17 17   9 9 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 19 19   2 2   21 21   11 11   23 23   12 12   1 1   13 13   27 27   14 14 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   2 2   25 25   50 50   25 25 
 29 29   3 3   31 31   16 16   33 33   17 17   7 7   18 18   37 37   19 19 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 39 39   4 4   41 41   21 21   43 43   22 22   9 9   23 23   47 47   24 24 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 49 49 
 51 51   26 26   53 53   27 27   11 11   28 28   57 57   29 29 
 , , [1, 1 ],  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50 
 50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 59 59   6 6   61 61   31 31   63 63   32 32   13 13   33 33   67 67   34 34 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 69 69   7 7   71 71   36 36   73 73   37 37   3 3   38 38   77 77   39 39 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   2 2   25 25   50 50   25 25 
 79 79   8 8   81 81   41 41   83 83   42 42   17 17   43 43   87 87   44 44 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 89 89   9 9   91 91   46 46   93 93   47 47   19 19   48 48   97 97   49 49 
 , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,  , ,
 50 50   5 5   50 50   25 25   50 50   25 25   10 10   25 25   50 50   25 25 
 99 99 
 , , [2, 2 ]
 50 50 
The command seq produces a sequence of points (lists) for each value in a range.
To plot the list that we have just produced we use listplot
> listplot([listLine],style=POINT,symbol=POINT);
2
1.5
1
0.5
0
0.5
1
1.5
2
We create another list of points, this time representing a circle of radius 1 centered at the origin:
> listCircle:=seq([cos(2*Pi*t/100),sin(2*Pi*t/100)],t=0..100):
We join the two lists of points in a new list:
> listBoth:=listCircle,listLine:
> listplot([listBoth],style=POINT,symbol=POINT);
2
1.5
1
0.5
–1
–0.5
0
0.5
1
1.5
2
–0.5
–1
We want to visualize next the action of different linear transformations on the plane. We start by
defining a matrix:
> A:=<<1,0>|<0,-1>>;
 1
0

A := 

 0
-1
Of course, A defines a linear transformation that maps, for instance, the vector <1,1> to
> A.<1,1>;
 1




 -1
We can apply the linear transformation to each point of our lists of points and use the transformed
points to generate a new graph. In this way, we will see how our line/circle image is transformed by
the mapping. Unfortunately, there is a minor technical issue here: the elements of the lists are lists
themselves and not Vectors, so that we cannot just multiply them by A. Instead, we define a function:
> T:=x->convert((A.convert(x,Vector)),list);
T := x → convert(A . (convert(x, Vector)), list)
What T does is to convert the list x first into a vector, then multiply by the matrix A and finally
convert the resulting Vector to a list.
We can apply T to each point in the lists that we have used using the map function
> transformedList:=map(T,[listBoth]):
listplot(transformedList,style=POINT,symbol=POINT);
1
0.5
–1
–0.5
0.5
1
1.5
2
0
–0.5
–1
–1.5
–2
We see from the graph that the effect of the transformation was to reflect the image across the x-axis.
Of course, there are other possible interpretations (like a rotation of 90 degrees in the clockwise
direction) and to distinguish among the different possibilities we should use different "test graphs".
Problem: construct a different "test graph" that can be used to tell if the linear transformation
discussed above is a rotation or a reflection.
Another interesting example comes from the matrix
> A:=<<2,0>|<0,1>>;
 2
0

A := 

 0
1
We do as before
> transformedList:=map(T,[listBoth]):
listplot(transformedList,style=POINT,symbol=POINT);
2
1.5
1
0.5
–2
–1
0
1
2
3
4
–0.5
–1
But, surprise, nothing seems to have happened... This is not quite true (compare the tick marks in this
last graph with those of the original, untransformed, line/circle). The problem is that Maple is using
two different scales on the axes. We can force Maple to use the same scale as we did above
> listplot(transformedList,style=POINT,symbol=POINT,scaling=constrai
ned);
2
1.5
1
0.5
–2
–1
0
1
2
3
4
–0.5
–1
The previous graph shows that the transformation expands the x-axis by a factor of two, while keeping
the y-axis fixed.
Problem: What is the effect of the matrix
> A:=<<1,2>|<3,4>>;
on the "test figure".
 1
3

A := 

 2
4
Problem: Write the coefficient matrix of a rotation by 60 degreees in the anticlockwise direction and
find the effect of this linear transformation on the "test figure".
Problem: Write the coefficient matrix of the orthogonal projection onto the line with direction (2,1)
going through the origin. Find the effect of this linear transformation on the "test figure".
One last, completely unrelated, subject is that of inverting matrices. Maple does this in a very simple
way. Start with a matrix:
> A:=<<1,2,3>|<4,5,6>|<7,8,0>>;
4
7
 1





5
8
A :=  2




3
6
0


To find the inverse we use the MatrixInverse command
> AI:=MatrixInverse(A);
14
-1 
 -16


 9
9
9 





 8
-7
2 


AI := 

9
9
9






 -1

2
-1


9
9 
 9
We immediately check that AI is the inverse of A:
> AI.A;
0
0
 1




 0

1
0






0
1
 0
> A.AI;
0
0
 1




 0

1
0






0
1
 0
As you know, some matrices are not invertible. Try inverting the matrix
> B:=<<1,2,3>|<4,5,6>|<7,8,9>>;
4
7
 1





5
8
B :=  2




6
9
 3
>
Problem: consider the matrix <<1,2,3>|<4,5,6>|<7,8,K>>. As we saw above, for some values of K
this matrix is invertible while for some others it is not. Find all the values of K where the matrix is
invertible.
Download