<html>
<head>
<title>Simultaneous linear equations ... The substitution method</title>
<script>
var y1 = 1.0;
var x1 = 1.0;
var f1 = 0.0;
var y2 = 1.0;
var x2 = 1.0;
var f2 = 0.0;


function init() {
if (window.location.search.indexOf("x1") != (0 - 1)) {
var myprmstr = window.location.search.substr(1);
var myprmarr = myprmstr.split ("&");
var myparams = {};
var eis = "";


for ( var i = 0; i < myprmarr.length; i++) {
var mytmparr = myprmarr[i].split("=");
myparams[mytmparr[0]] = mytmparr[1];
eis = mytmparr[0] + " = ";
eis = eis + mytmparr[1];
//alert(eis);
//eval(eis);
document.getElementById(mytmparr[0]).value = mytmparr[1];
}
//alert(stuff);
document.forms[0].onsubmit = function() { return solve_equations(); }
} else {
document.forms[0].onsubmit = function() { return solve_equations(); }
}
}


function ee1x(ee1y) {
var xis=0.0;
var fis=0.0;
// (y1)y=(x1)x + f1;
xis = eval(xis+(y1));
xis *= ee1y;
xis = eval((xis)-(f1));
xis /= x1;
return xis;
}

function ee2x(ee2y) {
var xis=0.0;
var fis=0.0;
// (y2)y=(x2)x + f2;
xis = eval(xis+(y2));
xis *= ee2y;
xis = eval((xis)-(f2));
xis /= x2;
return xis;
}


function e1y(e1x) {
var yis=0.0;
var fis=0.0;
yis = eval(yis+(x1)); //eval(((x1) * (xis)) + (f1));
//alert('yis 1 = eval((x1 * xis) + (f1)) = ' + yis);
yis *= e1x;
//alert('yis 2 = eval((x1 * xis) + (f1)) = ' + yis);
fis = eval((fis)+(f1));
yis = eval((yis)+(fis));
return yis;
}

function e2y(e2x) {
var yis=0.0;
var fis=0.0;
yis = eval(yis+(x2)); //eval(((x1) * (xis)) + (f1));
//alert('yis 1 = eval((x1 * xis) + (f1)) = ' + yis);
yis *= e2x;
//alert('yis 2 = eval((x1 * xis) + (f1)) = ' + yis);
fis = eval((fis)+(f2));
yis = eval((yis)+(fis));
return yis;
}

function solve_equations() {
var yis=0.0;
var fis=0.0;
x1 = document.getElementById("x1").value;
y1 = document.getElementById("y1").value;
f1 = document.getElementById("f1").value;
x2 = document.getElementById("x2").value;
y2 = document.getElementById("y2").value;
f2 = document.getElementById("f2").value;
var iurl = "http://www.rjmprogramming.com.au/PHP/LineChart/line_chart.php?title=Simultaneous%20Linear%20Equations&label=x&value=";
iurl = iurl + y1 + "y%3d" + x1 + "x%2b(" + f1 + ")," + y2 + "y%3d" + x2 + "x%2b(" + f2 + ")&data=";

if (y1 != 1) {
x1 = x1 / y1;
f1 = f1 / y1;
y1 = 1.0;
}
if (y2 != 1) {
x2 = x2 / y2;
f2 = f2 / y2;
y2 = 1.0;
}

var xx1 = eval((x1) - (x2));
//alert('xx1 = eval((x1) - (x2)) = ' + xx1);
var ff1 = eval((f2) - (f1));
//alert('ff1 = eval((f2) - (f1)) = ' + ff1);
var xis = eval((ff1) / (xx1));
//alert('xis = eval(ff1 / xx1) = ' + xis);

//yis = eval(yis+(x1)); //eval(((x1) * (xis)) + (f1));
////alert('yis 1 = eval((x1 * xis) + (f1)) = ' + yis);
//yis *= xis;
////alert('yis 2 = eval((x1 * xis) + (f1)) = ' + yis);
//fis = eval((fis)+(f1));
//yis = eval((yis)+(fis));
////alert('yis 3 = eval((x1 * xis) + (f1)) = ' + yis);

yis = e1y(xis);


//http://localhost:8888/line_chart.php?title=Simultaneous%20Equations&label=x&value=x,y&data=,[-1.0,0,6],[0.0,2,5],[1.0,4,4],[5.0,12,0]
var xxis=ee1x(0.0);
var yyis=e2y(xxis);
iurl = iurl + ",[" + xxis + ",0.0," + yyis + "]";
yyis = e1y(0.0);
iurl = iurl + ",[0.0," + yyis + "," + e2y(0.0) + "]";
iurl = iurl + ",[" + xis + "," + yis + "," + yis + "]";
xxis = ee2x(0.0);
yyis = e1y(xxis);
iurl = iurl + ",[" + xxis + "," + yyis + ",0.0]";
var qwt=document.getElementById('ifrm');
qwt.style.display = 'block';
window.open(iurl, 'ifrm');
qwt.src = iurl;
//var xxx=prompt("", iurl);
alert('Intersection point is (' + xis + ',' + yis + ')');

return true;
}

</script>
</head>
<body onload="init();" style="background-color: yellow;">
<form style="border: 5px solid blue; padding: 4px 4px 4px 4px;" method="GET">
<h2>Your Simultaneous Linear Equations</h2>
<p><label><input type="text" id="y1" name="y1" value="1" /> y = <input type="text" id="x1" name="x1" value="1" /> x + (<input type="text" id="f1" name="f1" value="0" />)</label></p>
<p><label><input type="text" id="y2" name="y2" value="1" /> y = <input type="text" id="x2" name="x2" value="1" /> x + (<input type="text" id="f2" name="f2" value="0" />)</label></p>
<p><input id="r" type="reset" />&nbsp;<input type="submit" id="s" value="Solve" /></p>
</form>
<iframe src="javascript:false;" id="ifrm" style="display:none;width:100%;height:600px;"></iframe>
</body>
</html>