operator / method

Matrix operator /(
  1. dynamic other
)

Divides this matrix by a scalar value.

divisor: The scalar value to divide this matrix by.

Returns a new matrix containing the result of the scalar division.

Example:

var matrix = Matrix([[2, 4], [6, 8]]);
var result = matrix / 2;
print(result);
// Output:
// 1  2
// 3  4

Implementation

Matrix operator /(dynamic other) {
  if (other is num) {
    if (other == 0) {
      throw Exception('Cannot divide by zero');
    }

    List<List<dynamic>> newData = List.generate(rowCount,
        (i) => List.generate(columnCount, (j) => _data[i][j] / other));

    return Matrix(newData);
  } else {
    throw Exception(
        'Invalid operand type, division is only supported by scalar');
  }
}