Calculate Math Problems

Quadratic Equation Solver

Use this calculator to find the roots (solutions) of a quadratic equation in the standard form: ax² + bx + c = 0.

Understanding Quadratic Equations

A quadratic equation is a polynomial equation of the second degree. The general form is ax² + bx + c = 0, where 'x' represents an unknown, and 'a', 'b', and 'c' are coefficients, with 'a' not equal to zero for it to be a true quadratic equation. The solutions to a quadratic equation are called its roots.

The Quadratic Formula

The roots of a quadratic equation can be found using the quadratic formula:

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

The term (b² - 4ac) is known as the discriminant (often denoted by Δ or D). The value of the discriminant determines the nature of the roots:

  • If Δ > 0: There are two distinct real roots.
  • If Δ = 0: There is exactly one real root (a repeated root).
  • If Δ < 0: There are two complex conjugate roots.

Examples of Quadratic Equations

Let's look at some examples:

  1. Equation: x² - 3x + 2 = 0
    • Here, a = 1, b = -3, c = 2.
    • Discriminant = (-3)² – 4(1)(2) = 9 – 8 = 1.
    • Since Δ > 0, there are two distinct real roots.
    • x = [3 ± √1] / 2(1)
    • x1 = (3 + 1) / 2 = 2
    • x2 = (3 – 1) / 2 = 1
  2. Equation: x² + 4x + 4 = 0
    • Here, a = 1, b = 4, c = 4.
    • Discriminant = (4)² – 4(1)(4) = 16 – 16 = 0.
    • Since Δ = 0, there is one real root.
    • x = [-4 ± √0] / 2(1)
    • x = -4 / 2 = -2
  3. Equation: x² + x + 1 = 0
    • Here, a = 1, b = 1, c = 1.
    • Discriminant = (1)² – 4(1)(1) = 1 – 4 = -3.
    • Since Δ < 0, there are two complex conjugate roots.
    • x = [-1 ± √-3] / 2(1)
    • x1 = (-1 + i√3) / 2
    • x2 = (-1 – i√3) / 2
.calculator-container { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f9f9f9; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); max-width: 700px; margin: 20px auto; border: 1px solid #ddd; } .calculator-container h2 { color: #333; text-align: center; margin-bottom: 20px; font-size: 24px; } .calculator-container h3 { color: #555; margin-top: 30px; margin-bottom: 15px; font-size: 20px; } .calculator-container h4 { color: #666; margin-top: 20px; margin-bottom: 10px; font-size: 18px; } .calculator-container p { line-height: 1.6; color: #444; margin-bottom: 10px; } .calculator-input-group { margin-bottom: 15px; display: flex; flex-direction: column; } .calculator-input-group label { margin-bottom: 5px; color: #555; font-weight: bold; } .calculator-input-group input[type="number"] { padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; width: 100%; box-sizing: border-box; } .calculator-container button { background-color: #007bff; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; font-size: 18px; width: 100%; box-sizing: border-box; transition: background-color 0.3s ease; } .calculator-container button:hover { background-color: #0056b3; } .calculator-result { margin-top: 25px; padding: 15px; background-color: #e9f7ef; border: 1px solid #d4edda; border-radius: 5px; font-size: 18px; color: #155724; min-height: 50px; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: bold; } .calculator-result.error { background-color: #f8d7da; border-color: #f5c6cb; color: #721c24; } .calculator-container ul { list-style-type: disc; margin-left: 20px; margin-bottom: 10px; color: #444; } .calculator-container ol { list-style-type: decimal; margin-left: 20px; margin-bottom: 10px; color: #444; } .calculator-container code { background-color: #e0e0e0; padding: 2px 4px; border-radius: 3px; font-family: 'Courier New', Courier, monospace; } 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.className = "calculator-result"; // Reset class for potential error states if (isNaN(a) || isNaN(b) || isNaN(c)) { resultDiv.innerHTML = "Please enter valid numbers for all coefficients."; resultDiv.classList.add("error"); return; } var output = ""; if (a === 0) { // This is a linear equation: bx + c = 0 if (b === 0) { if (c === 0) { output = "Infinite solutions (0 = 0)."; } else { output = "No solution (e.g., " + c + " = 0, which is false)."; resultDiv.classList.add("error"); } } else { var x = -c / b; output = "This is a linear equation (a=0). Solution: x = " + x.toFixed(4); } } else { 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); output = "Two distinct real roots:x1 = " + x1.toFixed(4) + "x2 = " + x2.toFixed(4); } else if (discriminant === 0) { var x = -b / (2 * a); output = "One real root (repeated root):x = " + x.toFixed(4); } else { // discriminant < 0, complex roots var realPart = -b / (2 * a); var imaginaryPart = Math.sqrt(Math.abs(discriminant)) / (2 * a); output = "Two complex conjugate roots:x1 = " + realPart.toFixed(4) + " + " + imaginaryPart.toFixed(4) + "ix2 = " + realPart.toFixed(4) + " – " + imaginaryPart.toFixed(4) + "i"; } } resultDiv.innerHTML = output; }

Leave a Reply

Your email address will not be published. Required fields are marked *