Quadratic Formula#
- pyquations.algebra.quadratic_formula.quadratic_formula(a: float, b: float, c: float) Tuple[complex, complex] [source]
Calculates the roots of a quadratic equation.
The quadratic formula is a closed-form expression describing the solutions of a quadratic equation. Other ways of solving quadratic equations, such as completing the square, yield the same solutions. [1]
\[ax^2 + bx + c = 0\]- Parameters:
a (float) – Coefficient of the quadratic term (x^2). Must not be zero.
b (float) – Coefficient of the linear term (x).
c (float) – Constant term.
- Returns:
- A tuple containing two roots of the quadratic
equation. The roots may be real or complex numbers depending on the discriminant.
- Return type:
Tuple[complex, complex]
- Raises:
ValueError – If ‘a’ is zero, as this would not represent a quadratic equation.
Examples
>>> quadratic_formula(1, -3, 2) (2.0, 1.0)
>>> quadratic_formula(1, 2, 5) (-1+2j, -1-2j)
- Resources:
References