Matrices-Unit3.mws

MATRICES AND MATRIX OPERATIONS: Unit 3

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

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

(3) Addition and subtraction of matrices

OBJECTIVES :

To define the operations of matrix addition and subtraction and state the addition conformability rule .

To provide alternative methods of matrix addition and subtraction with Maple .

To specify the laws obeyed by matrix addition and subtraction.

To introduce the concept of equal matrices.

To show how to add a scalar and a matrix.

To show how to add a scalar to each element of a matrix.

To show how to obtain with Maple the correct result of subtraction of a matrix from itself and introduce the concept of a zero or null matrix.

> restart : with(linalg, diag, matadd) :

A . Matrix addition

The matrices to be added must obey the addition conformability rule , which states:

"Two matrices can only be added together only if they are both of the same order."

Such matrices are called conformable or compatible for addition. If the matrices do not satisfy this rule, their sum is not defined (does not exist).

If two matrices to be added are [ A ] of order ( m × n ) with elements a[ij] and [ B ] of order ( m × n ) with elements b[ij] , then the sum [ A ] + [ B ] is the matrix [ C ] of order ( m × n ) with elements c[ij] that are found from the following definition.

The element of the i th row and j th column of [ C ] is obtained by summing the elements of the i th row and the j th column of both matrices.

Thus, the general element of the sum matrix [ C ] is given by

c[ij] = a[ij]+b[ij]

For example, consider a ( 2 × 3 ) matrix [ A ] given as

> A := matrix(2, 3, [a[11], a[12], a[13], a[21], a[22], a[23]]) : A = matrix(A) ;

A = matrix([[a[11], a[12], a[13]], [a[21], a[22], a...

and a ( 2 × 3 ) matrix [ B ] given as

> B := matrix(2, 3, [b[11], b[12], b[13], b[21], b[22], b[23]]) : B = matrix(B) ;

B = matrix([[b[11], b[12], b[13]], [b[21], b[22], b...

The sum [ A ] + [ B ] is a ( 2 × 3 ) matrix, which may be obtained using either of the following alternative methods.

Method 1 . Using the matadd function:

> `A+B` := matadd(A, B) : A + B = matrix(`A+B`) ;

A+B = matrix([[a[11]+b[11], a[12]+b[12], a[13]+b[13...

Method 2 . Using the evalm function:

> `A+B` := evalm(A + B) : A + B = matrix(`A+B`) ;

A+B = matrix([[a[11]+b[11], a[12]+b[12], a[13]+b[13...

This matrix addition may be displayed in "like-in-a-book" form, namely

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

matrix([[a[11], a[12], a[13]], [a[21], a[22], a[23]...

* * *

N.B. Matrix addition is commutative , so that

[ A ] + [ B ] = [ B ] + [ A ]

* * *

N.B. Matrix addition is associative , so that

[ A ] + ( [ B ] + [ C ] ) = ( [ A ] + [ B ] ) + [ C ]

* * *

N.B. Two matrices, [ A ] and [ B ], with elements a[ij] and b[ij] , respectively, are equal when they are both of the same order and a[ij] = b[ij] for all possible pairs of indices ( i , j ) .

[ Refer to Unit (10) where the function equal contained in the linalg package is used for the first time. ]

* * *

Numerical example of matrix addition

Let ( 2 × 3 ) matrices [ A ] and [ B ] be given as

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

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

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

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

The sum [ A ] + [ B ] is the following ( 2 × 3 ) matrix:

> `A+B` := matadd(A, B) : A + B = matrix(`A+B`) ;

A+B = matrix([[0, 1, 1], [1, 1, 1]])

or, in "like-in-a-book" form,

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

matrix([[1, -2, 0], [3, 2, 1]])+matrix([[-1, 3, 1],...

* * *

N.B. Maple recognises addition of a number (scalar) and any matrix.

For example, consider a square ( 3 × 3 ) matrix [ A ] given as

> A := matrix(3, 3, [a[11], a[12], a[13], a[21], a[22], a[23], a[31], a[32], a[33]]) : A = matrix(A) ;

A = matrix([[a[11], a[12], a[13]], [a[21], a[22], a...

and the number k .

The sum k + [ A ] is the following ( 3 × 3 ) matrix:

> `k+A` := evalm(k + A) : k + A = matrix(`k+A`) ;

k+A = matrix([[a[11]+k, a[12], a[13]], [a[21], a[22...

Notice that the matadd function cannot be used to obtain the sum k + [ A ] since the function "expects" two matrices to be added together.

It can be easily noticed that the result of this operation is equivalent to the addition of a scalar matrix [ K ] of the same ( 3 × 3 ) order, viz.

> K := diag(k, k, k) : K = matrix(K) ;

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

since the sum matrix [ K ] + [ A ] is the following ( 3 × 3 ) matrix:

> `K+A` := evalm(K + A) : K + A = matrix(`K+A`) ;

K+A = matrix([[a[11]+k, a[12], a[13]], [a[21], a[22...

[ Refer to Unit (7) for the scalar matrix , which is defined in Section A : The diagonal matrix. ]

* * *

N.B. If addition of a number (scalar) to each element of a matrix is required, the simplest method is using the map function together with the arrow-type functional operator ( x-> ).

For example, add the scalar mu to each element of the same square ( 3 × 3 ) matrix [ A ] as before:

> `elements(A)+mu` := map(x->x+mu, A) : elements(A)+mu = matrix(`elements(A)+mu`) ;

elements(A)+mu = matrix([[a[11]+mu, a[12]+mu, a[13]...

* * *

B . Matrix subtraction

The difference [ A ] [ B ] is defined by the relation

[ A ] [ B ] = [ A ] + ( -1 ) [ B ]

Therefore, similar rules and computation methods apply to matrix subtraction. This is illustrated hereunder for the matrices [ A ] and [ B ] containing the same symbolic elements as before.

> A := matrix(2, 3, [a[11], a[12], a[13], a[21], a[22], a[23]]) :

> B := matrix(2, 3, [b[11], b[12], b[13], b[21], b[22], b[23]]) :

The difference [ A ] [ B ] is a ( 2 × 3 ) matrix, which may be obtained using either of the following alternative methods.

Method 1 . Using the matadd function:

> `A-B` := matadd(A, -B) : A - B = matrix(`A-B`) ;

A-B = matrix([[a[11]-b[11], a[12]-b[12], a[13]-b[13...

Method 2 . Using the evalm function:

> `A-B` := evalm(A - B) : A - B = matrix(`A-B`) ;

A-B = matrix([[a[11]-b[11], a[12]-b[12], a[13]-b[13...

This matrix subtraction may be displayed in "like-in-a-book" form, namely

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

matrix([[a[11], a[12], a[13]], [a[21], a[22], a[23]...

Numerical example of matrix subtraction

Use the matrices [ A ] and [ B ] with the same numerical elements as before, namely

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

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

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

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

The difference [ A ] [ B ] is the following ( 2 × 3 ) matrix:

> `A-B` := matadd(A, -B) : A - B = matrix(`A-B`) ;

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

or, in "like-in-a-book" form,

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

matrix([[1, -2, 0], [3, 2, 1]])-matrix([[-1, 3, 1],...

* * *

N.B. Subtraction of a matrix from itself yields a zero or null matrix whose all elements are zeros

[ A ] [ A ] = [ 0 ]

To illustrate this case, use the above matrix [ A ] with its numerical elements. The difference [ A ] [ A ] is the following ( 2 × 3 ) zero matrix:

> `A-A` := matadd(A, -A) : `A – A` = matrix(`A-A`) ;

`A – A` = matrix([[0, 0, 0], [0, 0, 0]])

or, in "like-in-a-book" form,

> [0] = matrix(`A-A`) ;

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

Notice that the evalm function cannot be used for performing this operation because it returns the scalar number zero :

> `A-A` := evalm(A - A ) : `A – A` = `A-A` ;

`A – A` = 0

* * *

Proceed to Unit (4) for " Multiplication of matrices ".

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