figbertmath

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

commit 2466b4325c0c284fff7f683cb63f0c5a3929c875
Author: therealFIGBERT <naomi@Naomis-MacBook-Air.local>
Date:   Fri, 31 May 2019 21:28:47 -0700

First commit

Diffstat:
AmathPrograms/consecutiveNumberFinder.html | 459+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AmathPrograms/gearRatioFinder.html | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Amatrix/index.html | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amatrix/matrix.css | 32++++++++++++++++++++++++++++++++
Amatrix/matrix.js | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amatrix/matrixBeta.js | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 922 insertions(+), 0 deletions(-)

diff --git a/mathPrograms/consecutiveNumberFinder.html b/mathPrograms/consecutiveNumberFinder.html @@ -0,0 +1,458 @@ +<!DOCTYPE html> + +<html> + <body> + <script> + //numOne is the variable defining the first number that is consecutive + var numOne = null ; + //numTwo is the variable defining the first number that is consecutive + var numTwo = null ; + //numThree is the variable defining the first number that is consecutive + var numThree = null ; + //numFour is the variable defining the first number that is consecutive + var numFour = null ; + //numFive is the variable defining the first number that is consecutive + var numFive = null ; + //sum is the sum of all the num variables used + var sum = null; + //howMany is the variable defining the amount of consecutive numbers in the beginning of the program + var howMany = null ; + //oddEven is the variable defining whether or not you add one or two to the variables above + var oddEven = null ; + //oddEvenspecific is the variable defining which one, odd or even, the numbers are. + var oddEvenspecific = null + //again, as is implied, is the variable that asks the user if they want to run the program again + var again = null + //start, as its name implies, starts the program + var start = null + + var start = prompt("Ready to begin?") + if (start == "yes" || start == "Yes"){ + program(); + } + + function program() { + + var howMany = prompt("How many numbers are in a row?") + var howMany = parseInt(howMany); + if (howMany==2){ + twoConsec(); + } + if (howMany==3){ + threeConsec(); + } + if (howMany==4){ + fourConsec(); + } + if (howMany==5){ + fiveConsec(); + } + + function twoConsec() { + var sum = prompt("What is the sum of the two consecutive integers?") + var sum = parseInt(sum); + //The above definition is defining the total sum of the consecutive integers + //Below we're beginning to define whether or not the numbers are odd or even only + var oddEven = prompt("Are the numbers all odd or all even?") ; + //Below we've just confirmed that they are in fact odd or even, and now we begin to reply with question about which one it is. + if (oddEven == "yes" || oddEven == "Yes"){ + var oddEvenspecific = prompt("Are the numbers even or odd? If even, reply with 1. If odd, reply with 2.") ; + var oddEvenspecific = parseInt(oddEvenspecific) ; + if (oddEvenspecific == 1){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 2 ; + + while (numOne + numTwo != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + } + alert("Your two consecutive integers are " + numOne + " and " + numTwo) ; + } + if (sum < 0){ + var numOne = (-2) ; + var numTwo = 0 ; + while (numOne + numTwo != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + } + alert("Your two consecutive integers are " + numOne + " and " + numTwo) + + } + } + if (oddEvenspecific == 2){ + if (sum > 0){ + var numOne = 1 ; + var numTwo = 3 ; + + while (numOne + numTwo != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + } + alert("Your two consecutive integers are " + numOne + " and " + numTwo) ; + } + if (sum < 0){ + var numOne = (-3) ; + var numTwo = (-1) ; + while (numOne + numTwo != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + } + alert("Your two consecutive integers are " + numOne + " and " + numTwo) + + } + } + } + //Below we've just found that the numbers are a mix of odds and evens + if (oddEven == "no" || oddEven == "No"){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 1 ; + + while (numOne + numTwo != sum){ + var numOne = numOne + 1 ; + var numTwo = numTwo + 1 ; + } + alert("Your two consecutive integers are " + numOne + " and " + numTwo) ; + } + if (sum < 0){ + var numOne = (-1) ; + var numTwo = 0 ; + while (numOne + numTwo != sum){ + var numOne = numOne - 1 ; + var numTwo = numTwo - 1 ; + } + alert("Your two consecutive integers are " + numOne + " and " + numTwo) + + } + } + } + function threeConsec() { + var sum = prompt("What is the sum of the three consecutive integers?") + var sum = parseInt(sum); + //The above definition is defining the total sum of the consecutive integers + //Below we're beginning to define whether or not the numbers are odd or even only + var oddEven = prompt("Are the numbers all odd or all even?") ; + //Below we've just confirmed that they are in fact odd or even, and now we begin to reply with question about which one it is. + if (oddEven == "yes" || oddEven == "Yes"){ + var oddEvenspecific = prompt("Are the numbers even or odd? If even, reply with 1. If odd, reply with 2.") ; + var oddEvenspecific = parseInt(oddEvenspecific) ; + //Below we've just found that the numbers are all even. + if (oddEvenspecific == 1){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 2 ; + var numThree = 4 ; + + while (numOne + numTwo + numThree != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + var numThree = numThree + 2; + } + alert("Your three consecutive integers are " + numOne + " " + numTwo + " and " + numThree) ; + } + if (sum < 0){ + var numOne = (-4) ; + var numTwo = (-2) ; + var numThree = 0 ; + while (numOne + numTwo + numThree != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + var numThree = numThree -2 ; + } + alert("Your three consecutive integers are " + numOne + " " + numTwo + " and " + numThree) + + } + } + //Below we've just found that the numbers are all odd + if (oddEvenspecific == 2){ + if (sum > 0){ + var numOne = 1 ; + var numTwo = 3 ; + var numThree = 5 ; + + while (numOne + numTwo + numThree != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + var numThree = numThree + 2 ; + } + alert("Your three consecutive integers are " + numOne + " " + numTwo + " and " + numThree) ; + } + if (sum < 0){ + var numOne = (-5) ; + var numTwo = (-3) ; + var numThree = (-1) ; + while (numOne + numTwo + numThree != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + var numThree = numThree - 2 ; + } + alert("Your three consecutive integers are " + numOne + " " + numTwo + " and " + numThree) + + } + } + } + //Below we've just found out that the numbers are a mix of odds and evens + if (oddEven == "no" || oddEven == "No"){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 1 ; + var numThree = 2 ; + + while (numOne + numTwo + numThree != sum){ + var numOne = numOne + 1 ; + var numTwo = numTwo + 1 ; + var numThree = numThree + 1 ; + } + alert("Your three consecutive integers are " + numOne + " " + numTwo + " and " + numThree) ; + } + if (sum < 0){ + var numOne = (-2) ; + var numTwo = (-1) ; + var numThree = 0 ; + while (numOne + numTwo + numThree != sum){ + var numOne = numOne - 1 ; + var numTwo = numTwo - 1 ; + var numThree = numThree - 1 ; + } + alert("Your three consecutive integers are " + numOne + " " + numTwo + " and " + numThree) + + } + } + } + function fourConsec() { + var sum = prompt("What is the sum of the four consecutive integers?") + var sum = parseInt(sum); + //The above definition is defining the total sum of the consecutive integers + //Below we're beginning to define whether or not the numbers are odd or even only + var oddEven = prompt("Are the numbers all odd or all even?") ; + //Below we've just confirmed that they are in fact odd or even, and now we begin to reply with question about which one it is. + if (oddEven == "yes" || oddEven == "Yes"){ + var oddEvenspecific = prompt("Are the numbers even or odd? If even, reply with 1. If odd, reply with 2.") ; + var oddEvenspecific = parseInt(oddEvenspecific) ; + //Below we've just found that the numbers are all even. + if (oddEvenspecific == 1){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 2 ; + var numThree = 4 ; + var numFour = 6 ; + + while (numOne + numTwo + numThree + numFour != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + var numThree = numThree + 2 ; + var numFour = numFour + 2 ; + } + alert("Your four consecutive integers are " + numOne + " " + numTwo + " " + numThree + " and " + numFour) ; + } + if (sum < 0){ + var numOne = (-6) ; + var numTwo = (-4) ; + var numThree = (-2) ; + var numFour = 0 ; + + while (numOne + numTwo + numThree + numFour != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + var numThree = numThree - 2 ; + var numFour = numFour - 2 ; + } + alert("Your four consecutive integers are " + numOne + " " + numTwo + " " + numThree + " and " + numFour) + + } + } + //Below we've just found that the numbers are all odd + if (oddEvenspecific == 2){ + if (sum > 0){ + var numOne = 1 ; + var numTwo = 3 ; + var numThree = 5 ; + var numFour = 7 ; + + while (numOne + numTwo + numThree + numFour != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + var numThree = numThree + 2 ; + var numFour = numFour + 2 ; + } + alert("Your four consecutive integers are " + numOne + " " + numTwo + " " + numThree + " and " + numFour) ; + } + if (sum < 0){ + var numOne = (-7) ; + var numTwo = (-5) ; + var numThree = (-3) ; + var numFour = (-1) ; + while (numOne + numTwo + numThree + numFour != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + var numThree = numThree - 2 ; + var numFour = numFour - 2 ; + } + alert("Your four consecutive integers are " + numOne + " " + numTwo + " " + numThree + " and " + numFour) + + } + } + } + //Below we've been informed that the numbers are a mix of odds and evens + if (oddEven == "no" || oddEven == "No"){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 1 ; + var numThree = 2 ; + var numFour = 3 ; + + while (numOne + numTwo + numThree + numFour != sum){ + var numOne = numOne + 1 ; + var numTwo = numTwo + 1 ; + var numThree = numThree + 1 ; + var numFour = numFour + 1 ; + } + alert("Your four consecutive integers are " + numOne + " " + numTwo + " " + numThree + " and "+ numFour) ; + } + if (sum < 0){ + var numOne = (-3) ; + var numTwo = (-2) ; + var numThree = (-1) ; + var numFour = 0 ; + while (numOne + numTwo + numThree + numFour != sum){ + var numOne = numOne - 1 ; + var numTwo = numTwo - 1 ; + var numThree = numThree - 1 ; + var numFour = numFour - 1 ; + } + alert("Your four consecutive integers are " + numOne + " " + numTwo + " " + numThree + " and "+ numFour) + + } + } + } + function fiveConsec() { + var sum = prompt("What is the sum of the five consecutive integers?") + var sum = parseInt(sum); + //The above definition is defining the total sum of the consecutive integers + //Below we're beginning to define whether or not the numbers are odd or even only + var oddEven = prompt("Are the numbers all odd or all even?") ; + //Below we've just confirmed that they are in fact odd or even, and now we begin to reply with question about which one it is. + if (oddEven == "yes" || oddEven == "Yes"){ + var oddEvenspecific = prompt("Are the numbers even or odd? If even, reply with 1. If odd, reply with 2.") ; + var oddEvenspecific = parseInt(oddEvenspecific) ; + //Below we've just found that the numbers are all even. + if (oddEvenspecific == 1){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 2 ; + var numThree = 4 ; + var numFour = 6 ; + var numFive = 8 ; + + + while (numOne + numTwo + numThree + numFour + numFive != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + var numThree = numThree + 2 ; + var numFour = numFour + 2 ; + var numFive = numFive + 2 ; + } + alert("Your five consecutive integers are " + numOne + " " + numTwo + " " + numThree + " " + numFour + " and " + numFive) ; + } + if (sum < 0){ + var numOne = (-8) ; + var numTwo = (-6) ; + var numThree = (-4) ; + var numFour = (-2) ; + var numFive = 0 ; + + while (numOne + numTwo + numThree + numFour + numFive != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + var numThree = numThree - 2 ; + var numFour = numFour - 2 ; + var numFive = numFive - 2 ; + } + alert("Your five consecutive integers are " + numOne + " " + numTwo + " " + numThree + " " + numFour + " and " + numFive) + + } + } + //Below we've just found that the numbers are all odd + if (oddEvenspecific == 2){ + if (sum > 0){ + var numOne = 1 ; + var numTwo = 3 ; + var numThree = 5 ; + var numFour = 7 ; + var numFive = 9 + + while (numOne + numTwo + numThree + numFour + numFive != sum){ + var numOne = numOne + 2 ; + var numTwo = numTwo + 2 ; + var numThree = numThree + 2 ; + var numFour = numFour + 2 ; + var numFive = numFive + 2 ; + } + alert("Your five consecutive integers are " + numOne + " " + numTwo + " " + numThree + " " + numFour + " and " + numFive) ; + } + if (sum < 0){ + var numOne = (-9) ; + var numTwo = (-7) ; + var numThree = (-5) ; + var numFour = (-3) ; + var numFive = (-1) + while (numOne + numTwo + numThree + numFour + numFive != sum){ + var numOne = numOne - 2 ; + var numTwo = numTwo - 2 ; + var numThree = numThree - 2 ; + var numFour = numFour - 2 ; + var numFive = numFive - 2 ; + } + alert("Your five consecutive integers are " + numOne + " " + numTwo + " " + numThree + " " + numFour + " and " + numFive) + + } + } + } + //Below we've been informed that the numbers are a mix of odds and evens + if (oddEven == "no" || oddEven == "No"){ + if (sum > 0){ + var numOne = 0 ; + var numTwo = 1 ; + var numThree = 2 ; + var numFour = 3 ; + var numFive = 4 + + while (numOne + numTwo + numThree + numFour + numFive != sum){ + var numOne = numOne + 1 ; + var numTwo = numTwo + 1 ; + var numThree = numThree + 1 ; + var numFour = numFour + 1 ; + var numFive = numFive + 1 ; + } + alert("Your five consecutive integers are " + numOne + " " + numTwo + " " + numThree + " "+ numFour + " and " + numFive) ; + } + if (sum < 0){ + var numOne = (-4) ; + var numTwo = (-3) ; + var numThree = (-2) ; + var numFour = (-1) ; + var numFive = 0 ; + while (numOne + numTwo + numThree + numFour + numFive != sum){ + var numOne = numOne - 1 ; + var numTwo = numTwo - 1 ; + var numThree = numThree - 1 ; + var numFour = numFour - 1 ; + var numFive = numFive -1 ; + } + alert("Your five consecutive integers are " + numOne + " " + numTwo + " " + numThree + " "+ numFour + " and " + numFive) + + } + } + } + var again = prompt("Do you want to run the code again?") + if (again == "yes" || again == "Yes"){ + program(); + } + if (again == "no" || again == "No"){ + alert("Bye!") + } + } + </script> + </body> +</html> +\ No newline at end of file diff --git a/mathPrograms/gearRatioFinder.html b/mathPrograms/gearRatioFinder.html @@ -0,0 +1,52 @@ +<!DOCTYPE html> + +<html> + <body> + <script> + var again = null + + codeFortwo(); + + function codeFortwo(){ + //Defining variables + + //GearRatio = gear ratio + var GearRatio = null ; + //Teeth1 = teeth on first gear + var Teeth1 = null ; + //Teeth2 = teeth on second gear + var Teeth2 = null ; + //Spin1 = spin on first gear + var Spin1 = null ; + //Spin2 = spin on second gear + var Spin2 = null ; + + //Process begins + alert("Welcome to the Gear Ratio Robot, or GaRRy") ; + var Teeth1 = prompt("How many teeth are on the first gear?") ; + var Teeth1 = parseInt(Teeth1) ; + var Teeth2 = prompt("How many teeth are on the second gear?") ; + var Teeth2 = parseInt(Teeth2) ; + if (Teeth1 > Teeth2){ + Spin2 = Teeth1/Teeth2 ; + var GearRatio = alert("Your gear ratio is: 1:" + Spin2) ; + } + else if (Teeth1 < Teeth2){ + Spin1 = Teeth2/Teeth1 ; + var GearRatio = alert("Your gear ratio is: " + Spin1 + ":1") ; + } + else { + var GearRatio = alert("Your gear ratio is: 1:1") ; + } + } + var again = prompt("Do you have another gear ratio to calculate?") ; + if (again == "yes" || again == "Yes"){ + codeFortwo(); + } + else { + alert("Bye!") ; + } + + </script> + </body> +</html> +\ No newline at end of file diff --git a/matrix/index.html b/matrix/index.html @@ -0,0 +1,67 @@ +<!DOCTYPE html> + +<head> + <title>Matrix</title> + <meta charset="utf-8"> + <link href="Matrix.css" rel="stylesheet"> +</head> +<body> + <header> + <h1>Automatic Matrix Solver</h1> + <h2>by FIGBERT</h2> + </header> + <main> + <form> + <fieldset> + <legend>Pick the matrix format</legend> + <label for="two"><input id="two" type="radio" name="eqSet" value="2">Two equations, two variables</label><br> + <label for="three"><input id="three" type="radio" name="eqSet" value="3">Three equations, three variables</label><br> + <label for="four"><input id="four" type="radio" name="eqSet" value="4">Four equations, four variables</label><br> + <input type="button" value="Set" onclick="setUp(eqSet.value)"> + </fieldset> + <fieldset id="equations"> + <legend>Pick the matrix values</legend> + <div> + <label for="wOne" class="w"><input id="wOne" type="number" name="setOne" class="numSet w a" step="0.01">w</label> + <label for="xOne"><input id="xOne" type="number" name="setOne" class="numSet a" step="0.01">x</label> + <label for="yOne"><input id="yOne" type="number" name="setOne" class="numSet a" step="0.01">y</label> + <label for="zOne" class="z"><input id="zOne" type="number" name="setOne" class="numSet z a" step="0.01">z</label> + <label for="equalsOne">=<input id="equalsOne" type="number" name="setOne" class="numSet a" step="0.01"></label> + </div> + <div> + <label for="wTwo" class="w"><input id="wTwo" type="number" name="setTwo" class="numSet w a" step="0.01">w</label> + <label for="xTwo"><input id="xTwo" type="number" name="setTwo" class="numSet a" step="0.01">x</label> + <label for="yTwo"><input id="yTwo" type="number" name="setTwo" class="numSet a" step="0.01">y</label> + <label for="zTwo" class="z"><input id="zTwo" type="number" name="setTwo" class="numSet z a" step="0.01">z</label> + <label for="equalsTwo">=<input id="equalsTwo" type="number" name="setTwo" class="numSet a" step="0.01"></label> + </div> + <div id="thirdEquation"> + <label for="wThree" class="w"><input id="wThree" type="number" name="setThree" class="numSet w a" step="0.01">w</label> + <label for="xThree"><input id="xThree" type="number" name="setThree" class="numSet a" step="0.01">x</label> + <label for="yThree"><input id="yThree" type="number" name="setThree" class="numSet a" step="0.01">y</label> + <label for="zThree" class="z"><input id="zThree" type="number" name="setThree" class="numSet z a" step="0.01">z</label> + <label for="equalsThree">=<input id="equalsThree" type="number" name="setThree" class="numSet a" step="0.01"></label> + </div> + <div id="fourthEquation"> + <label for="wFour" class="w"><input id="wFour" type="number" name="setFour" class="numSet w a" step="0.01">w</label> + <label for="xFour"><input id="xFour" type="number" name="setFour" class="numSet a" step="0.01">x</label> + <label for="yFour"><input id="yFour" type="number" name="setFour" class="numSet a" step="0.01">y</label> + <label for="zFour" class="z"><input id="zFour" type="number" name="setFour" class="numSet z a" step="0.01">z</label> + <label for="equalsFour">=<input id="equalsFour" type="number" name="setFour" class="numSet a" step="0.01"></label> + </div> + <input type="button" value="Solve" onclick="solve(eqSet.value)"> + </fieldset> + </form> + <div id="out"> + <h3 id="titleOne">First Line:</h3> + <p id="outOne"></p> + <h3 id="titleTwo">Second Line:</h3> + <p id="outTwo"></p> + <h3 id="titleThree">Third Line:</h3> + <p id="outThree"></p> + <h3 id="titleFour">Fourth Line:</h3> + <p id="outFour"></p> + </div> + </main> + <script src="matrixBeta.js"></script> +</body> +\ No newline at end of file diff --git a/matrix/matrix.css b/matrix/matrix.css @@ -0,0 +1,31 @@ +* { + font-family: sans-serif, monospace; + font-weight: 300; +} + +h1 { + font-family: sans-serif, monospace; + color: black; + margin: 5px; + font-weight: 600; +} + +h2 { + font-family: sans-serif, monospace; + color: black; + margin: 5px; + font-weight: 100; + margin-bottom: 10px; +} + +.numSet { + width: 3%; +} + +#equations { + display: none; +} + +#out { + display: none; +} +\ No newline at end of file diff --git a/matrix/matrix.js b/matrix/matrix.js @@ -0,0 +1,158 @@ +//lcm() calculates the lowest common multiple by adding the first number until it is divisible by the second. +function lcm(numOne, numTwo) { + "use strict"; + var i = numOne; + while (i % numTwo !== 0) { + i += numOne; + } + return i; +} + +//invert() changes all of the values in a numerical array to their opposites (1 to -1, etc) with a for loop +function invert(value) { + "use strict"; + for (var a = 0; a < value.length; a++) { + value[a] = value[a] * -1; + } + return value; +} + +//hide() hides arrayed html elements using the "display: none" method and a for loop +function hide(elements) { + "use strict"; + for (var a = 0; a < elements.length; a++) { + elements[a].style.display = "none"; + } +} + +//reset() clears html number inputs by setting their value to null +function reset(elements) { + "use strict"; + for (var a = 0; a < elements.length; a++) { + elements[a].value = null; + } +} + +//show() shows arrayed html elements INLINE using a for loop +function show(elements) { + "use strict"; + for (var a = 0; a < elements.length; a++) { + elements[a].style.display = "inline"; + } +} + +//setUp() will determine the number of equations and variables and adjust the html accordingly. +function setUp(num) { + "use strict"; + var + allW = document.getElementsByClassName("w"), + allZ = document.getElementsByClassName("z"), + all = document.getElementsByClassName("a"); + if (num == 2) { + document.getElementById("equations").style.display = "block"; + hide(allW); + hide(allZ); + document.getElementById("out").style.display = "none"; + document.getElementById("thirdEquation").style.display = "none"; + document.getElementById("fourthEquation").style.display = "none"; + reset(all); + } else if (num == 3) { + document.getElementById("equations").style.display = "block"; + hide(allW); + show(allZ); + document.getElementById("out").style.display = "none"; + document.getElementById("thirdEquation").style.display = "block"; + document.getElementById("fourthEquation").style.display = "none"; + reset(all); + } else { + document.getElementById("equations").style.display = "block"; + show(allW); + show(allZ); + document.getElementById("out").style.display = "none"; + document.getElementById("thirdEquation").style.display = "block"; + document.getElementById("fourthEquation").style.display = "block"; + reset(all); + } +} + +//THE PROBLEM WITH SOLVETHREE() IS HERE +//solveTwo() accepts the first two equations as input and solves the second +function solveTwo(one, two, dimension) { + "use strict"; + var + multOne = lcm(one[0], two[0]) / one[0], + multTwo = lcm(one[0], two[0]) / two[0], + changingOne = [one[0], one[1], one[2]]; + if (dimension == 3) { + changingOne.push(one[3]); + } else if (dimension == 4) { + changingOne.push(one[3], one[4]); + } + for (var a = 0; a < two.length; a++) { + changingOne[a] = changingOne[a] * multOne; + two[a] = two[a] * multTwo; + } + if (changingOne[0] + two[0] !== 0) { + invert(changingOne); + } + for (var b = 0; b < two.length; b++) { + two[b] = changingOne[b] + two[b]; + } + return two; +} + +//solveThree() accepts the first three equations as input and solves the second +function solveThree(one, two, three) { + "use strict"; + var + multOne = lcm(one[0], three[0]) / one[0], + multThree = lcm(one[0], three[0]) / three[0], + changingOne = [one[0], one[1], one[2], one[3]], + simpleTwo = solveTwo(one, two); + console.log(multOne, multThree, changingOne, simpleTwo); + for (var a = 0; a < three.length; a++) { + changingOne[a] = changingOne[a] * multOne; + three[a] = three[a] * multThree; + } + if (changingOne[0] + three[0] !== 0) { + invert(changingOne); + } + for (var b = 0; b < three.length; b++) { + three[b] = changingOne[b] + three[b]; + } + var + multTwo = lcm(simpleTwo[1] + three[1]) / simpleTwo[1], + subMultThree = lcm(simpleTwo[1] + three[1]) / three[1]; + for (var c = 0; c < three.length; c++) { + simpleTwo[c] = simpleTwo[c] * multTwo; + three[c] = three[c] * subMultThree; + } + if (simpleTwo[1] + three[1] !== 0) { + invert(simpleTwo); + } + for (var d = 0; d < three.length; d++) { + three[d] = three[d] + simpleTwo[d]; + } + return three; +} + +//solve() uses a combination of other functions to simplify the matrix +function solve(dimension) { + "use strict"; + if (dimension == 2) { + var + firstXY = [parseInt(document.getElementById("xOne").value), parseInt(document.getElementById("yOne").value), parseInt(document.getElementById("equalsOne").value)], + secondXY = [parseInt(document.getElementById("xTwo").value), parseInt(document.getElementById("yTwo").value), parseInt(document.getElementById("equalsTwo").value)], + answerXY = solveTwo(firstXY, secondXY, dimension); + show([document.getElementById("out")]); + hide([document.getElementById("titleThree"), document.getElementById("outThree"), document.getElementById("titleFour"), document.getElementById("outFour")]); + document.getElementById("outOne").innerHTML = "[" + firstXY[0] + ", " + firstXY[1] + ", " + firstXY[2] + "]"; + document.getElementById("outTwo").innerHTML = "[" + answerXY[0] + ", " + answerXY[1] + ", " + answerXY[2] + "]"; + } else if (dimension == 3) { + var + firstXYZ = [parseInt(document.getElementById("xOne").value), parseInt(document.getElementById("yOne").value), parseInt(document.getElementById("zOne").value), parseInt(document.getElementById("equalsOne").value)], + secondXYZ = [parseInt(document.getElementById("xTwo").value), parseInt(document.getElementById("yTwo").value), parseInt(document.getElementById("zTwo").value), parseInt(document.getElementById("equalsTwo").value)], + thirdXYZ = [parseInt(document.getElementById("xThree").value), parseInt(document.getElementById("yThree").value), parseInt(document.getElementById("zThree").value), parseInt(document.getElementById("equalsThree").value)]; + console.log(solveThree(firstXYZ, secondXYZ, thirdXYZ)); + } +} +\ No newline at end of file diff --git a/matrix/matrixBeta.js b/matrix/matrixBeta.js @@ -0,0 +1,150 @@ +//lcm() calculates the lowest common multiple by adding the first number until it is divisible by the second. +function lcm(numOne, numTwo) { + "use strict"; + var i = numOne; + while (i % numTwo !== 0) { + i += numOne; + } + return i; +} + +//invert() changes all of the values in a numerical array to their opposites (1 to -1, etc) with a for loop +function invert(value) { + "use strict"; + for (var a = 0; a < value.length; a++) { + value[a] = value[a] * -1; + } + return value; +} + +//hide() hides arrayed html elements using the "display: none" method and a for loop +function hide(elements) { + "use strict"; + for (var a = 0; a < elements.length; a++) { + elements[a].style.display = "none"; + } +} + +//reset() clears html number inputs by setting their value to null +function reset(elements) { + "use strict"; + for (var a = 0; a < elements.length; a++) { + elements[a].value = null; + } +} + +//show() shows arrayed html elements INLINE using a for loop +function show(elements) { + "use strict"; + for (var a = 0; a < elements.length; a++) { + elements[a].style.display = "inline"; + } +} + +//setUp() will determine the number of equations and variables and adjust the html accordingly. +function setUp(num) { + "use strict"; + var + allW = document.getElementsByClassName("w"), + allZ = document.getElementsByClassName("z"), + all = document.getElementsByClassName("a"); + if (num == 2) { + document.getElementById("equations").style.display = "block"; + hide(allW); + hide(allZ); + document.getElementById("out").style.display = "none"; + document.getElementById("thirdEquation").style.display = "none"; + document.getElementById("fourthEquation").style.display = "none"; + reset(all); + } else if (num == 3) { + document.getElementById("equations").style.display = "block"; + hide(allW); + show(allZ); + document.getElementById("out").style.display = "none"; + document.getElementById("thirdEquation").style.display = "block"; + document.getElementById("fourthEquation").style.display = "none"; + reset(all); + } else { + document.getElementById("equations").style.display = "block"; + show(allW); + show(allZ); + document.getElementById("out").style.display = "none"; + document.getElementById("thirdEquation").style.display = "block"; + document.getElementById("fourthEquation").style.display = "block"; + reset(all); + } +} + +//THE PROBLEM WITH SOLVETHREE() IS HERE +//solveTwo() accepts the first two equations as input and solves the second +function solveTwo(one, two) { + "use strict"; + var + multOne = lcm(one[0], two[0]) / one[0], + multTwo = lcm(one[0], two[0]) / two[0]; + for (var a = 0; a < two.length; a++) { + one[a] = one[a] * multOne; + two[a] = two[a] * multTwo; + } + if (one[0] + two[0] !== 0) { + invert(one); + } + for (var b = 0; b < two.length; b++) { + two[b] = one[b] + two[b]; + } + return two; +} + +//solveThree() accepts the first three equations as input and solves the second +function solveThree(one, two, three) { + "use strict"; + var + multOne = lcm(one[0], three[0]) / one[0], + multThree = lcm(one[0], three[0]) / three[0], + simpleTwo = solveTwo(one, two); + for (var a = 0; a < three.length; a++) { + one[a] = one[a] * multOne; + three[a] = three[a] * multThree; + } + if (one[0] + three[0] !== 0) { + invert(one); + } + for (var b = 0; b < three.length; b++) { + three[b] = one[b] + three[b]; + } + var + multTwo = lcm(simpleTwo[1] + three[1]) / simpleTwo[1], + subMultThree = lcm(simpleTwo[1] + three[1]) / three[1]; + for (var c = 0; c < three.length; c++) { + simpleTwo[c] = simpleTwo[c] * multTwo; + three[c] = three[c] * subMultThree; + } + if (simpleTwo[1] + three[1] !== 0) { + invert(simpleTwo); + } + for (var d = 0; d < three.length; d++) { + three[d] = three[d] + simpleTwo[d]; + } + return three; +} + +//solve() uses a combination of other functions to simplify the matrix +function solve(dimension) { + "use strict"; + if (dimension == 2) { + var + firstXY = [parseInt(document.getElementById("xOne").value), parseInt(document.getElementById("yOne").value), parseInt(document.getElementById("equalsOne").value)], + secondXY = [parseInt(document.getElementById("xTwo").value), parseInt(document.getElementById("yTwo").value), parseInt(document.getElementById("equalsTwo").value)], + answerXY = solveTwo(firstXY, secondXY, dimension); + show([document.getElementById("out")]); + hide([document.getElementById("titleThree"), document.getElementById("outThree"), document.getElementById("titleFour"), document.getElementById("outFour")]); + document.getElementById("outOne").innerHTML = "[" + firstXY[0] + ", " + firstXY[1] + ", " + firstXY[2] + "]"; + document.getElementById("outTwo").innerHTML = "[" + answerXY[0] + ", " + answerXY[1] + ", " + answerXY[2] + "]"; + } else if (dimension == 3) { + var + firstXYZ = [parseInt(document.getElementById("xOne").value), parseInt(document.getElementById("yOne").value), parseInt(document.getElementById("zOne").value), parseInt(document.getElementById("equalsOne").value)], + secondXYZ = [parseInt(document.getElementById("xTwo").value), parseInt(document.getElementById("yTwo").value), parseInt(document.getElementById("zTwo").value), parseInt(document.getElementById("equalsTwo").value)], + thirdXYZ = [parseInt(document.getElementById("xThree").value), parseInt(document.getElementById("yThree").value), parseInt(document.getElementById("zThree").value), parseInt(document.getElementById("equalsThree").value)]; + console.log(solveThree(firstXYZ, secondXYZ, thirdXYZ)); + } +} +\ No newline at end of file