{
  "id": "complete-the-square",
  "version": "53e46d6b13a0",
  "status": "published",
  "name": "Complete The Square Calculator",
  "question": "How to complete the square?",
  "summary": "Completes the square of ax² + bx + c to a(x − h)² + k and solves ax² + bx + c = 0 by completing the square, with each step and exact, simplified roots.",
  "category": "math",
  "subcategory": "algebra",
  "url": "https://www.acalculator.org/math/complete-the-square-calculator",
  "markdown": "https://www.acalculator.org/math/complete-the-square-calculator.md",
  "kind": "function",
  "method": "Divide by a, move c/a across, add (b/(2a))² to both sides, write (x − h)² = q with h = −b/(2a) and q = (b² − 4ac)/(4a²), then x = h ± √q; a(x − h)² + k with k = c − b²/(4a).",
  "assumptions": [
    "a may not be 0. Coefficients are read as the exact decimals typed, so h, k and q are exact fractions.",
    "√q is simplified exactly when q’s top times its bottom is at most 10¹⁵."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "a",
        "description": "The coefficient of x². It may not be 0.",
        "type": "number",
        "minimum": -1000000,
        "maximum": 1000000
      },
      "b": {
        "title": "b",
        "description": "The coefficient of x.",
        "type": "number",
        "minimum": -1000000,
        "maximum": 1000000
      },
      "c": {
        "title": "c",
        "description": "The constant term.",
        "type": "number",
        "minimum": -1000000,
        "maximum": 1000000
      }
    }
  },
  "outputs": {
    "form": {
      "label": "Completed square",
      "description": "ax² + bx + c written as a(x − h)² + k.",
      "format": "text"
    },
    "solutions": {
      "label": "Solutions of ax² + bx + c = 0",
      "description": "x = h ± √q, exact and simplified, then as decimals.",
      "format": "text"
    },
    "h": {
      "label": "h",
      "description": "h = −b ÷ (2a), as a decimal.",
      "format": "number"
    },
    "k": {
      "label": "k",
      "description": "k = c − b² ÷ (4a), as a decimal.",
      "format": "number"
    },
    "square": {
      "label": "Square to add",
      "description": "The square of half the x coefficient after dividing by a: (b ÷ (2a))².",
      "format": "text"
    },
    "steps": {
      "label": "Steps",
      "description": "Each step of completing the square.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": 1,
      "b": -3,
      "c": -5
    },
    "outputs": {
      "form": "(x − 3/2)² − 29/4",
      "solutions": "x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404",
      "h": 1.5,
      "k": -7.25,
      "square": "9/4",
      "steps": "Move the constant: x² − 3x = 5; Add (−3/2)² = 9/4 to both sides: x² − 3x + 9/4 = 29/4; Write the left side as a square: (x − 3/2)² = 29/4; Take the square root: x − 3/2 = ± √29/2; x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404"
    },
    "text": "Completing the square gives (x − 3/2)² − 29/4. Solutions: x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404."
  },
  "examples": [
    {
      "given": {
        "a": 1,
        "b": -3,
        "c": -5
      },
      "expect": {
        "form": "(x − 3/2)² − 29/4",
        "solutions": "x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404",
        "square": "9/4",
        "steps": "Move the constant: x² − 3x = 5; Add (−3/2)² = 9/4 to both sides: x² − 3x + 9/4 = 29/4; Write the left side as a square: (x − 3/2)² = 29/4; Take the square root: x − 3/2 = ± √29/2; x = 3/2 ± √29/2 ≈ −1.192582404 and 4.192582404"
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §2.5 Quadratic Equations, Example 8 (x² − 3x − 5 = 0 gives x = 3/2 ± √29/2), https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-5-quadratic-equations"
    },
    {
      "given": {
        "a": 1,
        "b": 4,
        "c": 1
      },
      "expect": {
        "form": "(x + 2)² − 3",
        "solutions": "x = −2 ± √3 ≈ −3.732050808 and −0.2679491924"
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §2.5 Quadratic Equations, completing the square (x² + 4x + 1 = 0 gives (x + 2)² = 3 and x = −2 ± √3), https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-5-quadratic-equations"
    },
    {
      "given": {
        "a": 1,
        "b": -6,
        "c": -13
      },
      "expect": {
        "form": "(x − 3)² − 22",
        "solutions": "x = 3 ± √22 ≈ −1.69041576 and 7.69041576"
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §2.5 Quadratic Equations, Try It #7 (x² − 6x = 13), https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-5-quadratic-equations; hand calculation in content.mdx: (x − 3)² = 13 + 9 = 22"
    },
    {
      "given": {
        "a": 2,
        "b": -6,
        "c": 7
      },
      "expect": {
        "form": "2(x − 3/2)² + 5/2",
        "h": 1.5,
        "k": 2.5,
        "solutions": "No real solution; complex: x = 3/2 ± (√5/2)i",
        "steps": "Divide by a = 2: x² − 3x + 7/2 = 0; Move the constant: x² − 3x = −7/2; Add (−3/2)² = 9/4 to both sides: x² − 3x + 9/4 = −5/4; Write the left side as a square: (x − 3/2)² = −5/4; Take the square root: x − 3/2 = ± (√5/2)i; x = 3/2 ± (√5/2)i"
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §5.1 Quadratic Functions, Example 3 (f(x) = 2x² − 6x + 7 = 2(x − 3/2)² + 5/2), https://openstax.org/books/algebra-and-trigonometry-2e/pages/5-1-quadratic-functions; hand calculation in content.mdx: q = −5/4 < 0"
    },
    {
      "given": {
        "a": -0.5,
        "b": 2,
        "c": 6
      },
      "expect": {
        "form": "−(1/2)(x − 2)² + 8",
        "solutions": "x = −2 and x = 6",
        "k": 8
      },
      "source": "hand calculation in content.mdx: x² − 4x − 12 = 0, (x − 2)² = 16, x = 2 ± 4"
    }
  ],
  "sources": [
    "OpenStax, Algebra and Trigonometry 2e, §2.5 Quadratic Equations (completing the square: move the constant, add (b/2)² to both sides, factor the perfect square, use the square root property; Example 8: x² − 3x − 5 = 0 gives x = 3/2 ± √29/2; x² + 4x + 1 = 0 gives x = −2 ± √3; Try It #7: x² − 6x = 13). https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-5-quadratic-equations (retrieved 2026-10-05)",
    "OpenStax, Algebra and Trigonometry 2e, §5.1 Quadratic Functions (f(x) = a(x − h)² + k with h = −b/(2a); Example 3: 2x² − 6x + 7 = 2(x − 3/2)² + 5/2). https://openstax.org/books/algebra-and-trigonometry-2e/pages/5-1-quadratic-functions (retrieved 2026-10-05)"
  ],
  "related": [
    "vertex",
    "quadratic-formula",
    "factoring",
    "parabola"
  ],
  "changelog": []
}
