def supply(self): """ >>> sp.var('p q', positive=True) (p, q) >>> f = Firm(q, p, q**2/1000., SFC=1000) >>> f.supply() Piecewise((0, p < 1000.0), (500.0*p, And(0 <= p, p >= 1000.0))) >>> f = Firm(q, p, 10*q, SFC=0, FC=0) >>> f.supply() p - 10 == 0 """ min_atc, min_atc_cond = self.min_atc_sfc() supply, supply_cond = tools.maximize(self.earnings(), over=self.q) if supply is None: return sp.Eq(sp.diff(self.earnings(), self.q), 0) return sp.Piecewise((0, sp.Lt(self.p, min_atc)), (supply, sp.And(sp.Ge(self.p, min_atc), supply_cond, min_atc_cond)))
def supply(self): """ >>> sp.var('p q', positive=True) (p, q) >>> f = Firm(q, p, q**2/1000., SFC=1000) >>> f.supply() Piecewise((0, p < 1000.0), (500.0*p, And(0 <= p, p >= 1000.0))) >>> f = Firm(q, p, 10*q, SFC=0, FC=0) >>> f.supply() p - 10 == 0 """ min_atc, min_atc_cond = self.min_atc_sfc() supply, supply_cond = tools.maximize(self.earnings(), over=self.q) if supply is None: return sp.Eq(sp.diff(self.earnings(), self.q), 0) return sp.Piecewise( (0, sp.Lt(self.p, min_atc)), (supply, sp.And(sp.Ge(self.p, min_atc), supply_cond, min_atc_cond)))
def demand(self, rational=True): """Compute the demand as the maximization of the utility function. >>> sp.var('x p') (x, p) >>> cu = Consumer(x, p, benefit=tools.benefit_from_demand(x, p, 9/p - 1)) >>> sp.simplify(cu.benefit() - 9*sp.log(x + 1)) 0 >>> cu.demand() Piecewise((0, p < 0), ((-p + 9)/p, True)) >>> tau = sp.Symbol('tau') >>> cu_rat = Consumer(x, p, benefit=2*sp.sqrt(x)) >>> cu_del = Consumer(x, p, benefit=2*sp.sqrt(x), ... decision_benefit=20*sp.sqrt(x), ... other=-(1+tau)*p*x) >>> sp.solve(cu_del.demand(rational=False)-cu_rat.demand(), tau) [-11, 9] """ maxima, condition = tools.maximize(self.utility(rational), over=self.x) if maxima is None: maxima = 0 return sp.Piecewise((0, sp.Lt(self.p, 0)), (maxima, condition), (0, True))