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)$.
