# Symbolic Non-Linear Maximization using Lagrangian

I am trying to solve a constrained optimisation problem using Lagrangian Multipliers. The particular case is standard microeconomic problem of a firm maximizing profits, which I want to extend once I can solve the basic case. Specifically, \begin{equation} \underset{L,K}{max} \, \pi=pq -c(q) = pf(L,K)-(\rho K+\omega W) \quad \mbox{subject to} \quad L,K>0 \end{equation} The case I am interested in is where: $$f(L,K)=A(\alpha k^{\theta}+(1-\alpha)l^{\theta})^{\phi/\theta}$$

And where $\rho>0,\omega>0,\theta<1,A>0$. I am also, until I get it to work, assuming $\phi=1$.

In case it is more natural in mathematica it's worth noting that we can also write this as a minimization problem where first we solve for the firm's cost function: \begin{equation} c(y,\omega, rho)=\underset{l,k}{min}\ \rho k + \omega l \quad \mbox{subject to} \quad f(l,k)\geq y, l>0,k>0 \end{equation}

This gives the cost of a given level of output, which then allows us to maximize the profit function by solving: \begin{equation} \underset{y}{max}\ \pi=py - c(y,\rho, \omega) \quad \mbox{subject to} \quad f(l,k)\geq y, l>0,k>0 \end{equation}

I have had no success using Mathematica with either approach. I have tried a few different approaches. I initally tried solving for by explicitly writing out the first-order conditions and the necessary assumptions and using Solve which works for problems with a simpler specification for $f(L,K)$ e.g. $f(L,K)=L^{1/3}K^{1/3}$ but leads to errors for the case I'm interested in.

The code below which runs without error, but also seemingly without end, is based on the answer to this question: How can I implement the method of Lagrange multipliers to find constrained extrema? and to a lesser extent this one Finding maximum or minimum of implicit functions

 assumps =a > 0 && l > 0 && k > 0 && 1 > alpha > 0 && omega > 0 && rho > 0 && theta < 1
f[l_, k_] := a*(alpha*(k^theta]) + (1 - alpha) l^theta)^(1/theta)
g1[l_, k_] := omega*l + rho*k + beta*rho*k^2
h[x_, y_, lambda1_] := f[l, k]*p - lambda1 g1[l, k]
{l, k} /. Assuming[assumeCES, Reduce[Grad[h @@ #, #] == 0, #]] &@{l,
k, \[Lambda]1} // FullSimplify


I have also tried using Solve instead:

{l, k} /. Assuming[assumeCES, Reduce[Grad[h @@ #, #] == 0, #, Reals]] &@{l,
k, \[Lambda]1} // FullSimplify


My question is How can this problem (and extensions of it) be solved using Mathematica? Is there an alternative command or alternative statement of the problem such that Mathematica is better able to deal with it.

As a beginner and certainly an economist you should be aware of two points :

-- in Mathematica you should avoid capital letters as variable because capital letters are for build-in commands. And pay attention, there are unconsistencies in your exposal since you change the letters from capital to normal size in some places.

-- there is no free lunch. You should try to learn the language before trying to solve an equation. Twenty years ago, some of my collegues tried to solve the same type of problems and as they wanted the minimal investment they finish in saying that Mathematica was unable to solve this type of problem and finaly reject the incredibly powerfull soft. As a busy man, in that time, I have Barked with wolves.

Your question is very long an time consumming, so I will answer only to the first maximization

f[l_, k_] := γ (α k^θ + (1 - α)  l^θ)^(ϕ/θ)
sp[l_, k_] := p f[l, k] - (ρ k + ω l)


In that case using Solve Reduce ... directly gives no answer because they are well fitted to answer to algebraic question not to transcendant ones --- algebraic means that powers are integers. So you must help Mathematica to find the path to the solution.

If you ask for the derivatives of sp

D[sp[l, k], k]
D[sp[l, k], l]


you will find

-ρ +  k^(-1 + θ)    p α (l^θ (1 - α) + k^θ α)^(-1 + ϕ/θ) γ ϕ


and

l^(-1 + θ) p (1 - α) (l^θ (1 - α) + k^θ α)^(-1 + ϕ/θ) γ ϕ - ω


Exactly as on a sheet of paper, you see that p (l^θ (1 - α) + k^θ α)^(-1 + ϕ/θ) γ ϕ is common to both equations. So Certainly it can be eliminated. You can do this with the following commands

dk = D[sp[l, k], k] /. {p (l^θ (1 - α) + k^θ α)^(-1 + ϕ/θ) γ ϕ -> x}
dl = D[sp[l, k], l] /. {p (l^θ (1 - α) + k^θ α)^(-1 + ϕ/θ) γ ϕ -> x}


to obtain in a first time k^(-1 + θ) x α - ρ and l^(-1 + θ) x (1 - α) - ω. Notice that expr /. {a-> x} substitute x to a in expr.

Now you can eliminate x easily by the command and find l as a function of k by the command:

sol = Solve[FullSimplify[(k^(-1 + θ) x α)/(l^(-1 + θ) x (1 - α)) == ρ/ω], l]


which gives {{l -> ((k^(1 - θ) (1 - α) ρ)/(α ω))^(1/(1 - θ))}}

So you need to choose one of the two first order conditions and to substitute this rule for l to obtain a condition on k only:

-ρ + k^(-1 + θ) p α (l^θ (1 - α) + k^θ α)^(-1 + ϕ/θ) γ ϕ /. sol[]


which in is turn gives

-ρ + k^(-1 + θ) p α γ ϕ (k^θ α + (1 - α) (((k^(1 - θ) (1 - α) ρ)/(α ω))^(1/(1 - θ)))^θ)^(-1 + ϕ/θ)


Then you certainly are deceived because you see immediately that there are some factorization Mathematica should have taken for you. In fact it's impossible because by default all parameters and variables are complex number and without any information Mathematica could not make what seems natural for you because you know the assumptions. You need to do

PowerExpand[Simplify[PowerExpand[%, k^θ], Assumptions -> {θ > 0}],k]


which gives

-ρ + k^(-1 + ϕ) p α γ ϕ (α + (1 - α)^(1/(1 - θ)) α^(θ/(-1 + θ)) ρ^(θ/(1 - θ)) ω^(θ/(-1 + θ)))^(-1 + ϕ/θ)


Yep ! You are near the climax of the microeconomist k is separated of all the parameters. You need a final step

soll= Solve[-ρ + k^(-1 + ϕ)p α γ ϕ (α + (1 - α)^(1/(1 - θ)) α^(θ/(-1 + θ)) ρ^(θ/(1 - θ)) ω^(θ/(-1 + θ)))^(-1 + ϕ/θ) == 0, k]

{{k -> ((ρ (α + (1 - α)^(1/(1 - θ)) α^(θ/(-1 + θ)) ρ^(θ/(1 - θ)) ω^(θ/(-1 + θ)))^(1 - ϕ/θ))/(p α γ ϕ))^(1/(-1 + ϕ))}}


and if you want only the solution you must ask

soll[[1, 1, 2]]


Personnaly, I hate that the answer let no room for my own experiments.I let you find l. If you enconter some difficulties, I would try to answer to your questions.

• Thanks so much for this detailed answer. I have been trying to learn Mathematica and spent some time working on my own approach to the problem before I employed the one based on the posts I linked to. But I had clearly missed the point about transcendental versus algebraic problems. Do you know of a guide to mathematica well suited to economists? Jan 8, 2017 at 19:11
• I am trying to write a detail guide, but it is not finished and in french. It is largely inspired of MSE. If you want I can post it, but I do not know when it will be finished Jan 9, 2017 at 4:08
• That's great to hear. If you were willing to post it that would be wonderful. Thanks again. Jan 9, 2017 at 8:57
• I need an adress to send it. You can find mine on internet since my name is transparent Jan 9, 2017 at 10:14