# How do you maximize and minimize f(x,y)=x-siny constrained to 0<=x+y<=1?

May 27, 2017

Write a Lagrange function with 2 multipliers and 2 slack variables.
Compute the partial derivatives.
Solve the system of equations.

#### Explanation:

For the constraint, $0 \le x + y \le 1$, written separately:

$x + y \ge 0$ and $1 - x - y \ge 0$

We add two slack variables into two constraint functions:

${g}_{1} \left(x , y , s\right) = x + y - {s}^{2} = 0$

${g}_{2} \left(x , y , t\right) = 1 - x - y - {t}^{2} = 0$

Note: squaring the slack variables assures that the constraint is enforced by disallowing negative values.

We can write the Lagrange function:

$\setminus m a t h c a l L \left(x , y , s , t , u , v\right) = f \left(x , y\right) + u {g}_{1} \left(x , y , s\right) + v {g}_{2} \left(x , y , t\right)$

$\setminus m a t h c a l L \left(x , y , s , t , u , v\right) = x - \sin \left(y\right) + u \left(x + y - {s}^{2}\right) + v \left(1 - x - y - {t}^{2}\right)$

$\setminus m a t h c a l L \left(x , y , s , t , u , v\right) = x - \sin \left(y\right) + u x + u y - u {s}^{2} + v - v x - v y - v {t}^{2}$

Compute the partial derivatives:

$\frac{\partial \left(\setminus m a t h c a l L \left(x , y , s , t , u , v\right)\right)}{\partial x} = 1 + u - v$

$\frac{\partial \left(\setminus m a t h c a l L \left(x , y , s , t , u , v\right)\right)}{\partial y} = - \cos \left(y\right) + u - v$

$\frac{\partial \left(\setminus m a t h c a l L \left(x , y , s , t , u , v\right)\right)}{\partial s} = - 2 u s$

$\frac{\partial \left(\setminus m a t h c a l L \left(x , y , s , t , u , v\right)\right)}{\partial t} = - 2 v t$

$\frac{\partial \left(\setminus m a t h c a l L \left(x , y , s , t , u , v\right)\right)}{\partial u} = x + y - {s}^{2}$

$\frac{\partial \left(\setminus m a t h c a l L \left(x , y , s , t , u , v\right)\right)}{\partial v} = 1 - x - y - {t}^{2}$

Set the partial derivatives equal to 0 and the solve as a system of nonlinear equations:

$0 = 1 + u - v \text{ [1]}$

$0 = - \cos \left(y\right) + u - v \text{ [2]}$

$0 = - 2 u s \text{ [3]}$

$0 = - 2 v t \text{ [4]}$

$0 = x + y - {s}^{2} \text{ [5]}$

$0 = 1 - x - y - {t}^{2} \text{ [6]}$

Please observe that the extrema are located at the points are where equations [3] and [4] are satisfied by $s = t = 0$; this makes the remaining equations become:

$0 = 1 + u - v \text{ [1]}$

$0 = - \cos \left(y\right) + u - v \text{ [2]}$

$0 = x + y \text{ [5.1]}$

$0 = 1 - x - y \text{ [6.1]}$

Because u and v are not forced to be zero, we can subtract equation [2] from equation [1]

$0 = 1 + \cos \left(y\right)$

$\cos \left(y\right) = - 1$

$y = {\cos}^{-} 1 \left(- 1\right)$

$y = \pi$

Using equation [5.1] , we obtain the value for x:

$x = - \pi$

This gives the function's minimum:

$f \left(- \pi , \pi\right) = - \pi$

For the maximum, we have the condition where $u = s = t = 0$

$\cos \left(y\right) = 1$

$y = 0$

Equation [6.2] gives us the value for x:

$x = 1$

$f \left(1 , 0\right) = 1$