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
(
×
)
with elements
and [
B
] of order
(
×
)
with elements
,
then the sum [
A
]
+
[
B
] is the matrix [
C
] of order
(
×
)
with elements
that are found from the following definition.
The element of the
th row and
th column of [
C
] is obtained by summing the elements of the
th row and the
th column of both matrices.
Thus, the general element of the sum matrix [ C ] is given by
For example, consider a
(
×
)
matrix [
A
] given as
> A := matrix(2, 3, [a[11], a[12], a[13], a[21], a[22], a[23]]) : A = matrix(A) ;
and a
(
×
)
matrix [
B
] given as
> B := matrix(2, 3, [b[11], b[12], b[13], b[21], b[22], b[23]]) : B = matrix(B) ;
The sum [
A
]
+
[
B
] is a
(
×
)
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`) ;
Method 2 . Using the evalm function:
> `A+B` := evalm(A + B) : A + B = matrix(`A+B`) ;
This matrix addition may be displayed in "like-in-a-book" form, namely
> matrix(A) + matrix(B) = matrix(`A+B`) ;
* * *
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
and
, respectively, are
equal
when they are both of the same order and
for
all
possible pairs of indices
(
,
)
.
[ 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
(
×
)
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) ;
The sum [
A
]
+
[
B
] is the following
(
×
)
matrix:
> `A+B` := matadd(A, B) : A + B = matrix(`A+B`) ;
or, in "like-in-a-book" form,
> matrix(A) + matrix(B) = matrix(`A+B`) ;
* * *
N.B. Maple recognises addition of a number (scalar) and any matrix.
For example, consider a square
(
×
)
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) ;
and the number
.
The sum
+
[
A
] is the following
(
×
)
matrix:
> `k+A` := evalm(k + A) : k + A = matrix(`k+A`) ;
Notice that the
matadd
function
cannot
be used to obtain the sum
+
[
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
(
×
)
order, viz.
> K := diag(k, k, k) : K = matrix(K) ;
since the sum matrix [
K
]
+
[
A
] is the following
(
×
)
matrix:
> `K+A` := evalm(K + A) : K + A = matrix(`K+A`) ;
[ 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
to each element of the same square
(
×
)
matrix [
A
] as before:
> `elements(A)+mu` := map(x->x+mu, A) : elements(A)+mu = matrix(`elements(A)+mu`) ;
* * *
B . Matrix subtraction
The difference [ A ] – [ B ] is defined by the relation
[
A
]
–
[
B
]
=
[
A
]
+ (
)
[
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
(
×
)
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`) ;
Method 2 . Using the evalm function:
> `A-B` := evalm(A - B) : A - B = matrix(`A-B`) ;
This matrix subtraction may be displayed in "like-in-a-book" form, namely
> matrix(A) - matrix(B) = matrix(`A-B`) ;
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) ;
The difference [
A
]
–
[
B
] is the following
(
×
)
matrix:
> `A-B` := matadd(A, -B) : A - B = matrix(`A-B`) ;
or, in "like-in-a-book" form,
> matrix(A) - matrix(B) = matrix(`A-B`) ;
* * *
N.B.
Subtraction of a matrix from itself yields a
zero
or
null
matrix whose
all
elements are
[ A ] – [ A ] = [ 0 ]
To illustrate this case, use the above matrix [
A
] with its numerical elements. The difference [
A
]
–
[
A
] is the following
(
×
)
zero
matrix:
> `A-A` := matadd(A, -A) : `A – A` = matrix(`A-A`) ;
or, in "like-in-a-book" form,
> [0] = matrix(`A-A`) ;
Notice that the
evalm
function cannot be used for performing this operation because it returns the scalar number
:
> `A-A` := evalm(A - A ) : `A – A` = `A-A` ;
* * *
Proceed to Unit (4) for " Multiplication of matrices ".
-------------------------------------------------------------------