Simultaneous Linear Equations
The code for solving simultaneous equations is taken from my civil engineering Master's thesis, around 1972, written in FORTRAN IV.
Shown below is the original 1972 FORTRAN printout, with line numbers and a dreadful "Go To 9" statement! Next to it is
my recent translation to JavaScript (as used below).
function solveMTX(q, nn)
{
var lead, diag;
var i;
var nrow = nn;
var ncol = nrow + 1;
for( i = 1; i <= nrow; i++)
{
for(var k= i; k <= nrow; k++)
{
if(q[k][i] != 0) break;
if(k == nrow) return;
}
for(var j= 1; j <= ncol; j++)
{
b = q[i][j];
q[i][j]= q[k][j];
q[k][j]= b;
}
diag =q[i][i];
for(var j= i; j <= ncol; j++)
{
q[i][j] = q[i][j] / diag;
}
for(var k = 1; k <= nrow; k++)
{
if(k != i)
{
lead = q[k][i];
for(var j = i; j <= ncol; j++)
{
q[k][j] = q[k][j] - q[i][j]* lead
}
}
} // end of k loop
} // end of i loop
return
}
Input your own coefficients for two equations. For example, 4X + 3Y = 5.
Click Solve Equations and you will see the plot of the two lines representing the equations.
Where the lines cross is the solution.
Solution X =
Solution Y =
© 2018 T B Griffin