MATRICES AND MATRIX OPERATIONS: Unit 18
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
-------------------------------------------------------------------
(18) Replacing a column in a matrix with a column matrix
OBJECTIVES :
• To introduce this operation as a basis for solving systems of linear algebraic inhomogeneous equations using Cramer’ s rule.
• To provide alternative methods of replacing a column in a matrix with a column matrix.
• To show how to carry over the original matrix unchanged for use in computations that may follow its column-replacement operation.
> restart : with(linalg, copyinto, rowdim) :
Exemplarily, consider a
(
×
)
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 a
(
×
)
column matrix [
CM
] given as
> CM := matrix(3, 1, [cm[11], cm[21], cm[31]]) : CM = matrix(CM) ;
Replace the
nd column
(
)
of the matrix [
A
] with the elements of the column matrix [
CM
]. This
modifies
matrix [
A
] and returns a new
(
×
)
matrix [
B
].
* * *
N.B. Since replacing a column in [ A ] changes it and the original matrix [ A ] may be needed in further computations, it is convenient to create its copy at this point, e.g.
> C_A := copy(A) : C_A = matrix(C_A) ;
Maintaining the original matrix is necessary, for example, in solving systems of linear algebraic inhomogeneous equations by means of Cramer’ s rule – refer to Unit (19).
* * *
The column-replacement operation may be performed using any of the following alternative methods.
Method 1 . Using the for -loop construct:
> j := 2 : k := 1 : for i to rowdim(A) do A[i,j] := CM[i,k] od : B := matrix(A) : B = matrix(B) ;
Restore the original matrix [ A ]:
> A := matrix(C_A) : A = matrix(A) ;
Method 2 . Using the copyinto function:
> B := copyinto(CM, A, k, j) : B = matrix(B) ;
Restore the original matrix [ A ]:
> A := matrix(C_A) : A = matrix(A) ;
Method 3 . Using the subs function:
> B := subs(a[12]=cm[11], a[22]=cm[21], a[32]=cm[31], matrix(A)) : B = matrix(B) ;
N.B. This method does not affect the original matrix [ A ], i.e.
> A = matrix(A) ;
* * *
N.B. The operation of replacing a column in a matrix with a column matrix is necessary in solving systems of linear algebraic inhomogeneous equations by means of Cramer’ s rule – refer to Unit (19).
* * *
Proceed to Unit (19) for " Solution of systems of linear algebraic inhomogeneous equations using Cramer ’ s rule ".
-------------------------------------------------------------------