Quadratic Roots¶
- quadratic_roots(first_constant, second_constant, third_constant, precision=4)¶
Calculates the roots of a quadratic function
- Parameters
first_constant (int or float) – Coefficient of the quadratic term of the original quadratic function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001)
second_constant (int or float) – Coefficient of the linear term of the original quadratic function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001)
third_constant (int or float) – Coefficient of the constant term of the original quadratic function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001)
precision (int, default=4) – Maximum number of digits that can appear after the decimal place of the resultant roots
- Raises
TypeError – First three arguments must be integers or floats
ValueError – Last argument must be a positive integer
- Returns
roots – List of the x-coordinates of all of the x-intercepts of the original function; if the function never crosses the x-axis, then it will return a list of None
- Return type
list of float
Notes
Standard form of a quadratic function: \(f(x) = a\cdot{x^2} + b\cdot{x} + c\)
Quadratic formula: \(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\)
Examples
- Import quadratic_roots function from regressions library
>>> from regressions.analyses.roots.quadratic import quadratic_roots
- Calculate the roots of a quadratic function with coefficients 2, 7, and 5
>>> roots_first = quadratic_roots(2, 7, 5) >>> print(roots_first) [-2.5, -1.0]
- Calculate the roots of a quadratic function with coefficients 2, -5, and 3
>>> roots_second = quadratic_roots(2, -5, 3) >>> print(roots_second) [1.0, 1.5]
- Calculate the roots of a quadratic function with all inputs set to 0
>>> roots_zeroes = quadratic_roots(0, 0, 0) >>> print(roots_zeroes) [None]