2 by 2 Simultaneous Equations Code in JavaScript
Well, it has not been much of algebra so far; We are about to have
our first taste of it.
Simultaneous equations can be solved using either
Elimination or Substitution method.
We will be using the Elimination method.
Algorithm Steps to Follow for Simultaneous Equations with 2 unknowns in JavaScript
Consider the equations:
2x + 3y = 13; and
5x - y = 7
Step 1:
Pick a variable to eliminate, either x or y.
Our code will always eliminate the y variable.
Step 2:
Multiply equation 1 by the coefficient of variable y
in equation 2.
⇒
-1 X (2x + 3y = 13)
⇒
-2x - 3y = -13
Step 3:
Multiply equation 2 by the coefficient of variable y
in equation 1.
⇒
3 X (5x - y = 7)
⇒
15x - 3y = 21
Step 4:
Subtract the new equations obtained from Steps 2 and 3.
-2x - 3y = -13
-
15x - 3y = 21
⇒
-17x = -34
Step 5:
Divide the R.H.S. from Step 4 by the coefficient of
x to obtain x.
⇒
x = -34/-17 = 2;
Step 6:
Obtain y by solving for y from any of the
original equations, using the found value of x.
2x + 3y = 13
⇒
2(2) + 3y = 13;
⇒
3y = 13 - 4 = 9;
⇒
y = 9/3 = 3;
Create 2 new files; On Notepad++: File, New.
Call them Simultaneous2Unknown.html and Simultaneous2Unknown.js;
Type out the adjoining JavaScript code for solving simultaneous
equations with 2 unknowns.