toStringAugmented method
Prints the augmented matrix of this instance, which is the equations matrix plus the known values vector to the right. For example, if...
A = [1, 2]
[4, 5]
b = [3]
[6]
... then the Ax = b
system represented by this instance is printed in
the following way:
[1, 2 | 3]
[4, 5 | 6]
Implementation
String toStringAugmented() {
final buffer = StringBuffer();
// Printing the augmented matrix in the following format:
// [1, 2 | 3]
// [4, 5 | 6]
for (var i = 0; i < matrix.rowCount; ++i) {
// Leading opening [
buffer.write('[');
for (var j = 0; j < matrix.columnCount; ++j) {
buffer.write(matrix(i, j));
// Adding a comma only between two values
if (j < matrix.columnCount - 1) {
buffer.write(', ');
}
}
// Adding the known value associated to the current equation.
buffer
..write(' | ')
..write(knownValues[i]);
// Ending closing ]
if (i < matrix.rowCount - 1) {
buffer.writeln(']');
} else {
buffer.write(']');
}
}
return buffer.toString();
}