Open tpemartin opened 1 year ago
import numpy as np
from numpy.linalg import inv
class Demand:
def __init__(self, D, h):
self.D=D
self.h=h
def quantity(self, pd):
qd=np.array((self.D@pd)+self.h)
return qd
class Supply:
def __init__(self, C, e):
self.C=C
self.e=e
def quantity(self, ps):
qs=np.array((self.C@ps)+self.e)
return qs
class Market:
def __init__(self, demand, supply):
self.demand=demand
self.supply=supply
def price(self):
pe=inv(C-D)@(h-e)
return pe
def quantity(self):
qe=D@self.price()+h
return qe
demand = Demand(D, h)
supply = Supply(C, e)
market = Market(demand, supply)
D=np.array([
[-10,-5],
[-1,-10]
])
h=np.array([
[100],
[50]
])
C=np.array([
[10,5],
[5,10]
])
e=np.array([
[0],
[0]
])
market.price(), market.quantity(), demand.quantity([[2],[4]]), supply.quantity([[1],[3]])