JavaScript Source Code 3000: Calculators: Quadratic Solver
Quadratic Solver
Solves quadratic equations for inputted coefficients. Answers can be either real or complex. Awesome!
x2+ x + = 0
x1=
x2=
JavaScript Source Code 3000: Calculators: Quadratic Solver
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s). The script is yours!!!
<!-- TWO STEPS TO INSTALL QUADRATIC SOLVER:
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: John Caranta (caranta@netzero.net) -->
<! >
<! >
<!-- Begin
var rootparti;
var rootpart;
var det;
var rootparti1;
var rootparti2;
var a;
var b;
var c;
var x1;
var x2;
var i = "i";
function checkQuad() {
var a = document.fquad.fa.value;
var b = document.fquad.fb.value;
var c = document.fquad.fc.value;
if (a == 0 && c != 0) {
x1 = -c / b;
x2 = "Not a quadratic equation, but here is your answer for x";
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
else if (a == "" && c != 0) {
x1 = -c / b;
x2 = "Not a quadratic equation";
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
else {
quad();
}
}
function quad() {
var a = document.fquad.fa.value;
var b = document.fquad.fb.value;
var c = document.fquad.fc.value;
det = Math.pow(b,2) - 4 * a * c;
rootpart = Math.sqrt(det) / (2 * a);
rootparti = (Math.sqrt(-det) / (2 * a)) + i;
if (parseFloat(rootparti) < 0) {
rootparti1 = rootparti;
rootparti2 = (-1 * parseFloat(rootparti)) + i;
}
else {
rootparti1 = (-1 * parseFloat(rootparti)) + i;
rootparti2 = rootparti;
}
if (rootparti1 == "1i") {
rootparti1 = i;
rootparti2 = "-i";
}
else if (rootparti1 == "-1i") {
rootparti1 = "-i";
rootparti2 = i;
}
if (det == 0) {
x1 = x2 = -b / (2 * a);
}
else if (det > 0) {
x1 = (-b + Math.sqrt(det)) / (2 * a);
x2 = (-b - Math.sqrt(det)) / (2 * a);
}
else if ((-b / (2 * a)) == 0) {
x1 = rootparti1;
x2 = rootparti2;
}
else {
x1 = (-b / (2 * a) + " + " + rootparti1);
x2 = (-b / (2 * a) + " + " + rootparti2);
}
document.fquad.x1.value=x1;
document.fquad.x2.value=x2;
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<form name=fquad>
<table>
<tr>
<td>
<h2>
<input name=fa size=4> x<SUP>2</SUP>+ <input name=fb size=4> x + <input name=fc size=4> = 0
<input type=button value="Solve" onClick="checkQuad()"> <input type=reset value="Reset">
</h2>
</td>
</tr>
<tr>
<td>
<h2>
x<sub>1</sub>=<input name=x1 size=45>
<br>
x<sub>2</sub>= <input name=x2 size=45>
</h2>
</td>
</tr>
</table>
</form>
<!-- Script Size: 2.77 KB -->
Wyszukiwarka
Podobne podstrony:
Pronator Quadratus tape SPPronator Quadratus KT methodQuadratus Lumborum testSCRZIP BO Lab3 Blad Solvera IntBinQuadratus Lumborum Muscle and Iliotibial Band tapeSPie st2010ie lab07 solverNARZęDZIE SOLVER APLIKACJI MS EXCELQuadratisches Tuch AnleitungQuadragesimo annoquadratichanoi solverexpression solverQuadratus Lumborum tapeSPwięcej podobnych podstron