Multiplies one or more rows of a matrix by constants. This corresponds to multiplying or dividing equations by constants.

rowmult(x, row, mult)

Arguments

x

a matrix, possibly consisting of the coefficient matrix, A, joined with a vector of constants, b.

row

index of one or more rows.

mult

row multiplier(s)

Value

the matrix x, modified

See also

echelon, gaussianElimination

Other elementary row operations: rowadd(), rowswap()

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
Ab <- cbind(A, b)
(Ab <- rowadd(Ab, 1, 2, 3/2))  # row 2 <- row 2 + 3/2 row 1
#>                   b
#> [1,]  2 1.0 -1.0  8
#> [2,]  0 0.5  0.5  1
#> [3,] -2 1.0  2.0 -3
(Ab <- rowadd(Ab, 1, 3, 1))    # row 3 <- row 3 + 1 row 1
#>                 b
#> [1,] 2 1.0 -1.0 8
#> [2,] 0 0.5  0.5 1
#> [3,] 0 2.0  1.0 5
(Ab <- rowadd(Ab, 2, 3, -4))
#>                 b
#> [1,] 2 1.0 -1.0 8
#> [2,] 0 0.5  0.5 1
#> [3,] 0 0.0 -1.0 1
# multiply to make diagonals = 1
(Ab <- rowmult(Ab, 1:3, c(1/2, 2, -1)))
#>                  b
#> [1,] 1 0.5 -0.5  4
#> [2,] 0 1.0  1.0  2
#> [3,] 0 0.0  1.0 -1
# The matrix is now in triangular form