def exponential_roots_second_derivative(first_constant, second_constant, precision = 4): # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) # Create list to return result = [] # Determine root of second derivative root = None # Return result result.append(root) return result
def hyperbolic_roots_first_derivative(first_constant, second_constant, precision=4): # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) # Create list to return result = [] # Determine root of first derivative root = 0.0 # Return result result.append(root) return result
def hyperbolic_integral(first_constant, second_constant, precision=4): """ Generates the integral of a hyperbolic function Parameters ---------- first_constant : int or float Coefficient of the reciprocal variable of the original hyperbolic 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 hyperbolic 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 ------- 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; if zero inputted as argument, it will be converted to a small, non-zero decimal value (e.g., 0.0001) See Also -------- :func:`~regressions.analyses.equations.hyperbolic.hyperbolic_equation`, :func:`~regressions.analyses.derivatives.hyperbolic.hyperbolic_derivatives`, :func:`~regressions.analyses.roots.hyperbolic.hyperbolic_roots`, :func:`~regressions.models.hyperbolic.hyperbolic_model` Notes ----- - Standard form of a hyperbolic function: :math:`f(x) = a\\cdot{\\frac{1}{x}} + b` - Integral of a hyperbolic function: :math:`F(x) = a\\cdot{\\ln|x|} + b\\cdot{x}` - |indefinite_integral| - |integration_formulas| Examples -------- Import `sinusoidal_hyperbolic` function from `regressions` library >>> from regressions.analyses.hyperbolics.sinusoidal import sinusoidal_hyperbolic Generate the integral of a hyperbolic function with coefficients 2 and 3, then display its coefficients >>> integral_constants = hyperbolic_integral(2, 3) >>> print(integral_constants['constants']) [2.0, 3.0] Generate the integral of a hyperbolic function with coefficients -2 and 3, then evaluate its integral at 10 >>> integral_evaluation = hyperbolic_integral(-2, 3) >>> print(integral_evaluation['evaluation'](10)) 25.3948 Generate the integral of a hyperbolic function with all inputs set to 0, then display its coefficients >>> integral_zeroes = hyperbolic_integral(0, 0) >>> print(integral_zeroes['constants']) [0.0001, 0.0001] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create constants constants = [coefficients[0], coefficients[1]] # Create evaluation def hyperbolic_evaluation(variable): # Circumvent logarithm of zero if variable == 0: variable = 10**(-precision) evaluation = constants[0] * log( abs(variable)) + constants[1] * variable rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation # Package constants and evaluation in single dictionary results = {'constants': constants, 'evaluation': hyperbolic_evaluation} return results
def hyperbolic_derivatives(first_constant, second_constant, precision=4): """ Calculates the first and second derivatives of a hyperbolic function Parameters ---------- first_constant : int or float Coefficient of the reciprocal variable of the original hyperbolic 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 hyperbolic 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 ------- derivatives['first']['constants'] : list of float Coefficients of the resultant first derivative derivatives['first']['evaluation'] : func Function for evaluating the resultant first derivative at any float or integer argument; if zero inputted as argument, it will be converted to a small, non-zero decimal value (e.g., 0.0001) derivatives['second']['constants'] : list of float Coefficients of the resultant second derivative derivatives['second']['evaluation'] : func Function for evaluating the resultant second derivative at any float or integer argument; if zero inputted as argument, it will be converted to a small, non-zero decimal value (e.g., 0.0001) See Also -------- :func:`~regressions.analyses.equations.hyperbolic.hyperbolic_equation`, :func:`~regressions.analyses.integrals.hyperbolic.hyperbolic_integral`, :func:`~regressions.analyses.roots.hyperbolic.hyperbolic_roots`, :func:`~regressions.models.hyperbolic.hyperbolic_model` Notes ----- - Standard form of a hyperbolic function: :math:`f(x) = a\\cdot{\\frac{1}{x}} + b` - First derivative of a hyperbolic function: :math:`f'(x) = -a\\cdot{\\frac{1}{x^2}}` - Second derivative of a hyperbolic function: :math:`f''(x) = 2a\\cdot{\\frac{1}{x^3}}` - |differentiation_formulas| Examples -------- Import `hyperbolic_derivatives` function from `regressions` library >>> from regressions.analyses.derivatives.hyperbolic import hyperbolic_derivatives Generate the derivatives of a hyperbolic function with coefficients 2 and 3, then display the coefficients of its first and second derivatives >>> derivatives_constants = hyperbolic_derivatives(2, 3) >>> print(derivatives_constants['first']['constants']) [-2.0] >>> print(derivatives_constants['second']['constants']) [4.0] Generate the derivatives of a hyperbolic function with coefficients -2 and 3, then evaluate its first and second derivatives at 10 >>> derivatives_evaluation = hyperbolic_derivatives(-2, 3) >>> print(derivatives_evaluation['first']['evaluation'](10)) 0.02 >>> print(derivatives_evaluation['second']['evaluation'](10)) -0.004 Generate the derivatives of a hyperbolic function with all inputs set to 0, then display the coefficients of its first and second derivatives >>> derivatives_zeroes = hyperbolic_derivatives(0, 0) >>> print(derivatives_zeroes['first']['constants']) [-0.0001] >>> print(derivatives_zeroes['second']['constants']) [0.0002] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create first derivative first_constants = [-1 * coefficients[0]] def first_derivative(variable): # Circumvent division by zero if variable == 0: variable = 10**(-precision) evaluation = first_constants[0] / variable**2 rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation first_dictionary = { 'constants': first_constants, 'evaluation': first_derivative } # Create second derivative second_constants = [-2 * first_constants[0]] def second_derivative(variable): # Circumvent division by zero if variable == 0: variable = 10**(-precision) evaluation = second_constants[0] / variable**3 rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation second_dictionary = { 'constants': second_constants, 'evaluation': second_derivative } # Package both derivatives in single dictionary results = {'first': first_dictionary, 'second': second_dictionary} return results
def exponential_integral(first_constant, second_constant, precision = 4): """ Generates the integral of an exponential function Parameters ---------- first_constant : int or float Constant multiple of the original exponential function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001) second_constant : int or float Base rate of variable of the original exponential function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001); if one, it will be converted to a small, near-one decimal value (e.g., 1.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 ------- 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 See Also -------- :func:`~regressions.analyses.equations.exponential.exponential_equation`, :func:`~regressions.analyses.derivatives.exponential.exponential_derivatives`, :func:`~regressions.analyses.roots.exponential.exponential_roots`, :func:`~regressions.models.exponential.exponential_model` Notes ----- - Standard form of an exponential function: :math:`f(x) = a\\cdot{b^x}` - Integral of an exponential function: :math:`F(x) = \\frac{a}{\\ln{b}}\\cdot{b^x}` - |indefinite_integral| - |integration_formulas| Examples -------- Import `exponential_integral` function from `regressions` library >>> from regressions.analyses.integrals.exponential import exponential_integral Generate the integral of an exponential function with coefficients 2 and 3, then display its coefficients >>> integral_constants = exponential_integral(2, 3) >>> print(integral_constants['constants']) [1.8205, 3.0] Generate the integral of an exponential function with coefficients -2 and 3, then evaluate its integral at 10 >>> integral_evaluation = exponential_integral(-2, 3) >>> print(integral_evaluation['evaluation'](10)) -107498.7045 Generate the integral of an exponential function with all inputs set to 0, then display its coefficients >>> integral_zeroes = exponential_integral(0, 0) >>> print(integral_zeroes['constants']) [-0.0001, 0.0001] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Circumvent division by zero if coefficients[1] == 1: coefficients[1] = 1 + 10**(-precision) # Create constants integral_coefficients = [coefficients[0] / log(abs(coefficients[1])), coefficients[1]] constants = rounded_list(integral_coefficients, precision) # Create evaluation def exponential_evaluation(variable): evaluation = constants[0] * constants[1]**variable rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation # Package constants and evaluation in single dictionary results = { 'constants': constants, 'evaluation': exponential_evaluation } return results
def hyperbolic_roots(first_constant, second_constant, precision=4): """ Calculates the roots of a hyperbolic function Parameters ---------- first_constant : int or float Coefficient of the reciprocal variable of the original hyperbolic 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 hyperbolic 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 float 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` See Also -------- :func:`~regressions.analyses.equations.hyperbolic.hyperbolic_equation`, :func:`~regressions.analyses.derivatives.hyperbolic.hyperbolic_derivatives`, :func:`~regressions.analyses.integrals.hyperbolic.hyperbolic_integral`, :func:`~regressions.models.hyperbolic.hyperbolic_model` Notes ----- - Standard form of a hyperbolic function: :math:`f(x) = a\\cdot{\\frac{1}{x}} + b` - Hyperbolic formula: :math:`x = -\\frac{a}{b}` Examples -------- Import `hyperbolic_roots` function from `regressions` library >>> from regressions.analyses.roots.hyperbolic import hyperbolic_roots Calculate the roots of a hyperbolic function with coefficients 2 and 3 >>> roots_first = hyperbolic_roots(2, 3) >>> print(roots_first) [-0.6667] Calculate the roots of a hyperbolic function with coefficients -2 and 3 >>> roots_second = hyperbolic_roots(-2, 3) >>> print(roots_second) [0.6667] Calculate the roots of a hyperbolic function with all inputs set to 0 >>> roots_zeroes = hyperbolic_roots(0, 0) >>> print(roots_zeroes) [-1.0] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create list to return result = [] # Determine root root = -1 * coefficients[0] / coefficients[1] # Round root rounded_root = rounded_value(root, precision) # Return result result.append(rounded_root) return result
def generate_elements(initial_value, periodic_unit, precision=4): """ Generates a vector containing an initial numerical value, four additional numerical values created by incrementing the initial value by a periodic unit four times, and a string value for the general form of all values in the vector, made up of a multiple of the periodic unit added to the initial value; any negative periodic units will be converted their absolute values before any other evaluations occur Parameters ---------- initial_value : int or float Starting value to adjust to fit into a range periodic_unit : int or float Unit by which the initial value should be incrementally increased or decreased to fit into a range precision : int, default=4 Upper bound of range into which the initial value must be adjusted (final value should be less than or equal to maximum) Raises ------ TypeError First and second arguments must be integers or floats ValueError Last argument must be a positive integer Returns ------- generated_vector : list of float Vector containing five numerical values, each a set incremenent apart from one another, and a string value representing the general form of all numerical elements in the vector as well as any additional numerical elements that could be generated from it in the future See Also -------- :func:`~regressions.statistics.ranges.shift_into_range`, :func:`~regressions.analyses.points.shifted_points_within_range`, :func:`~regressions.analyses.roots.sinusoidal.sinusoidal_roots` Notes ----- - Initial value: :math:`v_i` - Periodic unit: :math:`\\lambda` - Set of all values derived from initial value and periodic unit: :math:`g = \\{ v \\mid v = v_i + \\lambda\\cdot{k} \\}` - :math:`k \\in \\mathbb{Z}` Examples -------- Import `generate_elements` function from `regressions` library >>> from regressions.vectors.generate import generate_elements Generate a vector of elements based off an initial value of 3 and a periodic unit of 2 >>> generated_vector_int = generate_elements(3, 2) >>> print(generated_vector_int) [3.0, 5.0, 7.0, 9.0, 11.0, '3.0 + 2.0k'] Generate a vector of elements based off an initial value of 3 and a periodic unit of -2 >>> generated_vector_neg = generate_elements(3, -2) >>> print(generated_vector_neg) [3.0, 5.0, 7.0, 9.0, 11.0, '3.0 + 2.0k'] Generate a vector of elements based off an initial value of 17.23 and a periodic unit of 5.89 >>> generated_vector_float = generate_elements(17.23, 5.89) >>> print(generated_vector_float) [17.23, 23.12, 29.01, 34.9, 40.79, '17.23 + 5.89k'] """ # Handle input errors two_scalars(initial_value, periodic_unit) positive_integer(precision) if periodic_unit < 0: periodic_unit = -1 * periodic_unit # Generate values from inputs first_value = initial_value + 1 * periodic_unit second_value = initial_value + 2 * periodic_unit third_value = initial_value + 3 * periodic_unit fourth_value = initial_value + 4 * periodic_unit # Store values in list values = [ initial_value, first_value, second_value, third_value, fourth_value ] # Sort values sorted_values = sorted_list(values) # Round values rounded_values = rounded_list(sorted_values, precision) # Create general form rounded_periodic_unit = rounded_value(periodic_unit, precision) rounded_initial_value = rounded_value(initial_value, precision) general_form = str(rounded_initial_value) + ' + ' + str( rounded_periodic_unit) + 'k' # Store numerical values and general form in single list results = [*rounded_values, general_form] return results
def logarithmic_equation(first_constant, second_constant, precision = 4): """ Generates a logarithmic function to provide evaluations at variable inputs Parameters ---------- first_constant : int or float Coefficient of the logarithmic term of the resultant logarithmic 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 resultant logarithmic 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 ------- evaluation : func Function for evaluating a logarithmic equation when passed any integer or float argument; if zero inputted as argument, it will be converted to a small, non-zero decimal value (e.g., 0.0001) See Also -------- :func:`~regressions.analyses.derivatives.logarithmic.logarithmic_derivatives`, :func:`~regressions.analyses.integrals.logarithmic.logarithmic_integral`, :func:`~regressions.analyses.roots.logarithmic.logarithmic_roots`, :func:`~regressions.models.logarithmic.logarithmic_model` Notes ----- - Standard form of a logarithmic function: :math:`f(x) = a\\cdot{\\ln{x}} + b` - |logarithmic_functions| Examples -------- Import `logarithmic_equation` function from `regressions` library >>> from regressions.analyses.equations.logarithmic import logarithmic_equation Create a logarithmic function with coefficients 2 and 3, then evaluate it at 10 >>> evaluation_first = logarithmic_equation(2, 3) >>> print(evaluation_first(10)) 7.6052 Create a logarithmic function with coefficients -2 and 3, then evaluate it at 10 >>> evaluation_second = logarithmic_equation(-2, 3) >>> print(evaluation_second(10)) -1.6052 Create a logarithmic function with all inputs set to 0, then evaluate it at 10 >>> evaluation_zero = logarithmic_equation(0, 0) >>> print(evaluation_zero(10)) 0.0003 """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create evaluation def logarithmic_evaluation(variable): # Circumvent logarithm of zero if variable == 0: variable = 10**(-precision) evaluation = coefficients[0] * log(abs(variable)) + coefficients[1] result = rounded_value(evaluation, precision) return result return logarithmic_evaluation
def exponential_equation(first_constant, second_constant, precision=4): """ Generates an exponential function to provide evaluations at variable inputs Parameters ---------- first_constant : int or float Constant multiple of the resultant exponential function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001) second_constant : int or float Base rate of variable of the resultant exponential 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 ------- evaluation : func Function for evaluating an exponential equation when passed any integer or float argument See Also -------- :func:`~regressions.analyses.derivatives.exponential.exponential_derivatives`, :func:`~regressions.analyses.integrals.exponential.exponential_integral`, :func:`~regressions.analyses.roots.exponential.exponential_roots`, :func:`~regressions.models.exponential.exponential_model` Notes ----- - Standard form of an exponential function: :math:`f(x) = a\\cdot{b^x}` - |exponential_functions| Examples -------- Import `exponential_equation` function from `regressions` library >>> from regressions.analyses.equations.exponential import exponential_equation Create an exponential function with coefficients 2 and 3, then evaluate it at 10 >>> evaluation_first = exponential_equation(2, 3) >>> print(evaluation_first(10)) 118098.0 Create an exponential function with coefficients -2 and 3, then evaluate it at 10 >>> evaluation_second = exponential_equation(-2, 3) >>> print(evaluation_second(10)) -118098.0 Create an exponential function with all inputs set to 0, then evaluate it at 10 >>> evaluation_zero = exponential_equation(0, 0) >>> print(evaluation_zero(10)) 0.0001 """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create evaluation def exponential_evaluation(variable): evaluation = coefficients[0] * coefficients[1]**variable result = rounded_value(evaluation, precision) return result return exponential_evaluation
def linear_integral(first_constant, second_constant, precision = 4): """ Generates the integral 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 ------- 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 See Also -------- :func:`~regressions.analyses.equations.linear.linear_equation`, :func:`~regressions.analyses.derivatives.linear.linear_derivatives`, :func:`~regressions.analyses.roots.linear.linear_roots`, :func:`~regressions.models.linear.linear_model` Notes ----- - Standard form of a linear function: :math:`f(x) = a\\cdot{x} + b` - Integral of a linear function: :math:`F(x) = \\frac{a}{2}\\cdot{x^2} + b\\cdot{x}` - |indefinite_integral| - |integration_formulas| Examples -------- Import `linear_integral` function from `regressions` library >>> from regressions.analyses.integrals.linear import linear_integral Generate the integral of a linear function with coefficients 2 and 3, then display its coefficients >>> integral_constants = linear_integral(2, 3) >>> print(integral_constants['constants']) [1.0, 3.0] Generate the integral of a linear function with coefficients -2 and 3, then evaluate its integral at 10 >>> integral_evaluation = linear_integral(-2, 3) >>> print(integral_evaluation['evaluation'](10)) -70.0 Generate the integral of a linear function with all inputs set to 0, then display its coefficients >>> integral_zeroes = linear_integral(0, 0) >>> print(integral_zeroes['constants']) [0.0001, 0.0001] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create constants integral_coefficients = [(1/2) * coefficients[0], coefficients[1]] constants = rounded_list(integral_coefficients, precision) # Create evaluation def linear_evaluation(variable): evaluation = constants[0] * variable**2 + constants[1] * variable rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation # Package constants and evaluation in single dictionary results = { 'constants': constants, 'evaluation': linear_evaluation } return results
def exponential_derivatives(first_constant, second_constant, precision=4): """ Calculates the first and second derivatives of an exponential function Parameters ---------- first_constant : int or float Constant multiple of the original exponential function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001) second_constant : int or float Base rate of variable of the original exponential 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 ------- derivatives['first']['constants'] : list of float Coefficients of the resultant first derivative derivatives['first']['evaluation'] : func Function for evaluating the resultant first derivative at any float or integer argument derivatives['second']['constants'] : list of float Coefficients of the resultant second derivative derivatives['second']['evaluation'] : func Function for evaluating the resultant second derivative at any float or integer argument See Also -------- :func:`~regressions.analyses.equations.exponential.exponential_equation`, :func:`~regressions.analyses.integrals.exponential.exponential_integral`, :func:`~regressions.analyses.roots.exponential.exponential_roots`, :func:`~regressions.models.exponential.exponential_model` Notes ----- - Standard form of an exponential function: :math:`f(x) = a\\cdot{b^x}` - First derivative of an exponential function: :math:`f'(x) = a\\cdot{\\ln{b}\\cdot{b^x}}` - Second derivative of an exponential function: :math:`f''(x) = a\\cdot{\\ln^2{b}\\cdot{b^x}}` - |differentiation_formulas| - |exponential| Examples -------- Import `exponential_derivatives` function from `regressions` library >>> from regressions.analyses.derivatives.exponential import exponential_derivatives Generate the derivatives of an exponential function with coefficients 2 and 3, then display the coefficients of its first and second derivatives >>> derivatives_constants = exponential_derivatives(2, 3) >>> print(derivatives_constants['first']['constants']) [2.1972, 3.0] >>> print(derivatives_constants['second']['constants']) [2.4139, 3.0] Generate the derivatives of an exponential function with coefficients -2 and 3, then evaluate its first and second derivatives at 10 >>> derivatives_evaluation = exponential_derivatives(-2, 3) >>> print(derivatives_evaluation['first']['evaluation'](10)) -129742.4628 >>> print(derivatives_evaluation['second']['evaluation'](10)) -142538.3811 Generate the derivatives of an exponential function with all inputs set to 0, then display the coefficients of its first and second derivatives >>> derivatives_zeroes = exponential_derivatives(0, 0) >>> print(derivatives_zeroes['first']['constants']) [-0.0009, 0.0001] >>> print(derivatives_zeroes['second']['constants']) [0.0083, 0.0001] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create first derivative first_coefficients = [ coefficients[0] * log(abs(coefficients[1])), coefficients[1] ] first_constants = rounded_list(first_coefficients, precision) def first_derivative(variable): evaluation = first_constants[0] * first_constants[1]**variable rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation first_dictionary = { 'constants': first_constants, 'evaluation': first_derivative } # Create second derivative second_coefficients = [ first_constants[0] * log(abs(first_constants[1])), first_constants[1] ] second_constants = rounded_list(second_coefficients, precision) def second_derivative(variable): evaluation = second_constants[0] * second_constants[1]**variable rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation second_dictionary = { 'constants': second_constants, 'evaluation': second_derivative } # Package both derivatives in single dictionary results = {'first': first_dictionary, 'second': second_dictionary} return results
def linear_derivatives(first_constant, second_constant, precision=4): """ Calculates the first and second derivatives 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 ------- derivatives['first']['constants'] : list of float Coefficients of the resultant first derivative derivatives['first']['evaluation'] : func Function for evaluating the resultant first derivative at any float or integer argument derivatives['second']['constants'] : list of float Coefficients of the resultant second derivative derivatives['second']['evaluation'] : func Function for evaluating the resultant second derivative at any float or integer argument See Also -------- :func:`~regressions.analyses.equations.linear.linear_equation`, :func:`~regressions.analyses.integrals.linear.linear_integral`, :func:`~regressions.analyses.roots.linear.linear_roots`, :func:`~regressions.models.linear.linear_model` Notes ----- - Standard form of a linear function: :math:`f(x) = a\\cdot{x} + b` - First derivative of a linear function: :math:`f'(x) = a` - Second derivative of a linear function: :math:`f''(x) = 0` - |differentiation_formulas| Examples -------- Import `linear_derivatives` function from `regressions` library >>> from regressions.analyses.derivatives.linear import linear_derivatives Generate the derivatives of a linear function with coefficients 2 and 3, then display the coefficients of its first and second derivatives >>> derivatives_constants = linear_derivatives(2, 3) >>> print(derivatives_constants['first']['constants']) [2.0] >>> print(derivatives_constants['second']['constants']) [0.0] Generate the derivatives of a linear function with coefficients -2 and 3, then evaluate its first and second derivatives at 10 >>> derivatives_evaluation = linear_derivatives(-2, 3) >>> print(derivatives_evaluation['first']['evaluation'](10)) -2.0 >>> print(derivatives_evaluation['second']['evaluation'](10)) 0.0 Generate the derivatives of a linear function with all inputs set to 0, then display the coefficients of its first and second derivatives >>> derivatives_zeroes = linear_derivatives(0, 0) >>> print(derivatives_zeroes['first']['constants']) [0.0001] >>> print(derivatives_zeroes['second']['constants']) [0.0] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Creat first derivative first_constants = [coefficients[0]] def first_derivative(variable): evaluation = first_constants[0] return evaluation first_dictionary = { 'constants': first_constants, 'evaluation': first_derivative } # Create second derivative second_constants = [0.0] def second_derivative(variable): evaluation = second_constants[0] return evaluation second_dictionary = { 'constants': second_constants, 'evaluation': second_derivative } # Package both derivatives in single dictionary results = {'first': first_dictionary, 'second': second_dictionary} return results
def test_two_scalars_integer_string_raises(self): with self.assertRaises(Exception) as context: two_scalars(good_integer, bad_scalar) self.assertEqual(type(context.exception), TypeError) self.assertEqual(str(context.exception), 'Second argument must be an integer or a float')
def test_two_scalars_integer_float(self): two_scalars_integer_float = two_scalars(good_integer, good_float) self.assertEqual( two_scalars_integer_float, 'Both first and second arguments are integers or floats')
def exponential_roots(first_constant, second_constant, precision = 4): """ Calculates the roots of an exponential function Parameters ---------- first_constant : int or float Constant multiple of the original exponential function; if zero, it will be converted to a small, non-zero decimal value (e.g., 0.0001) second_constant : int or float Base rate of variable of the original exponential 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 float 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` See Also -------- :func:`~regressions.analyses.equations.exponential.exponential_equation`, :func:`~regressions.analyses.derivatives.exponential.exponential_derivatives`, :func:`~regressions.analyses.integrals.exponential.exponential_integral`, :func:`~regressions.models.exponential.exponential_model` Notes ----- - Standard form of a exponential function: :math:`f(x) = a\\cdot{b^x}` - Exponential formula: :math:`x = \\varnothing` Examples -------- Import `exponential_roots` function from `regressions` library >>> from regressions.analyses.roots.exponential import exponential_roots Calculate the roots of an exponential function with coefficients 2 and 3 >>> roots_first = exponential_roots(2, 3) >>> print(roots_first) [None] Calculate the roots of an exponential function with coefficients -2 and 3 >>> roots_second = exponential_roots(-2, 3) >>> print(roots_second) [None] Calculate the roots of an exponential function with all inputs set to 0 >>> roots_zeroes = exponential_roots(0, 0) >>> print(roots_zeroes) [None] """ # Handle input errors two_scalars(first_constant, second_constant) positive_integer(precision) coefficients = no_zeroes([first_constant, second_constant], precision) # Create list to return result = [] # Determine root root = None # Return result result.append(root) return result