Matrices-Unit5.mws

MATRICES AND MATRIX OPERATIONS: Unit 5

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

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

(5) Multiplication of row and column matrices

OBJECTIVES :

To distinguish between two different structures in Maple : vector and row matrix .

To provide alternative methods of defining and inputting vectors with Maple .

To show how to convert a vector to a row matrix .

To show how to convert a vector to a column matrix .

To provide alternative methods of defining and inputting row matrices with Maple .

To show how to convert a row matrix to a vector .

To provide alternative methods of defining and inputting column matrices with Maple .

To show how to convert a column matrix to a vector .

To provide examples of multiplication of a row matrix and a column matrix.

To provide examples of multiplication of a column matrix and a row matrix.

> restart : with(linalg, multiply) :

It should be noted that although the function vector belongs to the linalg package, it need not be specified under the with(linalg) command since this function is also included in Maple s main library.

N.B. In textbooks, the names "row matrix" or "row vector" and "column matrix" or "column vector" are used interchangeably. In Maple , a row matrix and a vector are different objects and the name "vector" denotes in Maple a "row vector". There is no object called "column vector" in Maple . Instead, the name column matrix is used for the structure implied.

For example, consider 3 - element row and column structures of this kind.

A (row) vector is defined and input using any of the following four methods:

> RV := array([a, b, c]) : RV = eval(RV) ;

RV = vector([a, b, c])

> RV := array(1..3, [a, b, c]) : RV = eval(RV) ;

RV = vector([a, b, c])

> RV := convert([a, b, c], vector) : RV = eval(RV) ;

RV = vector([a, b, c])

> RV := vector(3, [a, b, c]) : RV = eval(RV) ;

RV = vector([a, b, c])

N.B. Alternatively, the command RV = op(RV) may be used to display the vector.

* * *

N.B. Application of the convert function together with the form name list and function matrix to the above 3 -element vector returns a ( 1 × 3 ) row matrix , viz.

> RM := matrix(1, 3, convert(RV, list)) : RM = matrix(RM) ; type(RM, matrix) ;

RM = matrix([[a, b, c]])

true

The Boolean value true returned by the type-checking function type verifies that [ RM ] is a matrix .

* * *

N.B. Application of the convert function together with the form name matrix to the above 3 -element vector returns a ( 3 × 1 ) column matrix , viz.

> CM := convert(RV, matrix) : CM = matrix(CM) ; type(CM, matrix) ;

CM = matrix([[a], [b], [c]])

true

The Boolean value true returned by the type-checking function type verifies that [ CM ] is a matrix .

* * *

A ( 1 × 3 ) row matrix is defined and input using any of the following four methods:

> RM := array([ [a, b, c] ]) : RM = matrix(RM) ;

RM = matrix([[a, b, c]])

> RM := convert([ [a, b, c] ], matrix) : RM = matrix(RM) ;

RM = matrix([[a, b, c]])

> RM := matrix(1, 3, [a, b, c]) : RM = matrix(RM) ;

RM = matrix([[a, b, c]])

> RM := matrix([ [a, b, c] ]) : RM = matrix(RM) ;

RM = matrix([[a, b, c]])

* * *

N.B. Triple application of the convert function together with the form names set , list , and vector to the above row matrix returns a (row) vector , e.g.

> RV := convert(convert(convert(RM, set), list), vector) : RV = eval(RV) ; type(RV, vector) ;

RV = vector([a, b, c])

true

The Boolean value true returned by the type-checking function type verifies that [ RV ] is a (row) vector .

* * *

A ( 3 × 1 ) column matrix is defined and input using any of the following four methods:

> CM := array([ [a], [b], [c] ]) : CM = matrix(CM) ;

CM = matrix([[a], [b], [c]])

> CM := convert([ [a], [b], [c] ], matrix) : CM = matrix(CM) ;

CM = matrix([[a], [b], [c]])

> CM := matrix(3, 1, [a, b, c]) : CM = matrix(CM) ;

CM = matrix([[a], [b], [c]])

> CM := matrix([ [a], [b], [c] ]) : CM = matrix(CM) ;

CM = matrix([[a], [b], [c]])

* * *

N.B. Application of the convert function together with the form name vector to the above column matrix returns a (row) vector , e.g.

> RV := convert(CM, vector) : RV = eval(RV) ; type(RV, vector) ;

RV = vector([a, b, c])

true

The Boolean value true returned by the type-checking function type verifies that [ RV ] is a (row) vector .

* * *

N.B. Conversion of a row matrix to a column matrix and vice versa is simplest using the transposition operation.

[ For the transpose of a matrix, refer to Unit (10). ]

* * *

A . Multiplication of a row matrix and a column matrix

According to the multiplication conformability rule, the product of a ( 1 × n ) row matrix [ RM ] and an ( m × 1 ) column matrix [ CM ] is possible only, if the number of columns in the row matrix is equal to the number of rows in the column matrix, i.e. n = m . The result is a scalar (number), which is displayed in Maple as a ( 1 × 1 ) matrix. This special form of product is called either the inner product or the scalar product of a row matrix and a column matrix . [ Refer also to Unit (4) for the concept of inner product used in a similar sense. ]

For example, consider a ( 1 × 3 ) row matrix [ RM ] given as

> RM := matrix(1, 3, [rm[11], rm[12], rm[13]]) : RM = matrix(RM) ;

RM = matrix([[rm[11], rm[12], rm[13]]])

and a ( 3 × 1 ) column matrix [ CM ] given as

> CM := matrix(3, 1, [cm[11], cm[21], cm[31]]) : CM = matrix(CM) ;

CM = matrix([[cm[11]], [cm[21]], [cm[31]]])

The product [ RM ] [ CM ] is the following ( 1 × 1 ) matrix:

> `RM CM` := multiply(RM, CM) : RM*CM = matrix(`RM CM`) ;

RM*CM = matrix([[rm[11]*cm[11]+rm[12]*cm[21]+rm[13]...

To convert the resultant matrix to the corresponding scalar (number), extract the matrix element using the subscript notation:

> `RM CM` := `RM CM`[1,1] : RM*CM = `RM CM` ;

RM*CM = rm[11]*cm[11]+rm[12]*cm[21]+rm[13]*cm[31]

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

> matrix(RM) * matrix(CM) = `RM CM` ;

matrix([[rm[11], rm[12], rm[13]]])*matrix([[cm[11]]...

* * *

N.B. The product of a (row) vector and a column matrix returns a single-element vector , which is displayed by Maple in a similar way. By convention, it is also a scalar .

* * *

Numerical example of multiplication of a row matrix and a column matrix

Let a ( 1 × 3 ) row matrix [ RM ] and a ( 3 × 1 ) column matrix [ CM ] be given as

> RM := matrix(1, 3, [1, -1, 2]) : CM := matrix(3, 1, [2, 1, -3]) : RM=matrix(RM) ; CM=matrix(CM) ;

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

CM = matrix([[2], [1], [-3]])

The product [ RM ] [ CM ] is the following ( 1 × 1 ) matrix:

> `RM CM` := multiply(RM, CM) : RM*CM = matrix(`RM CM`) ;

RM*CM = matrix([[-5]])

Conversion to scalar yields

> `RM CM` := `RM CM`[1,1] : RM*CM = `RM CM` ;

RM*CM = -5

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

> matrix(RM) * matrix(CM) = `RM CM` ;

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

B . Multiplication of a column matrix and a row matrix

According to the multiplication conformability rule, the product of an ( m × 1 ) column matrix [ CM ] and a ( 1 × n ) row matrix [ RM ] is possible only, if the number of rows in the column matrix is equal to the number of columns in the row matrix, i.e. m = n . The product matrix is a square matrix of order ( m × m ) or ( n × n ) .

For example, consider the same ( 3 × 1 ) column matrix [ CM ] and the ( 1 × 3 ) row matrix [ RM ] with symbolic elements, as defined in Section A of this Unit.

> CM := matrix(3, 1, [cm[11], cm[21], cm[31]]) : RM := matrix(1, 3, [rm[11], rm[12], rm[13]]) :

The product [ CM ] [ RM ] is the following ( 3 × 3 ) matrix:

> `CM RM` := multiply(CM, RM) : `CM RM` = matrix(`CM RM`) ;

`CM RM` = matrix([[rm[11]*cm[11], cm[11]*rm[12], cm...

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

> matrix(CM) * matrix(RM) = matrix(`CM RM`) ;

matrix([[rm[11], rm[12], rm[13]]])*matrix([[cm[11]]...

* * *

N.B. An attempt to multiply a column matrix and a (row) vector results in an error message.

* * *

Numerical example of multiplication of a column matrix and a row matrix

Let a ( 3 × 1 ) column matrix [ CM ] and a ( 1 × 3 ) row matrix [ RM ] be given as before, i.e.

> CM := matrix(3, 1, [2, 1, -3]) : RM := matrix(1, 3, [1, -1, 2]) : CM=matrix(CM) ; RM=matrix(RM) ;

CM = matrix([[2], [1], [-3]])

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

The product [ CM ] [ RM ] is the following ( 3 × 3 ) matrix:

> `CM RM` := multiply(CM, RM) : `CM RM` = matrix(`CM RM`) ;

`CM RM` = matrix([[2, -2, 4], [1, -1, 2], [-3, 3, -...

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

> matrix(CM) * matrix(RM) = matrix(`CM RM`) ;

matrix([[1, -1, 2]])*matrix([[2], [1], [-3]]) = mat...

* * *

Proceed to Unit (6) for " Multiplication of a multi-row multi-column matrix and a column matrix ".

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