def second_derivative(variable): exponential = exp(-1 * second_constants[1] * (variable - second_constants[2])) evaluation = second_constants[0] * exponential * (1 + exponential)**( -2) * (2 * exponential / (1 + exponential) - 1) rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
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
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
def hyperbolic_evaluation(variable): # Circumvent division by zero if variable == 0: variable = 10**(-precision) evaluation = coefficients[0] / variable + coefficients[1] result = rounded_value(evaluation, precision) return result
def logistic_roots_initial_value(first_constant, second_constant, third_constant, initial_value, precision=4): # Handle input errors four_scalars(first_constant, second_constant, third_constant, initial_value) positive_integer(precision) # Create list to return result = [] # Create pivot variable log_argument = first_constant / initial_value - 1 # Circumvent logarithm of zero if log_argument == 0: log_argument = 10**(-precision) # Create intermediary variables numerator = log(abs(log_argument)) denominator = second_constant ratio = numerator / denominator # Determine root given an initial value root = third_constant - ratio # Round root rounded_root = rounded_value(root, precision) # Return result result.append(rounded_root) return result
def exponential_roots_initial_value(first_constant, second_constant, initial_value, precision = 4): # Handle input errors three_scalars(first_constant, second_constant, initial_value) positive_integer(precision) # Create list to return result = [] # Create intermediary variables numerator = log(abs(initial_value / first_constant)) denominator = log(abs(second_constant)) # Circumvent division by zero if denominator == 0: denominator = 10**(-precision) # Determine root given an initial value ratio = numerator / denominator # Round root rounded_ratio = rounded_value(ratio, precision) # Return result result.append(rounded_ratio) return result
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
def logistic_roots_second_derivative(first_constant, second_constant, third_constant, precision=4): # Handle input errors three_scalars(first_constant, second_constant, third_constant) positive_integer(precision) # Create list to return result = [] # Determine root of second derivative root = rounded_value(third_constant) # Return root result.append(root) return result
def logistic_roots_derivative_initial_value(first_constant, second_constant, third_constant, initial_value, precision=4): # Handle input errors four_scalars(first_constant, second_constant, third_constant, initial_value) positive_integer(precision) # Create intermediary list and list to return roots = [] result = [] # Determine quadratic roots of derivative given an initial value intermediary_roots = quadratic_roots( initial_value, 2 * initial_value - first_constant * second_constant, initial_value, precision) # Handle no roots if intermediary_roots[0] == None: roots.append(None) # Convert quadratic roots using logarithms else: for intermediary in intermediary_roots: if intermediary == 0: intermediary = 10**(-precision) root = third_constant - log(abs(intermediary)) / second_constant rounded_root = rounded_value(root, precision) roots.append(rounded_root) # Sort roots sorted_roots = sorted_list(roots) # Return result result.extend(sorted_roots) return result
def hyperbolic_roots_derivative_initial_value(first_constant, second_constant, initial_value, precision=4): # Handle input errors three_scalars(first_constant, second_constant, initial_value) positive_integer(precision) # Create list to return result = [] # Create intermediary variable ratio = -1 * first_constant / initial_value # Handle no roots if ratio < 0: result.append(None) # Determine roots of derivative given an initial value else: radical = ratio**(1 / 2) rounded_radical = rounded_value(radical, precision) result.append(rounded_radical) return result
def test_round_missing(self): round_missing = rounded_value(normal_decimal) self.assertEqual(round_missing, 6.8172)
def first_derivative(variable): evaluation = first_constants[0] * cos(first_constants[1] * (variable - first_constants[2])) rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
def second_derivative(variable): evaluation = second_constants[0] * sin( second_constants[1] * (variable - second_constants[2])) rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
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 coordinate_pairs(equation_type, coefficients, inputs, point_type = 'point', precision = 4): """ Creates a list of coordinate pairs from a set of inputs Parameters ---------- equation_type : str Name of the type of function for which coordinate pairs must be determined (e.g., 'linear', 'quadratic') coefficients : list of int or float Coefficients to use to generate the equation to investigate inputs : list of int or float or str X-coordinates to use to generate the y-coordinates for each coordinate pair point_type : str, default='point' Name of the type of point that describes all points which must be generated (e.g., 'intercepts', 'maxima') precision : int, default=4 Maximum number of digits that can appear after the decimal place of the results Raises ------ ValueError First argument must be either 'linear', 'quadratic', 'cubic', 'hyperbolic', 'exponential', 'logarithmic', 'logistic', or 'sinusoidal' TypeError Second argument must be a 1-dimensional list containing elements that are integers or floats TypeError Third argument must be a 1-dimensional list containing elements that are integers, floats, strings, or None ValueError Fourth argument must be either 'point', 'intercepts', 'maxima', 'minima', or 'inflections' ValueError Last argument must be a positive integer Returns ------- points : list of float or str List containing lists of coordinate pairs, in which the second element of the inner lists are floats and the first elements of the inner lists are either floats or strings (the latter for general forms); may return a list of None if inputs list contained None See Also -------- :func:`~regressions.vectors.generate.generate_elements`, :func:`~regressions.vectors.unify.unite_vectors` Notes ----- - Set of x-coordinates of points: :math:`x_i = \\{ x_1, x_2, \\cdots, x_n \\}` - Set of y-coordinates of points: :math:`y_i = \\{ y_1, y_2, \\cdots, y_n \\}` - Set of coordinate pairs of points: :math:`p_i = \\{ (x_1, y_1), (x_2, y_2), \\cdots, (x_n, y_n) \\}` Examples -------- Import `coordinate_pairs` function from `regressions` library >>> from regressions.analyses.points import coordinate_pairs Generate a list of coordinate pairs for a cubic function with coefficients 2, 3, 5, and 7 based off x-coordinates of 1, 2, 3, and 4 >>> points_cubic = coordinate_pairs('cubic', [2, 3, 5, 7], [1, 2, 3, 4]) >>> print(points_cubic) [[1.0, 17.0], [2.0, 45.0], [3.0, 103.0], [4.0, 203.0]] Generate a list of coordinate pairs for a sinusoidal function with coefficients 2, 3, 5, and 7 based off x-coordinates of 1, 2, 3, and 4 >>> points_sinusoidal = coordinate_pairs('sinusoidal', [2, 3, 5, 7], [1, 2, 3, 4]) >>> print(points_sinusoidal) [[1.0, 8.0731], [2.0, 6.1758], [3.0, 7.5588], [4.0, 6.7178]] Generate a list of coordinate pairs for a quadratic function with coefficients 1, -5, and 6 based off x-coordinates of 2 and 3 (given that the resultant coordinates will be x-intercepts) >>> points_quadratic = coordinate_pairs('quadratic', [1, -5, 6], [2, 3], 'intercepts') >>> print(points_quadratic) [[2.0, 0.0], [3.0, 0.0]] """ # Handle input errors select_equations(equation_type) vector_of_scalars(coefficients, 'second') allow_none_vector(inputs, 'third') select_points(point_type, 'fourth') positive_integer(precision) # Create equations for evaluating inputs (based on equation type) equation = lambda x : x if equation_type == 'linear': equation = linear_equation(*coefficients, precision) elif equation_type == 'quadratic': equation = quadratic_equation(*coefficients, precision) elif equation_type == 'cubic': equation = cubic_equation(*coefficients, precision) elif equation_type == 'hyperbolic': equation = hyperbolic_equation(*coefficients, precision) elif equation_type == 'exponential': equation = exponential_equation(*coefficients, precision) elif equation_type == 'logarithmic': equation = logarithmic_equation(*coefficients, precision) elif equation_type == 'logistic': equation = logistic_equation(*coefficients, precision) elif equation_type == 'sinusoidal': equation = sinusoidal_equation(*coefficients, precision) # Round inputs rounded_inputs = [] for point in inputs: if isinstance(point, (int, float)): rounded_inputs.append(rounded_value(point, precision)) else: rounded_inputs.append(point) # Create empty lists outputs = [] coordinates = [] # Handle no points if rounded_inputs[0] == None: coordinates.append(None) # Fill outputs list with output value at each input else: for value in rounded_inputs: # Circumvent inaccurate rounding if point_type == 'intercepts': outputs.append(0.0) # Evaluate function at inputs else: # Evaluate numerical inputs if isinstance(value, (int, float)): output = equation(value) rounded_output = rounded_value(output, precision) outputs.append(rounded_output) # Handle non-numerical inputs else: outputs.append(outputs[0]) # Unite inputs and outputs for maxima into single list coordinates.extend(unite_vectors(rounded_inputs, outputs)) # Return final coordinate pairs return coordinates
def test_round_extreme_low(self): round_extreme_low = rounded_value(extreme_decimal, low_precision) self.assertEqual(round_extreme_low, 0.01)
def sinusoidal_evaluation(variable): evaluation = coefficients[0] * sin(coefficients[1] * (variable - coefficients[2])) + coefficients[3] result = rounded_value(evaluation, precision) return result
def average_value_integral(equation_type, coefficients, start, end, precision=4): """ Evaluates the average value of a given function between two points Parameters ---------- equation_type : str Name of the type of function for which the definite integral must be evaluated (e.g., 'linear', 'quadratic') coefficients : list of int or float Coefficients of the original function to integrate start : int or float Value of the x-coordinate of the first point to use for evaluating the average value end : int or float Value of the x-coordinate of the second point to use for evaluating the average value precision : int, default=4 Maximum number of digits that can appear after the decimal place of the result Raises ------ ValueError First argument must be either 'linear', 'quadratic', 'cubic', 'hyperbolic', 'exponential', 'logarithmic', 'logistic', or 'sinusoidal' TypeError Second argument must be a 1-dimensional list containing elements that are integers or floats TypeError Third and fourth arguments must be integers or floats ValueError Third argument must be less than or equal to fourth argument ValueError Last argument must be a positive integer Returns ------- average : float Average value of the function between two points; if start and end values are identical, then average value will be zero See Also -------- :func:`~regressions.analyses.accumulation.accumulated_area`, :func:`~regressions.analyses.mean_values.mean_values_integral`, :func:`~regressions.analyses.mean_values.average_value_derivative`, :func:`~regressions.analyses.mean_values.mean_values_derivative` Notes ----- - Average value of a function over an interval: :math:`f_{avg} = \\frac{1}{b - a}\\cdot{\\int_{a}^{b} f(x) \\,dx}` - |mean_integrals| Examples -------- Import `average_value_integral` function from `regressions` library >>> from regressions.analyses.mean_values import average_value_integral Evaluate the average value of a cubic function with coefficients 2, 3, 5, and 7 between end points of 10 and 20 >>> average_cubic = average_value_integral('cubic', [2, 3, 5, 7], 10, 20) >>> print(average_cubic) 8282.0 Evaluate the average value of a sinusoidal function with coefficients 2, 3, 5, and 7 between end points of 10 and 20 >>> average_sinusoidal = average_value_integral('sinusoidal', [2, 3, 5, 7], 10, 20) >>> print(average_sinusoidal) 6.9143 """ # Handle input errors select_equations(equation_type) vector_of_scalars(coefficients, 'second') compare_scalars(start, end, 'third', 'fourth') positive_integer(precision) # Determine accumulated value of function over interval accumulated_value = accumulated_area(equation_type, coefficients, start, end, precision) # Create intermediary variable change = end - start # Circumvent division by zero if change == 0: change = 10**(-precision) # Determine average value of function over interval ratio = accumulated_value / change # Round value rounded_ratio = rounded_value(ratio, precision) # Return result result = rounded_ratio return result
def sinusoidal_evaluation(variable): evaluation = constants[0] * cos( constants[1] * (variable - constants[2])) + constants[3] * variable rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
def exponential_evaluation(variable): evaluation = constants[0] * constants[1]**variable rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
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 test_round_normal_low(self): round_normal_low = rounded_value(normal_decimal, low_precision) self.assertEqual(round_normal_low, 6.82)
def test_round_normal_high(self): round_normal_high = rounded_value(normal_decimal, high_precision) self.assertEqual(round_normal_high, 6.81723983)
def logistic_evaluation(variable): evaluation = constants[0] * log( abs(exp(constants[1] * (variable - constants[2])) + 1)) rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
def test_round_extreme_high(self): round_extreme_high = rounded_value(extreme_decimal, high_precision) self.assertEqual(round_extreme_high, 1e-08)
def first_derivative(variable): evaluation = first_constants[0] * variable + first_constants[1] rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
def average_value_derivative(equation_type, coefficients, start, end, precision=4): """ Evaluates the average rate of change between two points for a given function Parameters ---------- equation_type : str Name of the type of function for which the definite integral must be evaluated (e.g., 'linear', 'quadratic') coefficients : list of int or float Coefficients of the original function to use for evaluating the average rate of change start : int or float Value of the x-coordinate of the first point to use for evaluating the rate of change end : int or float Value of the x-coordinate of the second point to use for evaluating the rate of change precision : int, default=4 Maximum number of digits that can appear after the decimal place of the result Raises ------ ValueError First argument must be either 'linear', 'quadratic', 'cubic', 'hyperbolic', 'exponential', 'logarithmic', 'logistic', or 'sinusoidal' TypeError Second argument must be a 1-dimensional list containing elements that are integers or floats TypeError Third and fourth arguments must be integers or floats ValueError Third argument must be less than or equal to fourth argument ValueError Last argument must be a positive integer Returns ------- average : float Slope of a function between two points; if start and end values are identical, then slope will be zero See Also -------- :func:`~regressions.analyses.mean_values.mean_values_derivative`, :func:`~regressions.analyses.mean_values.average_value_integral`, :func:`~regressions.analyses.mean_values.mean_values_integral` Notes ----- - Slope of a function over an interval: :math:`m = \\frac{f(b) - f(a)}{b - a}` - |mean_derivatives| Examples -------- Import `average_value_derivative` function from `regressions` library >>> from regressions.analyses.mean_values import average_value_derivative Evaluate the average rate of change of a cubic function with coefficients 2, 3, 5, and 7 between end points of 10 and 20 >>> average_cubic = average_value_derivative('cubic', [2, 3, 5, 7], 10, 20) >>> print(average_cubic) 1495.0 Evaluate the average rate of change of a sinusoidal function with coefficients 2, 3, 5, and 7 between end points of 10 and 20 >>> average_sinusoidal = average_value_derivative('sinusoidal', [2, 3, 5, 7], 10, 20) >>> print(average_sinusoidal) 0.0401 """ # Handle input errors select_equations(equation_type) vector_of_scalars(coefficients, 'second') compare_scalars(start, end, 'third', 'fourth') positive_integer(precision) # Create equation based on equation type equation = lambda x: x if equation_type == 'linear': equation = linear_equation(*coefficients, precision) elif equation_type == 'quadratic': equation = quadratic_equation(*coefficients, precision) elif equation_type == 'cubic': equation = cubic_equation(*coefficients, precision) elif equation_type == 'hyperbolic': equation = hyperbolic_equation(*coefficients, precision) elif equation_type == 'exponential': equation = exponential_equation(*coefficients, precision) elif equation_type == 'logarithmic': equation = logarithmic_equation(*coefficients, precision) elif equation_type == 'logistic': equation = logistic_equation(*coefficients, precision) elif equation_type == 'sinusoidal': equation = sinusoidal_equation(*coefficients, precision) # Create intermediary variables vertical_change = equation(end) - equation(start) horizontal_change = end - start # Circumvent division by zero if horizontal_change == 0: horizontal_change = 10**(-precision) # Determine average slope ratio = vertical_change / horizontal_change result = rounded_value(ratio, precision) return result
def second_derivative(variable): evaluation = second_constants[0] rounded_evaluation = rounded_value(evaluation, precision) return rounded_evaluation
def extrema_points(equation_type, coefficients, precision=4): """ Calculates the extrema of a specific function Parameters ---------- equation_type : str Name of the type of function for which extrema must be determined (e.g., 'linear', 'quadratic') coefficients : list of int or float Coefficients to use to generate the equation to investigate precision : int, default=4 Maximum number of digits that can appear after the decimal place of the results Raises ------ ValueError First argument must be either 'linear', 'quadratic', 'cubic', 'hyperbolic', 'exponential', 'logarithmic', 'logistic', or 'sinusoidal' TypeError Second argument must be a 1-dimensional list containing elements that are integers or floats ValueError Last argument must be a positive integer Returns ------- points['maxima'] : list of float or str Values of the x-coordinates at which the original function has a relative maximum; if the function is sinusoidal, then only two or three results within a two-period interval will be listed, but a general form will also be included; if the function has no maxima, then it will return a list of `None` points['minima'] : list of float or str Values of the x-coordinates at which the original function has a relative minimum; if the function is sinusoidal, then only two or three results within a two-period interval will be listed, but a general form will also be included; if the function has no minima, then it will return a list of `None` See Also -------- - Roots for key functions: :func:`~regressions.analyses.roots.linear.linear_roots`, :func:`~regressions.analyses.roots.quadratic.quadratic_roots`, :func:`~regressions.analyses.roots.cubic.cubic_roots`, :func:`~regressions.analyses.roots.hyperbolic.hyperbolic_roots`, :func:`~regressions.analyses.roots.exponential.exponential_roots`, :func:`~regressions.analyses.roots.logarithmic.logarithmic_roots`, :func:`~regressions.analyses.roots.logistic.logistic_roots`, :func:`~regressions.analyses.roots.sinusoidal.sinusoidal_roots` - Graphical analysis: :func:`~regressions.analyses.criticals.critical_points`, :func:`~regressions.analyses.intervals.sign_chart`, :func:`~regressions.analyses.maxima.maxima_points`, :func:`~regressions.analyses.minima.minima_points`, :func:`~regressions.analyses.points.key_coordinates` Notes ----- - Critical points for the derivative of a function: :math:`c_i = \\{ c_1, c_2, c_3, \\cdots, c_{n-1}, c_n \\}` - X-coordinates of the extrema of the function: :math:`x_{ext} = \\{ x \\mid x \\in c_i, \\left( f'(\\frac{c_{j-1} + c_j}{2}) < 0 \\cap f'(\\frac{c_j + c_{j+1}}{2}) > 0 \\right) \\\\ \\cup \\left( f'(\\frac{c_{j-1} + c_j}{2}) > 0 \\cap f'(\\frac{c_j + c_{j+1}}{2}) < 0 \\right) \\}` - |extrema_values| Examples -------- Import `extrema_points` function from `regressions` library >>> from regressions.analyses.extrema import extrema_points Calulate the extrema of a cubic function with coefficients 1, -15, 63, and -7 >>> points_cubic = extrema_points('cubic', [1, -15, 63, -7]) >>> print(points_cubic['maxima']) [3.0] >>> print(points_cubic['minima']) [7.0] Calulate the extrema of a sinusoidal function with coefficients 2, 3, 5, and 7 >>> points_sinusoidal = extrema_points('sinusoidal', [2, 3, 5, 7]) >>> print(points_sinusoidal['maxima']) [5.5236, 7.618, 9.7124, '5.5236 + 2.0944k'] >>> print(points_sinusoidal['minima']) [6.5708, 8.6652, '6.5708 + 2.0944k'] """ # Handle input errors select_equations(equation_type) vector_of_scalars(coefficients, 'second') positive_integer(precision) # Determine maxima and minima max_points = maxima_points(equation_type, coefficients, precision) min_points = minima_points(equation_type, coefficients, precision) # Create dictionary to return result = {} # Handle sinusoidal case if equation_type == 'sinusoidal': # Recreate sign chart intervals_set = sign_chart('sinusoidal', coefficients, 1, precision) # Grab general form general_form = intervals_set[-1] # Extract periodic unit periodic_unit_index = general_form.find(' + ') + 3 periodic_unit = 2 * float(general_form[periodic_unit_index:-1]) rounded_periodic_unit = rounded_value(periodic_unit, precision) # Create general forms for max and min max_general_form = str( max_points[0]) + ' + ' + str(rounded_periodic_unit) + 'k' min_general_form = str( min_points[0]) + ' + ' + str(rounded_periodic_unit) + 'k' # Append general form as final element of each list max_extended = max_points + [max_general_form] min_extended = min_points + [min_general_form] result = {'maxima': max_extended, 'minima': min_extended} # Handle all other cases else: result = {'maxima': max_points, 'minima': min_points} return result
def cubic_evaluation(variable): evaluation = coefficients[0] * variable**3 + coefficients[ 1] * variable**2 + coefficients[2] * variable + coefficients[3] result = rounded_value(evaluation, precision) return result