# Wolfram Cloud memory limit exceeded with complex Lagrange multipliers

I'm new to the forum and I have problems when I try to run this code. The computation exceeds the limit of my plan.

This is my code. What can I do?

clear[f,g]
f[k_,l_,m_,n_,o_]:=(k^0.05)(l^0.09)(m^0.08)(n^0.43)(o^0.35);
g[k_,l_,m_,n_,o_]:=116.7k+216.7l+183m+31n+833.3o-71500;
Solve[
D[f[k,l,m,n,o] - lambda g[k,l,m,n,o], {{k,l,m,n,o,lambda}}] == 0,
{k,l,m,n,o}, lambda]

• (1) The logarithm being monotonic, optimizing f is equivalent to optimizing log(f). So use PowerExpand[Log[f[k, l, m, n, o]]]. (2) This might all work better with exact numbers. But if you take that log it is not likely to matter. Oct 15, 2020 at 23:18
• clear should be Clear. This doesn't resolve the problem, though. Oct 16, 2020 at 6:55
• The lambda in Solve[... , ... , lambda] specifies a domain like Reals or Complex. I think this hardly what you want. Oct 16, 2020 at 13:25

Clear["Global*"]


Rationalize all of the constants

f[k_, l_, m_, n_, o_] = (k^0.05) (l^0.09) (m^0.08) (n^0.43) (o^0.35) //
Rationalize;
g[k_, l_, m_, n_, o_] =
116.7 k + 216.7 l + 183 m + 31 n + 833.3 o - 71500 // Rationalize;

D[f[k, l, m, n, o] -
lambda g[k, l, m, n, o], {{k, l, m, n, o, lambda}}] == 0] // Simplify;


Include lambda in the list of variables to be found and use the Solve option Method -> Reduce

(sol = Solve[eqns, {k, l, m, n, o, lambda}, Method -> Reduce] //
N) // AbsoluteTiming

(* {4.0572, {{k -> 30.6341, l -> 29.6954, m -> 31.2568, n -> 991.774,
o -> 30.0312, lambda -> 0.00189561}}} *)


Verifying the solution,

And @@ (eqns /. sol[[1]])

(* True *)


FindRoot works well on this problem:

Clear[f, g]
f[k_, l_, m_, n_, o_] := (k^0.05) (l^0.09) (m^0.08) (n^0.43) (o^0.35);
g[k_, l_, m_, n_, o_] := 116.7 k + 216.7 l + 183 m + 31 n + 833.3 o - 71500;
FindRoot[D[f[k, l, m, n, o] -
lambda g[k, l, m, n, o], {{k, l, m, n, o, lambda}}], {#, 1} & /@ {k, l, m, n, o,
lambda}] // AbsoluteTiming
(*
{0.0331255, {k -> 30.6341, l -> 29.6954, m -> 31.2568, n -> 991.774, o -> 30.0312,
lambda -> 0.00189561}}
*)
`