Enter coefficients 'a', 'b', and 'c' to see the solutions.
Understanding the Quadratic Equation Solver
The quadratic equation is a fundamental concept in algebra, represented in its standard form as:
ax² + bx + c = 0
where a, b, and c are coefficients, and a cannot be zero (if a=0, it becomes a linear equation). The solutions to this equation are the values of x that satisfy it. These solutions are also known as roots.
The Quadratic Formula
The most common method to find the roots of a quadratic equation is using the quadratic formula:
x = [-b ± √(b² - 4ac)] / 2a
This formula is derived by completing the square on the standard form of the equation. It provides a direct way to calculate the roots, regardless of whether they are real or complex.
The Discriminant (Δ)
A crucial part of the quadratic formula is the expression under the square root: b² - 4ac. This is called the discriminant, often denoted by the Greek letter Delta (Δ). The value of the discriminant tells us about the nature of the roots:
If Δ > 0: There are two distinct real roots.
If Δ = 0: There is exactly one real root (a repeated root).
If Δ < 0: There are two complex conjugate roots.
How the Calculator Works
This calculator takes your input for the coefficients a, b, and c. It first calculates the discriminant (Δ = b² - 4ac).
If the discriminant is non-negative (≥ 0), it calculates the real root(s) using the standard quadratic formula.
If the discriminant is negative (< 0), it indicates complex roots. The calculator will display the roots in the form real_part ± imaginary_part i, where i is the imaginary unit (√-1).
If coefficient 'a' is zero, it is not a quadratic equation and will display an error.
Use Cases
Quadratic equations and their solutions appear in many fields:
Physics: Describing projectile motion, understanding energy levels.
Economics: Modeling supply and demand, calculating profit maximization.
Mathematics: Solving algebraic problems, understanding function behavior (parabolas).
This solver helps quickly find the roots for any given set of coefficients, making it a useful tool for students, educators, and professionals.
function solveQuadratic() {
var a = parseFloat(document.getElementById("coeffA").value);
var b = parseFloat(document.getElementById("coeffB").value);
var c = parseFloat(document.getElementById("coeffC").value);
var resultDiv = document.getElementById("result");
resultDiv.className = ""; // Reset class for styling
// Check if inputs are valid numbers
if (isNaN(a) || isNaN(b) || isNaN(c)) {
resultDiv.innerHTML = "Please enter valid numbers for all coefficients.";
resultDiv.className = "error";
return;
}
// Handle the case where 'a' is 0 (linear equation)
if (a === 0) {
if (b === 0) {
if (c === 0) {
resultDiv.innerHTML = "Equation is 0 = 0. All real numbers are solutions.";
} else {
resultDiv.innerHTML = "Equation is " + c + " = 0, which is impossible. No solution.";
resultDiv.className = "error";
}
} else {
var x = -c / b;
resultDiv.innerHTML = "This is a linear equation (a=0). The solution is x = " + x.toFixed(4);
}
return;
}
var discriminant = b * b – 4 * a * c;
var solutions = [];
if (discriminant >= 0) {
var sqrtDiscriminant = Math.sqrt(discriminant);
var x1 = (-b + sqrtDiscriminant) / (2 * a);
var x2 = (-b – sqrtDiscriminant) / (2 * a);
solutions.push(x1.toFixed(4));
if (Math.abs(x1 – x2) > 1e-9) { // Check if roots are distinct
solutions.push(x2.toFixed(4));
}
if (solutions.length === 1) {
resultDiv.innerHTML = "The equation has one real solution: x = " + solutions[0] + "";
} else {
resultDiv.innerHTML = "The equation has two real solutions: x₁ = " + solutions[0] + "x₂ = " + solutions[1] + "";
}
} else { // Discriminant is negative, complex roots
var realPart = (-b / (2 * a)).toFixed(4);
var imaginaryPart = (Math.sqrt(-discriminant) / (2 * a)).toFixed(4);
solutions.push(realPart + " + " + imaginaryPart + "i");
solutions.push(realPart + " – " + imaginaryPart + "i");
resultDiv.innerHTML = "The equation has two complex solutions: x₁ = " + solutions[0] + "x₂ = " + solutions[1] + "";
}
}