# Profit maximisation with a cobb-Douglas function

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 close merge delete

Sort by » oldest newest most voted

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)
Grad=[Pi(L,K).diff(u) for u in (K, L)]
# Equations of shape monomial == monomial
# 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,

more

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 ?

( 2023-10-25 10:40:27 +0200 )edit

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

See edits.

( 2023-10-26 09:57:09 +0200 )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.

( 2023-10-27 19:02:27 +0200 )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...

( 2023-10-28 07:40:28 +0200 )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.

( 2023-10-29 16:32:20 +0200 )edit