Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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] 
# 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))]]

HTH,

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] 
# dictionary of unknowns
lK, lL = var("lK, lL")
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,

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
lK, lL = var("lK, lL")
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,