Skip to content
🛠️ToolsShed

Quadratic Equation Solver

Solve quadratic equations ax² + bx + c = 0 with step-by-step solutions.

Enter coefficients

ax² + bx + c = 0

x = (−b ± √(b² − 4ac)) / 2a

Formula

  • Discriminant: Δ = b² − 4ac
  • Δ > 0: two distinct real roots
  • Δ = 0: one repeated root
  • Δ < 0: two complex conjugate roots

About this tool

A quadratic equation is one of the most fundamental algebraic problems, appearing in everything from physics and engineering to finance and architecture. This tool instantly solves equations of the form ax² + bx + c = 0, showing you not just the final answer but the complete step-by-step working so you understand exactly how to arrive at the solution.

Simply enter the coefficients a, b, and c, and the solver will calculate the discriminant and apply the quadratic formula to find both real and complex roots. Whether you're checking homework, verifying calculations for a project, or refreshing your algebra skills, this tool provides clear, methodical solutions that demystify the process and help you learn the underlying mathematics.

Frequently Asked Questions

Code Implementation

import cmath

def solve_quadratic(a: float, b: float, c: float):
    """Solve ax^2 + bx + c = 0. Returns two roots (may be complex)."""
    if a == 0:
        if b == 0:
            raise ValueError("Not an equation (a=0, b=0)")
        return (-c / b,)  # linear case
    disc = b**2 - 4*a*c
    sqrt_disc = cmath.sqrt(disc)
    x1 = (-b + sqrt_disc) / (2 * a)
    x2 = (-b - sqrt_disc) / (2 * a)
    return x1, x2

def format_root(r: complex) -> str:
    if r.imag == 0:
        return f"{r.real:.6g}"
    return f"{r.real:.4g} + {r.imag:.4g}i"

# Two real roots: x^2 - 5x + 6 = 0  ->  x = 3, 2
x1, x2 = solve_quadratic(1, -5, 6)
print(format_root(x1), format_root(x2))  # 3   2

# Complex roots: x^2 + 1 = 0  ->  x = ±i
x1, x2 = solve_quadratic(1, 0, 1)
print(format_root(x1), format_root(x2))  # 0 + 1i   0 + -1i

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.