Matrices-Unit23.mws

MATRICES AND MATRIX OPERATIONS: Unit 23

Dr. Wlodzislaw Kostecki

The Papua New Guinea University of Technology (PNGUT)

Department of Electrical and Communication Engineering

Lae, Morobe Province

Papua New Guinea

Copyright © 2000 by Wlodzislaw Kostecki

All rights reserved

-------------------------------------------------------------------

(23) Functions of constant matrices

OBJECTIVES :

To provide essential information concerning expansion of functions of one variable using Taylor’ s and Maclaurin’ s series.

To introduce the concepts of an interval and circle of convergence of a series representing a function of a real and complex variable, respectively.

To provide definitions of the matrix series for real-valued and complex-valued matrices, based on the Maclaurin series.

To state the condition necessary for Maclaurin’ s series of a square matrix to be absolutely convergent.

To introduce the concept of a well-defined function of a matrix.

To provide a list of some common functions together with the interval of convergence of their corresponding Maclaurin’ s series for reference.

To provide a reference example of computation of a trigonometric function of a real and complex variable using infinite Taylor’ s series.

To introduce the only built-in function exponential for computation of the exponential function of matrices.

To provide six step-by-step solved examples for computation of functions of matrices with real and complex elements using truncated Maclaurin’ s series.

To show how to pre-process a matrix containing transcendental numbers to significantly reduce the computation time of its function.

To examine six common functions of the zero matrix.

To show how to obtain the exact result of the exponential function of the unit matrix and examine two other functions of this matrix.

To examine seven cases of exponentiation of the imaginary unit matrix multiplied by some scalars involving the various multiplicities of the imaginary unit.

To show how to make use of the Cayley-Hamilton theorem for computation of matrix functions.

To provide three step-by-step solved examples for computation of functions of matrices with real elements using a method based on the Cayley-Hamilton theorem and verify the results using the truncated Maclaurin’ s series.

To state the necessary conditions that a matrix must satisfy in order that its square root be unique .

To provide two step-by-step solved examples for computation of the square root of real and complex matrices using the method based on the Cayley-Hamilton theorem and verify the results using the truncated Maclaurin’ s series.

To determine the conditions that a matrix must satisfy in order that its unique square root could be computed in an alternative manner using the functions natural logarithm and exponential.

To provide a number of variants of the various square matrices of second order that are each a non-unique square root of the unit matrix of the same order.

To provide two step-by-step solved examples for computation of functions of diagonal matrices with real elements using similarity of matrices and verify the results using the truncated Maclaurin’ s series.

To provide four step-by-step solved examples for computation of functions of non-diagonal real matrices with distinct eigenvalues using similarity of matrices and verify the results using the truncated Maclaurin’ s series.

> restart : with(linalg, augment, coldim, definite, diag, eigenvals, eigenvects, exponential, inverse, jordan, matadd, rowdim) :

Functions of matrices are defined only for square matrices.

This Unit deals with computation of functions for constant matrices whose elements are real or complex numbers.

Consider a function of a real variable, f(x) , and a function of a complex variable, f(z) , and assume that either function has a Taylor series expansion about the points x[0] and z[0] , respectively, given by

f(x) = Sum(a[n]*(x-x[0])^n,n = 0 .. infinity) and f(z) = Sum(a[n]*(z-z[0])^n,n = 0 .. infinity)

Suppose that there is an interval [x[0]-r, x[0]+r] with the central point at x[0] and end points at -r and r , within which the series representing f(x) is absolutely convergent for all values of x , i.e. those which satisfy the inequality abs(x-x[0]) < r .

Suppose that there is a circle in the complex plane with the centre at z[0] , radius R , and equation abs(z-z[0]) = R , within which the series representing f(z) is absolutely convergent for all values of z , i.e. those which satisfy the inequality abs(z-z[0]) < R .

Setting, for convenience, x[0] = 0 and z[0] = 0 in the above Taylor’ s series yields the Maclaurin series, viz.

f(x) = Sum(a[n]*x^n,n = 0 .. infinity) and f(z) = Sum(a[n]*z^n,n = 0 .. infinity)

Similarly as for Taylor’ s series, it may be assumed that the Maclaurin series representing f(x) is absolutely convergent for abs(x) < r and the series representing f(z) is absolutely convergent for abs(z) < R .

The definitions of the matrix series for a real-valued matrix [ A ] and a complex-valued matrix [ Z ] are based on the Maclaurin series, viz.

f(A) = Sum(a[n]*A^n,n = 0 .. infinity) and f(Z) = Sum(a[n]*Z^n,n = 0 .. infinity)

Either series is absolutely convergent if the absolute value or modulus of every eigenvalue lambda[i][A] of [ A ] or the modulus of every eigenvalue lambda[i][Z] of [ Z ] satisfies the respective condition

abs(lambda[i][A]) < r or abs(lambda[i][Z]) < R

In such a case, the functions f( [ A ] ) and f( [ Z ] ) are said to be well defined for the matrix and may be computed using a suitable matrix series.

Maple has built-in procedures for computation of infinite Taylor’ s series of functions of one variable. For example, it uses the following series in computing cos(x) :

> `cos(x)` := Sum((-1)^n*x^(2*n)/(2*n)!, n=0..infinity) : cos(x) = `cos(x)` ; Cos(x) := `cos(x)` :

cos(x) = Sum((-1)^n*x^(2*n)/(2*n)!,n = 0 .. infinit...

Maple evaluates this series to an internally adopted accuracy and returns the result with the number of digits determined by the environment variable Digits (the default is 10 ). For example, set x = 2.7 and z = 2.7+1.2*I and compute cos(x) and cos(z) to 15 digits. Thus,

> Digits := 15 : x := 2.7 : `cos(x)` := evalf(`cos(x)`) : x := 'x' : cos(x) = `cos(x)` ; z := 2.7 + 1.2*I : `cos(z)` := evalf(subs(x=z, Cos(x))) : z := 'z' : cos(z) = `cos(z)` ; Digits := 10 :

cos(x) = -.904072142017061

cos(z) = -1.63696325720606-.645113413293649*I

No such built-in procedures exist in Maple for computation of matrix functions. The only exception is the exponential function, which is accessible through the linalg package.

Therefore, where computation of a matrix function is involved, the series must be truncated. The number of series terms adopted should result from a compromise between the computation time and required accuracy.

It is appropriate to list at this point some common functions together with the interval of convergence of their corresponding Maclaurin’ s series, which will be a good indication whether the sought-for function can be computed for a given matrix once its eigenvalues have been determined.

Although functions of a real variable x are shown together with the convergence interval of their series, substitute x with z and the term " interval of convergence " with " circle of convergence " where complex-numbered matrices are involved. If a real-valued matrix has complex eigenvalues, the designation f(x) still holds but the circle of convergence comes into play.

(1) Functions whose series is convergent for every x , i.e. having convergence interval abs(x) < infinity . These functions are well defined for every square matrix:

sin(x) , cos(x) , exp(x) , a^x = exp(x*ln(a)) , sinh(x) , cosh(x)

(2) Functions with convergence interval abs(x) < Pi/2

sec(x) , sech(x) , tan(x) , tanh(x)

(3) Functions with convergence interval 0 < abs(x) < Pi

cot(x) , csc(x) , coth(x) , csch(x)

(4) Functions with convergence interval abs(x) < 1

arcsin(x) , arccos(x) , arctan(x) , arccot(x) , arcsinh(x) , arctanh(x)

(5) Function with convergence interval 1 < abs(x)

arccoth(x)

(6) Function with convergence interval 1 < x

arccosh(x)

(7) Function with convergence interval 0 < x <= 2

ln(x) as given by the series ln(x) = Sum((-1)^(n+1)/n*(x-1)^n,n = 1 .. infinity)...

Note that there are also other series representations of ln(x) with their respective, different convergence intervals .

Apart from computation of matrix functions based on the Maclaurin series representation of a given function, there are two other methods that may be used for this purpose. One of them is based on the Cayley-Hamilton theorem [refer to Unit (21)] and the other on similarity of matrices [refer to Unit (22)].

All the three methods together with illustrating examples are presented in Sections A , B , and C of this Unit.

A. Computation of matrix functions using the Maclaurin series

Below presented are examples for computation of several different matrix functions with the use of this method.

Example 1

Compute the natural logarithm of ( 2 × 2 ) matrices [ A ] and [ B ] given as

> A := matrix(2, 2, [2, 3, 0, 2]) : B := matrix(2, 2, [1, -2, 1, 2]) : A = matrix(A) ; B = matrix(B) ;

A = matrix([[2, 3], [0, 2]])

B = matrix([[1, -2], [1, 2]])

Step 1 . Find the eigenvalues of either matrix:

for matrix [ A ]

> charroots(A) := eigenvals(A) : char_roots(A) = charroots(A) ;

char_roots(A) = (2, 2)

Since neither of the characteristic roots is greater than 2 , the function ln( [ A ] ) is well defined for this matrix and may be computed.

for matrix [ B ]

> charroots(B) := eigenvals(B) : char_roots(B) = charroots(B) ;

char_roots(B) = (3/2+1/2*I*sqrt(7), 3/2-1/2*I*sqrt(...

> root1(B) := charroots(B)[1] : char_root[1](B) = root1(B) ;

char_root[1](B) = 3/2+1/2*I*sqrt(7)

> `abs(root1(B))` := abs(root1(B)) : Abs(char_root[1](B)) = `abs(root1(B))` ;

Abs(char_root[1](B)) = 2

Since the modulus of neither characteristic root is greater than 2 , the function ln( [ A ] ) is well defined for this matrix and may be computed.

Step 2 . Write the expression for a Maclaurin’ s series representing the function ln(x) , substitute the matrix names for x , and replace subtrahend 1 with the name of the unit matrix [ U ]:

> `ln(A)` := subs((x-1)=(A-U), Sum((-1)^(n+1)*(x-1)^n/n, n=1..infinity)) : ln(A) = `ln(A)` ;

ln(A) = Sum((-1)^(n+1)*(A-U)^n/n,n = 1 .. infinity)...

> `ln(B)` := subs((x-1)=(B-U), Sum((-1)^(n+1)*(x-1)^n/n, n=1..infinity)) : ln(B) = `ln(B)` ;

ln(B) = Sum((-1)^(n+1)*(B-U)^n/n,n = 1 .. infinity)...

Step 3 . Bearing in mind that the unit matrix [ U ] appropriately sized for this case is

> U := diag(1, 1) : U = matrix(U) ;

U = matrix([[1, 0], [0, 1]])

substitute either matrix with its numerical values and the unit matrix:

> `ln(A)` := subs(A=matrix(A), U=matrix(U), `ln(A)`) : ln(A) = `ln(A)` ;

ln(A) = Sum((-1)^(n+1)*(matrix([[2, 3], [0, 2]])-ma...

> `ln(B)` := subs(B=matrix(B), U=matrix(U), `ln(B)`) : ln(B) = `ln(B)` ;

ln(B) = Sum((-1)^(n+1)*(matrix([[1, -2], [1, 2]])-m...

Step 4 . Evaluate the function of either matrix after truncating the series to the first 50 terms:

> `ln(A)` := evalf(evalm(sum((-1)^(n+1)*(A - U)^n/n, n=1..50))) : ln(A) = matrix(`ln(A)`) ;

ln(A) = matrix([[.6832471606, 0.], [0., .6832471606...

> `ln(B)` := evalf(evalm(sum((-1)^(n+1)*(B - U)^n/n, n=1..50))) : ln(B) = matrix(`ln(B)`) ;

ln(B) = matrix([[-32730.04511, -680944.7902], [3404...

Example 2

Compute the cosine of ( 2 × 2 ) matrices [ A ] and [ Z ] given as

> A := matrix(2, 2, [2, 4, 1, 2]) : Z := matrix(2, 2, [1+5*I, 2-4*I, 3+2*I, 1-2*I]) :

> A = matrix(A) ; Z = matrix(Z) ;

A = matrix([[2, 4], [1, 2]])

Z = matrix([[1+5*I, 2-4*I], [3+2*I, 1-2*I]])

Step 1 . Find the eigenvalues of either matrix:

for matrix [ A ]

> charroots(A) := eigenvals(A) : char_roots(A) = charroots(A) ;

char_roots(A) = (0, 4)

for matrix [ Z ]

> charroots(Z) := eigenvals(Z) : char_roots(Z) = charroots(Z) ;

char_roots(Z) = (1+3/2*I+1/2*sqrt(7-32*I), 1+3/2*I-...

> root1(Z) := charroots(Z)[1] : char_root[1](Z) = root1(Z) ;

char_root[1](Z) = 1+3/2*I+1/2*sqrt(7-32*I)

> `abs(root1(Z))` := evalf(abs(root1(Z))) : Abs(char_root[1](Z)) = `abs(root1(Z))` ;

Abs(char_root[1](Z)) = 3.242641258

Note that this step is not necessary since the series of cos(x) is convergent for all x , which implies that cos( [ A ] ) is well defined for every square matrix. Similarly, the series of cos(z) is convergent for all z , which implies that cos( [ Z ] ) is well defined for every complex-valued square matrix.

Step 2 . Write the expression for a Maclaurin’ s series representing the function cos(x) and cos(z) and substitute the matrix names [ A ] and [ Z ] for x and z , respectively:

> `cos(A)` := subs(x=A, Sum((-1)^n*x^(2*n)/(2*n)!, n=0..infinity)) : cos(A) = `cos(A)` ;

cos(A) = Sum((-1)^n*A^(2*n)/(2*n)!,n = 0 .. infinit...

> `cos(Z)` := subs(x=Z, Sum((-1)^n*x^(2*n)/(2*n)!, n=0..infinity)) : cos(Z) = `cos(Z)` ;

cos(Z) = Sum((-1)^n*Z^(2*n)/(2*n)!,n = 0 .. infinit...

N.B. Maple returns the first term of either series as the scalar value one , according to the result of the following computation performed exemplarily for the matrix [ A ]:

> `A^0` := evalm(A^0) : A ^ `0` = `A^0` ;

A^`0` = 1

Therefore, still with [ A ] as an example, the corresponding series for n = 0 to, e.g., n = 5 would be of the form

> cos(A) = subs(x=A, sum((-1)^n*x^(2*n)/(2*n)!, n=0..5)) ;

cos(A) = 1-1/2*A^2+1/24*A^4-1/720*A^6+1/40320*A^8-1...

in which the first term is the algebraic number 1 .

However, adhering to the common literature convention that [ A ] ^ 0 = [ U ], the first term of the series should be the unit matrix [ U ]. To obtain this result, the original expression for the series is modified by

(a) replacing n = 0 with n = 1 in the sum function, and

(b) adding the unit matrix [ U ] as the first term of the series representation of the matrix function.

Consequently, the following expressions are adopted in this case:

> `cos(A)` := U + subs(x=A, Sum((-1)^n*x^(2*n)/(2*n)!, n=1..infinity)) : cos(A) = `cos(A)` ;

cos(A) = U+Sum((-1)^n*A^(2*n)/(2*n)!,n = 1 .. infin...

> `cos(Z)` := U + subs(x=Z, Sum((-1)^n*x^(2*n)/(2*n)!, n=1..infinity)) : cos(Z) = `cos(Z)` ;

cos(Z) = U+Sum((-1)^n*Z^(2*n)/(2*n)!,n = 1 .. infin...

Step 3 . With the unit matrix as in Example 1, substitute the matrix names with their corresponding numerical structures:

> `cos(A)` := subs(U=matrix(U), A=matrix(A), `cos(A)`) : cos(A) = `cos(A)` ;

cos(A) = matrix([[1, 0], [0, 1]])+Sum((-1)^n*matrix...

> `cos(Z)` := subs(U=matrix(U), Z=matrix(Z), `cos(Z)`) : cos(Z) = `cos(Z)` ;

cos(Z) = matrix([[1, 0], [0, 1]])+Sum((-1)^n*matrix...

Step 4 . Evaluate the function of either matrix after truncating the series to the first 50 terms:

> `cos(A)` := evalf(evalm(U + sum((-1)^n*A^(2*n)/(2*n)!, n=1..50))) : cos(A) = matrix(`cos(A)`) ;

cos(A) = matrix([[.1731781896, -1.653643621], [-.41...

> `cos(Z)` := evalf(evalm(U + sum((-1)^n*Z^(2*n)/(2*n)!, n=1..50))) : cos(Z) = matrix(`cos(Z)`) ;

cos(Z) = matrix([[9.927559856+8.553052063*I, -8.085...

Example 3

Compute the exponential function of the ( 2 × 2 ) matrices [ A ] and [ Z ] given as before.

Step 1 . Find the eigenvalues of either matrix:

This step is not necessary since the series of exp(x) is convergent for all x , which implies that exp( [ A ] ) is well defined for every square matrix. Likewise, the series of exp(z) is convergent for all z , which implies that exp( [ Z ] ) is well defined for every square matrix with complex-numbered elements.

Step 2 . Write the expression for a Maclaurin’ s series representing the function exp(x) and exp(z) and substitute the matrix names [ A ] and [ Z ] for x and z , respectively:

> `exp(A)` := subs(x=A, Sum(x^n/n!, n=0..infinity)) : exp(A) = `exp(A)` ;

exp(A) = Sum(A^n/n!,n = 0 .. infinity)

> `exp(Z)` := subs(x=Z, Sum(x^n/n!, n=0..infinity)) : exp(Z) = `exp(Z)` ;

exp(Z) = Sum(Z^n/n!,n = 0 .. infinity)

N.B. Like in Example 2, Maple returns the first term of either series as the scalar value one . With the matrix [ A ] as an example, the corresponding series for n = 0 to, e.g., n = 5 would be of the form

> exp(A) = subs(x=A, sum(x^n/n!, n=0..5)) ;

exp(A) = 1+A+1/2*A^2+1/6*A^3+1/24*A^4+1/120*A^5

For the reasons set forth in Example 2, the following expressions are adopted in this case:

> `exp(A)` := U + subs(x=A, Sum(x^n/n!, n=1..infinity)) : exp(A) = `exp(A)` ;

exp(A) = U+Sum(A^n/n!,n = 1 .. infinity)

> `exp(Z)` := U + subs(x=Z, Sum(x^n/n!, n=1..infinity)) : exp(Z) = `exp(Z)` ;

exp(Z) = U+Sum(Z^n/n!,n = 1 .. infinity)

Step 3 . With the unit matrix as in Example 1, substitute the matrix names with their corresponding numerical structures:

> `exp(A)` := subs(U=matrix(U), A=matrix(A), `exp(A)`) : exp(A) = `exp(A)` ;

exp(A) = matrix([[1, 0], [0, 1]])+Sum(matrix([[2, 4...

> `exp(Z)` := subs(U=matrix(U), Z=matrix(Z), `exp(Z)`) : exp(Z) = `exp(Z)` ;

exp(Z) = matrix([[1, 0], [0, 1]])+Sum(matrix([[1+5*...

Step 4 . Evaluate the function of either matrix after truncating the series to the first 50 terms:

> `exp(A)` := evalf(evalm(U + sum(A^n/n!, n=1..50))) : exp(A) = matrix(`exp(A)`) ;

exp(A) = matrix([[27.79907502, 53.59815003], [13.39...

> `exp(Z)` := evalf(evalm(U + sum(Z^n/n!, n=1..50))) : exp(Z) = matrix(`exp(Z)`) ;

exp(Z) = matrix([[6.032081539+10.76071605*I, 15.010...

* * *

N.B. The exponential function of a square matrix may be computed in Maple directly , using the built-in exponential function. For the matrices of Example 3, it yields

> `exp(A)` := evalf(exponential(A)) : exp(A) = matrix(`exp(A)`) ;

exp(A) = matrix([[27.79907502, 53.59815003], [13.39...

> `exp(Z)` := evalf(exponential(Z)) : exp(Z) = matrix(`exp(Z)`) ;

exp(Z) = matrix([[5.452295902+11.20250976*I, 15.010...

Notice that computation using the exponential function is much faster.

[ Refer also to Units (24), (25), and (30) in which examples for the major applications of the exponential function are given. ]

* * *

Example 4

Compute the arc tangent of ( 2 × 2 ) matrices [ A ] and [ B ] given as

> A := matrix(2, 2, [1/3, -2/7, -1/6, 2/3]) : B := matrix(2, 2, [1/3, -2/7, 1/6, 2/3]) :

> A = matrix(A) ; B = matrix(B) ;

A = matrix([[1/3, -2/7], [-1/6, 2/3]])

B = matrix([[1/3, -2/7], [1/6, 2/3]])

Step 1 . Find the eigenvalues of either matrix:

for matrix [ A ]

> charroots(A) := eigenvals(A) : char_roots(A) = charroots(A) ;

char_roots(A) = (1/2+1/42*sqrt(133), 1/2-1/42*sqrt(...

> root1(A) := charroots(A)[1] : root2(A) := charroots(A)[2] :

> char_root[1](A) = root1(A) ; char_root[2](A) = root2(A) ;

char_root[1](A) = 1/2+1/42*sqrt(133)

char_root[2](A) = 1/2-1/42*sqrt(133)

> `abs(root1(A))` := evalf(abs(root1(A))) : `abs(root2(A))` := evalf(abs(root2(A))) :

> Abs(char_root[1](A)) = `abs(root1(A))` ; Abs(char_root[2](A)) = `abs(root2(A))` ;

Abs(char_root[1](A)) = .7745848238

Abs(char_root[2](A)) = .2254151762

Since either of the characteristic roots is smaller than 1 , the function arctan( [ A ] ) is well defined for this matrix and may be computed.

for matrix [ B ]

> charroots(B) := eigenvals(B) : char_roots(B) = charroots(B) ;

char_roots(B) = (1/2+1/42*I*sqrt(35), 1/2-1/42*I*sq...

> root1(B) := charroots(B)[1] : root2(B) := charroots(B)[2] :

> char_root[1](B) = root1(B) ; char_root[2](B) = root2(B) ;

char_root[1](B) = 1/2+1/42*I*sqrt(35)

char_root[2](B) = 1/2-1/42*I*sqrt(35)

> `abs(root1(B))` := evalf(abs(root1(B))) : Abs(char_root[1](B)) = `abs(root1(B))` ;

Abs(char_root[1](B)) = .5194624819

Since the modulus of either characteristic root is less than 1 , the function arctan( [ B ] ) is well defined for this matrix and may be computed.

Step 2 . Write the expression for a Maclaurin’ s series representing the function arctan(x) and substitute the matrix names [ A ] and [ B ] for x :

> `arctan(A)` := subs(x=A, Sum((-1)^n*x^(2*n+1)/(2*n+1), n=0..infinity)) : arctan(A) = `arctan(A)` ;

arctan(A) = Sum((-1)^n*A^(2*n+1)/(2*n+1),n = 0 .. i...

> `arctan(B)` := subs(x=B, Sum((-1)^n*x^(2*n+1)/(2*n+1), n=0..infinity)) : arctan(B) = `arctan(B)` ;

arctan(B) = Sum((-1)^n*B^(2*n+1)/(2*n+1),n = 0 .. i...

Step 3 . Substitute the matrix names with their corresponding numerical structures:

> `arctan(A)` := subs(A=matrix(A), `arctan(A)`) : arctan(A) = `arctan(A)` ;

arctan(A) = Sum((-1)^n*matrix([[1/3, -2/7], [-1/6, ...

> `arctan(B)` := subs(B=matrix(B), `arctan(B)`) : arctan(B) = `arctan(B)` ;

arctan(B) = Sum((-1)^n*matrix([[1/3, -2/7], [1/6, 2...

Step 4 . Evaluate the function of either matrix after truncating the series to the first 50 terms:

> `arctan(A)` := evalf(evalm(sum((-1)^n*A^(2*n+1)/(2*n+1), n=0..50))) :

> arctan(A) = matrix(`arctan(A)`) ;

arctan(A) = matrix([[.3076521293, -.2275336730], [-...

> `arctan(B)` := evalf(evalm(sum((-1)^n*B^(2*n+1)/(2*n+1), n=0..50))) :

> arctan(B) = matrix(`arctan(B)`) ;

arctan(B) = matrix([[.3365882789, -.2288044034], [....

Example 5

Compute the arc tangent of ( 2 × 2 ) matrices [ A ] and [ Z ] given as

> A := matrix(2, 2, [0.2, -0.4, 0.1, 0.3]) : Z := matrix(2, 2, [0.1+0.5*I, 0.2-0.4*I, 0.3+0.2*I, 0.1-0.2*I]) :

> A = matrix(A) ; Z = matrix(Z) ;

A = matrix([[.2, -.4], [.1, .3]])

Z = matrix([[.1+.5*I, .2-.4*I], [.3+.2*I, .1-.2*I]]...

Step 1 . Find the eigenvalues of either matrix:

for matrix [ A ]

> charroots(A) := eigenvals(A) : char_roots(A) = charroots(A) ;

char_roots(A) = (.2500000000+.1936491673*I, .250000...

> root1(A) := charroots(A)[1] : root2(A) := charroots(A)[2] :

> char_root[1](A) = root1(A) ; char_root[2](A) = root2(A) ;

char_root[1](A) = .2500000000+.1936491673*I

char_root[2](A) = .2500000000-.1936491673*I

> `abs(root1(A))` := abs(root1(A)) : Abs(char_root[1](A)) = `abs(root1(A))` ;

Abs(char_root[1](A)) = .3162277660

Since the modulus of either characteristic root is less than 1 , the function arctan( [ A ] ) is well defined for this matrix and may be computed.

for matrix [ Z ]

> charroots(Z) := eigenvals(Z) : char_roots(Z) = charroots(Z) ;

char_roots(Z) = (-.1229256567+.3294320162*I, .32292...

> root1(Z) := charroots(Z)[1] : root2(Z) := charroots(Z)[2] :

> char_root[1](Z) = root1(Z) ; char_root[2](Z) = root2(Z) ;

char_root[1](Z) = -.1229256567+.3294320162*I

char_root[2](Z) = .3229256568-.2943201602e-1*I

> `abs(root1(Z))` := abs(root1(Z)) : `abs(root2(Z))` := abs(root2(Z)) :

> Abs(char_root[1](Z)) = `abs(root1(Z))` ; Abs(char_root[2](Z)) = `abs(root2(Z))` ;

Abs(char_root[1](Z)) = .3516193544

Abs(char_root[2](Z)) = .3242641260

Since the modulus of either characteristic root is less than 1 , the function arctan( [ Z ] ) is well defined for this matrix and may be computed.

Step 2 . Write the expression for a Maclaurin’ s series representing the function arctan(x) and arctan(z) and substitute the matrix names [ A ] and [ Z ] for x and z , respectively:

> `arctan(A)` := subs(x=A, Sum((-1)^n*x^(2*n+1)/(2*n+1), n=0..infinity)) : arctan(A) = `arctan(A)` ;

arctan(A) = Sum((-1)^n*A^(2*n+1)/(2*n+1),n = 0 .. i...

> `arctan(Z)` := subs(x=Z, Sum((-1)^n*x^(2*n+1)/(2*n+1), n=0..infinity)) : arctan(Z) = `arctan(Z)` ;

arctan(Z) = Sum((-1)^n*Z^(2*n+1)/(2*n+1),n = 0 .. i...

Step 3 . Substitute the matrix names with their corresponding numerical structures:

> `arctan(A)` := subs(A=matrix(A), `arctan(A)`) : arctan(A) = `arctan(A)` ;

arctan(A) = Sum((-1)^n*matrix([[.2, -.4], [.1, .3]]...

> `arctan(Z)` := subs(Z=matrix(Z), `arctan(Z)`) : arctan(Z) = `arctan(Z)` ;

arctan(Z) = Sum((-1)^n*matrix([[.1+.5*I, .2-.4*I], ...

Step 4 . Evaluate the function of either matrix after truncating the series to the first 50 terms:

> `arctan(A)` := evalm(sum((-1)^n*A^(2*n+1)/(2*n+1), n=0..50)) : arctan(A) = matrix(`arctan(A)`) ;

arctan(A) = matrix([[.2060630137, -.3798899080], [....

> `arctan(Z)` := evalm(sum((-1)^n*Z^(2*n+1)/(2*n+1), n=0..50)) : arctan(Z) = matrix(`arctan(Z)`) ;

arctan(Z) = matrix([[.8841294886e-1+.5078360103*I, ...

Example 6

Compute the third power of sine of a ( 2 × 2 ) matrix [ A ] given as

> A := matrix(2, 2, [-3, 5, 1, 9]) : A = matrix(A) ;

A = matrix([[-3, 5], [1, 9]])

Step 1 . Find the eigenvalues of the matrix:

This step is not necessary since the series of sin(x) is convergent for all x , which implies that sin( [ A ] ) is well defined for every square matrix. So is {sin( [ A ] )}^3 and it may be computed.

Step 2 . Write the expression for a Maclaurin’ s series representing the function sin(x) and substitute the matrix name [ A ] for x :

> `sin(A)` := subs(x=A, Sum((-1)^n*x^(2*n+1)/(2*n+1)!, n=0..infinity)) : sin(A) = `sin(A)` ;

sin(A) = Sum((-1)^n*A^(2*n+1)/(2*n+1)!,n = 0 .. inf...

Step 3 . Substitute the matrix name with its corresponding numerical structure:

> `sin(A)` := subs(A=matrix(A), `sin(A)`) : sin(A) = `sin(A)` ;

sin(A) = Sum((-1)^n*matrix([[-3, 5], [1, 9]])^(2*n+...

Step 4 . Evaluate the matrix function after truncating the series to the first 50 terms:

> `sin(A)` := evalf(evalm(sum((-1)^n*A^(2*n+1)/(2*n+1)!, n=0..50))) : sin(A) = matrix(`sin(A)`) ;

sin(A) = matrix([[.2511027876, -.9249716118e-1], [-...

Step 5. Compute the third power of the matrix function:

> `(sin(A))^3` := evalm(`sin(A)` ^ 3) : (sin(A))^3 = matrix(`(sin(A))^3`) ;

sin(A)^3 = matrix([[.1674184341e-1, -.6744950864e-2...

N.B. Since Maclaurin’ s series representation of the function sin(x)^3 is known, viz.

> sin(x)^3 = (3/4)*Sum((-1)^n*(1-9^n)*x^(2*n+1)/(2*n+1)!, n=0..infinity) ;

sin(x)^3 = 3/4*Sum((-1)^n*(1-9^n)*x^(2*n+1)/(2*n+1)...

it may be used for direct computation of the function {sin( [ A ] )}^3 by following similar steps as above.

Evaluation of the matrix function after truncating the series to the first 50 terms yields the matrix

> `(sin(A))^3` := evalf(evalm((3/4)*sum((-1)^n*(1-9^n)*A^(2*n+1)/(2*n+1)!, n=0..50))) :

> (sin(A))^3 = matrix(`(sin(A))^3`) ;

sin(A)^3 = matrix([[.1674184340e-1, -.6744950862e-2...

which is practically equal to the matrix obtained by computing the third power of sin( [ A ] ) .

* * *

N.B. Various combinations of matrix functions may also be computed using the method based on Maclaurin’ s series representation of the functions concerned. Where each function in a combination has different convergence interval (or circle), the resultant function will be convergent within the narrowest interval.

Exemplarily, consider the product exp(x)*cos(x) where the series for either function is convergent for every x , i.e. has convergence interval abs(x) < infinity . Both functions are well defined for every square matrix and so is their product. Using the same matrix [ A ] as before, the exponential function, and the expression for cos( [ A ] ) obtained in Example 2 yields

> `exp(A) cos(A)` := evalm(evalf(exponential(A)) &* evalf(evalm(U + sum((-1)^n*A^(2*n)/(2*n)!, n=1..50)))) : exp(A)*cos(A) = matrix(`exp(A) cos(A)`) ;

exp(A)*cos(A) = matrix([[-381.6590378, -4733.365847...

* * *

N.B. Transcendental numbers in a matrix are normally accepted and processed by the sum function, but the computation time is prohibitive . As an example, consider a ( 2 × 2 ) matrix [ A ] given as

> A := matrix(2, 2, [exp(1), Pi, sin(Pi/9), sqrt(3)]) : A = matrix(A) ;

A = matrix([[exp(1), Pi], [sin(1/9*Pi), sqrt(3)]])

and compute the cosine of the matrix using the relevant series expression obtained in Example 2.

Please wait. The following computation will take several tens of seconds.

> `cos(A)` := evalf(evalm(U + sum((-1)^n*A^(2*n)/(2*n)!, n=1..50))) : cos(A) = matrix(`cos(A)`) ;

cos(A) = matrix([[-.5606188330, -1.980187549], [-.2...

Floating-point evaluation of the matrix elements before summation operations reduces the computation time significantly without any practical loss of accuracy, as demonstrated below.

> A := evalf(matrix(A)) : A = matrix(A) ;

A = matrix([[2.718281828, 3.141592654], [.342020143...

> `cos(A)` := evalf(evalm(U + sum((-1)^n*A^(2*n)/(2*n)!, n=1..50))) : cos(A) = matrix(`cos(A)`) ;

cos(A) = matrix([[-.560618831, -1.980187552], [-.21...

Notice the insignificant differences in the values of the elements of both resultant matrices for cos(A) . This is because of the floating-point evaluation of the elements of [ A ] prior to summation.

* * *

N.B. Notice the results of computation of some functions of the zero matrix [ 0 ]. Exemplarily, consider the ( 2 × 2 ) matrix:

> `0` := matrix(2, 2, [0, 0, 0, 0]) : 0 = matrix(`0`) ;

0 = matrix([[0, 0], [0, 0]])

> charroots(`0`) := eigenvals(`0`) : char_roots(0) = charroots(`0`) ;

char_roots(0) = (0, 0)

(1) The exponential function of [ 0 ] is the ( 2 × 2 ) unit matrix:

> `exp(0)` := eval(evalm(U + sum(`0`^n/n!, n=1..2))) : exp(`0`) = matrix(`exp(0)`) ;

exp(`0`) = matrix([[1, 0], [0, 1]])

or, using the exponential function,

> `exp(0)` := exponential(`0`) : exp(`0`) = matrix(`exp(0)`) ;

exp(`0`) = matrix([[1, 0], [0, 1]])

(2) The sine function of [ 0 ] is the same ( 2 × 2 ) zero matrix:

> `sin(0)` := eval(evalm(sum((-1)^n*`0`^(2*n+1)/(2*n+1)!, n=0..1))) : sin(`0`) = matrix(`sin(0)`) ;

sin(`0`) = matrix([[0, 0], [0, 0]])

(3) The cosine function of [ 0 ] is the ( 2 × 2 ) unit matrix:

> `cos(0)` := eval(evalm(U + sum((-1)^n*`0`^(2*n)/(2*n)!, n=1..2))) : cos(`0`) = matrix(`cos(0)`) ;

cos(`0`) = matrix([[1, 0], [0, 1]])

(4) The arc tangent function of [ 0 ] is the same ( 2 × 2 ) zero matrix:

> `arctan(0)`:=eval(evalm(sum((-1)^n*`0`^(2*n+1)/(2*n+1), n=0..1))) : arctan(`0`)=matrix(`arctan(0)`) ;

arctan(`0`) = matrix([[0, 0], [0, 0]])

(5) The hyperbolic sine function of [ 0 ] is the same ( 2 × 2 ) zero matrix:

> `sinh(0)` := eval(evalm(sum(`0`^(2*n+1)/(2*n+1)!, n=0..1))) : sinh(`0`) = matrix(`sinh(0)`) ;

sinh(`0`) = matrix([[0, 0], [0, 0]])

(6) The hyperbolic cosine function of [ 0 ] is the ( 2 × 2 ) unit matrix:

> `cosh(0)` := eval(evalm(U + sum(`0`^(2*n)/(2*n)!, n=1..2))) : cosh(`0`) = matrix(`cosh(0)`) ;

cosh(`0`) = matrix([[1, 0], [0, 1]])

Notice the number of series terms adopted in computation of the above functions of matrix [ 0 ]: n = 0...1 or n = 1...2. These numbers are sufficient because every term for 1 <= n equals zero , as shown exemplarily below for the functions exp( [ 0 ] ) and sinh( [ 0 ] ):

> exp(`0`) = matrix(U) + sum(matrix(`0`)^n/n!, n=1..2) ;

exp(`0`) = matrix([[1, 0], [0, 1]])+matrix([[0, 0],...

> sinh(`0`) = sum(matrix(`0`)^(2*n+1)/(2*n+1)!, n=0..2) ;

sinh(`0`) = matrix([[0, 0], [0, 0]])+1/6*matrix([[0...

* * *

N.B. Notice the result of computation of exp(U) with the unit matrix given as

> U := diag(1, 1) : U = matrix(U) ;

U = matrix([[1, 0], [0, 1]])

> charroots(U) := eigenvals(U) : char_roots(U) = charroots(U) ;

char_roots(U) = (1, 1)

> `exp(U)` := evalf(evalm(U + sum(U^n/n!, n=1..50))) : exp(U) = matrix(`exp(U)`) ;

exp(U) = matrix([[2.718281828, 0.], [0., 2.71828182...

The exact result of exp(U) may be obtained only if the exponential function is used, i.e.

> `exp(U)` := exponential(U) : exp(U) = matrix(`exp(U)`) ;

exp(U) = matrix([[exp(1), 0], [0, exp(1)]])

* * *

N.B. Notice the result of computation of ln( [ U ] ) with the unit matrix given as before:

> `ln(U)` := evalm(sum((-1)^(n+1)*(matadd(U, -U))^n/n, n=1..2)) : ln(U) = matrix(`ln(U)`) ;

ln(U) = matrix([[0, 0], [0, 0]])

* * *

N.B. Notice the result of computation of [ U ] ^(1/2) for the same unit matrix:

> `sqrt(U)` := exponential(`ln(U)`, 1/2) : U^`1/2` = matrix(`sqrt(U)`) ;

U^`1/2` = matrix([[1, 0], [0, 1]])

[ For details on computation of the function square root of a matrix, refer to Section B , Example 4. ]

* * *

N.B. Notice the following results of exponentiation of the ( 2 × 2 ) imaginary unit matrix [ IU ] multiplied by some scalars.

> IU := diag(I, I) : IU = matrix(IU) ;

IU = matrix([[I, 0], [0, I]])

> charroots(IU) := eigenvals(IU) : char_roots(IU) = charroots(IU) ;

char_roots(IU) = (I, I)

(1) The exponential function of [ IU ]:

> `exp(IU)` := exponential(IU) : exp(IU) = matrix(`exp(IU)`) ;

exp(IU) = matrix([[cos(1)+I*sin(1), 0], [0, cos(1)+...

or, as a floating-point approximation,

> exp(IU) = evalf(matrix(`exp(IU)`)) ;

exp(IU) = matrix([[.5403023059+.8414709848*I, 0.], ...

(2) The exponential function of the product of [ IU ] and the imaginary unit:

> `exp(IU I)` := exponential(IU*I) : exp(IU*I) = matrix(`exp(IU I)`) ;

exp(I*IU) = matrix([[exp(-1), 0], [0, exp(-1)]])

or, as a floating-point approximation,

>