Mathematica^® for Linear Algebra

Department of Mathematics
Rowan University





TABLE OF CONTENTS

Chapter One        Introduction      

        1.1    Mathematica's Conventions                        2

        1.2    Computations and Basic Inputs                    4

        1.3    Exercises                                5

Chapter Two        Matrices annd Linear Equations  

        2.1    Matrices: Addition, Multiplication, Transpose, Inverse        6

        2.2    Special  Matrices: Identity, Diagonal, Random             10

        2.3    Solutions of Linear Systems of Equations                 11

Chapter Three        Determinants                            18

Chapter Four        Vectors and Vector Spaces

        4.1    Vector Algebra                             21

        4.2    Linear Independence and Span                     23

        4.3    Null Space and Rank of a Matrix                    25

        4.4    Transtion Matrix                             27

        4.5    The Gram-Schmidt Orthogonalization Process                28

Chapter Five         Eigenvalues and Eigenvectors

        5.1    Eigenvalues, Eigenvectors, Diagonalization                31

        5.2    Diagonalization of Symmetic Matrices                 34

Chapter One    Introduction to Mathematica

1.1   Mathematica's Conventions

1. 1. 1   Naming

    Built-in Mathematica commands, functions, constants, and other expressions begin with capital  letters, and are - for the most part-  one or more full-length English words.  Mathematica is case sensitive and so a common cause of error is the failure to  capitalize command names. For example, Plot,  Integrate, FindRoot, ParametricPlot3D are valid function names. Sin, Exp, Det, GCD, Max are some of the standard mathematical abbreviations that are exceptions to  the full-length-English-word(s) rule. User defined functions and variables  can be any mixture of upper and lower case letters and numbers. However, a  name cannot begin with a number. By convention, user defined functions  begin  with a  lower-case letter, but this is not required. For example f, g1, myPlot, r12, sOLution, Method1, are permissible function names.
Example 1:      Evaluate cos(π)
Solution:     We will use this example to show two possible errors before giving the  correct answer.

In[1]:=

cos[Pi]

General :: spell1 : Possible spelling error: new symbol name \"cos\" is similar to existing symbol \"Cos\".

Out[1]=

cos[π]

    This is a typical capitalization error one makes when using Mathematica.  The comment before the output  Out[1] = cos[π] indicates a possible  error.

In[2]:=

Cos[pi]

Out[2]=

Cos[pi]

    Here Mathematica did not recognize pi and hence returned the command unevaluated. The correct command to  evaluate cos(π) is

In[3]:=

Cos[Pi]

Out[3]=

-1

    NOTE:    It is worth noting that Mathematica keeps track of the calculations it performs in a given session. The  inputs are denoted by In[k] and the outputs are denoted by Out[k]. Thus, In[1] is the first input and Out[1] is the output of the first  input.

1. 1. 2   Parentheses, Square Brackets and Braces

    Mathematica interprets various types of brackets differently. Using an incorrect type  of bracket is another common source of error.  Mathematica's bracketing conventions are:

1)     Parentheses, ( ), are used only for grouping. For example (x-y)^2, 1/(a+b), (x^3-y)/(x+3y^2). It is worth noting that Mathematica understands f(2) as f times 2, and not as the value of the function f at 2.

2)     Square Brackets, [ ], are used for function arguments. Thus Sin[Pi], Simplify[(x^3-y`^3)/x-y)], Sqrt[346] are proper use of square brackets. If f is a user-defined function, then f[2] is f evaluated at 2.

3)     Braces or curly brackets, { }, are used  for lists, ranges, and iterators. In all cases, elements are  separated by commas. Here are the typical use of braces:
    {1, 4, 9, 16, 25 ,36}   the list of the square of the first six positive integers.
    Plot[ f[x], {x, -5,5}]   specifies the range of values for x.
    Table[m^3, {m, 1, 100}] specifies the values of the iterator m, i.e., the values of m; m goes  from 1 to 100.

    NOTE:    We can write comments with an input. The comments should be enclosed  by (* and *). For example, Table[ n^2,{ n, 1, 6 } ]   (*returns a list of the square of the first six positive  integers*)

Example 2:     Below we give examples of the correct and incorrect usage of brackets.

In[4]:=

(2^3 - 4)/(4 + 3 * 9^2)           (* a  correct use of (...) *)

Out[4]=

4/247

In[5]:=

[2^3 - 4]/[4 + 3 * 9^2]         (* an incorrect use of [...] *)

                                                        3                2 Syntax :: sntxb : Expression cannot begin with \"[2  - 4]/[4 + 3 * 9 ] \".

  3 [2  - 4]/[4 + 3 * 9^2]

In[5]:=

Sqrt[343]        (* a correct use of [...] *)

Out[5]=

7 7^(1/2)

In[6]:=

Sqrt (343)      (* an incorrect use of (...) *)

Out[6]=

343 Sqrt

1. 1. 3   Equal Signs

The following are Mathematica rules of using the equal sign symbol.

1)      A single equal sign ( = )  assigns a value to a variable. Thus q=3 means that q will be assigned the value 3. If we enter 10+q^3, Mathematica will return 37. As another example take y=x^3-x+1. Now, if we assign a value for x, say x=2, then Mathematica evaluates y using that value of x  and uses the result, 7 in our case, in any input containing y afterwards.

2)     A colon-equal sign( := ) creates a delayed statement for an expression, used in defining a  function. For example f[x_]:=x^3-x+1 will reevaluate the function f for each new value of x.  

3)     A double equal sign( = = ) is a test for the equality of two expressions. If we set x = -5, then evaluating x == -5 returns True, and x == 5 returns False. Another common usage of == is as in Solve[x^3-x+1==0,x]

1. 1. 4   Referring to Previous Results

    Mathematica remembers all of the inputs and outputs in a session, and we can refer to  a previous output by using the percent sign (%) notation. A single % refers to Mathematica's last output, %% refers to the next-to-last output, and so on.   %k refers to output  line numbered k. For example %45 refers to output number 45.  (NOTE: CTRL +L reproduces the last input and CTRL+SHIFT+ L reproduces the last output.)   

1.2    Computations and Basic Inputs

    Mathematica uses +, - , * , / ,  and  ^  for addition, subtraction, multiplication, division and power, respectively. Multiplication can also be performed by leaving a blank  space between factors.

    Mathematica can  convert  numerical values to decimal form. The command for this is N[expr] or N[expr,n].  In most cases, N[expr] returns six digits of expr or gives expr in the form n.abcde*10^m.  N[expr,n] attempts to give n digits  of expr. Mathematica can perform calculations to arbitrary precision and can handle numbers  that are arbitrarily large or small.
Example 3:     Here are some typical usages of N[..]

In[7]:=

Pi

Out[7]=

π

In[8]:=

N[%]

Out[8]=

3.14159

    Note that the command   N[%] gives a decimalized version of the last output. Similarily  N[%k] can be used to get the decimal equivalent of Output[k].  

In[9]:=

N[Pi, 200]

Out[9]=

    Mathematica 3.0 allows us to enter mathematical expressions and some of the commonly used  commands from  6 different palettes. If we click on the File menu and go to Palettes we will find 7 options. The first six options conatin most of the symbols  we need.  BasicInput is a palette which can be used to enter mathematical  expressions involving exponents,  rational  expressions, radicals, integrals, derivatives, summation, product, matrices,  some of  the commonly used constants( π,  e, i,  ∞) and some of the Greek letters.  

Example 4:    Enter ∫_0^1x^3/(2x - 1)^(1/2)dx   in a notebook.

Solution:    One way to enter this expression into a Mathematica notebook is as follows: Go to the BasicInput palette and click on the definite integration symbol ∫_□^□d . Type 0 in the lower box and using the TAB key move to the top box and  type 1. Use the TAB to go to the box where the integrand should be typed.  While in this box go to the palette and  click on □/□. Go back to the pallete and click on □^□ and type x^3 in this box. Go to the box in the denominator and then go to the palette  to click on □^(1/2) and type 2x-1. Finally, using the TAB once again, go to the last box and  type x.

1.3     Exercises

1.    Evaluate the following expressions:
    a) 103.41+20*76    b) (5^2 + π)/(1 + π)     c) 1/(1 + 1/(1 + 1/4 !))     d) (2.06 * 10^9)/(0.99 * 10^(-8))

2.    Enter the following expressions in a notebook.
    (a)    80^(1/3)            (b)    1024^(1/5)/2^(-3)        (c)    125^(1/2)^(1/3)
    
    (d)    
(10a^7b)^(1/3)^(1/2)        (e)    ((x^(-3) y^4)/5)^(-3)        (f)     ((3m^1/6n^1/3)/(4n^-2/3))^2      

Chapter Two     Linear Equations and Matrices

2.1  Matrices: Addition, Multiplication, Transpose, Inverse

Example 1:  Consider the following matrices:

A=(

2 3 1
3 3 1
2 4 1
);    B =(
2 0 0
1 -4 8
1 -1 2
)
;   X =(
2 4
0 1
2 6
)
;   Y  =(
1
0
6
)
;   Z =(
-1 1 4
)

    Compute each of the following.
    a)     3A - 4B       b)     AB      c)     BA      d)    X^T       e)     X^T B Y Z

Solution:     We first enter the matrices in Mathematica as follows. A matrix can be typed using braces, with a pair of braces around each row. A comma separates the rows as well as the entries in a row. For example, the matrix A can be entered as follows.

In[10]:=

A = {{2, 3, 1}, {3, 3, 1}, {2, 4, 1}}

Out[10]=

{{2, 3, 1}, {3, 3, 1}, {2, 4, 1}}

    In order to display matrix A in the usual form, we use the command:

In[11]:=

A ; MatrixForm[A]

Out[11]//MatrixForm=

( {{2, 3, 1}, {3, 3, 1}, {2, 4, 1}} )

    In the above, note that the semicolon tells Mathematica not to print the result of matrix A in a list form.

    Another way of entering a matrix, such as B, is to perform the following. From the Input menu choose Create Table/Matrix/Palette.  Then, select Matrix and identify the number of rows and columns of the matrix to be 3. Click OK and a 3x3 matrix is generated. You can now insert the entries of the matrix and use TAB to go from one entry to the next.

In[12]:=

B = ({{2, 0, 0}, {1, -4, 8}, {1, -1, 2}})

Out[12]=

{{2, 0, 0}, {1, -4, 8}, {1, -1, 2}}

    Similarly, we enter matrix X.

In[13]:=

X = ({{2, 4}, {0, 1}, {2, 6}})

Out[13]=

{{2, 4}, {0, 1}, {2, 6}}

    A column matrix such as Y is entered by  putting  braces around each entry.

In[14]:=

Y = {{1}, {0}, {6}} ; MatrixForm[Y]

Out[14]//MatrixForm=

( {{1}, {0}, {6}} )

    We can also use the palettes to create a matrix and  enter matrix Y as follows.

In[15]:=

Y = ({{1}, {0}, {6}})

Out[15]=

{{1}, {0}, {6}}

    Next, we enter the row matrix  Z.

In[16]:=

Z = {{-1, 1, 4}} ; MatrixForm[Z]

Out[16]//MatrixForm=

( {{-1, 1, 4}} )

a ) We evaluate the matrix  3A - 4B and display it in matrix form.

In[17]:=

3 A - 4 B ; MatrixForm[3A - 4B]

Out[17]//MatrixForm=

( {{-2, 9, 3}, {5, 25, -29}, {2, 16, -5}} )

b)  The product of the matrices A & B is obtained by typing A .B. Note that if you omit the dot  that  is  between A & B, then the product is not obtained.

In[18]:=

A . B ; MatrixForm[A . B]

Out[18]//MatrixForm=

( {{8, -13, 26}, {10, -13, 26}, {9, -17, 34}} )

c)  Similarly, we get the product of matrices B and A.

In[19]:=

B . A ; MatrixForm[B . A]

Out[19]//MatrixForm=

( {{4, 6, 2}, {6, 23, 5}, {3, 8, 2}} )

    Observe that the above calculations show that matrix multiplication  is not commutative.

d)  The  transpose of X is obtained by entering:

In[20]:=

Transpose[X] ; MatrixForm[Transpose[X]]

Out[20]//MatrixForm=

( {{2, 0, 2}, {4, 1, 6}} )

e)   First, observe that the product of the matrices X^T   B  Y  Z   is a 2x3 matrix (Do you see why?).  This product is obtained by entering:

In[21]:=

Transpose[X] . B . Y . Z

MatrixForm[%]

Out[21]=

{{-30, 30, 120}, {-135, 135, 540}}

Out[22]//MatrixForm=

( {{-30, 30, 120}, {-135, 135, 540}} )

    Remark: In Mathematica, the notation % refers to the last output. Thus, in the above, the command MatrixForm[%] is used to express the last output in the usual matrix representation.

Example 2:  Use the matrices in Example 1 to verify each of the following identities.

    a)     (AX)^T = X^TA^T           b)     (AB)X =A (BX)          c)       (A+B)X = AX + BX

Solution:    a)  We verify that Transpose[AX] = Transpose[X]. Transpose[A] by computing:

In[23]:=

 Transpose[A . X] - Transpose[X] . Transpose[A]

Out[23]=

{{0, 0, 0}, {0, 0, 0}}

b) Next, we verify that matrix multiplication, when defined, is associative.

In[24]:=

(A . B) . X - A . (B . X)

Out[24]=

{{0, 0}, {0, 0}, {0, 0}}

c)  We show that matrix multiplication is distributive over matrix addition.

In[25]:=

(A + B) . X - (A . X + B . X)

Out[25]=

{{0, 0}, {0, 0}, {0, 0}}

Example 3: Let W = 3A - 4B, where A and B are the matrices defined in Example 1. Find each of the following.

    a)  w_21 = the entry in row 2 and column 1
    b)  the second row of W    
    c) the third column of W

    d) the submatrix obtained by deleting row 1 and column 3 of W.

Solution:    First, we find the matrix W as follows.

In[26]:=

W = 3 A - 4 B ; MatrixForm[W]

Out[26]//MatrixForm=

( {{-2, 9, 3}, {5, 25, -29}, {2, 16, -5}} )

    From a given matrix, such as W,  we can extract single entries, rows, columns or submatrices as follows.
a)  To obtain the entry in row 2 and column 1, the command is:

In[27]:=

W[ [ 2, 1]]

Out[27]=

5

b)   To obtain the second row of W, the command is:

In[28]:=

W[[2]]

Out[28]=

{5, 25, -29}

c)  To obtain the third column of W, we enter:

In[29]:=

W[[{1, 2, 3}, {3}]]//MatrixForm

Out[29]//MatrixForm=

( {{3}, {-29}, {-5}} )

d)  The submatrix obtained by deleting row 1 and column 2 of W  is the one having rows 2 & 3 and  columns 1 & 3 of W. This can be obtained as follows.

In[30]:=

W[[{2, 3}, {1, 3}]]//MatrixForm

Out[30]//MatrixForm=

( {{5, -29}, {2, -5}} )

Example 4:     a) For the matrix A  in Example 1, find  A^(-1) and show that A A^(-1) = I.

        b) Find the inverse of  a general 2x2 matrix  (

a b
c d
) assuming that ad - bc is nonzero.

Solution:    a)  The inverse of a nonsingular square matrix A is obtained by the command Inverse[A]. For our case, we see that

In[31]:=

Inverse[A] ; MatrixForm[Inverse[A]]

Out[31]//MatrixForm=

( {{-1, 1, 0}, {-1, 0, 1}, {6, -2, -3}} )

    We can check the result by computing the product of A with Inverse[A].

In[32]:=

A . Inverse[A]//MatrixForm

Out[32]//MatrixForm=

( {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}} )

b)  The formula for computing the inverse of a general 2x2 square matrix can be obtained as follows.

In[33]:=

Clear[a, b, c, d]

Inverse[{{a, b}, {c, d}}] //MatrixForm

Out[34]//MatrixForm=

( {{d/(-b c + a d), -b/(-b c + a d)}, {-c/(-b c + a d), a/(-b c + a d)}} )

2.2  Special  Matrices: Identity, Diagonal, Random  

1.    The command IdentityMatrix[n] gives the n×n identity matrix. For example, the 3x3 identity matrix is obtained by:

In[35]:=

IdentityMatrix[3]

MatrixForm[%]

Out[35]=

{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}

Out[36]//MatrixForm=

( {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}} )

2.     The command DiagonalMatrix[list] gives the diagonal matrix with the elements of the list on the main diagonal and 0 elsewhere. An example of a 3x3 diagonal matrix is,

In[37]:=

DiagonalMatrix[{3, -5, 7}]

MatrixForm[%]

Out[37]=

{{3, 0, 0}, {0, -5, 0}, {0, 0, 7}}

Out[38]//MatrixForm=

( {{3, 0, 0}, {0, -5, 0}, {0, 0, 7}} )

3.      One can generate a  random matrix of any size. For example a 3x3 random matrix whose entries are numbers between 0 and 1 can be obtained by:

In[39]:=

Table[Random[ ], {3}, {3}]

MatrixForm[%]

Out[39]=

{{0.112254, 0.328852, 0.909504}, {0.995198, 0.490657, 0.147693}, {0.383798, 0.12805, 0.602978}}

Out[40]//MatrixForm=

( {{0.112254, 0.328852, 0.909504}, {0.995198, 0.490657, 0.147693}, {0.383798, 0.12805, 0.602978}} )

    An example of a 5x4 random matrix whose entries are  integers -9 and 9 can be btained by:(Note: the semicolon at the end of the first input tells Mathematica not disply the output.)

In[41]:=

Table[Random[Integer, {-9, 9} ], {5}, {3}]

MatrixForm[%]

Out[41]=

{{-8, 2, 6}, {-2, 0, -9}, {3, -1, -2}, {8, -1, -4}, {-8, -6, 2}}

Out[42]//MatrixForm=

( {{-8, 2, 6}, {-2, 0, -9}, {3, -1, -2}, {8, -1, -4}, {-8, -6, 2}} )

2.3  Solutions of Linear Systems of Equations

Example 5:  Solve the following system of linear equations.

a)  

    x_1 - 2 x_2 + 3 x_3 = 9
-x_1 + 3x_2            = -4
2x_1 - 5x_2 + 5x_3 = 17
                b)  
    x_1    +      x_2 =  3
0.3x_1 + 0.3x_2 = 0.9

c)  

    x_1 - 2 x_2 + 5 x_3 - 3x_4 = 23.6
x_1 + 4x_2 - 7x_3 - 2x_4 = -4
3x_1 - 5x_2 + 7x_3 + 4x_4 = 29.9
            d)  
    2x  +y +z-2w=  1      
3x-2y+z-6w=-2
   x +   y-z-    w=-1
6x  +        z-9w=-2
5x-y+2z-8w=3

Solution:      A system of linear equations that is equivalent to the matrix equation Ax=b may be solved using the command LinearSolve[A,b].
a)  The system is equivalent to the matrix eqiuation Ax = b. We type A and b and then apply the command LinearSolve.

In[43]:=

A = {{1, -2, 3}, {-1, 3, 0}, {2, -5, 5}} ; MatrixForm[A]

Out[43]//MatrixForm=

( {{1, -2, 3}, {-1, 3, 0}, {2, -5, 5}} )

In[44]:=

b = {{9}, {-4}, {17}} ; MatrixForm[b]

Out[44]//MatrixForm=

( {{9}, {-4}, {17}} )

In[45]:=

x = LinearSolve[A, b]

Out[45]=

{{1}, {-1}, {2}}

    Thus, we see that the solution is   x_1=1 (, x) _2=-1 and x_3=2. Another way of solving the above is to form the augmented matrix Ao and express it in reduced row echelon form. The augmented matrix Ao is given by

In[46]:=

Ao = {{1, -2, 3, 9}, {-1, 3, 0, -4}, {2, -5, 5, 17}} ; MatrixForm[Ao]

Out[46]//MatrixForm=

( {{1, -2, 3, 9}, {-1, 3, 0, -4}, {2, -5, 5, 17}} )

    We now use the command RowReduce that puts the augmented matrix in reduced row echelon form. This gives matrix A1:

In[47]:=

A1 = RowReduce[Ao] ; MatrixForm[A1]

Out[47]//MatrixForm=

( {{1, 0, 0, 1}, {0, 1, 0, -1}, {0, 0, 1, 2}} )

    We  can now read the solution x_1=1 (, x) _2=-1 and x_3=2. A third way of solving the above system is to use x=Inverse[A].b, if the matrix A is invertible. In our case, this becomes

In[48]:=

x = MatrixForm[Inverse[A] . b]

Out[48]//MatrixForm=

( {{1}, {-1}, {2}} )

    Again, note that we get the previously obtained solution of the system.

b)  We type the coefficient matrix A and the constant matrix b and then apply LinearSolve.

In[49]:=

A = {{1, 1}, {.3, .3}}

Out[49]=

{{1, 1}, {0.3, 0.3}}

In[50]:=

b = {{3}, {.9}}

Out[50]=

{{3}, {0.9}}

In[51]:=

LinearSolve[A, b]

LinearSolve :: nosol : Linear equation encountered which has no solution.

Out[51]=

LinearSolve[{{1, 1}, {0.3, 0.3}}, {{3}, {0.9}}]

    In this case, Mathematica is indicating that the coefficient matrix is nonsingular and the system has no solution. However, the system has clearly infinite solutions given by x_2=3 - x_1, x_1  arbitrary.  This shows that it is always important to check the results. The reason for failure may be due to  round-off error in the use of decimals. Thus, we try to solve this by retyping A as A1, and b as b1, by expressing all entries as fractions, and applying the command LinearSolve.

In[52]:=

A1 = {{1, 1}, {3/10, 3/10}}

b1 = {{3}, {9/10}}

LinearSolve[A1, b1]

Out[52]=

{{1, 1}, {3/10, 3/10}}

Out[53]=

{{3}, {9/10}}

Out[54]=

{{3}, {0}}

    In this case, Mathematica gives a solution of x_1=3, x_2=0. This is just one of the infinitely many solutions. This shows that when using the command LinearSolve one has to avoid using decimals. Also, Mathematica may give one of infinitely many solutions.

    Another approach is to find the reduced row echelon form  of the augmented matrix. First,  we enter the augmented matrix  A2 where all entries are expressed in fractional form.

In[55]:=

A2 = {{1, 1, 3}, {3/10, 3/10, 9/10}} ; MatrixForm[A2]

Out[55]//MatrixForm=

( {{1, 1, 3}, {3/10, 3/10, 9/10}} )

    Next, we compute A3, the reduced row echelon form of A2.

In[56]:=

A3 = RowReduce[A2] ; MatrixForm[A3]

Out[56]//MatrixForm=

( {{1, 1, 3}, {0, 0, 0}} )

    From the above we see that the system has infinite solutions given by   x_2=t, x_1=3-t.

c)  First, we use the command LinearSolve after entering the coefficient matrix A and the constant matrix b.

In[57]:=

A = {{1, -2, 5, -3}, {1, 4, -7, -2}, {3, -5, 7, 4}} ; MatrixForm[A]

Out[57]//MatrixForm=

( {{1, -2, 5, -3}, {1, 4, -7, -2}, {3, -5, 7, 4}} )

In[58]:=

b = {{236/10}, {457/10}, {299/10}}

Out[58]=

{{118/5}, {457/10}, {299/10}}

In[59]:=

LinearSolve[A, b]

Out[59]=

{{8473/360}, {1669/90}, {535/72}, {0}}

    In this case, among the infinite solutions of the system, Mathematica gives a solution of the system where x_4=0. We can obtain these infinite solutions by expressing the augmented matrix in reduced row echelon form. First, we enter the augmented matrix as Ao.

In[60]:=

Ao = {{1, -2, 5, -3, 236/10}, {1, 4, -7, -2, 457/10}, {3, -5, 7, 4, 299/10}} ;

MatrixForm[Ao]

Out[61]//MatrixForm=

( {{1, -2, 5, -3, 118/5}, {1, 4, -7, -2, 457/10}, {3, -5, 7, 4, 299/10}} )

    Next, we find the reduced row echelon form of the augmented matrix and call it A1.

In[62]:=

A1 = RowReduce[Ao] ; MatrixForm[A1]

Out[62]//MatrixForm=

( {{1, 0, 0, -19/36, 8473/360}, {0, 1, 0, -37/9, 1669/90}, {0, 0, 1, -77/36, 535/72}} )

    From the above, we see that x_4 is a free variable. Thus, the solution is given by x_4=t, x_3=535/72+77/36 t, x_2=1669/90+37/9 t, and x_1=8473/360+19/36 t. In particular, if we use t=0, we get a  solution  of the system as x_4=0, x_3=535/72, x_2=1669/90, and x_1=8473/360, which was the solution obtained previously using the command LinearSolve.

d)  We first enter the coefficient matrix A and the constant matrix b.

In[63]:=

A = ({{2, 1, 1, -2}, {3, -2, 1, -6}, {1, 1, -1, -1}, {6, 0, 1, -9}, {5, -1, 2, -8}})

Out[63]=

{{2, 1, 1, -2}, {3, -2, 1, -6}, {1, 1, -1, -1}, {6, 0, 1, -9}, {5, -1, 2, -8}}

In[64]:=

b = ({{1}, {-2}, {-1}, {-2}, {3}})

Out[64]=

{{1}, {-2}, {-1}, {-2}, {3}}

In[65]:=

LinearSolve[A, b]

LinearSolve :: nosol : Linear equation encountered which has no solution.

Out[65]=

LinearSolve[{{2, 1, 1, -2}, {3, -2, 1, -6}, {1, 1, -1, -1}, {6, 0, 1, -9}, {5, -1, 2, -8}}, {{1}, {-2}, {-1}, {-2}, {3}}]

    The above indicates that the system has no solution. We can check this by obtaining the reduced row echelon form of the augmented matrix as follows.

In[66]:=

Ao = ({{2, 1, 1, -2, 1}, {3, -2, 1, -6, -2}, {1, 1, -1, -1, -1}, {6, 0, 1, -9, -2}, {5, -1, 2, -8, 3}})

Out[66]=

{{2, 1, 1, -2, 1}, {3, -2, 1, -6, -2}, {1, 1, -1, -1, -1}, {6, 0, 1, -9, -2}, {5, -1, 2, -8, 3}}

In[67]:=

A1 = RowReduce[Ao] ; MatrixForm[A1]

Out[67]//MatrixForm=

( {{1, 0, 0, -17/11, 0}, {0, 1, 0, 9/11, 0}, {0, 0, 1, 3/11, 0}, {0, 0, 0, 0, 1}, {0, 0, 0, 0, 0}} )

    The fourth row of the above matrix shows that the system has no solution (do you see why?).

Example 6: Determine the value of the parameter a for which the linear system:
                    

(3+a)x+2y+3z=4
         -x+ y  -  z=-2
             y+ a z=0

  is inconsistent.         

Solution:      First, we form the augmented matrix A. Then, we apply elementary row operations on A.

In[68]:=

Clear[a]

A = ({{3 + a, 2, 3, 4}, {-1, 1, -1, -2}, {0, 1, a, 0}})

Out[69]=

{{3 + a, 2, 3, 4}, {-1, 1, -1, -2}, {0, 1, a, 0}}

    Interchange rows 1 and 2 of matrix A and denote the resulting matrix by A1.

In[70]:=

A1 = {A[[2]], A[[1]], A[[3]]}

MatrixForm[%]

Out[70]=

{{-1, 1, -1, -2}, {3 + a, 2, 3, 4}, {0, 1, a, 0}}

Out[71]//MatrixForm=

( {{-1, 1, -1, -2}, {3 + a, 2, 3, 4}, {0, 1, a, 0}} )

    Next, we multiply row 1 of matrix A1  by -1 to obtain matrix A2.

In[72]:=

A2 = {-A1[[1]], A1[[2]], A1[[3]]}

MatrixForm[%]

Out[72]=

{{1, -1, 1, 2}, {3 + a, 2, 3, 4}, {0, 1, a, 0}}

Out[73]//MatrixForm=

( {{1, -1, 1, 2}, {3 + a, 2, 3, 4}, {0, 1, a, 0}} )

    Myltiply  row 1 of matrix A2 by -(3+a)  and add it to row 2 of A2 to get matrix A3.

In[74]:=

A3 = {A2[[1]], -(3 + a) * A2[[1]] + A2[[2]], A2[[3]]}

MatrixForm[%]

Out[74]=

{{1, -1, 1, 2}, {0, 5 + a, -a, 4 + 2 (-3 - a)}, {0, 1, a, 0}}

Out[75]//MatrixForm=

( {{1, -1, 1, 2}, {0, 5 + a, -a, 4 + 2 (-3 - a)}, {0, 1, a, 0}} )

    We  interchange rows 2 and 3 of A3 to obtain matrix A4.

In[76]:=

A4 = {A3[[1]], A3[[3]], A3[[2]]}

MatrixForm[%]

Out[76]=

{{1, -1, 1, 2}, {0, 1, a, 0}, {0, 5 + a, -a, 4 + 2 (-3 - a)}}

Out[77]//MatrixForm=

( {{1, -1, 1, 2}, {0, 1, a, 0}, {0, 5 + a, -a, 4 + 2 (-3 - a)}} )

    We now multiply row 2 of A4  by - (5+a) and add it to row 3 of A4. This gives matrix A5.

In[78]:=

A5 = {A4[[1]], A4[[2]], -(5 + a) * A4[[2]] + A4[[3]]}

MatrixForm[%]

Out[78]=

{{1, -1, 1, 2}, {0, 1, a, 0}, {0, 0, -a + (-5 - a) a, 4 + 2 (-3 - a)}}

Out[79]//MatrixForm=

( {{1, -1, 1, 2}, {0, 1, a, 0}, {0, 0, -a + (-5 - a) a, 4 + 2 (-3 - a)}} )

In[80]:=

Simplify[%]

MatrixForm[%]

Out[80]=

{{1, -1, 1, 2}, {0, 1, a, 0}, {0, 0, -a (6 + a), -2 (1 + a)}}

Out[81]//MatrixForm=

( {{1, -1, 1, 2}, {0, 1, a, 0}, {0, 0, -a (6 + a), -2 (1 + a)}} )

    From the above matrix, we see that the system is inconsistent when a = 0,   a= -6  or a= -1. (Do you see why?)

Chapter Three        Determinants

Example 1: Let A  be the matrix given by   A=  (

2 1 -3
0 4 5
-1 3 2
).

a)     Find  Det(A).    

b)      Show that Det(A^T) = Det(A)  

c)     Verify that Det(2A) = 2^3 Det(A)  

d)     Let A_1  be the matrix that is obtained by interchanging rows 1 and 2 of A. Show that Det(A_1) =  -  Det(A).

e)     Let A_2  be the matrix that is obtained from A by replacing the third row of A by the sum of row 3 and 5 times row 1. Show that  Det(A_2) = Det(A).

Solution:      We first enter the matrix A.

In[82]:=

A = {{2, 1, -3}, {0, 4, 5}, {-1, 3, 2}} ; MatrixForm[A]

Out[82]//MatrixForm=

( {{2, 1, -3}, {0, 4, 5}, {-1, 3, 2}} )

a)  Next, we evaluate the determinant of A:

In[83]:=

Det[A]

Out[83]=

-31

b)  We evaluate the determinant of Transpose[A]:

In[84]:=

Det[Transpose[A]]

Out[84]=

-31

c) We find the determinant of 2A and compare it with 8 times the determinant of A.

In[85]:=

Det[2 A]

Out[85]=

-248

In[86]:=

2^3 Det[A]

Out[86]=

-248

d) We first define matrix A1, the matrix obtained by interchanging rows 1 & 2 of A. Then, we evaluate its determinant.

In[87]:=

A1 = {A[[2]], A[[1]], A[[3]]} ; MatrixForm[A1]

Out[87]//MatrixForm=

( {{0, 4, 5}, {2, 1, -3}, {-1, 3, 2}} )

In[88]:=

Det[A1]

Out[88]=

31

e) The matrix A2 obtained by adding 5 times row 1 to row 3 of A is given by:

In[89]:=

A2 = {A[[1]], A[[2]], 5A[[1]] + A[[3]]} ; MatrixForm[A2]

Out[89]//MatrixForm=

( {{2, 1, -3}, {0, 4, 5}, {9, 8, -13}} )

In[90]:=

Det[A2]

Out[90]=

-31

Example 2: Redo Example 1  if  A  is an arbitrary  3x3 matrix.

Solution:  We first enter a general 3x3 matrix A.

In[91]:=

A = ({{a_11, a_12, a_13}, {a_21, a_22, a_23}, {a_31, a_32, a_33}})

Out[91]=

{{a_11, a_12, a_13}, {a_21, a_22, a_23}, {a_31, a_32, a_33}}

a) The determinant of A is given by:

In[92]:=

Det[A]

Out[92]=

-a_13 a_22 a_31 + a_12 a_23 a_31 + a_13 a_21 a_32 - a_11 a_23 a_32 - a_12 a_21 a_33 + a_11 a_22 a_33

b)  To show that Det[Transpose A] = Det[A], we compute

In[93]:=

Det[Transpose[A]] - Det[A]

Out[93]=

0

c)  To show that Det[2A] = 8 Det[A], we compute

In[94]:=

Det[2 A] - 8 Det[A]

Out[94]=

It is not clear why the above is equal to zero and so we:

In[95]:=

Simplify[%]

Out[95]=

0

d)  First we enter matrix A1 that is obtained by interchanging rows 1 & 2 of A.

In[96]:=

A1 = {A[[2]], A[[1]], A[[3]]} ; MatrixForm[A1]

Out[96]//MatrixForm=

( {{a_21, a_22, a_23}, {a_11, a_12, a_13}, {a_31, a_32, a_33}} )

To show that Det[A1] = -Det[A], we compute

In[97]:=

Det[A1] + Det[A]

Out[97]=

0

e)  The matrix A2, obtained by adding 5 times row 1 to row 3 of A, is given by:

In[98]:=

A2 = {A[[1]], A[[2]], 5A[[1]] + A[[3]]} ; MatrixForm[A2]

Out[98]//MatrixForm=

( {{a_11, a_12, a_13}, {a_21, a_22, a_23}, {5 a_11 + a_31, 5 a_12 + a_32, 5 a_13 + a_33}} )

To show that Det[A2] = Det[A], we calculate

In[99]:=

Det[A2] - Det[A]

Out[99]=

0

Chapter Four         Vectors and Vector Spaces

4.1  Vector Algebra

Vectors are typed in braces with commas between components. For example if a is the vector a= i+3j -5k we type

In[100]:=

a={1,3,-5}

Out[100]=

{1, 3, -5}

Vector addition, subtraction and scalar multiplication are perfomed in the same way as the corresponding operations on numbers.The dot product of vectors a and b is obtained by  a.b and the length of a is obtained by using the command Sqrt[a.a].

Example 1:  Let  a= i+3j -5k and  b= -i+2j +3k.  Find 3a-2b, a.b, and ||b||.

Solution:     First we will enter the components of a and b as lists. Then, we enter the solutions for all the problems in one cell:

In[101]:=

a={1,3,-5}
b={-1,2,3}

Out[101]=

{1, 3, -5}

Out[102]=

{-1, 2, 3}

In[103]:=

3a - 2b

a . b

Sqrt[b . b]

Out[103]=

{5, 5, -21}

Out[104]=

-10

Out[105]=

14^(1/2)

Example 2:  Show that the dot product of vectors  is commutative and that dot product is distributive over addition, that is , a.b= b.a  and a.(b+c)=a.b+a.c for any  vectors a ,b and c.

Solution:  We will verify the above properties for vectors in space.

In[106]:=

Clear[a,b,c,a1,a2,a3,b1,b2,b3,c1,c2,c3]
a={a1,a2,a3}
b={b1,b2,b3}
c={c1,c2,c3}
a.b-b.a (*if this is equal to 0, this proves the
distributive property*)
a.(b+c)-(a.b+a.c) (*if this is equal to 0, this proves the
distributive property*)

Out[107]=

{a1, a2, a3}

Out[108]=

{b1, b2, b3}

Out[109]=

{c1, c2, c3}

Out[110]=

0

Out[111]=

-a1 b1 - a2 b2 - a3 b3 - a1 c1 + a1 (b1 + c1) - a2 c2 + a2 (b2 + c2) - a3 c3 + a3 (b3 + c3)

It is not clear why the last output is zero. We check this by entering:

In[112]:=

Simplify[%]

Out[112]=

0

Example 3:  Let  u= i+3j + 2k,  v= 2i+3 j  and w = -2i+3j +4k. Find  u × v and (u × v).w

Solution:     In order to calculate the cross product of two vectors we need a package, called  Calculus`VectorAnalysis`. It is recommended that you  load this package before starting your work.  The command to load  this package is  Needs["Calculus`VectorAnalysis`"].  To compute the cross product u × v of  u and v we type Cross[u,v].  In Mathematica 3.0, there is a   palette that contains the command for cross product. It is in File-Palettes-Lists and Matrices-Matrix  Operations and is denoted by Cross[□ ,□]. First, we  load the package:

In[113]:=

Needs["Calculus`VectorAnalysis`"]

In[114]:=

u={1,3,2}
v={-2,3,0}
w={-2,3,4}

Out[114]=

{1, 3, 2}

Out[115]=

{-2, 3, 0}

Out[116]=

{-2, 3, 4}

In[117]:=

prod= CrossProduct[u,v]
prod.w

Out[117]=

{-6, -4, 9}

Out[118]=

36

Thus, we see that u x v = -6i - 4j + 9k  and (u x v ) . w = 36.

Example 4: Consider the parallelepiped  with sides a=i+k, b=2i+j+3k  and c=i+j-2k.  
a)   Find the volume.        b)  Find the area of the face determined by b and c.

Solution:

In[119]:=

a = {1, 0, 1}

b = {2, 1, 3}

c = {1, 1, -2}

volume = Abs[a . Cross[b, c]]

area = Cross[b, c] . Cross[b, c] ^(1/2)/2

Out[119]=

{1, 0, 1}

Out[120]=

{2, 1, 3}

Out[121]=

{1, 1, -2}

Out[122]=

4

Out[123]=

(5 3^(1/2))/2

Hence, the volume of the parallellepiped is 4 and the area of the face determined by vectors b and c is 5  3^(1/2)/ 2

4.2  Linear Independence and Span

Example 5:  If S={p_1(t), p_2(t), p_3(t)}={t-1, t+1, t^2+t+1}, determine whether p(t)= 2 t^2 + t - 2 belongs to the span of S.

Solution:    We find scalars c_1, c_2,and c_3 such that c_1p_1(t) + c_2p_2(t) +  c_3p_3(t) = p(t).  This is equivalent to solving a system of linear equations with augmented matrix:

In[124]:=

A = ({{0, 0, 1, 2}, {1, 1, 1, 1}, {-1, 1, 1, -2}})

Out[124]=

{{0, 0, 1, 2}, {1, 1, 1, 1}, {-1, 1, 1, -2}}

The reduced row echelon form of A is obtained by:

In[125]:=

RowReduce[A]//MatrixForm

Out[125]//MatrixForm=

( {{1, 0, 0, 3/2}, {0, 1, 0, -5/2}, {0, 0, 1, 2}} )

The above shows that  c_1= 3/2,  c_2 = - 5/2  and c_3 =  2 and so p(t) belongs to the span of S.

Example 6:  Determine if   S ={(1,1,-1),  (1, 7, 2),  (0, 4, 2),  (2, 8, 1) }  spans R^3.

Solution:  Given any vector (a,b,c)  in   R^3,  we have to check if there exist scalars  c_1,  c_2, c_3,  and c_4 such that:
c_1 (1, 1, -1)  + c_2 (1, 7, 2)  + c_3 (0, 4, 2)  +  c_4 (2, 8, 1)   =  (a, b, c).
This leads to solving a system of equations whose augmented matrix is given by:

In[126]:=

Clear[a, b, c]

A = ({{1, 1, 0, 2, a}, {1, 7, 4, 8, b}, {-1, 2, 2, 1, c}})

Out[127]=

{{1, 1, 0, 2, a}, {1, 7, 4, 8, b}, {-1, 2, 2, 1, c}}

Now, we use elementary row operations on A to solve the system. Add -1 times  row 1 to row 2 and add row 1 to row 3 to obtain matrix A1.

In[128]:=

A1 = {A[[1]], -A[[1]] + A[[2]], A[[1]] + A[[3]]}

MatrixForm[%]

Out[128]=

{{1, 1, 0, 2, a}, {0, 6, 4, 6, -a + b}, {0, 3, 2, 3, a + c}}

Out[129]//MatrixForm=

( {{1, 1, 0, 2, a}, {0, 6, 4, 6, -a + b}, {0, 3, 2, 3, a + c}} )

Next, we divide row 2 of  A1 by 6 to get a leading 1. We denote the resulting matrix by A2.

In[130]:=

A2 = {A1[[1]], A1[[2]]/6, A1[[3]]}

MatrixForm[%]

Out[130]=

{{1, 1, 0, 2, a}, {0, 1, 2/3, 1, 1/6 (-a + b)}, {0, 3, 2, 3, a + c}}

Out[131]//MatrixForm=

( {{1, 1, 0, 2, a}, {0, 1, 2/3, 1, 1/6 (-a + b)}, {0, 3, 2, 3, a + c}} )

Next, we multiply row 2 of A2 by -3 and add it to row 3 and denote the resulting matrix by A3.

In[132]:=

A3 = {A2[[1]], A2[[2]], -3A2[[2]] + A2[[3]]}

MatrixForm[%]

Out[132]=

{{1, 1, 0, 2, a}, {0, 1, 2/3, 1, 1/6 (-a + b)}, {0, 0, 0, 0, a + (a - b)/2 + c}}

Out[133]//MatrixForm=

( {{1, 1, 0, 2, a}, {0, 1, 2/3, 1, 1/6 (-a + b)}, {0, 0, 0, 0, a + (a - b)/2 + c}} )

The last row of the above matrix shows that the vectors do not span R^3 . (do you see why?)

Example 7:  Determine if S={ (1, 1, 0, 0),  (2, 1, 1, -1),  (0, 0, 1, 1),  (1 , 2, 1, 2)} is a basis of R^4 .

Solution:    Since we know that the dimension of R^4 is 4 and S contains 4 elements, it suffices to check whether or not S is linearly independent. Thus, we consider a solution of the system of equations   c_1 v_1  +  c_2 v_2  +c_3  v_3 + c_4v_4= 0 .  Thus the augmented matrix, A , of the system of equations has the given vectors as column vectors(do you see why?) and so:

In[134]:=

A = ({{1, 2, 0, 1, 0}, {1, 1, 0, 2, 0}, {0, 1, 1, 1, 0}, {0, -1, 1, 2, 0}})

Out[134]=

{{1, 2, 0, 1, 0}, {1, 1, 0, 2, 0}, {0, 1, 1, 1, 0}, {0, -1, 1, 2, 0}}

In[135]:=

RowReduce[A]//MatrixForm

Out[135]//MatrixForm=

( {{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 1, 0}} )

The above shows that c_1 =c_2 = c_3   = c_4  = 0 and so S is linearly independent. Hence S forms a basis of R^4.

4.3  Null Space and Rank of a Matrix

Example 8:  Let    A= (

2 1 2 0
0 0 0 0
1 2 2 1
4 5 6 2
3 3 4 1
).

a)  Find a basis for the null space of A. Also, find the nullity of A and the rank of A.

b)  Find a basis for the row space of A consisting of vectors that are not row vectors of A.

c)  Find a basis for the row space of A consisting of vectors that are  row vectors of A.

d)   It can be shown that v = (7, 11, 12, 5) is in the row space of A. Express v as a linear combination of the basis elements obtained in b) and c) above.

Solution:     We first enter the matrix as:

In[136]:=

A = ({{2, 1, 2, 0}, {0, 0, 0, 0}, {1, 2, 2, 1}, {4, 5, 6, 2}, {3, 3, 4, 1}})

Out[136]=

{{2, 1, 2, 0}, {0, 0, 0, 0}, {1, 2, 2, 1}, {4, 5, 6, 2}, {3, 3, 4, 1}}

The command NullSpace[A] gives a basis for the null space of A, and so we find:

In[137]:=

NullSpace[A]

Out[137]=

{{1, -2, 0, 3}, {-2, -2, 3, 0}}

This shows that a basis for the null space of A is {(1, -2, 0, 3),  (-2, -2, 3, 0)} and so the nullity is 2. Hence, the rank of the matrix is given by  4 - nullity of A = 2. (Do you see why?

b)  To find a basis for the row space of A consisting of vectors that are not row vectors of A, we find the nonzero vectors in the reduced row echelon form of A and so we calculate:

In[138]:=

RowReduce[A]//MatrixForm

Out[138]//MatrixForm=

( {{1, 0, 2/3, -1/3}, {0, 1, 2/3, 2/3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}} )

Thus, a basis for the row space of A is given by {(1, 0, 2/3, -1/3),  (0, 1, 2/3, 2/3)}.

c) To find a basis for  the row space of A consisting of row vectors of A, we find the reduced row echelon form of the transpose of A.

In[139]:=

RowReduce[Transpose[A]]//MatrixForm

Out[139]//MatrixForm=

( {{1, 0, 0, 1, 1}, {0, 0, 1, 2, 1}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}} )

The leading 1's occur in columns 1 and 3. Hence,  the vectors corresponding to columns 1 & 3 of the transpose of A form a basis of the row space of A. Thus, a basis is  { (2,1,2,0), (1,2,2,1)}.

d) Using the "natural basis" obtained in a): We see that the leading 1's in the reduced row echelon form of A occur at columns 1 and 2. Thus, v= (7, 11, 12, 5) = 7 (1, 0, 2/3, -1/3) +11 (0, 1, 2/3, 2/3). For the basis obtained in b) above, we have to find scalars a and b such that a (2, 1, 2, 0) + b ( 1, 2, 2, 1) = v= (7, 11, 12, 5). This leads to a system of equations whose augmented matrix is B, given by:

In[140]:=

B = ({{2, 1, 7}, {1, 2, 11}, {2, 2, 12}, {0, 1, 5}})

RowReduce[B]//MatrixForm

Out[140]=

{{2, 1, 7}, {1, 2, 11}, {2, 2, 12}, {0, 1, 5}}

Out[141]//MatrixForm=

( {{1, 0, 1}, {0, 1, 5}, {0, 0, 0}, {0, 0, 0}} )

Thus, we see that a = 1 and b = 5 and so v = (7, 11, 12, 5) =  (2, 1, 2, 0) + 5 (1, 2, 2, 1).  

4.4 Transtion Matrix  

Example 9 :  In R^3 consider the bases S and T  given by:
S = {v_1  , v_2, v_3 } ={ (1, 1, 0),  (1, 0, 1),  (1, 1, 1)}  and T = { w_1,  w_2, w_3} ={ (1, 2, 1),  (1, 2, 0),  (1,0,2)} .

a) Find the transition matrix P from the T-basis to the S-basis.

b) Let v be a vector whose coordinates with respect to the T-basis is [v] _T  =  (-1,2,5). Find the coordinates of v with respect to the S-basis by using the transition matrix P.

Solution:     We proceed by finding the coordinates of the basis  vectors w_1, w_2, and w_3  with respect to the S-basis. This computation requires that we solve 3  linear systems  whose coefficient matrix is composed of the vectors from the S-basis and  the constant matrix  is a column matrix with entries from  w_1, w_2, and w_3. So we consider the augmented matrix:

In[142]:=

A = ({{1, 1, 1, 1, 1, 1}, {1, 0, 1, 2, 2, 0}, {0, 1, 1, 1, 0, 2}})

Out[142]=

{{1, 1, 1, 1, 1, 1}, {1, 0, 1, 2, 2, 0}, {0, 1, 1, 1, 0, 2}}

In[143]:=

RowReduce[A]

MatrixForm[%]

Out[143]=

{{1, 0, 0, 0, 1, -1}, {0, 1, 0, -1, -1, 1}, {0, 0, 1, 2, 1, 1}}

Out[144]//MatrixForm=

( {{1, 0, 0, 0, 1, -1}, {0, 1, 0, -1, -1, 1}, {0, 0, 1, 2, 1, 1}} )

Hence the transition matrix is given by:
                        P = (

0 1 -1
-1 -1 1
2 1 1
).

b) In order to find the coordinates of v with respect to the S-basis, we use the equation: [v] _S = P . [v] _T. Hence the coordinates of v with repect to the S-basis is given by:

In[145]:=

({{0, 1, -1}, {-1, -1, 1}, {2, 1, 1}}) . ({{-1}, {2}, {5}})

Out[145]=

{{-3}, {4}, {5}}

We can verify our work by computing:(do you see why?)

In[146]:=

( -1 {1, 2, 1} + 2 {1, 2, 0} + 5 {1, 0, 2} ) - <br />     (-3 {1, 1, 0} + 4 {1, 0, 1} + 5 {1, 1, 1})

Out[146]=

{0, 0, 0}

4.5 The Gram-Schmidt Orthogonalization Process

For many purposes, the most convenient type of basis for a vector space is an orthonormal basis, i.e., the vectors are of unit length and are pairwise orthogonal. The Gram-Schmidt procedure takes an arbitrary basis of R^n and generates an orthonormal one. Given a basis {v_1, v_2, ...,  v_n} of R^n , an orthonormal basis is obtained by using the command  GramSchmidt[{v_1, v_2, ...,  v_n}].

Example 10: Cosider the basis  S={u_1,  u_2, u_3 } for R^3 ,   where u_1   = (1,1,1),  u_2 =  (-1, 0, -1),  and u_3 =(-1,2,3).

a) Use the Gram-Schmidt process to transform S into an orthonormal basis for R^3.

b) Express v=(-1, 2, 0) as a linear combination of the orthonormal basis obtained in a) above, i.e., find the coordinates of v with respect to the orthonormal basis.

Solution:      First, we  load the  package  to use the Gram-Schmidt process.

In[147]:=

<<LinearAlgebra`Orthogonalization`

If  we denote the orthonormal basis, obtained  from the given basis S, by  w1, w2, and w3,  then we obtain

In[148]:=

{w1, w2, w3} = GramSchmidt[{ {1, 1, 1}, {-1, 0, -1}, {-1, 2, 3} }]

Out[148]=

{{1/3^(1/2), 1/3^(1/2), 1/3^(1/2)}, {-1/6^(1/2), 2/3^(1/2), -1/6^(1/2)}, {-1/2^(1/2), 0, 1/2^(1/2)}}

The above gives an orthonormal basis. Thus, the dot product of each pair of different vectors is zero and each vector has length 1. We can verify this by computing the dot products as follows.

In[149]:=

{w1 . w2, w1 . w3, w2 . w3, w1 . w1, w2 . w2, w3 . w3}

Out[149]=

{0, 0, 0, 1, 1, 1}

b)  To find the coordinates of v with respect to the orthonormal basis obtained above, we find  real numbers a, b, and c such that a w1 + b  w2 + c w3 = v. Recall that if a basis is orthonormal, then the coordinates a, b, and c are obtained by computing the dot products  v.w1, v.w2, and v.w3, repectively.  We obtain this as follows.

In[150]:=

v = {-1, 2, 0}

Out[150]=

{-1, 2, 0}

In[151]:=

{a, b, c} = {v . w1,   v . w2, v . w3}

Out[151]=

{1/3^(1/2), 2 2/3^(1/2) + 1/6^(1/2), 1/2^(1/2)}

In[152]:=

Simplify[%]

Out[152]=

{1/3^(1/2), 5/6^(1/2), 1/2^(1/2)}

The above gives the values of a, b, and  c,  respectively.  We can check the above result by computing:

In[153]:=

a * w1 + b * w2 + c * w3

Out[153]=

{-1/6 - (2 2/3^(1/2) + 1/6^(1/2))/6^(1/2), 1/3 + 2/3^(1/2) (2 2/3^(1/2) + 1/6^(1/2)), 5/6 - (2 2/3^(1/2) + 1/6^(1/2))/6^(1/2)}

It is not clear why the above is equal to v =(-1, 2, 0) and so we:

In[154]:=

Simplify[%]

Out[154]=

{-1, 2, 0}

Example 11: Let W be the subspace of R^4 with basis S={u_1,  u_2, u_3 }  where
u_1   = (1, -2, 0, 1),  u_2 =  (-1, 0, 0, -1),  and u_3 =(1,1,0, 0). Use the Gram-Schmidt process to find an orthonormal basis for W.

Solution:      An orthonormal basis of W is obtained by:

In[155]:=

GramSchmidt[ { {1, -2, 0, 1}, {-1, 0, 0, -1}, {1, 1, 0, 0} }]

Out[155]=

{{1/6^(1/2), -2/3^(1/2), 0, 1/6^(1/2)}, {-1/3^(1/2), -1/3^(1/2), 0, -1/3^(1/2)}, {1/2^(1/2), 0, 0, -1/2^(1/2)}}

Chapter Five         Eigenvalues and Eigenvectors

5.1  Eigenvalues, Eigenvectors, Diagonalization

If A is a square matrix of size n, then the command Det[A - λ* IdentityMatrix[n]] gives the characteristic polynomial of A. The command Eigenvalues[A] gives the eigenvalues of A. Repeated eigenvalues are represented as many times as the algebraic multiplicity indicates. Eigenvectors are obtained by the command Eigenvectors[A].

Example 1:  Find the characteristic polynomial, the eigenvalues and the corresponding eigenvectors of  
                        A=(

1 2 -1
1 0 1
4 -4 5
).
Is A diagonalizable? If so, find a diagonal matrix D and an invertible matrix P such that P^(-1)A P = D.

Solution:

In[156]:=

A = ({{1, 2, -1}, {1, 0, 1}, {4, -4, 5}})

Out[156]=

{{1, 2, -1}, {1, 0, 1}, {4, -4, 5}}

We obtain the characteristic polynomial ,  f (λ),  as follows.

In[157]:=

f[ λ] = Det[A - λ * IdentityMatrix[3]]

Out[157]=

6 - 11 λ + 6 λ^2 - λ^3

We can obtain the eigenvalues by solving for the roots of the characteristic polynomial. We do this as follows.

In[158]:=

Solve[ f[ λ]    == 0,   λ]

Out[158]=

{{λ→1}, {λ→2}, {λ→3}}

From the above, we see that there are 3 real eigenvalues: 1, 2, and 3.  We can also find the eigenvalues and eigenvectors as follows.

In[159]:=

Eigenvalues[A]

Out[159]=

{1, 2, 3}

In[160]:=

 Eigenvectors[A]

Out[160]=

{{-1, 1, 2}, {-2, 1, 4}, {-1, 1, 4}}

Thus, the matrix has three eigenvalues: 1, 2,  & 3 and three eigenvectors: (-1, 1, 2), (-2, 1, 4), and (-1, 1, 4). However, the eigenvalues and eigenvectors may not appear in corresponding order. Thus, to find both the eigenvalues and their corresponding eigenvectors, we use the command:

In[161]:=

Eigensystem[A]

Out[161]=

{{1, 2, 3}, {{-1, 1, 2}, {-2, 1, 4}, {-1, 1, 4}}}

This shows that 1 is an eigenvalue of A and (-1, 1, 2) is the corresponding eigenvector. Similarly, for the eigenvalue 2, an eigenvector is (-2,1,4) ; for the eigenvalue 3 an eigenvector is (-1, 1, 4). We can verify this by computing:

In[162]:=

A . ({{-1}, {1}, {2}}) - ({{-1}, {1}, {2}})

A . ({{-2}, {1}, {4}}) - 2 ({{-2}, {1}, {4}})

A . ({{-1}, {1}, {4}}) - 3 ({{-1}, {1}, {4}})

Out[162]=

{{0}, {0}, {0}}

Out[163]=

{{0}, {0}, {0}}

Out[164]=

{{0}, {0}, {0}}

Since A has distinct  eigenvalues, A is diagonalizable. If  we now let P be the matrix whose columns are the eigenvectors, then P^(-1)A P = D, where  D is the diagonal matrix whose diagonal entries are the respective eigenvalues. We verify this as follows.

In[165]:=

P = ({{-1, -2, -1}, {1, 1, 1}, {2, 4, 4}})

Inverse[P] . A . P

MatrixForm[%]

Out[165]=

{{-1, -2, -1}, {1, 1, 1}, {2, 4, 4}}

Out[166]=

{{1, 0, 0}, {0, 2, 0}, {0, 0, 3}}

Out[167]//MatrixForm=

( {{1, 0, 0}, {0, 2, 0}, {0, 0, 3}} )

Example 2:  Let A = (

4 2 3
2 1 2
-1 -2 0
). Find the eigenvalues and corresponding eigenvectors of A. Also, if A is diagonalizable , find an invertible  matrix P and a diagonal matrix D  such that P^(-1) A P = D.

Solution:

In[168]:=

A = ({{4, 2, 3}, {2, 1, 2}, {-1, -2, 0}})

Eigensystem[A]

Out[168]=

{{4, 2, 3}, {2, 1, 2}, {-1, -2, 0}}

Out[169]=

{{1, 1, 3}, {{-1, 0, 1}, {0, 0, 0}, {-5, -2, 3}}}

The above shows that A has two eigenvalues λ = 1 and λ = 3. The eigenvalue λ =1 has multiplicity 2. However, the eigenspace for λ =1 has dimension 1.  Thus A is not diagonalizable.

Example 3:  Let A = (

0 0 -2
1 2 1
1 0 3
). Find the eigenvalues and corresponding eigenvectors of A. Also, if A is diagonalizable , find an invertible  matrix P and a diagonal matrix D  such that P^(-1) A P = D.

Solution:

In[170]:=

A = ({{0, 0, -2}, {1, 2, 1}, {1, 0, 3}})

Eigensystem[A]

Out[170]=

{{0, 0, -2}, {1, 2, 1}, {1, 0, 3}}

Out[171]=

{{1, 2, 2}, {{-2, 1, 1}, {-1, 0, 1}, {0, 1, 0}}}

The above shows that A has two eigenvalues λ = 1 and λ=2. The eigenvalue λ =2 has multiplicity 2 and has two eigenvectors (-1,0,1)  and (0,1,0), which are clearly linearly independent(do you see why?). In other words, the eigenspace for  λ =2 has dimension =2. Thus A is diagonalizable,  P is the matrix whose columns are the eigenvectors of A, and D is the diagonal matrix whose diagonal entries are the eigenvalues of A. We verify this as follows:

In[172]:=

P = ({{-2, -1, 0}, {1, 0, 1}, {1, 1, 0}})

Inverse[P] . A . P

MatrixForm[%]

Out[172]=

{{-2, -1, 0}, {1, 0, 1}, {1, 1, 0}}

Out[173]=

{{1, 0, 0}, {0, 2, 0}, {0, 0, 2}}

Out[174]//MatrixForm=

( {{1, 0, 0}, {0, 2, 0}, {0, 0, 2}} )

5.2  Diagonalization of Symmetic Matrices


Example 4: Find an orthogonal matrix P that diagonalizes the symmetric matrix:     A= (

1 -4 2
-4 1 -2
2 -2 -2
).

Solution:     First, we find the eigenvalues and corresponding eigenvectors of A.

In[175]:=

A = ({{1, -4, 2}, {-4, 1, -2}, {2, -2, -2}})

Eigensystem[A]

Out[175]=

{{1, -4, 2}, {-4, 1, -2}, {2, -2, -2}}

Out[176]=

{{-3, -3, 6}, {{-1, 0, 2}, {1, 1, 0}, {2, -2, 1}}}

Next, for each eigenvalue, we find an orthonormal basis of the eigenspace using the Gram-Schmidt Orthogonalization Process. First, we consider the eigenspace for  the eigenvalue λ = -3 which has dimension 2. An orthonormal basis of its eigenspace is given by w1, w2 where

In[177]:=

<<LinearAlgebra`Orthogonalization`

In[178]:=

{w1, w2} = GramSchmidt[{ {-1, 0, 2}, {1, 1, 0} }]

Out[178]=

{{-1/5^(1/2), 0, 2/5^(1/2)}, {4/(3 5^(1/2)), 5^(1/2)/3, 2/(3 5^(1/2))}}

For the eigenvlaue λ=6, the eigenspace has dimension 1 and an orthonormal basis is given by w3:

In[179]:=

{w3} = GramSchmidt[{ {2, -2, 1}}]

Out[179]=

{{2/3, -2/3, 1/3}}

Recall that the diagonalizing matrix P is  the matrix whose column entries are the orthonormal basis of the eigenspaces. Thus, matrix P is given by:

In[180]:=

P = ({{-1/5^(1/2), 4/(35^(1/2)), 2/3}, {0, 5^(1/2)/3, -2/3}, {2/5^(1/2), 2/(35^(1/2)), 1/3}})

Out[180]=

{{-1/5^(1/2), 4/(3 5^(1/2)), 2/3}, {0, 5^(1/2)/3, -2/3}, {2/5^(1/2), 2/(3 5^(1/2)), 1/3}}

We verify that P is an orthogonal matrix by computing:

In[181]:=

Inverse[P] - Transpose[P]

Out[181]=

{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}

Finally, we show that P is a diagonalizing matrix by computing:

In[182]:=

Inverse[P] . A . P<br />

Out[182]=

It is not clear that this is a diagonal matrix whose diagonal entries are the eigenvalues of A and so we :

In[183]:=

Simplify[%]//MatrixForm

Out[183]//MatrixForm=

( {{-3, 0, 0}, {0, -3, 0}, {0, 0, 6}} )

Exercises

1    Consider the following system of linear equations.
            

4x-3y+2z-w = -5
2x+y-3z              =   7
-x+4y+z+2w =    8


a)     Use the command  LinearSolve[A,b]   to find the solutions of the above system.

b)     Express the augmented matrix in reduced row echelon form and find the solutions of the system of equations.

2.    Let A=(

1 -2 3
-1 3 0
2 -5 5
) and b=(
9
-4
1
)
. Solve the system A X= b.

3.    Let B=(

1 3 4 -5
2 -3 5 6
4 9 -6 7
)    Find the matrices that are obtained by performing the following row operations in succession on matrix B.

    a)      Multiply row 1 by 2.
    
    b)    Add 3  times row 1 to row 2.
    
    c)    Add -4  times row 1 to row 3.
    
    d)    Interchange rows 2 and 3.

4.    For what values of a does the following system of equations have no solution, a unique solution or infinitely many solutions?

            

x-y+z=1
x+3y+a z=2
2x+a y+3z=3
             

5.    Let A=(

1 2 3 4
2 0 -1 3
2 -5 5 1
)    B=(
1 2 3 4
6 8 5 19
4 -5 4 4
)
          
        
        C=(
4 1 4 4
2 0 -1 3
2 4 6 8
)
    D=(
-4 10 -10 -2
2 0 -1 3
2 4 6 8
)
    
        
    i)    Find     a)   A-3B        b)    C^TD        c)   B(A^T+D^T)        
    
    ii)    Use the RowReduce command to detrmine which of the above matrices are row equivalent.

6.    Let F=(

0 1 0 0
-1 0 0 0
0 0 0 1
0 0 1 0
).
a)    Find the smallest positive integer  k so that F^k= F.  [  Hint:   Note that the command  MatrixPower[F,n]  gives F^n.]

b)    Assume that  F is nonsingular. Use the result in a) to find the smallest value of n for which F^(-1)=F^n.

7.    Let A=(

1 1/3
0 1/4
). Find A^2, A^3, and A^8. Can you guess what A^nis?. Verify your guess.

8.    If S={p_1(t), p_2(t), p_3(t)}={t, 2t+1, t^2+t}, determine whether p(t)= 2 t^2 + t - 2 belongs to the span of S.

9.    Determine if   S ={(

2
1
0
), (
-1
0
3
)
, (
-4
1
8
)
,  (
0
1
1
)
}  spans R^3.

10.    Determine if  S ={(

1
0
2
0
), (
2
1
-1
-1
)
, (
1
0
2
0
)
,  (
1
3
-1
4
)
} is a basis of R^4 .

11.    In R^3 consider the bases S and T  given by:
     

    a) Find the transition matrix P from the T-basis to the S-basis.

    b) Let v be a vector whose coordinates with respect to the T-basis is [v] _T  =  (

-1
2
5
). Find the coordinates of v with respect to the S-basis by using the transition matrix P.

12.     Cosider the basis  S={u_1,  u_2, u_3 } for R^3 ,   where u_1   =(

1
1
1
), u_2=  (
1
1
0
), and    u_3=(
0
1
-2
)

    a) Use the Gram-Schmidt process to transform S into an orthonormal basis for R^3.

    b) Express v=(

-1
2
0
) as a linear combination of the orthonormal basis obtained in a) above, i.e., find the coordinates of v with respect to the orthonormal basis.

13.     Let W be the subspace of R^4 with basis S={u_1,  u_2, u_3 }  where
u_1   = (

1
0
2
1
),  u_2 =  (
-1
0
1
0
)  and u_3 =(
1
1
0
1
).
Use the Gram-Schmidt process to find an orthonormal basis for W.

14.    Let  a= -i+3j -k and  b= i-2j +5k.  Find 3a-2b, a.b, and ||b||.

15.      Let A  be the matrix given by   A=  (

2 7 3
1 6 1
3 4 5
).

a)     Find  Det(A).    

b)      Show that Det(A^T) = Det(A)  

c)     Verify that Det(2A) = 2^3 Det(A)  

d)     Let A_1  be the matrix that is obtained by interchanging rows 1 and 2 of A. Show that Det(A_1) =  -  Det(A).

e)     Let A_2  be the matrix that is obtained from A by replacing the third row of A by the sum of row 3 and 5 times row 1. Show that  Det(A_2) = Det(A).

16.    Let A = (

1 0 0
-1 3 0
3 2 -2
). Find the eigenvalues and corresponding eigenvectors of A. Also, if A is diagonalizable , find an invertible  matrix P and a diagonal matrix D  such that P^(-1) A P = D.


Created by Mathematica  (May 24, 2007) Valid XHTML 1.1!