operator / method
Divides this matrix by a scalar value.
other: 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 || other is Complex) {
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 is num ? Complex.fromReal(other) : other)));
return Matrix(newData);
} else {
throw Exception(
'Invalid operand type, division is only supported by scalar');
}
}