File size: 718 Bytes
02cc45b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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)