Quadratic Equation Solver
Enter the coefficients (a, b, c) of your quadratic equation in the standard form ax² + bx + c = 0 to find its roots and the step-by-step solution.
Results:
Step-by-Step Solution:
ax² + bx + c = 0:";
stepsHtml += "Your equation is: " + a + "x² + " + b + "x + " + c + " = 0";
stepsHtml += "Step 1: Identify the coefficients.";
stepsHtml += "a = " + a + "";
stepsHtml += "b = " + b + "";
stepsHtml += "c = " + c + "";
if (a === 0) {
resultDiv.innerHTML = "Coefficient 'a' cannot be zero for a quadratic equation. This is a linear equation.";
if (b === 0) {
stepsHtml += "Step 2: Handle special case (a=0).";
stepsHtml += "Since a = 0, the equation becomes " + b + "x + " + c + " = 0.";
if (c === 0) {
stepsHtml += "Since b = 0 and c = 0, the equation is 0 = 0, which is true for all x (infinite solutions).";
resultDiv.innerHTML = "This is a degenerate case: 0 = 0. Infinite solutions.";
} else {
stepsHtml += "Since b = 0 and c ≠ 0, the equation is " + c + " = 0, which is false (no solution).";
resultDiv.innerHTML = "This is a degenerate case: " + c + " = 0. No solution.";
}
} else {
stepsHtml += "Step 2: Handle special case (a=0).";
stepsHtml += "Since a = 0, the equation simplifies to a linear equation: " + b + "x + " + c + " = 0.";
stepsHtml += "Solving for x: " + b + "x = " + (-c) + "";
var x_linear = -c / b;
stepsHtml += "x = " + (-c) + " / " + b + " = " + x_linear + "";
resultDiv.innerHTML = "This is a linear equation. The root is: x = " + x_linear.toFixed(4) + "";
}
stepsDiv.innerHTML = stepsHtml;
return;
}
stepsHtml += "Step 2: Calculate the discriminant (Δ).";
stepsHtml += "The discriminant is given by the formula: Δ = b² - 4ac";
stepsHtml += "Substitute the values: Δ = (" + b + ")² - 4 * (" + a + ") * (" + c + ")";
var discriminant = b * b – 4 * a * c;
stepsHtml += "Δ = " + (b * b) + " - (" + (4 * a * c) + ")";
stepsHtml += "Δ = " + discriminant + "";
stepsHtml += "Step 3: Determine the nature of the roots based on the discriminant.";
if (discriminant > 0) {
stepsHtml += "Since Δ > 0 (" + discriminant + " > 0), there are two distinct real roots.";
stepsHtml += "Step 4: Apply the quadratic formula.";
stepsHtml += "The quadratic formula is: x = [-b ± √Δ] / 2a";
stepsHtml += "Substitute the values: x = [-" + b + " ± √" + discriminant + "] / (2 * " + a + ")";
stepsHtml += "x = [-" + b + " ± " + Math.sqrt(discriminant).toFixed(4) + "] / " + (2 * a) + "";
var x1 = (-b + Math.sqrt(discriminant)) / (2 * a);
var x2 = (-b – Math.sqrt(discriminant)) / (2 * a);
stepsHtml += "Calculate x1: x1 = (-" + b + " + " + Math.sqrt(discriminant).toFixed(4) + ") / " + (2 * a) + " = " + x1.toFixed(4) + "";
stepsHtml += "Calculate x2: x2 = (-" + b + " - " + Math.sqrt(discriminant).toFixed(4) + ") / " + (2 * a) + " = " + x2.toFixed(4) + "";
resultDiv.innerHTML = "The equation has two distinct real roots:";
resultDiv.innerHTML += "x1 = " + x1.toFixed(4) + "";
resultDiv.innerHTML += "x2 = " + x2.toFixed(4) + "";
} else if (discriminant === 0) {
stepsHtml += "Since Δ = 0, there is exactly one real root (a repeated root).";
stepsHtml += "Step 4: Apply the simplified quadratic formula.";
stepsHtml += "When Δ = 0, the formula simplifies to: x = -b / 2a";
stepsHtml += "Substitute the values: x = -" + b + " / (2 * " + a + ")";
var x = -b / (2 * a);
stepsHtml += "x = -" + b + " / " + (2 * a) + " = " + x.toFixed(4) + "";
resultDiv.innerHTML = "The equation has one real (repeated) root:";
resultDiv.innerHTML += "x = " + x.toFixed(4) + "";
} else { // discriminant < 0
stepsHtml += "Since Δ < 0 (" + discriminant + " < 0), there are two complex conjugate roots.";
stepsHtml += "Step 4: Apply the quadratic formula for complex roots.";
stepsHtml += "The quadratic formula is: x = [-b ± i√|Δ|] / 2a";
stepsHtml += "Substitute the values: x = [-" + b + " ± i√" + Math.abs(discriminant) + "] / (2 * " + a + ")";
stepsHtml += "x = [-" + b + " ± i" + Math.sqrt(Math.abs(discriminant)).toFixed(4) + "] / " + (2 * a) + "";
var realPart = (-b / (2 * a)).toFixed(4);
var imaginaryPart = (Math.sqrt(Math.abs(discriminant)) / (2 * a)).toFixed(4);
stepsHtml += "Calculate x1: x1 = " + realPart + " + i" + imaginaryPart + "";
stepsHtml += "Calculate x2: x2 = " + realPart + " - i" + imaginaryPart + "";
resultDiv.innerHTML = "The equation has two complex conjugate roots:";
resultDiv.innerHTML += "x1 = " + realPart + " + i" + imaginaryPart + "";
resultDiv.innerHTML += "x2 = " + realPart + " - i" + imaginaryPart + "";
}
stepsDiv.innerHTML = stepsHtml;
}
.calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 8px;
padding: 25px;
max-width: 700px;
margin: 20px auto;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.calculator-container h2 {
color: #333;
text-align: center;
margin-bottom: 20px;
font-size: 1.8em;
}
.calculator-container p {
color: #555;
line-height: 1.6;
margin-bottom: 10px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 6px;
color: #444;
font-weight: bold;
}
.form-group input[type="number"] {
width: calc(100% – 20px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1em;
box-sizing: border-box;
}
.calculate-button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 20px;
}
.calculate-button:hover {
background-color: #0056b3;
}
.result-section, .steps-section {
background-color: #e9f7ef;
border: 1px solid #d4edda;
border-radius: 5px;
padding: 15px;
margin-top: 25px;
}
.result-section h3, .steps-section h3 {
color: #28a745;
margin-top: 0;
margin-bottom: 10px;
font-size: 1.4em;
}
.result-section p, .steps-section p {
margin-bottom: 8px;
color: #333;
}
.steps-section p code {
background-color: #e0e0e0;
padding: 2px 5px;
border-radius: 3px;
font-family: 'Courier New', Courier, monospace;
color: #c7254e;
}
Understanding the Quadratic Equation and Its Solutions
A quadratic equation is a polynomial equation of the second degree, meaning it contains at least one term in which the unknown variable is raised to the power of two. The standard form of a quadratic equation is:
ax² + bx + c = 0
Where:
xrepresents the unknown variable.a,b, andcare coefficients, withanot equal to zero. Ifawere zero, the equation would become a linear equation (bx + c = 0).
The Quadratic Formula
The most common method to find the roots (solutions) of a quadratic equation is by using the quadratic formula. This formula provides a direct way to calculate the values of x that satisfy the equation:
x = [-b ± √(b² - 4ac)] / 2a
This formula is incredibly powerful because it works for any quadratic equation, regardless of the nature of its roots.
The Discriminant (Δ)
A crucial part of the quadratic formula is the expression under the square root sign: b² - 4ac. This value is called the **discriminant**, often denoted by the Greek letter Delta (Δ). The discriminant tells us about the nature of the roots without actually solving the entire equation:
- If
Δ > 0(Discriminant is positive): The equation has two distinct real roots. This means there are two different numerical values forxthat satisfy the equation, and both are real numbers. Graphically, the parabola intersects the x-axis at two different points. - If
Δ = 0(Discriminant is zero): The equation has exactly one real root (also called a repeated root or a double root). In this case, the two solutions from the quadratic formula become identical. Graphically, the parabola touches the x-axis at exactly one point (its vertex). - If
Δ < 0(Discriminant is negative): The equation has two complex conjugate roots. This means there are no real numbers that satisfy the equation. The roots involve the imaginary uniti(wherei² = -1). Graphically, the parabola does not intersect the x-axis at all.
How to Use the Quadratic Equation Solver
Our calculator simplifies the process of finding the roots of any quadratic equation. Follow these steps:
- Identify Coefficients: Look at your quadratic equation and determine the values for
a,b, andc. Remember, if a term is missing, its coefficient is 0 (e.g., inx² - 4 = 0,b = 0). - Enter Values: Input the identified values for 'Coefficient a', 'Coefficient b', and 'Coefficient c' into the respective fields in the calculator.
- Calculate: Click the "Calculate Roots" button.
- Review Results and Steps: The calculator will instantly display the roots of your equation and provide a detailed, step-by-step breakdown of how the solution was reached, including the calculation of the discriminant and the application of the quadratic formula.
Examples of Quadratic Equations
Let's look at a few examples to illustrate the different types of roots:
Example 1: Two Distinct Real Roots
Equation: x² - 5x + 6 = 0
a = 1b = -5c = 6
Discriminant Δ = (-5)² - 4(1)(6) = 25 - 24 = 1. Since Δ > 0, there are two real roots.
Roots: x1 = 3, x2 = 2
Example 2: One Real (Repeated) Root
Equation: x² - 4x + 4 = 0
a = 1b = -4c = 4
Discriminant Δ = (-4)² - 4(1)(4) = 16 - 16 = 0. Since Δ = 0, there is one real repeated root.
Root: x = 2
Example 3: Two Complex Conjugate Roots
Equation: x² + 2x + 5 = 0
a = 1b = 2c = 5
Discriminant Δ = (2)² - 4(1)(5) = 4 - 20 = -16. Since Δ < 0, there are two complex conjugate roots.
Roots: x1 = -1 + 2i, x2 = -1 - 2i
Use the calculator above to explore these examples and solve your own quadratic equations with ease!