+ I wanted to write a little algorithm to visually solve linear systems of equations for fun. I am only going to deal with 3x3 matrices for now, but I'll make it so that I can easily extend it to more matrices in the future if I think that would be cool.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/posts/linear_system_solver.html~ b/posts/linear_system_solver.html~
new file mode 100644
index 0000000..a280a8b
--- /dev/null
+++ b/posts/linear_system_solver.html~
@@ -0,0 +1,77 @@
+
+
Linear Systems Solver
+
2021-08-01 by Matthew Kosarek
+
+ I wanted to write a little algorithm to visually solve linear systems of equations for fun. I am only going to deal with 3x3 matrices for now, but I'll make it so that I can easily extend it to more matrices in the future if I think that would be cool.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/posts/linear_system_solver.js b/posts/linear_system_solver.js
new file mode 100644
index 0000000..9eb901f
--- /dev/null
+++ b/posts/linear_system_solver.js
@@ -0,0 +1,172 @@
+var $ = window.$,
+ rows = 3,
+ columns = 3,
+ currentLhs = [], // rows x columns matrix
+ currentRhs = []; // rows x 1 matrix
+ solutionContainer = $('#solution_container');
+
+function main() {
+ $('#reset_button').on('click', onResetClicked);
+ $('#solve_button').on('click', onSolveClicked);
+ resetView();
+}
+
+function resetView() {
+ renderLHS();
+ renderUnknowns();
+ renderRHS();
+
+ currentLhs = [];
+ currentRhs = [];
+ for (var r = 0; r < rows; r++) {
+ for (var c = 0; c < columns; c++) {
+ currentLhs.push(0);
+ }
+ }
+
+ for (var otherR = 0; otherR < rows; otherR++) {
+ currentRhs.push(0);
+ }
+
+ solutionContainer.empty();
+}
+
+// Renders for the input container.
+function renderLHS() {
+ var lhs = $('#matrix_lhs').empty(),
+ addCell = function(index) {
+ $('').type('number').val(0).on('change', function(event) {
+ currentLhs[index] = Number(event.target.value);
+ }).appendTo(lhs);
+ };
+
+ for (var r = 0; r < rows; r++) {
+ for (var c = 0; c < columns; c++) {
+ addCell((r * rows) + c);
+ }
+ }
+}
+
+function renderUnknowns() {
+ var unknownsContainer = $('#unknown_variables').empty();
+
+ for (var r = 0; r < columns; r++) {
+ var cell = $('').disabled(true).val(String.fromCharCode('x'.charCodeAt(0) + r).toUpperCase());
+ unknownsContainer.append(cell);
+ }
+}
+
+function renderRHS() {
+ var rhs = $('#matrix_rhs').empty(),
+ addCell = function(index) {
+ $('').type('number').val(0).on('change', function(event) {
+ currentRhs[index] = Number(event.target.value);
+ }).appendTo(rhs);
+ };
+
+ for (var r = 0; r < rows; r++) {
+ addCell(r);
+ }
+}
+
+// Renders for the augmented matrix container
+function renderAugmentedMatrix(lhs, rhs) {
+ var container = $('