Math Online Calculator

Quadratic Equation Solver

Enter the coefficients a, b, and c for the quadratic equation in the standard form ax² + bx + c = 0.

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) { // It's a linear equation: bx + c = 0 if (b === 0) { if (c === 0) { resultDiv.innerHTML = "This is the identity 0 = 0. There are infinitely many solutions."; } else { resultDiv.innerHTML = "This is a contradiction (" + c + " = 0). There are no solutions."; } } else { var x = -c / b; resultDiv.innerHTML = "This is a linear equation (a=0). The root is: x = " + x.toFixed(4) + ""; } 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:x1 = " + x1.toFixed(4) + "x2 = " + x2.toFixed(4) + ""; } else if (discriminant === 0) { var x = -b / (2 * a); resultDiv.innerHTML = "The equation has one real root (repeated):x = " + x.toFixed(4) + ""; } else { // discriminant < 0, complex roots var realPart = -b / (2 * a); var imaginaryPart = Math.sqrt(Math.abs(discriminant)) / (2 * a); resultDiv.innerHTML = "The equation has two complex roots:x1 = " + realPart.toFixed(4) + " + " + imaginaryPart.toFixed(4) + "ix2 = " + realPart.toFixed(4) + " – " + imaginaryPart.toFixed(4) + "i"; } } /* Basic styling for the calculator */ .calculator-container { background-color: #f9f9f9; border: 1px solid #ddd; padding: 20px; border-radius: 8px; max-width: 600px; margin: 20px auto; font-family: Arial, sans-serif; } .calculator-container h2 { color: #333; text-align: center; margin-bottom: 20px; } .calc-input-group { margin-bottom: 15px; } .calc-input-group label { display: block; margin-bottom: 5px; font-weight: bold; color: #555; } .calc-input-group input[type="number"] { width: calc(100% – 22px); padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button { background-color: #007bff; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; width: 100%; box-sizing: border-box; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } .calc-result { margin-top: 20px; padding: 15px; border: 1px solid #e0e0e0; border-radius: 4px; background-color: #eaf6ff; min-height: 50px; } .calc-result p { margin: 5px 0; color: #333; line-height: 1.5; } .calc-result p.error { color: #d9534f; font-weight: bold; }

Understanding Quadratic Equations

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:

ax² + bx + c = 0

Where:

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

The solutions to a quadratic equation are called its roots. These roots represent the x-intercepts of the parabola that the quadratic equation forms when graphed.

The Quadratic Formula

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

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

This formula allows you to directly calculate the values of 'x' once you know the coefficients a, b, and c.

The Discriminant (b² – 4ac)

A crucial part of the quadratic formula is the expression under the square root, b² – 4ac, which is known as the discriminant (often denoted by the Greek letter Delta, Δ). The value of the discriminant tells us about the nature of the roots:

  • If Δ > 0 (positive): There are two distinct real roots. This means the parabola intersects the x-axis at two different points.
  • If Δ = 0: There is exactly one real root (also called a repeated or double root). The parabola touches the x-axis at exactly one point.
  • If Δ < 0 (negative): There are two complex (or imaginary) roots. The parabola does not intersect the x-axis. Complex roots always come in conjugate pairs (a + bi, a – bi).

How to Use the Calculator

Our Quadratic Equation Solver simplifies the process of finding roots. Simply input the coefficients 'a', 'b', and 'c' from your equation (e.g., for 2x² + 5x – 3 = 0, you would enter a=2, b=5, c=-3) and click "Calculate Roots". The calculator will instantly provide the real or complex solutions.

Examples

Let's look at some examples to illustrate the different types of roots:

Example 1: Two Distinct Real Roots

Equation: x² – 3x + 2 = 0

  • a = 1
  • b = -3
  • c = 2

Discriminant = (-3)² – 4(1)(2) = 9 – 8 = 1 (positive)

Roots: x1 = [-(-3) + sqrt(1)] / (2*1) = (3 + 1) / 2 = 2

Roots: x2 = [-(-3) – sqrt(1)] / (2*1) = (3 – 1) / 2 = 1

Calculator Output: x1 = 2.0000, x2 = 1.0000

Example 2: One Real (Repeated) Root

Equation: x² – 4x + 4 = 0

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

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

Root: x = [-(-4)] / (2*1) = 4 / 2 = 2

Calculator Output: x = 2.0000

Example 3: Two Complex Roots

Equation: x² + 2x + 5 = 0

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

Discriminant = (2)² – 4(1)(5) = 4 – 20 = -16 (negative)

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

Roots: x2 = [-2 – sqrt(-16)] / (2*1) = (-2 – 4i) / 2 = -1 – 2i

Calculator Output: x1 = -1.0000 + 2.0000i, x2 = -1.0000 – 2.0000i

Example 4: Linear Equation (a=0)

Equation: 0x² + 5x – 10 = 0 (or simply 5x – 10 = 0)

  • a = 0
  • b = 5
  • c = -10

Root: 5x = 10 => x = 2

Calculator Output: This is a linear equation (a=0). The root is: x = 2.0000

Leave a Reply

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