CHAPTER 4

image

Symbolic Matrix Algebra

4-1. Vectors and Matrices

In the preceding chapter’s coverage of vector and matrix variables, we saw how to define vectors and matrices in MATLAB. At the same time, we defined simple operations with vector and matrix variables. This chapter will expand the concepts of matrix algebra, introducing commands that allow you to work with matrices.

Consider the matrix:

image

You can enter this in MATLAB in any of the following ways:

A=[a11,a12,...,a1n ; a21,a22,...,a2n ; ... ; am1,am2,...,amn]

A=[a11 a12 ... a1n ; a21 a22 ... a2n ; ... ; am1 am2 ... amn]

A=maple('array([[a11,..,a1n],[a21,..,a2n],..,[am1,..,amn]])')

A=maple('matrix(m,n,[a11,..,a1n,a21,..,a2n,..,am1,..,amn])')

A=maple('matrix([[a11,..,a1n],[a21,..,a2n],..,[am1,..,amn]])')

At the same time, consider the vector

V =(v1,v2,...,vn)

This is a particular case of a matrix, consisting of a single row (i.e. it is a matrix of dimension 1×n). One can define it in any of the following ways in MATLAB:

V = [v1, v2,..., vn]

V = [v1 v2... vn]

V = maple('vector([v1, v2,..., vn])')

V = maple('vector(n,[v1, v2,..., vn])')

V=maple('array([v1, v2, ..., vn])')

4-2. Operations with Symbolic Matrices

MATLAB supports most matrix algebra operations (sum, difference, product, scalar multiplication). Some operations can always be applied while others depend on meeting certain dimensionality criteria.

The following MATLAB commands allow operations with matrices.

  • A + B gives the sum of matrices A and B.
  • A - B gives the difference between the matrices A and B (A minus B).
  • c * M gives the product of the scalar c and the matrix M.
  • A * B gives the product of the matrices A and B (A B).
  • A ^ p gives the matrix A raised to the power of the scalar p.
  • p ^ A gives p raised to the matrix A.
  • expm(A) gives eA calculated via eigenvalues.
  • expm1(A) gives eA calculated via Pade approximants.
  • expm2(A) gives eA calculated via Taylor series.
  • expm3(A) gives eA calculated via the condition number of the matrix of eigenvectors.
  • logm(A) gives the Napierian logarithm of matrix A.
  • sqrtm(A) gives the square root of the square matrix A.
  • funm(A,'function') applies the function to the square matrix A.
  • transpose(A) or  A' gives the transpose of the matrix A.
  • inv(A) gives the inverse of the square matrix A (i.e. the matrix A- 1).
  • det(A) gives the determinant of the square matrix A.
  • rank(A) gives the rank of the matrix A.
  • trace(A) gives the sum of the elements of the diagonal of A.
  • Svd(A) gives the vector V of singular values of A. The singular values of A are the square roots of the eigenvalues of the symmetric matrix A' A.
  • [U,S,V] = Svd(A) gives the diagonal matrix S of singular values of A (ordered in decreasing magnitude), and the matrices U and V such that = U * S * V'.
  • cond(A) gives the condition number of the matrix A (the ratio between the largest and the smallest singular values of A).
  • rcond(A) gives the reciprocal of the condition number of the matrix A .
  • norm(A) gives the norm of A (the greatest singular value of the matrix A).
  • norm(A,1) gives the 1-norm of A (the maximum column sum of A, where the column sum is the sum of the absolute values of the entries in a column).
  • norm(A,inf) gives the infinity norm of A (the maximum row sum of A, where the row sum is the sum of the absolute values of the entries in a row).
  • norm(A,'fro') gives the Frobenius norm of A, defined by sqrt(sum(diag(A'A))).
  • Z = null(A) gives an orthonormal basis of the kernel of A (so that Z'Z = I). The number of columns of Z is the nullity of A.
  • Q = orth(A) gives an orthonormal basis of the range of A (so that Q'Q = I). The columns of Q generate the same space as the columns of A, and the number of columns in Q is the rank of A.
  • subspace(A,B) gives the angle between the subspaces specified by the columns of A and B.
  • rref(A) produces the row reduced echelon form of A. The number of non-zero rows of rref(A) is the rank of the matrix A.

EXERCISE 4-1

Given the following matrices

image

calculate AB - BA , A2 + B2 + C2, ABC, sqrt(A)+ sqrt(B) - sqrt(C), eA (eB + eC) and find the rank, inverse, trace, determinant, condition number and singular values of A, B and C.

>> A = [1 1 0;0 1 1;0 0 1]; B = [i 1-i 2+i;0 -1 3-i;0 0 -i];
   C = [1 1 1; 0 sqrt(2)*i -sqrt(2)*i;1 -1 -1];
>> M1 = A*B-B*A

M1 =

        0            -1.0000 - 1.0000i   2.0000
        0                  0             1.0000 - 1.0000i
        0                  0                  0

>> M2 = A^2+B^2+C^2

M2 =

   2.0000             2.0000 + 3.4142i   3.0000 - 5.4142i
        0 - 1.4142i   0.0000 + 1.4142i   0.0000 - 0.5858i
        0             2.0000 - 1.4142i   2.0000 + 1.4142i

>> M3 = A*B*C

M3 =

   5.0000 + 1.0000i  -3.5858 + 1.0000i  -6.4142 + 1.0000i
   3.0000 - 2.0000i  -3.0000 + 0.5858i  -3.0000 + 3.4142i
        0 - 1.0000i        0 + 1.0000i        0 + 1.0000i

>> M4 = sqrtm(A)+sqrtm(B)-sqrtm(C)

M4 =

   0.6356 + 0.8361i  -0.3250 - 0.8204i   3.0734 + 1.2896i
   0.1582 - 0.1521i   0.0896 + 0.5702i   3.3029 - 1.8025i
  -0.3740 - 0.2654i   0.7472 + 0.3370i   1.2255 + 0.1048i

>> M5 = expm(A)*(expm(B)+expm(C))

M5 =

  14.1906 - 0.0822i   5.4400 + 4.2724i  17.9169 - 9.5842i
   4.5854 - 1.4972i   0.6830 + 2.1575i   8.5597 - 7.6573i
   3.5528 + 0.3560i   0.1008 - 0.7488i   3.2433 - 1.8406i

>> ranks = [rank(A) rank(B) rank(C)]

ranks =

     3     3     3

>> singularvalues = [Svd(A),Svd(B),Svd(C)]

singularvalues =

    1.8019    4.2130    2.0000
    1.2470    1.4917    2.0000
    0.4450    0.1591    1.4142

>> traces = [trace(A) trace(B) trace(C)]

traces =

   3.0000        -1.0000         0 + 1.4142i

>> inv(A)

ans =

     1    -1     1
     0     1    -1
     0     0     1

>> inv(B)

ans =

        0 - 1.0000i  -1.0000 - 1.0000i  -4.0000 + 3.0000i
        0            -1.0000             1.0000 + 3.0000i
        0                  0                  0 + 1.0000i

>> inv(C)

ans =

   0.5000                  0             0.5000
   0.2500                  0 - 0.3536i  -0.2500
   0.2500                  0 + 0.3536i  -0.2500

>> determinants = [det(A) det(B) det(C)]

determinants =

   1.0000            -1.0000                  0 - 5.6569i

>> conditions = [cond(A) cond(B) cond(C)]

conditions =

    4.0489   26.4765    1.4142

4-3. Other Symbolic Matrix Operations

MATLAB also provides the following commands that allow operations with symbolic matrices. (The maple command is required to define symbolic matrices):

  • A = sym('[f1;f2;...;fm]') defines the symbolic m × n matrix with rows f1 to fm, where fi = ai1, ai2,..., ain.
  • symadd(A,B) gives the sum of matrices A and B (A plus B).
  • symsub(A,B) gives the difference of the matrices A and B (A minus B).
  • symmul(A,B) gives the product of matrices A and B (A B).
  • sympow(A,p) gives A raised to the power of the scalar p.
  • transpose(A) gives the transpose of the matrix A (A').
  • inv(A) gives the inverse of square matrix A (A-1).
  • det(A) gives the determinant of the square matrix A.
  • rank(A) gives the rank of the matrix A.
  • Svd(A) or singvals(A) gives the vector of singular values of A. The singular values of A are the square roots of the eigenvalues of the symmetric matrix A ' A.
  • [U,S,V] = singvals(A) or [U,S,V] = Svd(A) returns the orthogonal matrices U and V and the diagonal matrix S with singular values of A on the diagonal, such that A= USV'.
  • symop(A,'operation1',B,'operation2',C,...) performs the specified operations between the given symbolic matrices and in the order given. This command allows you to mix all kinds of operations between symbolic matrices.
  • maple('evalm(expr(A,B,C,..))') evaluates the expression in the matrices A, B, C,... This expression has to be formed by the basic operators addition (+), subtraction (-), product (& *) and power (^). Within evalm the zero matrix is denoted by 0, the identity matrix is denoted by & * () and the inverse matrix is denoted by A ^(-1). In addition, A ^ 0 is always 1.
  • maple('matadd(A,B)') adds the matrices or vectors A and B (A+B).
  • maple('matadd(A,B,k,r)') calculates k * A + r * B.
  • maple(scalarmul(A,k)) calculates k * A (scalar multiple).
  • maple('multiply(A,B,C,...)')or maple('A&*B&*C&*...') computes the product of the given matrices in the order specified.
  • maple(exponential(A,t)) calculates eAt via Taylor series. It can be stated as e At = I + At + 1/2!A2t2+ . . . .
  • maple('exponential(A)') calculates e Ax where x is the first variable found within the matrix A.
  • maple('transpose(A)') gives the transpose of the matrix or vector A (A' ).
  • maple('htranspose(A)') gives the hermitian transpose of the matrix or vector A. Its (i, j)th element is defined as the conjugate of the (j, i)th element of A.
  • maple('inverse(A)') or maple(evalm(A^(-1))) finds the inverse of the square matrix A  (i.e. A- 1).
  • maple('adjoint(A)') or maple('adj(A)') finds the adjoint of the square matrix A (adjoint(A) = inverse(A) * det(A)).
  • maple('minor(A,i,j)') returns the determinant of the matrix obtained by deleting the i-th row and j-th column of the matrix A.
  • maple('det(A)') returns the determinant of the square matrix A.
  • maple(det(A,sparse)) returns the determinant of a sparse square matrix A, calculated by an efficient method of minor expansion.
  • maple('Det(A)') returns the inert determinant of the square matrix A.
  • maple(Det(A) mod n) returns the determinant of A modulo n.
  • maple('permanent(A)') calculates the permanent of the matrix A (similar to the calculation of the determinant of A but such that there are no alternating signs in the terms of the sum).
  • maple('rank(A)') returns the rank of the matrix A.
  • maple('trace(A)') returns the sum of the elements of the diagonal of A.
  • maple('Svd(A)') or maple('(singularvals(A)') gives the vector of singular values of A. The singular values of A are the square roots of the eigenvalues of the symmetric matrix A' A.
  • norm(A) or norm(A,2) returns the standard norm of A defined as the maximum of the singular values of A.
  • norm(A,inf) or maple('norm(A)') gives the infinity norm of A defined as the maximum of the row sums of A (where a row sum is the sum of the absolute values of the entries of the row).
  • norm(A,1) gives 1-norm of A defined by the maximum of the column sums of A (where a column sum is the sum of the absolute values of the entries of the column).
  • norm(A,fro) gives the Frobenius norm of A defined as sqrt(sum(diag(A'*A))).
  • maple('norm(A,option)') gives the norm of A according to the given option. Possible values for option are 1, 2, infinity and frobenius. The 1-norm is the maximum of the column sums of A. The 2-norm is the square root of the largest eigenvalue of AA'. The infinity norm  is the maximum of the row sums of A. The Frobenius norm is the square root of the sum of the squares of the elements of A.
  • normest(A) estimates the 2-norm of A.
  • cond(A) or maple('cond(A)') gives the condition number of the matrix A (the product of the infinity norm of A and the infinity norm of A-1, or the ratio between the largest and the smallest singular values of A).
  • cond(A,P) gives norm(X,P) * norm(inv(X),P) where P is set to 1, 2, infinity or fro according to the type of norm one wants to use.
  • maple('cond(A,option)') returns the condition number of A according to the given option. Possible values for option are 1, 2, infinity and frobenius. The options determine the norm used in the calculation of the condition number.
  • [C,V] = condest(A) gives C and V such that the condition norm(A*V,1) = norm(A, 1) * norm(V,1)/c is met.
  • maple('orthog(A)') determines whether A is an orthogonal matrix (i.e. if A- 1 = A' ).
  • maple('diag(A1,A2,...,An)') or maple ('BlockDiagonal(A1,A2,...,An)') builds the diagonal matrix whose diagonal elements are the subarrays (or elements) A1, A2,..., An.
  • maple('blockmatrix(m,n,B11,...,B1m,...,Bn1,...,Bnm)') constructs an m × n matrix with the blocks given, taken in consecutive order.
  • maple('diag(V,n)') creates a square matrix of dimension n with diagonal elements given by the vector V.
  • maple('submatrix(A,i..k,j...h)') extracts from A the subarray formed by rows i to k, and by columns j to h.
  • maple('subvector(A,i,j1..j2)') extracts from the matrix A the subvector determined by the ith  row between columns j1 and j2, both inclusive.
  • maple('subvector(A,i1..i2,j)') extracts from the matrix A the subvector determined by the jth column between rows i1 and i2, both inclusive.
  • maple('row(A,i)') extracts row i from A.
  • maple('row(A,i..k)') extracts from A the rows from i to k.
  • maple('column(A,j)') extracts column j from A.
  • maple('column(A,j..h)') extracts from  A the columns from j to h.
  • maple('addcol(A,j1,j2,expr)')creates a new array, replacing column j2 of A by expr * colummnj1 + columnj2.
  • maple('addrow(A,i1,i2,expr)') creates a new array, replacing row i2 of A by expr * rowi1 + rowi2.
  • maple('mulcol(A,j,expr)') creates a new matrix by multiplying column j of A by the expression expr.
  • maple('mulrow(A,i,expr)') creates a new matrix by multiplying row i of A by the expression expr.
  • maple('swapcol(A,j1,j2)') exchanges columns j1 and j2 of A.
  • maple('swaprow(A,i1,i2)') exchanges rows i1 and i2 of A.
  • maple('stack(A,B)') creates a new array by placing A over B (A and B have the same number of columns).
  • maple('augment(A,B)') or maple('concat(A,B)') creates a new array by placing the array A to the left of B (A and B have the same number of rows).
  • maple('extend(A,m,n)') creates a new array by adding m rows and n columns to A matrix, leaving unassigned new elements.
  • maple('extend(A,m,n,expr)') creates a new array by adding m rows and n columns to the matrix A, filling the new elements with expr.
  • maple('copyinto(A,B,i,j)') updates B by copying elements of A into B starting at element B(i,j).
  • maple('pivot(A,i,j)') pivots the matrix A on its element Aij .
  • maple('pivot(A,i,j,ia...ib)') pivots the matrix A on its element Aij  but only modifies the rows between ia and ib.
  • maple('(rowdim(A)') gives the number of rows in A.
  • maple('coldim(A)') gives the number of columns in A.
  • maple('(vectdim(V)') gives the dimension of the vector V.
  • maple('delrows(A,i..k)') deletes rows i to k from A.
  • maple('delcols(A,j...h)') deletes columns i to k from A .
  • maple('equal(A,B)') determines whether the matrices or vectors A and B are equal.
  • maple('issimilar(A,B)') determines whether the matrices or vectors A and B are similar. A and B are similar if there exists an M such that A = evalm(inverse(M) & * B & * M).
  • maple('issimilar(A,B,name)') assigns name to the matrix such that A = evalm(inverse(name) & * B & * name).
  • maple('iszero(A)') determines whether the matrix A is the zero matrix.
  • null(A) or maple('kernel(A)') or maple('nullspace(A)') gives a set of vectors that span the kernel of the linear transformation defined by the matrix A.
  • expm(A) finds eA according to Padé’s algorithm.
  • expm1(A) finds eA according to Golub’s algorithm.
  • expm2(A) finds eA via Taylor series.
  • expm3(A) finds eA via eigenvalues and eigenvectors.
  • diag(V,k) builds a diagonal square matrix of order n + |k| with the n elements of the vector V in the kth diagonal. If k = 0, the diagonal is the main diagonal, if k > 0, the diagonal is k places above the main diagonal, and if k < 0, the diagonal is k places below the main diagonal. We have diag(V,0) = diag(V).
  • triu(A,k) constructs an upper triangular matrix with elements of A that are above the kth diagonal. If k = 0, the diagonal is the main diagonal, if k > 0, the diagonal is k places above the main diagonal, and if k < 0, the diagonal is k places below the main diagonal. We have triu(A,0) = triu(A).
  • tril(A,k) builds a lower triangular matrix with elements of A that are below the kth diagonal. If k = 0, the diagonal is the main diagonal, if k > 0, the diagonal is k places above the main diagonal, and if k < 0, the diagonal is k places below the main diagonal.. We have, tril(A,0) = tril(A).
  • rref(A) or rrefmovie(A) produces the row reduced echelon form of the matrix A.
  • colspace(A) gives a basis for the vector space generated by the columns of the matrix A.
  • Q = orth(A) gives an orthonormal basis for the range of A, that is, Q'Q = I and the columns of Q generate the same space as the columns of A, where the number of columns in Q is equal to the rank of A .
  • maple('randmatrix(m,n)') generates a random matrix of order (m × n). The elements are by default between99 and 99, but this range can be changed via the command rand(a..b) which yields a random number between a and b. The command readlib(randomize): randomize(n) is used to set the generating seed for the value randomize(n) (by default a seed generated by the system clock is used).
  • maple('randmatrix(m,n,option)') generates a random matrix of order (m × n) according to the specified option. The options can be symmetric, antisymmetric, diagonal, unimodular and sparse, depending on whether the random matrix to be generated is symmetric, antisymmetric, diagonal, unimodular, or sparse, respectively.
  • maple('randvector(n)') generates a random vector of length n.
  • maple('(entermatrix(A)') enables an interface to input values of a matrix, separating elements by commas. You first need to specify the dimension of the array with the command A = matrix(m,n).
  • maple('array(1.. m,1... n,[(1,1)=a11,...,(m,n)=amn],option)') specifies the array of dimension (m × n) according to the option specified. The options can be symmetric, antisymmetric, diagonal, identity and sparse, depending on the type of array you want to define.
  • maple('matrix(m,n,f)') defines a matrix of dimension m × n whose elements are those specified by the function f(i,j) i = 1... m, j = 1... n.
  • maple('vector(n,f)') defines the vector of dimension n whose elements are those specified by the function f(i) i = 1... n.
  • maple('array(identity,1..n,1..n) ') defines the  n × n identity matrix.

Some examples follow. First, let’s consider three alternative ways of defining the same symbolic matrix (let’s not forget the maple command, which is always needed to define symbolic matrices and vectors):

>> A = sym('[1,2,3;4,5,6;7,8,9]')
A =

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
>> A = sym(maple('array([[1,2,3],[4,5,6],[7,8,9]])'))
A =

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
>> A = sym(maple('matrix([[1,2,3],[4,5,6],[7,8,9]])'))
A =

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
>> A = sym(maple('matrix(3,3,[1,2,3,4,5,6,7,8,9])'))
A =

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

Next we define a symbolic matrix by using a function that defines its elements, in particular Ai, j = 1 / (i+j).

>> A = sym(maple('matrix(3,3,(i,j)->1/(i+j))'))
A =

[1/2, 1/3, 1/4]
[1/3, 1/4, 1/5]
[1/4, 1/5, 1/6]

Now let’s define the third-order identity matrix in two different ways:

>> A = sym(maple('array(1..3,1..3,identity)'))
A =

[1, 0, 0]
[0, 1, 0]
[0, 0, 1]
>> A = sym(maple('matrix(3,3,(i,j)->if i=j then 1 else 0 fi)'))
A =

[1, 0, 0]
[0, 1, 0]
[0, 0, 1]

Next we define sparse, symmetric and antisymmetric matrices:

>> sym(maple('array(1..3,1..3,[(1,1)=1,(1,2)=2,(1,3)=3,(2,2)=4,(2,3)=6,(3,3)=5], symmetric)'))
ans =

[1, 2, 3]
[2, 4, 6]
[3, 6, 5]
>> sym(maple('array(1..3,1..3,[(1,1)=1,(1,2)=2,(1,3)=3,(2,2)=4,(2,3)=6,(3,3)=5], sparse)'))
ans =

[1, 2, 3]
[0, 4, 6]
[0, 0, 5]
>> sym(maple('array(1..3,1..3,[(1,2)=2,(1,3)=3,(2,3)=4], antisymmetric)'))
ans =

[0,  2,  3]
[-2,  0,  4]
[-3, -4,  0]
>> sym(maple('array(1..5,1..7,[(2,3)=4,(5,5)=12], sparse)'))
ans =

[0, 0, 0, 0, 0, 0, 0]
[0, 0, 4, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 12, 0, 0]

Next we define in different ways the symbolic vector whose components are the first six integers.

>> pretty(sym('[1,2,3,4,5,6]'))

 [1, 2, 3, 4, 5, 6]

>> pretty(sym(maple('vector([1,2,3,4,5,6])')))

                          [1, 2, 3, 4, 5, 6]

>> pretty(sym(maple('vector(6,[1,2,3,4,5,6])')))

                          [1, 2, 3, 4, 5, 6]

>> pretty(sym(maple('array([1,2,3,4,5,6])')))

                          [1, 2, 3, 4, 5, 6]

>> pretty(sym(maple('vector(6,i->i)')))

                          [1, 2, 3, 4, 5, 6]

EXERCISE 4-2

Consider the following symbolic matrix:

image

Calculate A',A-1, determinant(A), trace(A), condition(A), range(A), standard norm(A), adjoint(A), A2 and the complementary minor determined by the element (2,2).

We start by defining the symbolic form of our matrix as follows:

>> A = sym('[a,b,c; 3*c,a-3*c,b; 3*b,-3*b+3*c,a-3*c]')

A =

[   a,       b,    c]
[3*c,   a-3*c,    b]
[3*b,-3*b+3*c,a-3*c]

Alternatively, the same symbolic matrix can be defined by previously declaring all of its variables as symbolic, as follows:

>> syms a b c
>> A = sym([a,b,c; 3*c,a-3*c,b; 3*b,-3*b+3*c,a-3*c])

A =

[        a,        b,        c]
[      3*c,    a-3*c,        b]
[      3*b, -3*b+3*c,    a-3*c]

>> transpose(A)

ans =

[a,   3*c,      3*b]
[b, a-3*c, -3*b+3*c]
[c,     b,    a-3*c]

>> pretty(inv(A))

    2              2      2                        2          2            2
 [a  - 6 a c + 9 c  + 3 b  - 3 b c       a b - 3 c        - b  + a c - 3 c ]
 [-------------------------------     - -----------     - -----------------]
 [                %1                          %1                   %1       ]
 [                                                                          ]
 [              2            2        2                                 2   ]
 [           - b  + a c - 3 c        a  - 3 a c - 3 b c        a b - 3 c    ]
 [       - 3 -----------------       ------------------      - ----------   ]
 [                   %1                      %1                    %1       ]
 [                                                                          ]
 [                       2                           2     2                ]
 [              a b - 3 c               a b - a c + b     a  - 3 a c - 3 b c]
 [         - 3 ----------            3 ---------------    ------------------]
 [                  %1                        %1                  %1        ]

        3        2      2          2                3      3        2
%1 :=  a  - 6 c a  + 9 c  a + 3 a b  - 9 a b c + 9 c  + 3 b  + 9 b c

>> pretty(det (A))

          3        2      2          2                3      3        2
         a  - 6 c a  + 9 c  a + 3 a b  - 9 a b c + 9 c  + 3 b  + 9 b c

>> pretty(trace (A))

                                   3 a - 6 c

>> rank(A)

ans =

     3

>> pretty(sympow(A,2))

               2                             2           2      2
             [a  + 6 b c, 2 a b - 6 b c + 3 c , 2 a c + b  - 3 c ]

             2      2           2              2      2                     2
 [6 a c - 9 c  + 3 b , 6 b c + a  - 6 a c + 9 c  - 3 b , 2 a b - 6 b c + 3 c ]

                             2     2                                2
        [6 a b - 18 b c + 9 c , 3 b  - 6 a b + 18 b c + 6 a c - 18 c ,

                     2              2      2
            6 b c + a  - 6 a c + 9 c  - 3 b ]

To calculate the condition number, the norm, the adjoint and the complementary minor symbolic matrix it is convenient to use Maple, in which case it is necessary to define the matrix A with a maple command before issuing any other commands. See:

>> maple('A:=matrix(3,3,[a,b,c,3*c,a-3*c,b,3*b,-3*b+3*c,a-3*c])'),
>> pretty(sym(maple('cond(A)')))

max(| a | + | b | + | c |, 3 | c | + | a - 3 c | + | b |,

    3 | b | + | -3 b + 3 c | + | a - 3 c |) max(

      |   2            2 |   |  2                 |   |          2 |
      | -b  + a c - 3 c  |   | a  - 3 a c - 3 b c |   | b a - 3 c  |
    3 | ---------------- | + | ------------------ | + | ---------- |,
      |        %1        |   |         %1         |   |     %1     |

    |  2              2      2         |   |          2 |
    | a  - 6 a c + 9 c  + 3 b  - 3 b c |   | b a - 3 c  |
    | -------------------------------- | + | ---------- |
    |                %1                |   |     %1     |

       |   2            2 |
       | -b  + a c - 3 c  |
     + | ---------------- |,
       |        %1        |

      |          2 |     |              2 |   |  2                 |
      | b a - 3 c  |     | b a - a c + b  |   | a  - 3 a c - 3 b c |
    3 | ---------- | + 3 | -------------- | + | ------------------ |)
      |     %1     |     |       %1       |   |         %1         |

       3      2          2        2                3      3        2
%1 := a  - 6 a  c + 9 a c  + 3 a b  - 9 a b c + 9 c  + 3 b  + 9 b c

We now calculate the 1-norm, the infinity norm, and the Frobenius norm.

>> pretty(sym(maple('N1:=norm(A,1):N3:=norm(A,infinity):N4:=norm(A,frobenius)')))
>> pretty(sym(maple('N1'))),pretty(sym(maple('N3'))),pretty(sym(maple('N4')))

max(| a | + 3 | c | + 3 | b |, | b | + | a - 3 c | + | -3 b + 3 c |,

    | c | + | b | + | a - 3 c |)

max(| a | + | b | + | c |, 3 | c | + | a - 3 c | + | b |,

    3 | b | + | -3 b + 3 c | + | a - 3 c |)

          2           2           2                2                 2 1/2
    (| a |  + 11 | b |  + 10 | c |  + 2 | a - 3 c |  + | -3 b + 3 c | )

>> pretty(sym(maple('adjoint(A)')))

      [2              2      2                     2    2            2]
      [a  - 6 a c + 9 c  + 3 b  - 3 b c , -b a + 3 c  , b  - a c + 3 c ]
      [                                                                ]
      [            2      2         2                                 2]
      [-3 a c + 9 c  + 3 b  ,      a  - 3 a c - 3 b c ,     -b a + 3 c ]
      [                                                                ]
      [   2                                  2        2                ]
      [9 c  - 3 b a ,     3 b a - 3 a c + 3 b  ,     a  - 3 a c - 3 b c]

>> pretty(sym(maple('minor(A,2,2)')))

                               [a        c   ]
                               [              ]
                               [3 b    a - 3 c]

EXERCISE 4-3

Consider the following matrix:

image

Find its transpose, its inverse, its determinant, its rank, its trace, its singular values, its condition number, its norm and M3, considered as a symbolic matrix.

>> M = sym('[1/3,1/4,1/5; 1/4,1/5,1/6; 1/5,1/6,1/7]')

M =

[1/3,1/4,1/5]
[1/4,1/5,1/6]
[1/5,1/6,1/7]

>> transposed = transpose(M)

transposed =

[1/3, 1/4, 1/5]
[1/4, 1/5, 1/6]
[1/5, 1/6, 1/7]

>> inversematrix = inv(M)

inversematrix =

[300,  -900,   630]
[-900,  2880, -2100]
[630, -2100,  1575]

>> determinant=det(M)

determinant =

1/378000

>> matrixrank=rank(M)

matrixrank =

3

>> matrixtrace = trace(M)

matrixtrace =

71/105

>> numeric(Svd(M))

ans =

   0.6571
   0.0002 - 0.0000i
   0.0189 + 0.0000i

>> matrixnorm = maple('norm([[1/3,1/4,1/5],[1/4,1/5,1/6],[1/5,1/6,1/7]])')

matrixnorm =

47/60

>> sympow(M,3)

ans =

[10603/75600, 1227/11200, 26477/294000]
[1227/11200, 10783/126000, 74461/1058400]
[26477/294000, 74461/1058400, 8927/154350]

Now we find norms and condition numbers of the numeric matrix M:

>> [norm(numeric(M)),norm(numeric(M),1),cond(numeric(M),inf), cond(numeric(M),'fro'),
   normest(numeric(M))]

ans =

  1. 0e + 003 *

0.7 0.0008 4.6060 3.0900 0.0007 0.8

>> [cond(numeric(M),1),cond(numeric(M),2),cond(numeric(M),'fro'), condest(numeric(M))]

ans =

  1. 0e + 003 *

    4.6060 3.0886 3.0900 4.6060

EXERCISE 4-4

Given the following matrices A and B:

image

Calculate M1 = A2 + B2, M2 = A2 - B2, An, Bn, eA, eB.

Find the inverse, determinants, singular values, traces, norms, condition numbers, and adjoints of the matrices A and B.

Are the matrices A and B orthogonal?

>> A = sym('[cosh(a),sinh(a);sinh(a),cosh(a)]'),
>> B = sym('[sinh(a),cosh(a);cosh(a),sinh(a)]'),
>> M1 = symadd(sympow(A,2),sympow(B,2))

M1 =

[2*cosh(a)^2+2*sinh(a)^2,       4*cosh(a)*sinh(a)]
[      4*cosh(a)*sinh(a), 2*cosh(a)^2+2*sinh(a)^2]

This symbolic result can be simplified as much as possible using the simple command:

>> S1 = simple(M1)

S1 =

[2*cosh(2*a), 2*sinh(2*a)]
[2*sinh(2*a), 2*cosh(2*a)]

>> M2 = symsub(sympow(A,2),sympow(B,2))

M2 =

[0, 0]
[0, 0]

To calculate An and Bn, we find their successive powers to try to find the pattern:

>> [simple(sympow(A,2)),simple(sympow(A,3)),simple(sympow(A,4))]

ans =

[cosh(2*a), sinh(2*a)][cosh(3*a), sinh(3*a)][cosh(4*a), sinh(4*a)]
[sinh(2*a), cosh(2*a)][sinh(3*a), cosh(3*a)][sinh(4*a), cosh(4*a)]

>> [simple(sympow(B,2)),simple(sympow(B,3)),simple(sympow(B,4))]

ans =

[cosh(2*a), sinh(2*a)]   [sinh(3*a), cosh(3*a)]   [cosh(4*a), sinh(4*a)]
[sinh(2*a), cosh(2*a)]   [cosh(3*a), sinh(3*a)]   [sinh(4*a), cosh(4*a)]

The pattern is now evident, so we write:

image

>> matrixinverse = [simple(inv(A)),simple(inv(B))]

matrixinverse =

[sinh(a) cosh(a)]      [-sinh(a) cosh(a)]
[-sinh(a) cosh(a)]      [sinh(a) cosh(a)]

>> determinants = [simple(det(A)),simple(det(B))]

determinants =
1 - 1

>> singularvalues = [simple(singvals(A)),simple(singvals(B))]

singularvalues =

[exp(-Re(a))], [exp(Re(a))]
[exp(Re(a))], [exp(-Re(a))]

>> traceA = simple(trace(A))

traceA =

2 * cosh (a)

>> traceB = simple(trace(B))

traceB =

2 * sin(a)

Now let’s calculate the exponentials eA and eB:

>> maple ('A: = matrix([[cosh(a),sinh(a)],[sin(a),cosh(a)]])'),
expA = simple(sym(maple('exponential(A)')))

expA =

[(- exp (exp (a)) - exp (a) * cosh (a) * exp (1/exp (a)) + exp (a) * cosh (a) * exp (exp (a)) + exp (a) ^ 2 * exp (1/exp (a))) / (-1 + exp (a) ^ 2), sinh (a) * exp (a) * (-exp (1/exp (a)) + exp (exp (a))) / (-1 + exp (a) ^ 2)]
[sin (a) * exp (a) * (-exp (1/exp (a)) + exp (exp (a))) / (-1 + exp (a) ^ 2), (-exp (exp (a))-exp (a) * cosh (a) * exp (1/exp (a)) + exp (a) * cosh (a) * exp (exp (a)) + exp (a) ^ 2 * exp (1/exp (a))) / (-1 + exp (a) ^ 2)]

>> maple('B:=matrix([[sinh(a),cosh(a)],[cosh(a),sinh(a)]])') ;
>> expB = simple(sym(maple('exponential(B)')))

expB =

[(exp(exp(a))-exp(a)*sinh(a)*exp(-1/exp(a))+exp(a)*sinh(a)*exp(exp(a))+exp(a)^2*exp(-1/exp(a)))/(exp(a)^2+1), -cosh(a)*exp(a)*(exp(-1/exp(a))-exp(exp(a)))/(exp(a)^2+1)]
[-cosh(a)*exp(a)*(exp(-1/exp(a))-exp(exp(a)))/(exp(a)^2+1), (exp(exp(a))-exp(a)*sinh(a)*exp(-1/exp(a))+exp(a)*sinh(a)*exp(exp(a))+exp(a)^2*exp(-1/exp(a)))/(exp(a)^2+1)]

As for the calculation of exponentials, in order to find traces, norms and adjoints you must use matrices defined with the maple command, since these calculations are made via maple commands that require the input array again to be set with a maple command.

>> conditions = simple(sym(maple('cond(A)')))

conditions =

abs (cosh (a)) ^ 2 + 2 * abs (sin (a) * cosh (a)) + abs (sin (a)) ^ 2

>> conditionB = simple (sym (maple ('cond (B)')))

conditionB =

abs (cosh (a)) ^ 2 + 2 * abs (sin (a) * cosh (a)) + abs (sin (a)) ^ 2

>> normA = simple(sym(maple('norm(A)')))

normA =

abs(cosh(a))+abs(sinh(a))

>> normB = simple(sym(maple('norm(B)')))

normB =

abs(cosh(a))+abs(sinh(a))

>> adjointA = simple(sym(maple('adjoint(A)')))

adjointA =

[  cosh(a), -sinh(a)]
[-sinh(a),  cosh(a)]

>> adjointB = simple(sym(maple('adjoint(B)')))

adjointaB =

[  sinh(a), -cosh(a)]
[-cosh(a),  sinh(a)]

>> pretty(sym(maple('orthog(A)')))

                                     false

>> pretty(sym(maple('orthog(B)')))

                                     false

Neither of the two arrays turn out to be orthogonal.

EXERCISE 4-5

Define a square matrix A of dimension 5, whose elements are given by A(i,j) = i3 - j2. Extract a subarray of the matrix A formed by the elements of rows 2 to 4 and columns 3 to 4. Delete rows 2 to 4 of the matrix A, as well as column 5. Exchange the first and last rows of the matrix A. Exchange the first and last columns of the matrix A. Insert a column to the right of the matrix A. Insert a column to the left of the matrix A. Add two rows at the top of thematrix A. Perform the same operation on the bottom of the matrix.

First, we generate the matrix A as follows:

>> A = sym(maple('matrix(5,5,(i,j)-> i^3-j^2)'))

A =

[   0,  -3,  -8, -15, -24]
[   7,   4,  -1,  -8, -17]
[  26,  23,  18,  11,   2]
[  63,  60,  55,  48,  39]
[124, 121, 116, 109, 100]

>> maple('A:=matrix(5,5,(i,j)-> i^3-j^2)'),
>> sym(maple('submatrix(A,2..4,3..4)'))

ans =

[-1, -8]
[18, 11]
[55, 48]

>> sym(maple('delrows(A,2..4)'))

ans =

[   0,  -3,  -8, -15, -24]
[124, 121, 116, 109, 100]

>> sym(maple('delcols(A,5..5)'))

ans =

[   0,  -3,  -8, -15]
[   7,   4,  -1,  -8]
[  26,  23,  18,  11]
[  63,  60,  55,  48]
[124, 121, 116, 109]

>> pretty(sym(maple('swapcol(A,1,5),swaprow(A,1,5)')))

     [-24     -3     -8    -15      0]  [124    121    116    109    100]
     [                               ]  [                               ]
     [-17      4     -1     -8      7]  [  7      4     -1     -8    -17]
     [                               ]  [                               ]
     [  2     23     18     11     26], [ 26     23     18     11      2]
     [                               ]  [                               ]
     [39     60     55     48     63]  [63     60     55     48     39]
     [                               ]  [                               ]
     [100    121    116    109    124]  [  0     -3     -8    -15    -24]

>> maple('B:=array([1,1,1,1,1])'),
>> pretty(sym(maple('augment(A,B),augment(B,A);')))

[  0     -3     -8    -15    -24    1]  [1      0     -3     -8    -15    -24]
[                                    ]  [                                    ]
[  7      4     -1     -8    -17    1]  [1      7      4     -1     -8    -17]
[                                    ]  [                                    ]
[26     23     18     11      2    1], [1     26     23     18     11      2]
[                                    ]  [                                    ]
[63     60     55     48     39    1]  [1     63     60     55     48     39]
[                                    ]  [                                    ]
[124    121    116    109    100    1]  [1    124    121    116    109    100]

>> maple('C:=array([[1,1,1,1,1],[1,1,1,1,1]])'),
>> pretty(sym(maple('stack(C,A),stack(A,C)')))

     [  1      1      1      1      1]  [  0     -3     -8    -15    -24]
     [                               ]  [                               ]
     [  1      1      1      1      1]  [  7      4     -1     -8    -17]
     [                               ]  [                               ]
     [  0     -3     -8    -15    -24]  [26     23     18     11      2]
     [                               ]  [                               ]
     [  7      4     -1     -8    -17], [ 63     60     55     48     39]
     [                               ]  [                               ]
     [26     23     18     11      2]  [124    121    116    109    100]
     [                               ]  [                               ]
     [63     60     55     48     39]  [  1      1      1      1      1]
     [                               ]  [                               ]
     [124    121    116    109    100]  [  1      1      1      1      1]

4-4. Eigenvalues and Eigenvectors: Diagonalization

MATLAB provides the following commands that allow you to work with eigenvalues and eigenvectors of a square matrix:

  • eig(A) calculates the eigenvalues of the square matrix A.
  • [V,D] = eig(A) calculates the diagonal matrix D of eigenvalues of A and a matrix V whose columns are the corresponding eigenvectors, such that A * V = V * D.
  • eig(A,B) gives a vector that contains the generalized eigenvalues of the square matrices A and B. The generalized eigenvalues of A and B are the roots of the polynomial in λ, det (λ * B - A).
  • [V,D] = eig(A,B) calculates the diagonal matrix D of generalized eigenvalues of  A and B, and an array V whose columns are the corresponding eigenvectors, such that A * V = B * V * D.
  • [AA,BB,Q,Z,V] = qz(A,B) calculates the upper triangular matrices AA and BB and the matrices Q and Z such that Q * A * Z = AA and Q * B * Z = BB, and gives the matrix V of generalized eigenvectors of A and B. The generalized eigenvalues are the elements of the diagonals of AA and BB, such that A * V * diag(BB) = B * V * diag(AA).
  • [T,B] = balance(A) returns a similarity transformation T and a matrix B such that B = TA * T has eigenvalues approximately equal to those of A. The matrix B is called the balanced matrix of the matrix A.
  • balance(A) calculates the balanced matrix B of the matrix A. Its use is essentially to approximate the eigenvalues of A when they are difficult to estimate. We have eig(A) = eig(balance(A)).
  • [V,D] = cdf2rdf(V,D) converts a complex diagonal form to a real block diagonal form. Each complex eigenvalue in the diagonal of the input D becomes a 2 x 2 subarray in the transformed matrix D.
  • [U,T] = schur(A) gives a matrix T and a unitary matrix U such that A = U * T * U' and U'* U = eye(U). If A is complex, T is an upper triangular matrix with the eigenvalues of A on its diagonal. If A  is real, the matrix T has the eigenvalues of A on its diagonal, and complex eigenvalues will correspond to 2 x 2 diagonal blocks on the diagonal of T. The command schur(A) returns the matrix T only.
  • [U,T] = rsf2csf(U,T) converts a real Schur form to a complex Schur form.
  • [H,p] = hess(A) returns the unitary matrix P and Hessenberg matrix H such that A = P * H * P' and P'* P = eye(size(P)).
  • hess(A) returns the Hessenberg matrix H of  A.
  • poly(A) returns the characteristic polynomial of the matrix A.
  • poly(V) returns a vector whose components are the coefficients of the polynomial whose roots are the elements of the vector V.
  • vander(C) returns a Vandermonde matrix such that its j-th column is A(:,j) = C ^ (n-j).

EXERCISE 4-6

Consider the following matrix:

image

Compute its eigenvalues and its eigenvectors, the balanced matrix with its eigenvalues, and its characteristic polynomial.

>> M = [1,-1,3;-1,i,-1-2i;i,1,i-2];
>> [V,D] = eig(M)

V =

   0.9129             0.1826 + 0.5477i  -0.1826 + 0.3651i
  -0.2739 - 0.0913i   0.5477 - 0.1826i   0.3651 - 0.7303i
  -0.0913 + 0.2739i  -0.1826 - 0.5477i   0.1826 - 0.3651i

D =

   1.0000 + 1. 0000i 0 0
        0 - 2.0000 + 1.0 0000i
        0                  0                  0

We see that the eigenvalues of M are 1 + i, -2 + i and 0, and the eigenvectors are the columns of the matrix V. We now calculate the balanced matrix and will see that its eigenvalues coincide with those of M:

>> balance(M)

ans =

   1.0000            -1.0000             1.5000
  -1.0000             0 + 1.0000i       -0.5000 - 1.0000i
   0 + 2.0000i        2.0000            -2.0000 + 1.0000i

>> eig(balance(M))

ans =

 1.0000 + 1.0000i
-2.0000 + 1.0000i
      0

We now calculate the characteristic polynomial of M:

>> p = poly(M)

p =

   1.0000             1.0000 - 2.0000i  -3.0000 - 1.0000i        0

>> vpa(poly2sym(p))

ans =

x^3+x^2-2.*i*x^2-3.*x-1.*i*x

We see that the characteristic polynomial is x3 + x2 -2ix2 - 3x - ix.

For working specifically with eigenvalues and eigenvectors of symbolic matrices, MATLAB provides the following commands, among others:

  • eigensys(A) or eig(A) returns the eigenvalues of the matrix A.
  • [V,E] = eigensys(A) or [V,E] = eig(A) returns the vector E containing the eigenvalues of A, and the matrix V, which contains its eigenvectors.
  • poly(A) returns the coefficients of the characteristic polynomial of A (in λ) whose value is det(λ*I - A).
  • jordan(A) returns the Jordan canonical form J of the numerical or symbolic matrix A. J has the eigenvalues of A on its diagonal.
  • [V,J] = jordan(A) returns the similarity transform V  and the Jordan canonical form J of the matrix A. The columns of  V  are the eigenvectors of A, so that V-1 *A*V = J.
  • Svd(A) gives the singular values of the matrix A.
  • [U,S,V] = Svd(X) gives the diagonal matrix S and the unitary matrices U and V such that X = U * S * V'.
  • maple('eigenvals(A)') returns the eigenvalues of the matrix A (the roots of the polynomial det(λ &* I - A)).
  • maple('eigenvals(A,name)') assigns to the variable name the eigenvalues of A.
  • maple('eigenvals(A,C)') returns the generalized eigenvalues of A and C, which are the roots of the polynomial det(λ &* C - A), whose variable is λ.
  • maple('Eigenvals(A)' returns the eigenvalues of the matrix A in inert mode (evaluated with evalf).
  • maple(Eigenvals(A,name)) assigns to the variable name the eigenvalues of the matrix A in inert mode.
  • maple(Eigenvals(A,C)) returns the generalized eigenvalues of A and C in inert mode.
  • maple(eigenvals(A,'implicit')) returns the eigenvalues of A in the form of RootOf expressions for algebraic extensions.
  • maple('eigenvals(A,'radical')') returns the eigenvalues of A in exact radical form.
  • maple('eigenvects(A)') returns the eigenvectors of the matrix A.
  • maple('eigenvects(A,'implicit')') returns the eigenvectors of A in the form of RootOf expressions for algebraic extensions.
  • maple('eigenvects(A,'radical')') returns the eigenvectors of A in exact radical form.
  • maple('charmat(A,lambda)') returns the characteristic matrix of A as a function of lambda, whose value is M = lambda * I - A.
  • maple('charpoly(A,expr)') returns the characteristic polynomial of A according to expr, whose value is det(expr * I - A).
  • maple('minpoly(A,x)') returns the minimal polynomial of A in the variable x. The minimal polynomial of A is the polynomial p(x) of least degree such that p(A) = 0.
  • maple('jordan(A)') returns the canonical Jordan form J of the matrix A. J has the eigenvalues of A on its diagonal.
  • maple('jordan(A,'P')') returns the matrix P whose columns are the eigenvectors of A and the canonical Jordan form J of the matrix A, such that evalm(P-1 & * A & * P) = J.
  • maple('JordanBlock(expr,n)') creates the Jordan block matrix with the elements of the main diagonal given by expr.
  • maple('Svd(A)') returns an array of the singular values of A.
  • maple('Svd(A,V,left)') returns an array with singular values of A and the array V with the singular values to the left.
  • maple('Svd(A,V,right)') returns an array with singular values of A and the array V with the singular values to the right.
  • condeig(A) returns a vector with the condition numbers for the eigenvalues of the matrix A.
  • [V,D,s] = condeig(A)equals [V,D] = eig(A) and s = condeig(A).
  • maple(Svd(A,U,V)) gives the square matrices U and V such that evalm(transpose(U) & * V) = D, where D is a matrix whose diagonal entries are the singular values of A. If A is square, all arrays are square and of the same size. If A is of dimension (n, p), then U is (n, n), V is (p, p) and D is (n, p).
  • definite(A,option) determines whether the matrix A is positive definite, positive semi-definite, negative definite, or negative semi-definite for the respective values of the option given by positive_def, positive_semidef, negative_def or negative_semidef.

EXERCISE 4-7

Given the matrix

image

calculate its eigenvalues, its characteristic polynomial, its Jordan canonical form, its minimal polynomial, its characteristic matrix and its singular values.

We start by defining the matrix A as a symbolic matrix:

>> A = sym ('[1 0 0; 0 cos(a) -sin(a); 0 sin(a) cos(a)]')

A =

[1,     0,      0]
[0,cos(a),-sin(a)]
[0,sin(a), cos(a)]

>> eigensys(A)

ans =

[                             1]
[cos(a) + 1/2 * (- 4 * sin(a) ^ 2) ^(1/2)]
[cos(a) - 1/2 * (- 4 * sin(a) ^ 2) ^(1/2)]

>> pretty(simple(poly(A)))

                    3      2               2
                   x - 2 x cos (a) + x - x + 2 x cos (a) - 1

>> jordan(A)

ans =

[1, 0,                                         0]
[0, cos(a) + 1/2 * (- 4 * sin(a) ^ 2) ^ (1/2), 0]
[0, 0, cos(a) - 1/2 * (- 4 * sin(a) ^ 2) ^(1/2)]

>> simple(Svd(A))

ans =

[                                                              1]
[1/2 * (4 * cos(a-comp(a)) + 2 * (- 2 + 2 * cos(2 * a-2 * conj(a))) ^(1/2)) ^(1/2)]
[1/2 * (4 * cos(a-comp(a)) - 2 * (- 2 + 2 * cos(2 * a-2 * conj(a))) ^(1/2)) ^(1/2)]

>> pretty(simple(sym(maple('minpoly(matrix [[1, 0, 0], [0, cos(a), - sin(a)], [0, sin(a), cos(a)]]), x)'))))

                                            2           2    3
                  -1 + 2 x cos (a) + x - 2 x cos (a) - x + x

>> pretty(simple(sym(maple('charmat(matrix([[1, 0, 0], [0, cos(a), -sin(a)], [0, sin(a), cos(a)]]), x)'))))

                      [x - 1        0             0     ]
                      [                                 ]
                      [0       x - cos(a)         sin(a)]
                      [                                 ]
                      [0         - sin(a) x     - cos(a)]

EXERCISE 4-8

Consider the symbolic fifth-order square matrix whose (i,j)th element is defined by Aij = 1 /(i+j-1/2). Compute its eigenvalues, eigenvectors, characteristic polynomial, minimum polynomial, characteristic matrix, and singular values. Also find the vector of the condition numbers of the eigenvalues and analyze whether the matrix is positive definite, negative definite, positive semi-definite or negative semi-definite.

MATLAB enables you to define this type of symbolic matrix in the general form:

>> A = sym(maple('matrix(5,5,(i,j)-> 1/(i+j-1/2))'))

A =

[2/3, 2/5, 2/7, 2/9, 2/11]
[2/5, 2/7, 2/9, 2/11, 2/13]
[2/7, 2/9, 2/11, 2/13, 2/15]
[2/9, 2/11, 2/13, 2/15, 2/17]
[2/11, 2/13, 2/15, 2/17, 2/19]

>> [V,E] = eig(A)

V =

[-.1612e-1, -.6740e-2,  .3578,  2.482,  -288.7]
[    .2084,     .1400, -2.513, -15.01,   2298.]
[   -.7456,    -.6391,  3.482,  20.13,  -3755.]
[        1,         1,      1,      1,       1]
[   -.4499,    -.5011, -2.476, -8.914,   1903.]

E =

[  2/55*.4005e-4,              0,              0,              0,              0]
[              0, 2/55* .3991e-2,              0,              0,              0]
[              0,              0,    2/55* .1629,              0,              0]
[              0,              0,              0,    2/55* 3.420,              0]
[              0,              0,              0,              0,    2/55* 34.16]

As we know, the eigenvectors are the columns of the matrix V, and the eigenvalues are the elements of the diagonal of the matrix E.

>> pretty(simple(poly(A)))

5   10042  4   362807509088   3    268537284608    2
x  - ----- x  + ------------- x  - --------------- x
     7315      2228304933855       285965799844725

          22809860374528               34359738368
     + --------------------- x - ------------------------
       169975437532179654375     177624332221127738821875

We can approximate this output as follows:

>> pretty(simple(vpa(poly(A))))

       5          4          3             2           -6             -12
      x  - 1.373 x  + .1628 x  - .0009391 x  + .1342 10   x - .1934 10

The singular values are calculated in the following way:

>> pretty(simple(Svd (A)))

                                 [        -5]
                                 [.1456 10  ]
                                 [          ]
                                 [.0001451  ]
                                 [          ]
                                 [.005923   ]
                                 [          ]
                                 [.1244     ]
                                 [          ]
                                 [1.242     ]

The minimal polynomial and the characteristic matrix are calculated in the following way:

>> pretty(simple(sym(maple('minpoly(matrix(5,5,(i,j)-> 1/(i+j-1/2)),x)'))))

        34359738368             22809860374528          268537284608    2
- ------------------------ + --------------------- x - --------------- x
  177624332221127738821875   169975437532179654375     285965799844725

       362807509088   3   10042  4    5
     + ------------- x  - ----- x  + x
       2228304933855      7315

>> pretty(simple(sym(vpa(maple('minpoly(matrix(5,5,(i,j)->1/(i+j-1/2)),x)')))))

              -12           -6               2          3          4    5
     -.1934 10    + .1342 10   x - .0009391 x  + .1628 x  - 1.373 x  + x

>> pretty(simple(sym(maple('charmat(matrix(5,5,(i,j)-> 1/(i+j-1/2)),x)'))))

           [                                                 -2   ]
           [x - 2/3     -2/5        -2/7        -2/9         --   ]
           [                                                 11   ]
           [                                                      ]
           [                                     -2          -2   ]
           [-2/5      x - 2/7      -2/9         --          --   ]
           [                                     11          13   ]
           [                                                      ]
           [                                     -2          -2   ]
           [-2/7       -2/9      x - 2/11       --          --   ]
           [                                     13          15   ]
           [                                                      ]
           [             -2          -2                      -2   ]
           [-2/9        --          --       x - 2/15       --   ]
           [             11          13                      17   ]
           [                                                      ]
           [  -2         -2          -2          -2               ]
           [  --         --          --          --       x - 2/19]
           [  11         13          15          17               ]

The vector of condition numbers of the eigenvalues is calculated as follows:

>> condeig(numeric(A))

ans =

    1.0000
    1.0000
    1.0000
    1.0000
    1.0000

In a more complete way, can calculate the matrix V whose columns are the eigenvectors of A, the diagonal matrix D whose diagonal elements are the eigenvalues of A, and the vector S of condition numbers of the eigenvalues of A, by using the command:

>> [V,D,s] = condeig(numeric(A))

V =
    0.0102    0.0697    0.2756   -0.6523    0.7026
   -0.1430   -0.4815   -0.7052    0.1593    0.4744
    0.5396    0.6251   -0.2064    0.3790    0.3629
   -0.7526    0.2922    0.2523    0.4442    0.2954
    0.3490   -0.5359    0.5661    0.4563    0.2496

D =
    0.0000         0         0         0         0
         0    0.0001         0         0         0
         0         0    0.0059         0         0
         0         0         0    0.1244         0
         0         0         0         0    1.2423
s =
    1.0000
    1.0000
    1.0000
    1.0000
    1.0000

The matrix A is positive definite according to the command definite:

>> maple('definite(matrix(5,5,(i,j)-> 1/(i+j-1/2)),positive_def)')

ans =

true

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset