Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Smoother Derivations of Hicksian Demands in Sage

The problem I'm solving is an economics one relating to solving for hicksian demands,given my difficulty solving for them directly, Im trying to tackle this same problem indirectly and it works for the most part however I'd like it to run smoother.

Setting up the problem we have:

x1, x2, l, p1, p2, a, b,  R= var('x1, x2, l, p1, p2, a, b,  R')
U = x1^a*x2^b
m = p1*x1+p2*x2;
L = U+ l * (R-m);
dLdx = L.diff(x1);
dLdy = L.diff(x2);
dLdl = L.diff(l);
solve([dLdx == 0, dLdy == 0, dLdl == 0], x1, x2, l)

Out: [[x1 == R*a/((a + b)*p1), x2 == R*b/((a + b)*p2), l == (a + b)*(R*a/((a + b)*p1))^a*(R*b/((a + b)*p2))^b/R]]

I then manually plug in the values for $x_1$ and and $x_2$ into $U$ to get the indirect utility function and solve for the expenditure function:

 expend=solve(U==(R*a/((a + b)*p1))^a*(R*b/((a + b)*p2)^b),R);expend
 Out: [R == ((a + b)*p2)^b*x1^a*x2^b/(b*(R*a/((a + b)*p1))^a)]

I again need to plug in this exact functional form to get the hicksian demands using shephard's lemma:

expend1=((a + b)*p2)^b*x1^a*x2^b/(b*(R*a/((a + b)*p1))^a)
expend1.diff(p1) #the hicksian demand for x1
Out:  ((a + b)*p2)^(b - 1)*(a + b)*x1^a*x2^b/(R*a/((a + b)*p1))^a

expend1.diff(p2) #the hicksian demand for x2
Out: ((a + b)*p2)^(b - 1)*(a + b)*x1^a*x2^b/(R*a/((a + b)*p1))^a

I'm interested in getting my code to run more parsimoniously as I find myself having to manually pull out solved values to move to next stages of the problem. This is frustrating because I'd have to do this each time if i change my functional form.

Smoother Derivations of Hicksian Demands in Sage

The problem I'm solving is an economics one relating to solving for hicksian demands,given my difficulty solving for them directly, Im trying to tackle this same problem indirectly and it works for the most part however I'd like it to run smoother.

Setting up the problem we have:

x1, x2, l, p1, p2, a, b,  R= var('x1, x2, l, p1, p2, a, b,  R')
U = x1^a*x2^b
m = p1*x1+p2*x2;
L = U+ l * (R-m);
dLdx = L.diff(x1);
dLdy = L.diff(x2);
dLdl = L.diff(l);
solve([dLdx == 0, dLdy == 0, dLdl == 0], x1, x2, l)

Out: [[x1 == R*a/((a + b)*p1), x2 == R*b/((a + b)*p2), l == (a + b)*(R*a/((a + b)*p1))^a*(R*b/((a + b)*p2))^b/R]]

I then manually plug in the values for $x_1$ and and $x_2$ into $U$ to get the indirect utility function and solve for the expenditure function:

 expend=solve(U==(R*a/((a + b)*p1))^a*(R*b/((a + b)*p2)^b),R);expend
 Out: [R == ((a + b)*p2)^b*x1^a*x2^b/(b*(R*a/((a + b)*p1))^a)]

I again need to plug in this exact functional form to get the hicksian demands using shephard's lemma:

expend1=((a + b)*p2)^b*x1^a*x2^b/(b*(R*a/((a + b)*p1))^a)
expend1.diff(p1) #the hicksian demand for x1
Out:  ((a + b)*p2)^(b - 1)*(a + b)*x1^a*x2^b/(R*a/((a + b)*p1))^a

expend1.diff(p2) #the hicksian demand for x2
Out: ((a + b)*p2)^(b - 1)*(a + b)*x1^a*x2^b/(R*a/((a + b)*p1))^a

I'm interested in getting my code to run more parsimoniously as I find myself having to manually pull out solved values to move to next stages of the problem. This is frustrating because I'd have to do this each time if i change my functional form.

Note: I see that this method actually does not work as I didnt notice R on the Left hand side of this problem.