Price elasticity is the percentage change in quantity sold for a 1% change in price. With a constant-elasticity demand curve , taking logs gives a straight line: .
Implement:
fit_elasticity(prices, quantities): the least-squares slope and intercept of log q on log p, returned as (e, log_A)predict_quantity(p, e, log_A)revenue_effect(e): "increase" if raising prices would increase revenue (inelastic, e > -1), "decrease" if e < -1, and "flat" if e == -1optimal_price(e, unit_cost): the profit-maximising price for constant elasticity, . Raise ValueError if e >= -1 (no finite optimum).