## `linalg::setRow` -- change a row of a matrix

#### Introduction

`linalg::setRow``(A, p, r)` returns a copy of the matrix A with the p-th row replaced by the row vector r.

#### Call(s)

`linalg::setRow(A, p, r)`

#### Parameters

`A` | - | an m x n matrix of a domain of category `Cat::Matrix`
`r` | - | a row vector or a list that can be converted into a row vector the domain `Dom::Matrix(R)`, where `R` is the component ring of `A` (a row vector is a 1 x n matrix)

#### Returns

a matrix of the same domain type as `A`.

#### Related Functions

`linalg::col`, `linalg::delCol`, `linalg::delRow`, `linalg::row`, `linalg::setCol`

#### Details

- If `r` is a list with at most n elements, then `r` is converted into a row vector. An error message is returned if the conversion is not possible (e.g., if an element of the list cannot be converted into an object of the component ring of `A`; see example 2).

#### Example 1

We define a matrix over the rationals:

    >> MatQ := Dom::Matrix(Dom::Rational):
       A := MatQ([[1, 2], [3, 2]])

                                    +-      -+
                                    |  1, 2  |
                                    |        |
                                    |  3, 2  |
                                    +-      -+

and replace the 2nd row by the 1x2 zero vector:

    >> linalg::setRow(A, 2, MatQ(1, 2, [0, 0]))

                                    +-      -+
                                    |  1, 2  |
                                    |        |
                                    |  0, 0  |
                                    +-      -+

#### Example 2

We create the 2x2 zero matrix over Z6:

    >> B := Dom::Matrix(Dom::IntegerMod(6))(2, 4)

                     +-                                    -+
                     |  0 mod 6, 0 mod 6, 0 mod 6, 0 mod 6  |
                     |                                      |
                     |  0 mod 6, 0 mod 6, 0 mod 6, 0 mod 6  |
                     +-                                    -+

and replace the 2nd row by the vector [1,-1,1,-1]. We give the row vector in form of a list. Its elements are converted implicitly into objects of the component ring of `B`:

    >> linalg::setRow(B, 2, [1, -1, 1, -1])

                     +-                                    -+
                     |  0 mod 6, 0 mod 6, 0 mod 6, 0 mod 6  |
                     |                                      |
                     |  1 mod 6, 5 mod 6, 1 mod 6, 5 mod 6  |
                     +-                                    -+

The following input leads to an error message because the number 1/3 can not be converted into an object of type `Dom::IntegerMod(6)`:

    >> linalg::setRow(B, 1, [1/3, 0, 1, 0])

          Error: invalid row vector [linalg::setRow]

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000