Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unable to calculate market equilibrium

Here is a huge notebook, but as the error arrives just at the end I am obliged to show that if Sage lacks of an assume() about a variable, I can't see which hypothesis is missing. The object of the notebook is to calculate the equilibrium price.

We begin by the demand side

var('a x y p_x p_y D Rev R l')
assume(a,'real')
assume(x,'real')
assume(y,'real')
assume(p_x,'real')
assume(p_y,'real')
assume(D,'real')
assume(Rev,'real')
assume(R,'real')
assume(l,'real')
assume(p_x,'real')
assume(p_y,'real')
assume(l,'real')
assume(l>0)
#assume(a>-1)
assume(a>0)
assume(p_x>0)
assume(p_y>0)
assume(R>0)
U =(1/(1-(1/a)))*x^(1-(1/a))+y
show(LatexExpr(r"""\text{La fonction d'utilité est }U(x,y) = """),U)
D= x*p_x + y*p_y
show(LatexExpr(r'\text{La Dépense } D = '),D)
Rev= R
show(LatexExpr(r'\text{Le Revenu } Rev = '),R)
L=U+l*(Rev-D)
show(LatexExpr(r'\text{Le lagrangien est } \mathcal{L}(x, y, λ) = '),L)
FOC = [diff(L,x),diff(L,y),diff(L,l)]
show(LatexExpr(r'\text{Les condition du premier ordre sont } \left\{\begin{array}{c}\mathcal{L}_x= 0\\\mathcal{L}_y= 0\\\mathcal{L}_λ= 0\end{array}\right. '))
show(LatexExpr(r'\text{soit }'))
show(LatexExpr(r'\mathcal{L}_x= 0 \Longleftrightarrow '),FOC[0]==0)    
show(LatexExpr(r'\mathcal{L}_y= 0 \Longleftrightarrow '),FOC[1]==0)
show(LatexExpr(r'\mathcal{L}_λ= 0 \Longleftrightarrow '),FOC[2]==0)
sol = solve([FOC[0]==0,FOC[1]==0,FOC[2]==0],x,y,l, algorithm="sympy")
xs=sol[0][x]
ys=sol[0][y]
ls=sol[0][l]
show(LatexExpr(r"""\text{À l'optimum, on a :}"""))
show(LatexExpr(r'  \,\,\,\,\,\,\,\,\,         x^d = '),xs)
show(LatexExpr(r'  \,\,\,\,\,\,\,\,\,         y^d = '),ys)
show(LatexExpr(r'  \,\,\,\,\,\,\,\,\,         \lambda^\star = '),ls)
show(LatexExpr(r'\text{Si le bien } y \text{ sert de numéraire, on  a : }p_y =1 \text{ et, ainsi :}'))
xsn=xs.substitute(p_y=1).factor()
ysn=ys.substitute(p_y=1).factor()
lsn=ls.substitute(p_y=1).factor()
show(LatexExpr(r'  \,\,\,\,\,\,\,\,\,         x^\star = '),xsn)
show(LatexExpr(r'  \,\,\,\,\,\,\,\,\,         y^\star = '),ysn)
show(LatexExpr(r'  \,\,\,\,\,\,\,\,\,         \lambda^\star = '),lsn)
show(LatexExpr(r'\text{On a :}'))
x_p=diff(xsn,p_x).simplify()
show(LatexExpr(r'x_p = '),x_p,LatexExpr(r'< 0.'))

Then follows the offer side

var('C c')
assume(c, 'real')
assume(c>0)
C= (1/2)*c*x^2
show(LatexExpr(r'\text{On suppose que la fonction de coût du producteur est  :  } C(x) ='), C)
pi=(p_x *x- C)
show(LatexExpr(r'\text{ Le profit est :  } \pi(x) = '), pi)
pip= diff(pi,x)
show(LatexExpr(r'\text{ Le profit marginal est :  } \pi^\prime(x) = '), pip, LatexExpr(r'( = 0\text{  à l}^\prime\text{optimum})'))
pipp= diff(pi,x,2)
show(LatexExpr(r"""\text{Il s'agit bien d'un maximum puisque :  } \pi^{\prime\prime}(x) = """),pipp,LatexExpr(r'<0'))
prod=solve(pip==0,x)[0].rhs()
show(LatexExpr(r"""\text{L'offre de produit est :  } x^o = """),prod)

And now the market equilibrium where Sage seems to lack an hypothesis :

show(LatexExpr(r'\text{L}^\prime\text{équilibre de concurrence pure et parfaite est caractérisé par le système d}^\prime\text{équations :  } '))
show(LatexExpr(r'x^d = x^o'))
show(LatexExpr(r'x^d = '),xsn)
show(LatexExpr(r'x^o = '),prod)
pem= solve(xsn==prod, p_x)[0].rhs()
show(pem)

Also I would like to have the inverse demand fonction directly that is from the notebook if

$x_s= (1/p_x)^a \Longrightarrow p_x = (1/x_s)^{1/a}$, I have tried

def symbolic_inverse(f, x):
     y = SR.var('y')
     g = (f - y).roots(x, multiplicities=False)
     return [expr.subs(y=x) for expr in g]

symbolic_inverse(SR(1/(x^(1/a))),x)

but even there it seem to lack an assumption.