{
  "id": "quadratic-formula",
  "version": "080522d19d87",
  "status": "published",
  "name": "Quadratic Formula Calculator",
  "question": "What is x by the quadratic formula?",
  "summary": "Solves ax² + bx + c = 0 with the quadratic formula: real or complex roots, the discriminant, and the vertex, with a graph of the parabola.",
  "category": "math",
  "subcategory": "algebra",
  "url": "https://www.acalculator.org/math/quadratic-formula-calculator",
  "markdown": "https://www.acalculator.org/math/quadratic-formula-calculator.md",
  "kind": "function",
  "method": "x = (−b ± √(b² − 4ac)) ÷ 2a, the roots of ax² + bx + c = 0 with a ≠ 0.",
  "assumptions": [
    "a must not be 0; b and c can be any real numbers, including 0.",
    "A negative discriminant gives two complex roots, re ± im·i, shown as text and as their real and imaginary parts.",
    "Real roots are listed smallest first. Roots and the vertex are shown to 6 decimal places."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "a",
        "description": "The coefficient of x². Not 0.",
        "type": "number"
      },
      "b": {
        "title": "b",
        "description": "The coefficient of x.",
        "type": "number"
      },
      "c": {
        "title": "c",
        "description": "The constant term.",
        "type": "number"
      },
      "x": {
        "title": "x value",
        "description": "A value of x at which to evaluate ax² + bx + c; the graph marks this point.",
        "type": "number"
      }
    }
  },
  "outputs": {
    "roots": {
      "label": "Roots",
      "description": "The solutions of ax² + bx + c = 0, such as x = 1 or x = 2, or x = −0.5 ± 1.322876i.",
      "format": "text"
    },
    "x1": {
      "label": "First real root (x₁)",
      "description": "The smaller real root.",
      "format": "number"
    },
    "x2": {
      "label": "Second real root (x₂)",
      "description": "The larger real root.",
      "format": "number"
    },
    "re": {
      "label": "Real part",
      "description": "For complex roots: −b ÷ 2a.",
      "format": "number"
    },
    "im": {
      "label": "Imaginary part",
      "description": "For complex roots: √(4ac − b²) ÷ 2|a|.",
      "format": "number"
    },
    "discriminant": {
      "label": "Discriminant (b² − 4ac)",
      "description": "Positive for two real roots, 0 for one repeated root, negative for two complex roots.",
      "format": "number"
    },
    "kind": {
      "label": "Type of roots",
      "description": "Two real, one repeated real, or two complex roots.",
      "format": "text"
    },
    "vertexX": {
      "label": "Vertex x (axis of symmetry)",
      "description": "The x of the parabola’s turning point: −b ÷ 2a.",
      "format": "number"
    },
    "vertexY": {
      "label": "Vertex y",
      "description": "The value at the turning point: c − b² ÷ 4a, the minimum (a > 0) or maximum (a < 0).",
      "format": "number"
    },
    "y": {
      "label": "y value",
      "description": "ax² + bx + c at the x value.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": 1,
      "b": -3,
      "c": 2,
      "x": 0
    },
    "outputs": {
      "roots": "x = 1 or x = 2",
      "x1": 1,
      "x2": 2,
      "discriminant": 1,
      "kind": "Two real roots",
      "vertexX": 1.5,
      "vertexY": -0.25,
      "y": 2
    },
    "text": "For a = 1, b = -3 and c = 2, the roots are x = 1 or x = 2."
  },
  "examples": [
    {
      "given": {
        "a": 1,
        "b": -3,
        "c": 2,
        "x": 0
      },
      "expect": {
        "roots": "x = 1 or x = 2",
        "x1": 1,
        "x2": 2,
        "discriminant": 1,
        "kind": "Two real roots",
        "vertexX": 1.5,
        "vertexY": -0.25,
        "y": 2
      },
      "source": "hand calculation in content.mdx: D = 9 − 8 = 1, x = (3 ± 1) ÷ 2"
    },
    {
      "given": {
        "a": 2,
        "b": 4,
        "c": 5,
        "x": 1
      },
      "expect": {
        "roots": "x = -1 ± 1.224745i",
        "re": -1,
        "im": 1.224744871391589,
        "discriminant": -24,
        "kind": "Two complex roots",
        "vertexY": 3,
        "y": 11
      },
      "source": "hand calculation in content.mdx: D = 16 − 40 = −24, x = (−4 ± √24 i) ÷ 4; Python 3: math.sqrt(24) / 4 = 1.224744871391589"
    },
    {
      "given": {
        "a": 1,
        "b": -6,
        "c": 9,
        "x": 0
      },
      "expect": {
        "roots": "x = 3",
        "x1": 3,
        "x2": 3,
        "discriminant": 0,
        "kind": "One repeated real root",
        "vertexY": 0
      },
      "source": "hand calculation in content.mdx: D = 36 − 36 = 0, x = 6 ÷ 2 = 3"
    },
    {
      "given": {
        "a": 1,
        "b": 0,
        "c": -2,
        "x": 0
      },
      "expect": {
        "x1": -1.4142135623730951,
        "x2": 1.4142135623730951,
        "discriminant": 8
      },
      "source": "hand calculation in content.mdx: x² = 2, x = ±√2; Python 3: math.sqrt(2) = 1.4142135623730951"
    },
    {
      "given": {
        "a": -4.9,
        "b": 20,
        "c": 1.5,
        "x": 2
      },
      "expect": {
        "x1": -0.07367030800115854,
        "x2": 4.155302961062383,
        "vertexX": 2.0408163265306123,
        "vertexY": 21.908163265306122,
        "y": 21.9
      },
      "source": "hand calculation in content.mdx (a ball thrown up at 20 m/s from 1.5 m); Python 3: (-20 - math.sqrt(429.4)) / -9.8 = 4.155302961062383, (-20 + math.sqrt(429.4)) / -9.8 = -0.07367030800115855",
      "tolerance": 1e-12
    },
    {
      "given": {
        "a": 1,
        "b": 0,
        "c": 4,
        "x": 0
      },
      "expect": {
        "roots": "x = ±2i",
        "re": 0,
        "im": 2
      },
      "source": "hand calculation in content.mdx: x² = −4, x = ±2i"
    }
  ],
  "sources": [
    "NIST Digital Library of Mathematical Functions, section 1.11(iii) Polynomials, Quadratic Equations: https://dlmf.nist.gov/1.11",
    "OpenStax, Elementary Algebra 2e, section 10.3 Solve Quadratic Equations Using the Quadratic Formula: https://openstax.org/books/elementary-algebra-2e/pages/10-3-solve-quadratic-equations-using-the-quadratic-formula"
  ],
  "related": [
    "square-root",
    "slope"
  ],
  "changelog": []
}
