Recover the history of the row operations that have been performed. This function combines the transformation matrices into a single transformation matrix representing all row operations or may optionally print all the individual operations which have been performed.

buildTmat(x, all = FALSE)

# S3 method for trace
as.matrix(x, ...)

# S3 method for trace
print(x, ...)

Arguments

x

a matrix A, joined with a vector of constants, b, that has been passed to gaussianElimination or the row operator matrix functions

all

logical; print individual transformation ies?

...

additional arguments

Value

the transformation matrix or a list of individual transformation matrices

Author

Phil Chalmers

Examples

A <- matrix(c(2, 1, -1,
             -3, -1, 2,
             -2,  1, 2), 3, 3, byrow=TRUE)
b <- c(8, -11, -3)

# using row operations to reduce below diagonal to 0
Abt <- Ab <- cbind(A, b)
Abt <- rowadd(Abt, 1, 2, 3/2)
Abt <- rowadd(Abt, 1, 3, 1)
Abt <- rowadd(Abt, 2, 3, -4)
Abt
#>                 b
#> [1,] 2 1.0 -1.0 8
#> [2,] 0 0.5  0.5 1
#> [3,] 0 0.0 -1.0 1

# build T matrix and multiply by original form
(T <- buildTmat(Abt))
#>      [,1] [,2] [,3]
#> [1,]  1.0    0    0
#> [2,]  1.5    1    0
#> [3,] -5.0   -4    1
T %*% Ab    # same as Abt
#>                 b
#> [1,] 2 1.0 -1.0 8
#> [2,] 0 0.5  0.5 1
#> [3,] 0 0.0 -1.0 1

# print all transformation matrices
buildTmat(Abt, TRUE)
#> $T1
#>      [,1] [,2] [,3]
#> [1,]  1.0    0    0
#> [2,]  1.5    1    0
#> [3,]  0.0    0    1
#> 
#> $T2
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    1    0
#> [3,]    1    0    1
#> 
#> $T3
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    1    0
#> [3,]    0   -4    1
#> 

# invert transformation matrix to reverse operations
inv(T) %*% Abt
#>                 b
#> [1,]  2  1 -1   8
#> [2,] -3 -1  2 -11
#> [3,] -2  1  2  -3

# gaussian elimination
(soln <- gaussianElimination(A, b))
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    2
#> [2,]    0    1    0    3
#> [3,]    0    0    1   -1
T <- buildTmat(soln)
inv(T) %*% soln
#>      [,1] [,2] [,3] [,4]
#> [1,]    2    1   -1    8
#> [2,]   -3   -1    2  -11
#> [3,]   -2    1    2   -3