figbertmath

[RADIOACTIVE] miscellaneous math programs in website form
git clone git://git.figbert.com/figbertmath.git
Log | Files | Refs | README

commit 860e88d83b9e32e9db4f1a56d7e23b6e16592b0e
parent baab68b5a12bcd8ee673d97587141ec825b63185
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Thu,  5 Dec 2019 15:32:51 -0800

Add functionality to the simultaneous equation calculator

This update implements a function to check, on change of input values, if the calculator should solve the equation. If it detects that the necessary values have been provided, it passes a deep copy to the solve function which calculates the output using the Gaussian theorem.

The READEME has been updated to reflect the calculator's completion.

Diffstat:
MREADME.md | 5++---
Msrc/components/highLevel/simultaneousEquation.js | 34++++++++++++++++++++++++++++++++--
2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -5,8 +5,8 @@ A calculator for miscellaneous formulas I encounter that can, and thus shall, be * Simple Calculator * Angular/Real Size Calculator * Consecutive Number Calculator +* Simultaneous Equation Calculator * Polygon Angle Calculator ## Planned -* Simultaneous Equation Calculator -* Forces and Energy Calculator -\ No newline at end of file +* Forces and Energy Calculator diff --git a/src/components/highLevel/simultaneousEquation.js b/src/components/highLevel/simultaneousEquation.js @@ -13,6 +13,7 @@ export class SimultaneousEquation extends React.Component { coefficients: [['', ''], ['', '']], sums: ['', ''] }; + this.checkSolve = this.checkSolve.bind(this); this.modifyMatrix = this.modifyMatrix.bind(this); this.solveMatrix = this.solveMatrix.bind(this); this.onChange = this.onChange.bind(this); @@ -28,11 +29,15 @@ export class SimultaneousEquation extends React.Component { k = Number(name.split('_')[1]); this.setState({ coefficients: update(this.state.coefficients, {[i]: {[k]: {$set: value}}}) + }, () => { + this.checkSolve() }); } else if (name.indexOf('s') > -1) { i = Number(name.substr(1)); this.setState({ sums: update(this.state.sums, {[i]: {$set: value}}) + }, () => { + this.checkSolve() }); } else { this.setState({ @@ -41,6 +46,32 @@ export class SimultaneousEquation extends React.Component { } } + checkSolve() { + const coefficients = JSON.parse(JSON.stringify(this.state.coefficients)), + sums = JSON.parse(JSON.stringify(this.state.sums)); + let truth = true; + for (let i = 0; i < coefficients.length; i++) { + for (let k = 0; k < coefficients[i].length; k ++) { + if (coefficients[i][k] === '') { + truth = false; + } else { + coefficients[i][k] = Number(coefficients[i][k]); + } + } + } + if (truth) { + for (let i = 0; i < sums.length; i++) { + if (sums[i] === '') { + truth = false; + } else { + sums[i] = Number(sums[i]); + } + } + } + if (truth) { + this.solveMatrix(coefficients, sums) + } + } modifyMatrix(object) { const value = object.target.value; @@ -153,4 +184,4 @@ export class SimultaneousEquation extends React.Component { SimultaneousEquation.propTypes = { mode: PropTypes.string.isRequired, onModeChange: PropTypes.func.isRequired -}; -\ No newline at end of file +};