Ask Your Question
0

Profit maximisation with a cobb-Douglas function

asked 2023-10-23 15:45:33 +0100

Cyrille gravatar image

I dont know how to solve this optimization problem in SageMath

$\max_{L,K}\pi(K,L) = p A L^\alpha K^\beta - w L - rk$

Here is my code

var('L K p A α K β w r')
assume(L>0)
assume(K>0)
assume(p>0)
assume(w>0)
assume(r>0)
assume(α>0)
assume(β>0)
assume(α<=1)
assume(β<=1)
π(L,K)= p*A*L^α*K^β - w*L - r*K
π_L = diff(π(L,K),L)
π_K = diff(π(L,K),K)
sol= solve([π_L==0,π_K==0],[L,K])

You can see that SageMath is unable to solve the system of two equations defined by solve. I have tried to decompose each stage one by one but I haven't found a way to obtain any result. It's a standard textbook problem in economics. Is there somebody who knows a way to d it ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2023-10-24 13:26:36 +0100

Emmanuel Charpentier gravatar image

updated 2023-10-26 09:56:10 +0100

One possible way : run :

var('A')
var('L K p alpha K beta w r', domain="positive") # Use reasonable identifiers, typeable from keyboard
assume(alpha<=1)
assume(beta<=1)
Pi(L,K)= p*A*L^alpha*K^beta - w*L - r*K
Pi_L = diff(Pi(L,K),L)
Pi_K = diff(Pi(L,K),K)
# Gradient to nullify
Grad=[Pi(L,K).diff(u) for u in (K, L)] 
# Equations of shape monomial == monomial
Sys0=[(u==0)-u.operands()[1] for u in Grad] 
# a==b ==> log(a)==log(b)
Sys1=[u.operator()(*map(lambda v:v.log().log_expand(), u.operands())) for u in Sys0] 
# EDIT : variables for unknowns change. Forgotten in answer's preparation.
lK, lL = var("lK, lL")
# dictionary of unknowns
D={log(K):lK, log(L):lL} 
# Rename and solve
lSol=solve([u.subs(D) for u in Sys1], list(D.values())) 
# Name back
Sol1 = [[u.subs({D[v]:v for v in D}) for u in s] for s in lSol] 
# Back to original variables.
Sol=[[u.operator()(*map(exp, u.operands())) for u in v] for v in Sol1]

Then :

sage: Sol
[[K == e^(-(alpha*(log(alpha) - log(w)) - (alpha - 1)*log(beta) + (alpha - 1)*log(r) + log(A) + log(p))/(alpha + beta - 1)),
  L == e^((beta*(log(alpha) - log(w)) - beta*log(beta) + beta*log(r) - log(A) - log(alpha) - log(p) + log(w))/(alpha + beta - 1))]]

$$ \left[\left[K = e^{\left(-\frac{\alpha {\left(\log\left(\alpha\right) - \log\left(w\right)\right)} - {\left(\alpha - 1\right)} \log\left(\beta\right) + {\left(\alpha - 1\right)} \log\left(r\right) + \log\left(A\right) + \log\left(p\right)}{\alpha + \beta - 1}\right)}, L = e^{\left(\frac{\beta {\left(\log\left(\alpha\right) - \log\left(w\right)\right)} - \beta \log\left(\beta\right) + \beta \log\left(r\right) - \log\left(A\right) - \log\left(\alpha\right) - \log\left(p\right) + \log\left(w\right)}{\alpha + \beta - 1}\right)}\right]\right] $$

BTW, Mathematica does not need this hand guidance :

sage: [[v[1].sage()==v[2].sage() for v in w] for w in mathematica.Solve([u==0 for u in Grad], [K, L])]
[[K == e^(-(alpha*log(alpha) - alpha*log(beta) + alpha*log(r) - alpha*log(w) + log(A) + log(beta) + log(p) - log(r))/(alpha + beta - 1)),
  L == e^((beta*log(alpha) - beta*log(beta) + beta*log(r) - beta*log(w) - log(A) - log(alpha) - log(p) + log(w))/(alpha + beta - 1))]]

EDIT : If you want to "factorize" the exponentials, try :

sage: [[u.lhs()==u.rhs().canonicalize_radical() for u in v] for v in Sol]
[[K == beta^((alpha - 1)/(alpha + beta - 1))*w^(alpha/(alpha + beta - 1))/(A^(1/(alpha + beta - 1))*alpha^(alpha/(alpha + beta - 1))*p^(1/(alpha + beta - 1))*r^((alpha - 1)/(alpha + beta - 1))),
  L == alpha^((beta - 1)/(alpha + beta - 1))*r^(beta/(alpha + beta - 1))/(A^(1/(alpha + beta - 1))*beta^(beta/(alpha + beta - 1))*p^(1/(alpha + beta - 1))*w^((beta - 1)/(alpha + beta - 1)))]]

$$ \left[\left[K = \frac{\beta^{\frac{\alpha - 1}{\alpha + \beta - 1}} w^{\frac{\alpha}{\alpha + \beta - 1}}}{A^{\left(\frac{1}{\alpha + \beta - 1}\right)} \alpha^{\frac{\alpha}{\alpha + \beta - 1}} p^{\left(\frac{1}{\alpha + \beta - 1}\right)} r^{\frac{\alpha - 1}{\alpha + \beta - 1}}}, L = \frac{\alpha^{\frac{\beta - 1}{\alpha + \beta - 1}} r^{\frac{\beta}{\alpha + \beta - 1}}}{A^{\left(\frac{1}{\alpha + \beta - 1}\right)} \beta^{\frac{\beta}{\alpha + \beta - 1}} p^{\left(\frac{1}{\alpha + \beta - 1}\right)} w^{\frac{\beta - 1}{\alpha + \beta - 1}}}\right]\right] $$

HTH,

edit flag offensive delete link more

Comments

Thanks a lot Emmanuel. Just I cannot find a way to get up with the $\log$ and $\textrm{exp}$. Is there a command to factorize/expand logarithm ? If not, could some one think a way to add this to SageMath ?

Cyrille gravatar imageCyrille ( 2023-10-25 10:40:27 +0100 )edit

I cannot find a way to get up with the log and exp. Is there a command to factorize/expand logarithm ?

See edits.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-10-26 09:57:09 +0100 )edit

I would like to know if ti is possible to have all powers in the numerator. I understand that the repartition is liked to the sign of the power.

Cyrille gravatar imageCyrille ( 2023-10-27 19:02:27 +0100 )edit

I understand that the repartition is liked to the sign of the power.

of which factor(s) ?

I would like to know if ti is possible to have all powers in the numerator.

You can always rewrite $\displaystyle\frac{a}{b^p}=a\cdot b^{-p}$, but that's pure cosmetics...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-10-28 07:40:28 +0100 )edit

Emmanuel you are true but it's like that that standard textbook write the results. And even if cosmetic, I do not know how to do that.

Cyrille gravatar imageCyrille ( 2023-10-29 16:32:20 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-10-23 15:45:33 +0100

Seen: 225 times

Last updated: Oct 26 '23