A quadratic equation is a second-order polynomial equation in a single variable. The standard form is ax² + bx + c = 0, where x represents an unknown, and a, b, and c represent known numbers (coefficients), with a not equal to 0.
The Quadratic Formula
To find the values of x, we use the formula:
x = [-b ± √(b² – 4ac)] / 2a
Step-by-Step Breakdown
Identify Coefficients: Determine the values for a, b, and c from your equation.
Calculate the Discriminant (D): Find D = b² – 4ac. This tells us the nature of the roots.
If D > 0: Two distinct real roots.
If D = 0: One real repeated root.
If D < 0: Two complex (imaginary) roots.
Apply the Formula: Substitute the values back into the formula to solve for x₁ and x₂.
Practical Example
Equation: x² – 5x + 6 = 0
Step 1: a = 1, b = -5, c = 6
Step 2: D = (-5)² – 4(1)(6) = 25 – 24 = 1
Step 3: x = (5 ± √1) / 2
Step 4: x₁ = (5 + 1)/2 = 3; x₂ = (5 – 1)/2 = 2
function solveQuadratic() {
var a = parseFloat(document.getElementById('coeff_a').value);
var b = parseFloat(document.getElementById('coeff_b').value);
var c = parseFloat(document.getElementById('coeff_c').value);
var output = document.getElementById('steps-output');
var container = document.getElementById('solution-container');
if (isNaN(a) || isNaN(b) || isNaN(c)) {
alert("Please enter valid numbers for a, b, and c.");
return;
}
if (a === 0) {
alert("Coefficient 'a' cannot be zero in a quadratic equation.");
return;
}
container.style.display = 'block';
var steps = "";
// Step 1: Identify
steps += "Step 1: Identify coefficients";
steps += "a = " + a + ", b = " + b + ", c = " + c + "";
// Step 2: Discriminant
var d = (b * b) – (4 * a * c);
steps += "Step 2: Calculate the Discriminant (D)";
steps += "D = b² – 4ac";
steps += "D = (" + b + ")² – 4(" + a + ")(" + c + ")";
steps += "D = " + (b * b) + " – " + (4 * a * c) + "";
steps += "D = " + d + "";
// Step 3: Solve
steps += "Step 3: Solve for x using the formula";
steps += "x = [-b ± √D] / 2a";
if (d > 0) {
var sqrtD = Math.sqrt(d);
var x1 = (-b + sqrtD) / (2 * a);
var x2 = (-b – sqrtD) / (2 * a);
steps += "D is positive, so there are two real roots.";
steps += "x = [" + (-b) + " ± √" + d + "] / " + (2 * a) + "";
steps += "x = [" + (-b) + " ± " + sqrtD.toFixed(4) + "] / " + (2 * a) + "";
steps += "Results:";
steps += "x₁ = " + x1.toFixed(4) + "";
steps += "x₂ = " + x2.toFixed(4);
} else if (d === 0) {
var x = -b / (2 * a);
steps += "D is zero, so there is one repeated real root.";
steps += "x = " + (-b) + " / " + (2 * a) + "";
steps += "Result:";
steps += "x = " + x.toFixed(4);
} else {
var realPart = (-b / (2 * a)).toFixed(4);
var imaginaryPart = (Math.sqrt(-d) / (2 * a)).toFixed(4);
steps += "D is negative, so roots are complex (imaginary).";
steps += "x = [" + (-b) + " ± √(" + d + ")] / " + (2 * a) + "";
steps += "Results:";
steps += "x₁ = " + realPart + " + " + imaginaryPart + "i";
steps += "x₂ = " + realPart + " – " + imaginaryPart + "i";
}
output.innerHTML = steps;
container.scrollIntoView({ behavior: 'smooth' });
}