addRow method

void addRow(
  1. int sourceIndex,
  2. int targetIndex,
  3. dynamic scaleFactor
)

Adds a multiple of one row to another row.

This function multiplies the elements in the row with the specified sourceIndex by the given scaleFactor and adds the result to the elements in the row with the specified targetIndex.

Example:

Matrix A = Matrix.fromList([
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
]);
A.addRow(0, 2, -3);
print(A);

Output:

 1  2  3
 4  5  6
-4 -2  0

Validation: Throws RangeError if sourceIndex or targetIndex is not a valid row index in the matrix.

Implementation

void addRow(int sourceIndex, int targetIndex, dynamic scaleFactor) {
  RangeError.checkValidIndex(sourceIndex, this, "sourceIndex", rowCount);
  RangeError.checkValidIndex(targetIndex, this, "targetIndex", rowCount);

  for (int j = 0; j < columnCount; j++) {
    this[targetIndex][j] += scaleFactor * this[sourceIndex][j];
  }
}