Finding Maxima and Minima of functions with more than 2 variables

When a function has one variable we know how to find the maxima and minima of the function by differentiating and equating to zero to find the points.

But when a function has more than two variables, we use partial differentiation to find the maxima and minima.

1. $f(x,y) = {x^3} + 3x{y^2} + 2xy$ subject to the condition x + y = 4
Sol: The local maximum and minimum of f(x,y) subject to the constraint g(x,y)=0 correspond to the stationary points of $L(x,y,\lambda ) = f(x,y) - \lambda .g(x,y)$
where $\lambda $ is Lagrange multiplier.
We have $L(x,y,\lambda ) = {x^3} + 3x{y^2} + 2xy - \lambda .(x + y - 4)$
Now $\displaystyle\frac{{\partial L}}{{\partial x}} = 3{x^2} + 3{y^2} + 2y - \lambda $
$\displaystyle\frac{{\lambda L}}{{\lambda y}} = 6xy + 2x - \lambda $
$\displaystyle\frac{{\partial L}}{{\partial y}} = 6xy + 2x - \lambda $
$\displaystyle\frac{{\partial L}}{{\partial \lambda }} =  - (x + y - 4)$

Note: in doing partial differentiation, except the independent variable everything is considered a constant.  For example, when we do differentiation w.r.t x then, except x all others should be considered constant.
Also $\displaystyle\frac{d}{{dx}}({x^n}) = n.{x^{n - 1}}$

Putting $\displaystyle\frac{{\partial L}}{{\partial x}} = \frac{{\partial L}}{{\partial y}} = \frac{{\partial L}}{{\partial \lambda }} = 0$
$3{x^2} + 3{y^2} + 2y = \lambda $ ------(1)
$6xy + 2x = \lambda $ -----(2)
x + y - 4 = 0 ------------(3)
From equations (1) and (2) we get $3{x^2} + 3{y^2} + 2y = 6xy + 2x$ --------(4)
Putting y = - x + 4 in equation (4)
we get $3{x^2} + 3{( - x + 4)^2} + 2( - x + 4) = 6x( - x + 4) + 2x$
$3{x^2} + 3({x^2} - 8x + 16) - 2x + 8 =  - 6{x^2} + 24x + 2x$
$12{x^2} - 52x + 56 = 0$
$ \Rightarrow 3{x^2} - 13x + 14 = 0$
$ \Rightarrow (3x - 7)(x - 2) = 0$
$ \Rightarrow x = 2,\displaystyle\frac{7}{3}$

For x = 2, from equation (3) we get y = 2 and F(x,y)) = 40
and for $x = \displaystyle\frac{7}{3}$, $y = \displaystyle\frac{5}{3}$ and F(x,y) = $39\displaystyle\frac{{25}}{{27}}$

Alternatively: By substituting y = x - 4 in the equation f(x, y) = ${x^3} + 3x{y^2} + 2xy$
we get, F(x, 4-x) = ${x^3} + 3x{(4 - x)^2} + 2x(4 - x)$
F(x) = ${x^3} + 3x(16 - 8x + {x^2}) + 2x(4 - x)$
F(x) = $4{x^3} - 26{x^2} + 56x$
Differentiation F with respect to x we get, ${F^1}(x) = 12{x^2} - 52x + 56$
Solving like above we get the values of $ \Rightarrow x = 2,\displaystyle\frac{7}{3}$

2. Find the point on the line 3x + 2y = 5 that is closest to the point (3,1)
Sol:  The distance between a general point (x,y) and the point (3, 1) is $\sqrt {{{(x - 3)}^2} + {{(y - 1)}^2}} $
We want to find the minimum value of this distance subject to the constraint 3x + 2y = 5.  Infact we have to minimize the square of the distance, and so we minimize f(x, y) = ${{{(x - 3)}^2} + {{(y - 1)}^2}}$
subject to the given constraint.
$L(x,y,\lambda ) = {\left( {x - 3} \right)^2} + {\left( {y - 1} \right)^2} - \lambda (3x + 2y - 5)$
$\frac{{\partial L}}{{\partial x}} = 2(x - 3) + 3\lambda $
$\frac{{\partial L}}{{\partial y}} = 2(y - 1) + 2\lambda $
$\frac{{\partial L}}{{\partial \lambda }} =  - 3x - 2y + 5$

Putting $\displaystyle\frac{{\partial L}}{{\partial x}} = \frac{{\partial L}}{{\partial y}} = \frac{{\partial L}}{{\partial \lambda }} = 0$
$2(x - 3) + 3\lambda  = 0$ -------(1)
$2(y - 1) + 2\lambda  = 0$ ------(2)
3x + 2y = 5 ------------(3)

Multiplying (1) by 2 and (2) by 3 will give
$4(x - 3) + 6\lambda  = 0$
$6(y - 1) + 6\lambda  = 0$
So 4(x-3) = 6(y-1) $ \Rightarrow $ 2x - 3y = 3 -------(4)
Multiplying equation (3) by 3 and (4) by 2, gives
9x + 6y = 15
4x - 6y = 6
Solving we get x = $\displaystyle\frac{{21}}{{13}}$ and y = $\frac{{1}}{{13}}$
Thus the point $\left( {\displaystyle\frac{{21}}{{13}},\frac{1}{{13}}} \right)$ is on the given line and closest to (3,1)