Cubic Integral¶
- cubic_integral(first_constant, second_constant, third_constant, fourth_constant, precision=4)¶
Generates the integral of a cubic function
- Parameters
first_constant (int or float) – Coefficient of the cubic term of the original 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 original 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 original 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 original 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
integral[‘constants’] (list of float) – Coefficients of the resultant integral
integral[‘evaluation’] (func) – Function for evaluating the resultant integral at any float or integer argument
Notes
Standard form of a cubic function: \(f(x) = a\cdot{x^3} + b\cdot{x^2} + c\cdot{x} + d\)
Integral of a cubic function: \(F(x) = \frac{a}{4}\cdot{x^4} + \frac{b}{3}\cdot{x^3} + \frac{c}{2}\cdot{x^2} + d\cdot{x}\)
Examples
- Import cubic_integral function from regressions library
>>> from regressions.analyses.integrals.cubic import cubic_integral
- Generate the integral of a cubic function with coefficients 2, 3, 5, and 7, then display its coefficients
>>> integral_constants = cubic_integral(2, 3, 5, 7) >>> print(integral_constants['constants']) [0.5, 1.0, 2.5, 7.0]
- Generate the integral of a cubic function with coefficients 7, -5, -3, and 2, then evaluate its integral at 10
>>> integral_evaluation = cubic_integral(7, -5, -3, 2) >>> print(integral_evaluation['evaluation'](10)) 15703.3
- Generate the integral of a cubic function with all inputs set to 0, then display its coefficients
>>> integral_zeroes = cubic_integral(0, 0, 0, 0) >>> print(integral_zeroes['constants']) [0.0001, 0.0001, 0.0001, 0.0001]