Beruflich Dokumente
Kultur Dokumente
LINEAR ALGEBRA,
VECTOR CALCULUS
Chapter 7
67
68 Examples for Chapter 7 Chap. 7
−2 1
F := 4 1
−1 5
> G := evalm(A&*F); # Product of two matrices
−22 2
G :=
−4 −13
Chap. 7 Examples for Chapter 7 69
Vectors occur together with matrices, particularly in connection with linear systems.
Let
> v := [3, 5]; # Resp. v := [3, 5]
> evalm(v&*A); # Resp. [45, −4, −20]
> evalm(A&*v);
Error, (in linalg[multiply]) non matching dimensions for vector/matrix product
> evalm(F&*v); # Resp. [−1, 17, 22]
Note that for vectors entered in the form v = [v1 , v2 , ...] Maple does not distinguish
between row and column vectors, leaving the interpretation to you. Thus the last
response is a column vector. If C is a 3 × 3 matrix and x = [x1 , x2 , x3 ], you can
compute C& ∗ x or x& ∗ C obtaining a row vector r = [r1 , r2 , r3 ] in both cases, but in
the first case x and r are column vectors and in the second case they are row vectors.
Further let
> u := [4, -2]; # Resp. u = [4, −2]
> u*v; # Resp. [4, −2][3, 5]
> evalm(u&*v); # Resp. 2 # Inner product (dot product)
> dotprod(u, v); # Resp. 2 # Inner product
> innerprod(u, v); # Resp. 2 # Inner product
So here you have three different commands for the inner product (dot product)
u • v or, regarding the vectors as column vectors, uT v. Similarly, you obtain vT G (v
regarded as a column vector).
> evalm(v&*G); # Resp. [−86, −59]
On rare occasions you may need the n × n matrix vuT (where n = 2 for our vectors).
> v := matrix([[3, 5]]); # Resp. v := [ 3 5 ]
4
> u := matrix([[4], [-2]]); # Resp. u :=
−2
12 20
> evalm(u&*v); # Resp.
−6 −10
Similar M ate r ial in AEM : Secs. 7.1, 7.2
70 Examples for Chapter 7 Chap. 7
This shows how to extract an entry of A = [ajk ], namely, a23 = 4. A whole row or
column is obtained by
Chap. 7 Examples for Chapter 7 71
3 −4 0 0
You will need this in the Gauss elimination. Similarly for interchanging columns, say,
2 and 4, type swapcol(A, 2, 4) . The next command, basic in the Gauss elimination,
adds −3 times Row 1 to Row 3, creating a 0 in the left lower corner.
> C := addrow(B, 1, 3, -3);
1 −2 4 −3
C := 0 1 −1 2
0 2 −12 9
Composition of matrices from vectors. The au g me nte d matr ix [A, b] of A
and a vector b, say,
> b := [4, 5, 2]; # Resp. b := [4, 5, 2]
is obtained by typing
> augment(A, b); # Here, Maple takes b as a column vector.
0 1 −1 2 4
1 −2 4 −3 5
3 −4 0 0 2
More generally, the command augment composes a matrix from given vectors as
columns, and by taking the transpose you get the matrix with these vectors as rows.
For instance, let
> a := [2, 1]: b := [3, 8]: c := [-1, 2]:
Then
2 3 −1
> augment(a, b, c); # Resp.
1 8 2
72 Examples for Chapter 7 Chap. 7
> transpose(%);
2 1
3 8
−1 2
Similar M ate r ial in AEM : Sec. 7.2
Solu tion. Fir s t me thod. Write the system in matrix form Ax = b and type the
coefficient matrix A and the vector b as shown.
> with(linalg): # Ignore the warning.
> A := matrix([[-1, 1, 2], [3, -1, 1], [-1, 3, 4]]);
−1 1 2
A := 3 −1 1
−1 3 4
> b := [2, 6, 4]; # Resp. b := [2, 6, 4]
> x := linsolve(A, b); # Resp. x := [1, −1, 2]
Se c ond me thod. In the method just discussed you get the solution without
seeing what is going on. The second method does elimination and back substitution
separately. Accordingly, first type the augmented matrix by the command augment
(see the previous example) and then apply gausselim , which does the Gauss elimi-
nation. As Step 2 of the method then follows the back substitution by the command
backsub .
> A1 := augment(A, b);
−1 1 2 2
A1 := 3 −1 1 6
−1 3 4 4
> B := gausselim(A1);
−1 1 2 2
B := 0
2 7 12
0 0 −5 −10
> x := ’x’: # Unassign x (used just before).
> x := backsub(B);
x := [1, −1, 2]
> rank(A); # Resp. 3
The process of solution is the same as in the first method in the previous example.
> with(linalg): # Ignore the warning.
> Digits := 5: # This restricts floating numbers to 5 digits.
> A := matrix([[3.0, 2.0, 2.0, -5.0],
> [0.6, 1.5, 1.5, -5.4],
> [1.2, -0.3, -0.3, 2.4]]);
3.0 2.0 2.0 −5.0
A := 0.6 1.5 1.5 −5.4
1.2 −0.3 −0.3 2.4
> b := [8.0, 2.7, 2.1];
b := [8.0, 2.7, 2.1]
> x := linsolve(A, b);
x := [−0.2500, 10. − 1. t 1 , t 1 , 2.2500]
Furthermore, if in the general solution you choose x4 = 2.25, you obtain the partial
solution set first obtained. Hence be prepared that y ou r s oftwar e may not alway s
g iv e y ou all the s olu tions . Thus it may often be worthwhile to do all the steps of
the Gauss elimination.
Try out whether the second method in the previous example will give better
results. Type
> A1 := augment(A, b);
3.0 2.0 2.0 −5.0 8.0
A1 := 0.6 1.5 1.5 −5.4 2.7
1.2 −0.3 −0.3 2.4 2.1
74 Examples for Chapter 7 Chap. 7
> B := gausselim(A1);
3.0 2.0 2.0 −5.0 8.0
B := 0 1.1000 1.1000 −4.4000 1.1000
0 0 0 0 0
> x := ’x’: # Unassign x used just before.
> x := backsub(B);
x := [ 2.0000 − 0.99999 t 1 , 1.0000 − 1.0000 t 2 + 4.0000 t 1 , t 2 , t 1 ]
With this method you have obtained the full solution set (except for the small round-
off error; −0.99999 should be −1), x1 = 2 − t1 , x2 = 1 − t2 + 4 t1 , x3 = t2 arbitrary,
x4 = t1 arbitrary.
C as e 2. A u niq u e s olu tion. See the previous example.
C as e 3. N o s olu tions . For instance, x1 + x2 = 3, 2 x1 + 2 x2 = 5 has no
solutions. To see what happens, type
> A := matrix([[1, 1], [2, 2]]); b := [3, 5];
1 1
A :=
2 2
b := [3, 5]
> linsolve(A, b); # No response. Hence you get no solutions.
Similar M ate r ial in AEM : Sec. 7.3
Show the invariance of rank A under elementary row operations. Interchange, for
instance, Rows 1 and 3:
> rank(swaprow(A, 1, 3)); # Resp. 2
The second row operation is the addition of a constant multiple of a row to another
row, for instance, add −5 times Row 2 to Row 3:
Chap. 7 Examples for Chapter 7 75
The third row operation is the multiplication of a row by a nonze r o constant c. For
instance, multiply Row 3 of A by −1/3 (by adding −2/3 of Row 3 to Row 3):
> addrow(A, 3, 3, -2/3);
3 0 2 2
−6 42 24 54
7 −7 0 −5
> rank(%); # Resp. 2
0 0 0 0
I I . By the command rowspace(A) or colspace(A) , which compute a basis of the
row space or the column space of A, respectively, and the fact that rank A equals
the dimension 2 of these spaces:
> rowspace(A); colspace(A);
2 29 2 2
{ 0, 1, , , 1, 0, , }
3 21 3 3
−1
{[1, 0, 6], 0, 1, }
2
Linear independence and dependence of vectors can also be tested by the use
of a rank, namely, by the rank of the matrix whose rows or columns are the given
vectors. For instance, let the vectors be
> a := [-6, 42, 24, 54]; b := [21, -21, 0, -15]; c := [3, 0, 2, 2];
a := [−6, 42, 24, 54]
c := [3, 0, 2, 2]
Obtain the matrix with these vectors as columns by the command augment ,
76 Problem Set for Chapter 7 Chap. 7
Hence the given vectors are linearly dependent. Indeed, M is obtained from A by
interchanging the rows and then taking the transpose.
Similar M ate r ial in AEM : Sec. 7.4
for n = 2, 3, 4. What does this mean in terms of rotations through an angle θ? (Use
the command map(combine,A2 ) , etc., which operates on each entry separately. Type
?map for information.) (AEM Sec. 7.2)
Pr.7.8 (Transposition rule for products) Prove (A B)T = BT AT for general 2 × 2
matrices on the computer. (AEM Sec. 7.2)
Chap. 7 Problem Set for Chapter 7 77
Pr.7.9 (Experiment on Hankel matrices) Find empirically a law for the smallest n as a
function of m (> 0, integer) such that det A = 0, where the n×n matrix A = [ajk ] has
the entries ajk = (j + k)m . (Enjoy these special Hankel matrices, whose determinants
have very fast growing values, but all of sudden become 0 from some n on. This is of
practical interest in connection with the so-called Padé approximation.)
Pr.7.10 (Inverse) Using the computer, find the formula for the inverse of a 2 × 2 matrix
A = [ajk ] in terms of ajk and det A. (AEM Sec. 7.8)
Pr.7.11 (Inverse of a product) Verify the basic relation (A B)−1 = B−1 A−1 for the ma-
trices
0 −2 −1 1 2 3
A = −2
3 2
and B = 2
3 4
−1 2 1 3 4 6
(AEM Sec. 7.8)
Pr.7.12 (Linear transformations) With respect to Cartesian coordinates in space, let
y = Ax and x = Bw with A and B as in the previous problem. Find the trans-
formation y = Cw which transforms w directly into y. Find the inverse of this
transformation. (AEM Sec. 7.2)
Pr.7.13 (Orthogonal vectors) Show that the following vectors are orthogonal.
(AEM Sec. 7.9)
c = [3 2 −2 1 0 ], d = [2 0 3 0 4 ], e = [ 1 −3 −2 −1 1]