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:
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.
EXERCISE 4-1
Given the following matrices
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):
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:
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:
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:
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:
>> 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:
EXERCISE 4-6
Consider the following matrix:
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:
EXERCISE 4-7
Given the matrix
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