performFunction method
Perform a function on the matrix
functionThe function to perform- Returns The new matrix
- Example
Matrix matrix = Matrix(2, 2);
Matrix newMatrix = matrix.performFunction((a) => a * 2);
- Note The function should take a double as input and return a double
Implementation
Matrix performFunction(Function(double) function) {
Matrix newMatrix = Matrix(_row, _col);
for (int i = 0; i < _row; i++) {
for (int j = 0; j < _col; j++) {
double result = function(getAt(i, j));
newMatrix.setAt(i, j, value: result);
}
}
return newMatrix;
}