This calculator helps you rewrite a quadratic expression in the form a(x-h)^2 + k.
Enter coefficients above to see the completed square form.
Understanding the Complete Square Form
The "complete the square" method is a technique used in algebra to rewrite a quadratic expression of the form ax^2 + bx + c into the vertex form a(x – h)^2 + k. This form is incredibly useful for several reasons:
Graphing Quadratics: It directly reveals the vertex of the parabola ((h, k)) and its direction of opening (determined by a).
Solving Quadratic Equations: It can simplify the process of finding the roots of a quadratic equation.
Finding Maxima/Minima: It easily shows the maximum or minimum value of the quadratic function.
The Math Behind the Calculation
To convert ax^2 + bx + c into a(x – h)^2 + k, we follow these steps:
Factor out 'a': If a is not 1, factor it out from the first two terms:
a(x^2 + (b/a)x) + c
Complete the Square for the inner expression: Take half of the coefficient of the x term inside the parenthesis ((b/a)), square it, and add and subtract it *inside* the parenthesis.
Half of (b/a) is (b / (2a)).
Squaring it gives (b / (2a))^2 = b^2 / (4a^2).
So we have: a(x^2 + (b/a)x + b^2 / (4a^2) – b^2 / (4a^2)) + c
Form the perfect square: The first three terms inside the parenthesis now form a perfect square:
a((x + b / (2a))^2 – b^2 / (4a^2)) + c
Distribute 'a' and simplify: Distribute a back into the parenthesis and combine the constants.
a(x + b / (2a))^2 – a(b^2 / (4a^2)) + ca(x + b / (2a))^2 – b^2 / (4a) + ca(x + b / (2a))^2 + (c – b^2 / (4a))
Comparing this to the target form a(x – h)^2 + k, we can identify:
h = -b / (2a)
k = c – b^2 / (4a)
Example Calculation
Let's complete the square for the expression 2x^2 + 12x + 10.
Here, a = 2, b = 12, c = 10.
Step 1: Factor out 'a' (which is 2):
2(x^2 + 6x) + 10
Step 2: Half of the x-coefficient (6) is 3. Square it to get 9. Add and subtract 9 inside the parenthesis:
2(x^2 + 6x + 9 – 9) + 10
Step 3: Form the perfect square:
2((x + 3)^2 – 9) + 10
Step 4: Distribute the 2 and simplify:
2(x + 3)^2 – 18 + 102(x + 3)^2 – 8
So, the completed square form is 2(x + 3)^2 – 8. The vertex of this parabola is at (-3, -8).
function calculateCompleteSquare() {
var a = parseFloat(document.getElementById("coefficient_a").value);
var b = parseFloat(document.getElementById("coefficient_b").value);
var c = parseFloat(document.getElementById("coefficient_c").value);
var resultDiv = document.getElementById("result");
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 expression.';
return;
}
// Calculate h and k
var h_numerator = -b;
var h_denominator = 2 * a;
var h = h_numerator / h_denominator;
var k_term1 = c;
var k_term2_numerator = b * b;
var k_term2_denominator = 4 * a;
var k = k_term1 – (k_term2_numerator / k_term2_denominator);
// Determine the sign for h in the final expression
var h_sign = h >= 0 ? "-" : "+";
var h_abs = Math.abs(h);
// Format the output string
var formulaString = "";
if (a === 1) {
formulaString = "x";
} else if (a === -1) {
formulaString = "-x";
} else {
formulaString = a + "x";
}
formulaString += " " + h_sign + " " + h_abs;
if (a !== 1) { // Parentheses are only needed if 'a' is not 1
formulaString = "(" + formulaString + ")^2";
} else {
formulaString = formulaString + ")^2″;
}
if (a !== 1) {
formulaString = a + " (" + formulaString + ")";
}
var finalK = k;
var k_sign = finalK >= 0 ? "+" : "-";
var k_abs = Math.abs(finalK);
var completedSquareForm = formulaString + " " + k_sign + " " + k_abs;
// Display results
resultDiv.innerHTML += 'Vertex (h, k): (' + h.toFixed(4) + ', ' + k.toFixed(4) + ')';
resultDiv.innerHTML += 'Completed Square Form:';
resultDiv.innerHTML += " + completedSquareForm + ";
// Display the derived formula used
resultDiv.innerHTML += '