A quadratic equation is a second-order polynomial equation in a single variable x. The standard form is ax² + bx + c = 0, where a is not equal to zero. The solutions to this equation are called the roots of the equation.
This calculator uses the Quadratic Formula to find the roots:
x = [-b ± √(b² – 4ac)] / 2a
Understanding the Discriminant (D)
The term inside the square root, b² – 4ac, is known as the discriminant. It determines the nature of the roots:
D > 0: Two distinct real roots exist.
D = 0: Exactly one real root exists (a repeated root).
D < 0: No real roots exist; the roots are complex or imaginary.
Example Calculation
Suppose you have the equation: 1x² – 5x + 6 = 0.
a = 1, b = -5, c = 6
Discriminant = (-5)² – 4(1)(6) = 25 – 24 = 1
Since D > 0, we use the formula: [5 ± √1] / 2
Root 1: (5 + 1) / 2 = 3
Root 2: (5 – 1) / 2 = 2
function solveQuadratic() {
var a = parseFloat(document.getElementById('coeffA').value);
var b = parseFloat(document.getElementById('coeffB').value);
var c = parseFloat(document.getElementById('coeffC').value);
var output = document.getElementById('mathOutput');
var resultArea = document.getElementById('mathResultArea');
if (isNaN(a) || isNaN(b) || isNaN(c)) {
alert("Please enter valid numbers for all coefficients.");
return;
}
if (a === 0) {
if (b === 0) {
output.innerHTML = "This is not a valid equation (0 = " + c + ").";
} else {
var x = -c / b;
output.innerHTML = "This is a linear equation. Root x = " + x.toFixed(4) + "";
}
resultArea.style.display = "block";
return;
}
var discriminant = (b * b) – (4 * a * c);
var resultText = "";
if (discriminant > 0) {
var r1 = (-b + Math.sqrt(discriminant)) / (2 * a);
var r2 = (-b – Math.sqrt(discriminant)) / (2 * a);
resultText = "Discriminant: " + discriminant.toFixed(4) + "" +
"The equation has two distinct real roots:" +
"x₁ = " + r1.toFixed(4) + "" +
"x₂ = " + r2.toFixed(4) + "";
} else if (discriminant === 0) {
var r = -b / (2 * a);
resultText = "Discriminant: 0" +
"The equation has one repeated real root:" +
"x = " + r.toFixed(4) + "";
} else {
var realPart = (-b / (2 * a)).toFixed(4);
var imaginaryPart = (Math.sqrt(-discriminant) / (2 * a)).toFixed(4);
resultText = "Discriminant: " + discriminant.toFixed(4) + "" +
"The equation has complex roots:" +
"x₁ = " + realPart + " + " + imaginaryPart + "i" +
"x₂ = " + realPart + " – " + imaginaryPart + "i";
}
output.innerHTML = resultText;
resultArea.style.display = "block";
}