Quadratic Math Calculator

Quadratic Equation Solver

Enter the coefficients a, b, and c for your quadratic equation (ax² + bx + c = 0) to find its roots.

Results will appear here.

function calculateQuadraticRoots() { 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("quadraticResult"); resultDiv.innerHTML = ""; // Clear previous results if (isNaN(a) || isNaN(b) || isNaN(c)) { resultDiv.innerHTML = "Please enter valid numbers for all coefficients."; return; } if (a === 0) { resultDiv.innerHTML = "Coefficient 'a' cannot be zero for a quadratic equation. This would be a linear equation."; // Optionally, solve as linear equation: // if (b !== 0) { // var x = -c / b; // resultDiv.innerHTML += "Since 'a' is 0, this is a linear equation. The root is x = " + x.toFixed(6) + ""; // } else if (c === 0) { // resultDiv.innerHTML += "Since 'a' and 'b' are 0, and 'c' is 0, this equation has infinite solutions (0 = 0)."; // } else { // resultDiv.innerHTML += "Since 'a' and 'b' are 0, and 'c' is not 0, this equation has no solution (c = 0 is false)."; // } return; } var discriminant = b * b – 4 * a * c; if (discriminant > 0) { var x1 = (-b + Math.sqrt(discriminant)) / (2 * a); var x2 = (-b – Math.sqrt(discriminant)) / (2 * a); resultDiv.innerHTML = "The equation has two distinct real roots:"; resultDiv.innerHTML += "x₁ = " + x1.toFixed(6) + ""; resultDiv.innerHTML += "x₂ = " + x2.toFixed(6) + ""; } else if (discriminant === 0) { var x = -b / (2 * a); resultDiv.innerHTML = "The equation has one real root (repeated):"; resultDiv.innerHTML += "x = " + x.toFixed(6) + ""; } else { // discriminant < 0 var realPart = -b / (2 * a); var imaginaryPart = Math.sqrt(Math.abs(discriminant)) / (2 * a); resultDiv.innerHTML = "The equation has two complex conjugate roots:"; resultDiv.innerHTML += "x₁ = " + realPart.toFixed(6) + " + " + imaginaryPart.toFixed(6) + "i"; resultDiv.innerHTML += "x₂ = " + realPart.toFixed(6) + " – " + imaginaryPart.toFixed(6) + "i"; } }

Understanding Quadratic Equations and Their Roots

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 written as:

ax² + bx + c = 0

Where:

  • a, b, and c are coefficients, with 'a' not equal to zero.
  • x represents the unknown variable.

The 'roots' of a quadratic equation are the values of 'x' that satisfy the equation, meaning when substituted into the equation, they make the equation true (equal to zero). Graphically, these roots represent the x-intercepts of the parabola defined by the quadratic function y = ax² + bx + c.

The Quadratic Formula

The most common method to find the roots of a quadratic equation is using the quadratic formula:

x = [-b ± sqrt(b² - 4ac)] / (2a)

This formula directly provides the values of x once the coefficients a, b, and c are known.

The Discriminant (Δ)

A crucial part of the quadratic formula is the expression under the square root: Δ = b² - 4ac. This is called the discriminant, and its value determines the nature of the roots:

  • If Δ > 0 (Positive Discriminant): The equation has two distinct real roots. This means the parabola intersects the x-axis at two different points.
  • If Δ = 0 (Zero Discriminant): The equation has exactly one real root (sometimes called a repeated or double root). The parabola touches the x-axis at exactly one point.
  • If Δ < 0 (Negative Discriminant): The equation has two complex conjugate roots. The parabola does not intersect the x-axis at all. These roots involve the imaginary unit 'i', where i = sqrt(-1).

How to Use the Calculator

Simply input the coefficients 'a', 'b', and 'c' from your quadratic equation into the respective fields. For example, if your equation is x² - 3x + 2 = 0, you would enter:

  • Coefficient a: 1
  • Coefficient b: -3
  • Coefficient c: 2

Click "Calculate Roots" to see the solutions for 'x'. The calculator will tell you if the roots are real or complex and provide their values.

Examples:

Example 1: Two Distinct Real Roots

Equation: x² - 5x + 6 = 0

  • a = 1
  • b = -5
  • c = 6

Discriminant Δ = (-5)² – 4(1)(6) = 25 – 24 = 1 (Δ > 0)

Roots: x₁ = [5 + sqrt(1)] / 2 = 3, x₂ = [5 – sqrt(1)] / 2 = 2

Example 2: One Real Root (Repeated)

Equation: x² - 4x + 4 = 0

  • a = 1
  • b = -4
  • c = 4

Discriminant Δ = (-4)² – 4(1)(4) = 16 – 16 = 0 (Δ = 0)

Root: x = [4 + sqrt(0)] / 2 = 2

Example 3: Two Complex Conjugate Roots

Equation: x² + 2x + 5 = 0

  • a = 1
  • b = 2
  • c = 5

Discriminant Δ = (2)² – 4(1)(5) = 4 – 20 = -16 (Δ < 0)

Roots: x₁ = [-2 + sqrt(-16)] / 2 = [-2 + 4i] / 2 = -1 + 2i

x₂ = [-2 – sqrt(-16)] / 2 = [-2 – 4i] / 2 = -1 – 2i

Leave a Comment