Spaces:
Sleeping
Sleeping
| # linear_equilibrium_calculations.py | |
| import re | |
| import numpy as np | |
| def extract_numbers(phrase): | |
| """Extract numerical values from a text input.""" | |
| return [float(num) for num in re.findall(r'-?\d+\.?\d*', phrase)] | |
| def calculate_linear_equilibrium(demand_intercept, slope_demand, supply_intercept, supply_slope): | |
| """Compute Competitive Equilibrium: Quantity and Price for LINEAR functions.""" | |
| if (supply_slope - slope_demand) == 0: | |
| raise ValueError("Error: Division by zero in equilibrium calculation!") | |
| Q_eq = (demand_intercept - supply_intercept) / (supply_slope - slope_demand) | |
| P_eq = demand_intercept + slope_demand * Q_eq | |
| return round(Q_eq, 2), round(P_eq, 2) | |