Cubic Equation¶
- cubic_equation(first_constant, second_constant, third_constant, fourth_constant, precision=4)¶
Generates a cubic function to provide evaluations at variable inputs
- Parameters
first_constant (int or float) – Coefficient of the cubic term of the resultant cubic 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 quadratic term of the resultant cubic 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 linear term of the resultant cubic function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001)
fourth_constant (int or float) – Coefficient of the constant term of the resultant cubic 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 four arguments must be integers or floats
ValueError – Last argument must be a positive integer
- Returns
evaluation – Function for evaluating a cubic equation when passed any integer or float argument
- Return type
func
Notes
Standard form of a cubic function: \(f(x) = a\cdot{x^3} + b\cdot{x^2} + c\cdot{x} + d\)
Examples
- Import cubic_equation function from regressions library
>>> from regressions.analyses.equations.cubic import cubic_equation
- Create a cubic function with coefficients 2, 3, 5, and 7, then evaluate it at 10
>>> evaluation_first = cubic_equation(2, 3, 5, 7) >>> print(evaluation_first(10)) 2357.0
- Create a cubic function with coefficients 7, -5, -3, and 2, then evaluate it at 10
>>> evaluation_second = cubic_equation(7, -5, -3, 2) >>> print(evaluation_second(10)) 6472.0
- Create a cubic function with all inputs set to 0, then evaluate it at 10
>>> evaluation_zero = cubic_equation(0, 0, 0, 0) >>> print(evaluation_zero(10)) 0.1111