# Optimising function of two variables with Lagrange multipliers

I am trying to find formulae for the $x$ and $y$ that maximise the function $f(x,y)=a(x + p)^bc(y + q)^d$, subject to the constraints:

$$x \geq 0$$ $$y \geq 0$$ $$x + y + p + q \leq M$$

Where $a$, $b$, $c$, $d$, $p$, $q$ and $M$ are positive constants, $b < 1$ and $d < 1$. All the constants can be determined experimentally beforehand, except $M$, which is set by a 'user'. I want to work out general formulae for $x$ and $y$ so that I can easily find the best values given a combination of the constants.

Ignoring the constraints $x \geq 0$ and $y \geq 0$ for the moment, I have used the method of Lagrange multipliers to derive that, for the maximum, $x=(bM)/(b+d) - p$ and $y=(dM)/(b+d) - q$. However, these formulae sometimes give values of $x$ and $y$ that are zero or negative.

How can I take account of the other two constraints? When I try to add them to the Lagrange multiplier method, I can't seem to eliminate the extra Lagrange multiplier variables - and I'm not even sure I can use those constraints with Lagrange. What is the right way to do this?

-

$a,c$ are useless. Put $x+p=X,y+q=Y$. Then $f(X,Y)=X^bY^d$ and $X\geq p,Y\geq q,X+Y\leq M$. There is no free maximum because $X>0,Y>0$. Then the max (that exists because we are in a compact set) is reached on the edge.

Case 1. $X+Y=M$ and $f(X,Y)=g(X)=X^b(M-X)^d$. Then $g'$ is $0$ for $X_1=\dfrac{b}{b+d}M$; if $p\leq X_1\leq M-q$, then the first candidate is $C_1=(X_1,M-X_1)$, else we do not consider this possibility.

Case 2. $X=p$ and $f(X,Y)=g(Y)=p^bY^d$. The second candidate is $C_2=(p,M-p)$.

Case 3. In the same way , the third candidate is $C_3=(M-q,q)$.

It remains to compare $f(C_1),f(C_2),f(C_3)$.

-
I have corrected what was likely a small typo in the first sentence: I suspect you wanted $\ c \$ , rather than $\ b \$ there. – RecklessReckoner Jul 17 '14 at 17:53
Yes, you are right. Thanks. – loup blanc Jul 17 '14 at 19:40

You could use weighted A.M-G.M inequality, as all the quantities are non-negative.

[b(x+p) + d(y+q)]/(b+d) ≥ [(x+p)^b + (y+q)^d]^{1/(b+d)}

Raising both sides to power (b+d) and multiplying by ac, you get the maximum value, achieved when both sides are equal. This is possible only when

x+p = y+q (i.e. all terms in the A.M are equal)

Also, x+y+p+q ≤ M

So, for maximum value, x = M/2 - p and y = M/2 -q

(Sorry for the style of writing. Am new to this forum)

-
I don't understand - if I have, say, $a = 2$, $b = 0.5$, $c = 3$, $d = 0.3$, $p = 10$, $q = 20$, $M = 200$, then these formulae predict that $x$ should be 90 and $y$ should be 80, at which $f(x,y) = 238.86$. But by trial and error, I can get a higher value of $f$ by setting $x = 100$ and $y = 70$, at which $f(x,y) = 242.73$, so the formulae aren't giving the maximum values. Is this right? – cjc Nov 6 '13 at 10:34

The Lagrange-multiplier method doesn't always give much insight into an optimization problem. Here, regular old homely single-variable extremization is probably more helpful. I will largely be following what loup blanc has already posted, but I think a little more can be said.

It does make matters a bit clearer to use the variable $\ X \ = \ x \ + \ p \$ and $\ Y \ = \ y \ + \ q \$ . The function to be maximized becomes $\ f(X, \ Y) \ = \ ac \ X^b \ Y^d \$ , under the constraints $\ X \ \ge \ p \$ , $\ Y \ \ge \ q \$ , and $\ X + Y \ \le \ M \$ . In the graph above, the region to be considered is the white triangle, including its "edges".

Since all of the values $\ a \ , \ b \ , \ c \ , \ d \ , \ p \ , \ q \$ and $\ M \$ are positive, and presumably $\ M \ > \ p \ + \ q \$ (or we have no region to consider at all), then $\ f(X, \ Y) \$ is an increasing function over this region. This will "drive" the maximization "all the way up" to the line $\ X \ + \ Y \ = \ M \$ (the minimum of the function will lie at $\ (X , \ Y) \ = \ ( p, \ q) \$ or $\ (x, \ y) \ = \ (0, \ 0) \$ ).

With any possible solutions for the maximum falling on that line, we can "eliminate" one of the variables to simply work with, say, $\ Y \ = \ M \ - \ X \$ and the function $\ g(X) \ = \ ac \ X^b \ (M - X)^d \$ on the interval $\ p \ \le \ X \ \le \ M-q \$ . Extremization of the function produces

$$\ \frac{dg}{dX} \ = \ ac \ [ \ b X^{b-1} \ (M-X)^d \ + \ X^b \ d \ (M-X)^{d-1} \ (-1) \ ] \ = \ 0 \ \$$

$$\Rightarrow \ \ ac \ X^{b-1} \ (M-X)^{d-1} \ [ \ b \ (M-X) \ - \ dX \ ] \ = \ 0 \ \ ;$$

since $\ X \ = \ 0 \$ and $\ X \ = \ M \$ are excluded by the constraints, there is a single critical point given by $\ b \ (M-X) \ = \ dX \ \ \Rightarrow \ \ X_c \ = \ \frac{b}{b+d} M \$ , all quite as already described by loup blanc.

This leads us to $\ Y_c \ = \ M \ - \ \frac{b}{b+d} M \ = \ \frac{(b+d) \ - \ b}{b+d} M \ = \ \frac{d}{b+d} M \$ , marked by point 3 on the graph above; in a sense, the location of the critical point is a "weighted average" of the two exponents in $\ f(x, \ y) \$ . The value of our function there is

$$f(X_c, \ Y_c ) \ = \ f(x_c, \ y_c ) \ = \ ac \ \left( \frac{b}{b+d} M \right)^b \ \left( \frac{d}{b+d} M \right)^d \ = \ ac \ b^b \ d^d \ \left( \frac{M}{b+d} \right)^{b+d} \ \ .$$

[In terms of the original variables, this critical point lies at

$$\ x_c \ = \ \frac{b}{b+d} M \ - \ p \ , \ y_c \ = \ \frac{d}{b+d} M \ - \ q \ \ . ]$$

We should, of course, also consider the values of the function at the endpoints of the relevant interval:

point 1 -- $\ f(X=M-q, \ Y=q) \ = \ ac \ (M-q)^b \ q^d \$ ,

point 2 -- $\ f(X=p, \ Y=M-p) \ = \ ac \ p^b \ (M-p)^d \$ .

However, unless $\ M \$ is only slightly larger than $\ p + q \$ , the maximum value of the function will clearly be attained at $\ (x_c, \ y_c) \$ .

$$\ \$$

If we use the values of the constants set in your comment on Marty's answer ( $\ a = 2 \ , \ c = 3 \ ,$ $b = 0.5 \ , \ d = 0.3 \ , \ p = 10 \ , \ q = 20 \ , \$ and $\ M = 200 \$ ) , we can compute the values of the function as

point 1 -- $\ f(X = 180, \ Y = 20) \ = \ 2 \cdot 3 \cdot 180^{0.5} \cdot 20^{0.3} \ \approx \ 197.7 \ ,$

point 2 -- $\ f(X = 10, \ Y = 190) \ = \ 2 \cdot 3 \cdot 10^{0.5} \cdot 190^{0.3} \ \approx \ 91.6 \ ,$

point 3 -- $\ f(X_c = \frac{0.5}{0.5 + 0.3} \cdot 200 = 125, \ Y_c = 75)$

$$= \ f(x_c = 125 - 10 = 115 \ , \ y_c = 75 - 20 = 55) \ = \ 2 \cdot 3 \cdot 125^{0.5} \cdot 75^{0.3}$$ $$= \ 2 \cdot 3 \cdot 0.5^{0.5} \cdot 0.3^{0.3} \ \left( \frac{200}{0.8} \right)^{0.8} \ \approx \ 245.0 \ .$$

The graph below shows the values of the function along the line $\ X + Y \ = \ 200 \$ :

the regions shaded in green are excluded by the constraints

-