Linear Roots¶
- linear_roots(first_constant, second_constant, precision=4)¶
Calculates the roots of a linear function
- Parameters
first_constant (int or float) – Coefficient of the linear term of the original linear 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 constant term of the original linear 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 two 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
- Return type
list of float
Notes
Standard form of a linear function: \(f(x) = a\cdot{x} + b\)
Linear formula: \(x = -\frac{b}{a}\)
Examples
- Import linear_roots function from regressions library
>>> from regressions.analyses.roots.linear import linear_roots
- Calculate the roots of a linear function with coefficients 2 and 3
>>> roots_first = linear_roots(2, 3) >>> print(roots_first) [-1.5]
- Calculate the roots of a linear function with coefficients -2 and 3
>>> roots_second = linear_roots(-2, 3) >>> print(roots_second) [1.5]
- Calculate the roots of a linear function with all inputs set to 0
>>> roots_zeroes = linear_roots(0, 0) >>> print(roots_zeroes) [-1.0]