Mathematics for Information Science 1. Module 4, lagrange multipliers to linear programming.

GAMAT101 · 14 pages · Your place is saved in this browser

Contents · Where each topic sits
Text size18

Page 1 of 14

Module 4 at a glance

In Modules 2 and 3 we used derivatives to study functions. In Module 4 we use them, along with a little geometry, to find the best choice: the largest profit, the smallest cost, the shortest distance.

  1. Lagrange multipliers. Find the maximum or minimum of f(x,y)f(x,y) when xx and yy are connected by a condition such as x2+y2=1x^2+y^2=1. There can be one condition (constraint) or two.
  2. Linear programming. Optimise a linear objective like z=3x1+5x2z=3x_1+5x_2 when the variables must satisfy some linear inequalities. Write word problems in mathematical form, and then solve them by the graphical method.
  3. Gradient descent (steepest descent). A step-by-step numerical method that moves downhill to a minimum, using the gradient from Module 3.

What you will be able to do

  • Set up the Lagrange function L=f+λgL=f+\lambda g and solve the system ∇L=0\nabla L=0.
  • Find the point on a plane that is closest to the origin, the largest area for a fixed perimeter, and similar problems.
  • Solve problems with two constraints using two multipliers λ\lambda and μ\mu.
  • Convert a word problem into a linear programming problem (LPP).
  • Draw the feasible region of a two-variable LPP, find its corner points and choose the optimal one.
  • Identify infeasible, unbounded and multiple-optimum problems.
  • Do gradient descent iterations by hand.

How to use these notes

  • Every topic has the same shape: idea → method → worked examples → common mistakes.
  • Try each worked example yourself before reading the solution.
  • Green boxes hold key ideas. Amber boxes marked Watch out show the mistakes that make you lose marks. Boxes marked Note on the source show where the handwritten class notes were corrected.
  • The last page has practice questions with answers and a formula sheet.

Where each topic sits

PartTopics
Lagrange multipliersOne constraint, applications in three variables, two constraints
Linear programmingTerms and general form, formulation, graphical method, special cases
Numerical optimisationGradient descent

Before you start. You should know partial derivatives and the gradient (Modules 2 and 3), how to solve simultaneous linear equations, and how to draw straight lines using their intercepts.

Page 2 of 14

Lagrange multipliers

The idea

In Module 3 we found extreme values of f(x,y)f(x,y) where xx and yy could take any values. Many times they are not free: a fence of fixed length, a point that must stay on a circle, a budget that must be spent fully. Such a condition is called a constraint, and it is written as

g(x,y)=0g(x,y)=0

We want the largest or smallest value of ff among the points that satisfy the constraint.

Key idea. At a constrained maximum or minimum, the level curve of ff just touches the constraint curve g=0g=0. Curves that touch have parallel normals, so ∇f\nabla f and ∇g\nabla g are parallel: ∇f=−λ∇g\nabla f=-\lambda\nabla g for some number λ\lambda. This is the Lagrange multiplier.

Method

  1. Write the function f(x,y)f(x,y), and write the constraint in the form g(x,y)=0g(x,y)=0.
  2. Build the Lagrange function
L(x,y,λ)=f(x,y)+λ g(x,y)L(x,y,\lambda)=f(x,y)+\lambda\,g(x,y)
  1. Put all its partial derivatives equal to zero:
∂L∂x=0,∂L∂y=0,∂L∂λ=0\frac{\partial L}{\partial x}=0,\qquad\frac{\partial L}{\partial y}=0,\qquad\frac{\partial L}{\partial\lambda}=0

That is,

{fx+λgx=0fy+λgy=0g(x,y)=0\begin{cases} f_x+\lambda g_x=0\\ f_y+\lambda g_y=0\\ g(x,y)=0 \end{cases}

The third equation is just the constraint itself.

  1. Solve for xx, yy (and λ\lambda). The solutions are the critical points.
  2. Find ff at every critical point. On a closed, bounded constraint curve (a circle, an ellipse) the largest value is the maximum and the smallest value is the minimum.

Solving tip. The usual trick: find λ\lambda from the first two equations, put the two expressions equal (this removes λ\lambda), and put the resulting relation between xx and yy in the constraint.

First example

Example 1. Find the extreme value of f(x,y)=x2+y2f(x,y)=x^2+y^2 subject to x+y=1x+y=1.

Here g(x,y)=x+y−1=0g(x,y)=x+y-1=0 and

L(x,y,λ)=x2+y2+λ(x+y−1)L(x,y,\lambda)=x^2+y^2+\lambda(x+y-1) ∂L∂x=2x+λ=0  (1)∂L∂y=2y+λ=0  (2)∂L∂λ=x+y−1=0  (3)\frac{\partial L}{\partial x}=2x+\lambda=0\ \ (1)\qquad \frac{\partial L}{\partial y}=2y+\lambda=0\ \ (2)\qquad \frac{\partial L}{\partial\lambda}=x+y-1=0\ \ (3)

From (1) and (2), λ=−2x=−2y\lambda=-2x=-2y, so x=yx=y. Putting this in (3): 2x=12x=1, so

x=y=12,f ⁣(12,12)=14+14=12x=y=\tfrac12,\qquad f\!\left(\tfrac12,\tfrac12\right)=\tfrac14+\tfrac14=\mathbf{\tfrac12}

This is the minimum. x2+y2x^2+y^2 is the square of the distance from the origin, and (12,12)\left(\tfrac12,\tfrac12\right) is the point on the line x+y=1x+y=1 that is nearest to the origin.

Note on the source. The class notes asked to "maximise" x2+y2x^2+y^2 on x+y=1x+y=1. There is no maximum, because points on the line far from the origin make x2+y2x^2+y^2 as large as we like. The only critical point (12,12)\left(\tfrac12,\tfrac12\right) gives the minimum value 12\tfrac12.

Watch out. The Lagrange method gives only possible points. Decide whether each point is a maximum or a minimum by comparing the values. Remember that on an unbounded constraint (a line, a plane), one of the two may not exist.

Page 3 of 14

Lagrange multipliers: worked examples

Example 1. Find the maximum and minimum of f(x,y)=xyf(x,y)=xy subject to x2+y2=1x^2+y^2=1.

L=xy+λ(x2+y2−1)L=xy+\lambda(x^2+y^2-1) Lx=y+2λx=0  (1)Ly=x+2λy=0  (2)Lλ=x2+y2−1=0  (3)L_x=y+2\lambda x=0\ \ (1)\qquad L_y=x+2\lambda y=0\ \ (2)\qquad L_\lambda=x^2+y^2-1=0\ \ (3)

From (1), λ=−y2x\lambda=-\dfrac{y}{2x}; from (2), λ=−x2y\lambda=-\dfrac{x}{2y}. Equating them, y2=x2y^2=x^2. Then (3) gives 2x2=12x^2=1, so x=±12x=\pm\dfrac1{\sqrt2}, y=±12y=\pm\dfrac1{\sqrt2}: four critical points.

Pointf=xyf=xy
(12,12)\left(\frac1{\sqrt2},\frac1{\sqrt2}\right), (−12,−12)\left(-\frac1{\sqrt2},-\frac1{\sqrt2}\right)12\tfrac12
(12,−12)\left(\frac1{\sqrt2},-\frac1{\sqrt2}\right), (−12,12)\left(-\frac1{\sqrt2},\frac1{\sqrt2}\right)−12-\tfrac12

Maximum 12\tfrac12 at the first pair, minimum −12-\tfrac12 at the second pair.

Example 2. Maximise f(x,y)=xyf(x,y)=xy subject to x2+4y2=4x^2+4y^2=4.

L=xy+λ(x2+4y2−4)L=xy+\lambda(x^2+4y^2-4) Lx=y+2λx=0  (1)Ly=x+8λy=0  (2)Lλ=x2+4y2−4=0  (3)L_x=y+2\lambda x=0\ \ (1)\qquad L_y=x+8\lambda y=0\ \ (2)\qquad L_\lambda=x^2+4y^2-4=0\ \ (3)

From (1), λ=−y2x\lambda=-\dfrac{y}{2x}; from (2), λ=−x8y\lambda=-\dfrac{x}{8y}. Equating and cross-multiplying:

8y2=2x2 ⇒ x2=4y2 ⇒ x=±2y8y^2=2x^2\ \Rightarrow\ x^2=4y^2\ \Rightarrow\ x=\pm2y

Put x2=4y2x^2=4y^2 in (3): 4y2+4y2=44y^2+4y^2=4, so y2=12y^2=\tfrac12 and y=±12y=\pm\dfrac1{\sqrt2}, x=±2x=\pm\sqrt2.

Pointf=xyf=xy
(2,12)\left(\sqrt2,\frac1{\sqrt2}\right), (−2,−12)\left(-\sqrt2,-\frac1{\sqrt2}\right)11
(2,−12)\left(\sqrt2,-\frac1{\sqrt2}\right), (−2,12)\left(-\sqrt2,\frac1{\sqrt2}\right)−1-1

The maximum is 11 at (2,12)\left(\sqrt2,\tfrac1{\sqrt2}\right) and (−2,−12)\left(-\sqrt2,-\tfrac1{\sqrt2}\right).

Note on the source. The class notes went from 8y2=2x28y^2=2x^2 to "y=x/4y=x/4", where the square root was taken wrongly (it should be x=±2yx=\pm2y). Then they found xyxy at (45,15)\left(\frac4{\sqrt5},\frac1{\sqrt5}\right) by adding the coordinates and got 5\sqrt5. That point does lie on the ellipse, but xyxy there is only 45\frac45. The correct maximum is 11.

Example 3. Find the extreme values of f(x,y)=xyf(x,y)=xy subject to x2+y2=10x^2+y^2=10.

Exactly as in Example 1: Lx=y+2λx=0L_x=y+2\lambda x=0 and Ly=x+2λy=0L_y=x+2\lambda y=0 give x2=y2x^2=y^2, and the constraint gives 2x2=102x^2=10, so x=±5x=\pm\sqrt5, y=±5y=\pm\sqrt5.

Pointf=xyf=xy
(5,5)(\sqrt5,\sqrt5), (−5,−5)(-\sqrt5,-\sqrt5)55
(5,−5)(\sqrt5,-\sqrt5), (−5,5)(-\sqrt5,\sqrt5)−5-5

Maximum 55, minimum −5-5.

Note on the source. One line of the handwritten table wrote f(−5,5)=5f(-\sqrt5,\sqrt5)=5. It should be −5-5. The final conclusion in the notes was correct.

Example 4. Find the maximum and minimum of f(x,y)=3x+4yf(x,y)=3x+4y on the circle x2+y2=1x^2+y^2=1.

L=3x+4y+λ(x2+y2−1)L=3x+4y+\lambda(x^2+y^2-1) Lx=3+2λx=0 ⇒ x=−32λLy=4+2λy=0 ⇒ y=−42λL_x=3+2\lambda x=0\ \Rightarrow\ x=-\frac{3}{2\lambda}\qquad L_y=4+2\lambda y=0\ \Rightarrow\ y=-\frac{4}{2\lambda}

Put this in the constraint:

94λ2+164λ2=1 ⇒ 254λ2=1 ⇒ λ=±52\frac{9}{4\lambda^2}+\frac{16}{4\lambda^2}=1\ \Rightarrow\ \frac{25}{4\lambda^2}=1\ \Rightarrow\ \lambda=\pm\frac52
  • λ=−52\lambda=-\tfrac52: x=35x=\tfrac35, y=45y=\tfrac45, and f=95+165=5f=\tfrac95+\tfrac{16}5=\mathbf{5} (maximum).
  • λ=52\lambda=\tfrac52: x=−35x=-\tfrac35, y=−45y=-\tfrac45, and f=−95−165=−5f=-\tfrac95-\tfrac{16}5=\mathbf{-5} (minimum).

Note on the source. In the copied notes, the page was blank after the value −5-5. The maximum 55 at (35,45)\left(\tfrac35,\tfrac45\right) is completed here.

Watch out. When you divide by xx or yy to get λ\lambda, you are assuming that they are not zero. Check separately whether x=0x=0 or y=0y=0 can satisfy the equations. (In these examples it cannot, because then the other variable would also be 00, and that point is not on the curve.)

Page 4 of 14

Lagrange multipliers: applications

The method works in the same way with three variables: L=f(x,y,z)+λg(x,y,z)L=f(x,y,z)+\lambda g(x,y,z) and four equations Lx=Ly=Lz=Lλ=0L_x=L_y=L_z=L_\lambda=0.

Example 1. Closest point on a plane. Find the point P(x,y,z)P(x,y,z) on the plane 2x+y−z−5=02x+y-z-5=0 that is closest to the origin.

The distance is d=x2+y2+z2d=\sqrt{x^2+y^2+z^2}. Minimising dd is the same as minimising d2d^2, which has no square root, so take

f(x,y,z)=x2+y2+z2,g(x,y,z)=2x+y−z−5=0f(x,y,z)=x^2+y^2+z^2,\qquad g(x,y,z)=2x+y-z-5=0 L=x2+y2+z2+λ(2x+y−z−5)L=x^2+y^2+z^2+\lambda(2x+y-z-5) Lx=2x+2λ=0⇒x=−λLy=2y+λ=0⇒y=−λ2Lz=2z−λ=0⇒z=λ2L_x=2x+2\lambda=0\Rightarrow x=-\lambda\qquad L_y=2y+\lambda=0\Rightarrow y=-\frac\lambda2\qquad L_z=2z-\lambda=0\Rightarrow z=\frac\lambda2

Put these in the plane equation:

2(−λ)−λ2−λ2−5=0 ⇒ −3λ=5 ⇒ λ=−532(-\lambda)-\frac\lambda2-\frac\lambda2-5=0\ \Rightarrow\ -3\lambda=5\ \Rightarrow\ \lambda=-\frac53

so

P=(53, 56, −56),d=259+2536+2536=256=56≈2.04P=\left(\frac53,\ \frac56,\ -\frac56\right),\qquad d=\sqrt{\frac{25}9+\frac{25}{36}+\frac{25}{36}}=\sqrt{\frac{25}{6}}=\frac{5}{\sqrt6}\approx2.04

Check. The distance from the origin to ax+by+cz=kax+by+cz=k is ∣k∣a2+b2+c2=56\dfrac{|k|}{\sqrt{a^2+b^2+c^2}}=\dfrac{5}{\sqrt6}. ✓\checkmark

Note on the source. The notes wrote "x=−λ/2x=-\lambda/2" from 2x+2λ=02x+2\lambda=0, but it should be x=−λx=-\lambda. The next lines actually used x=−λx=-\lambda, so the final point (53,56,−56)\left(\tfrac53,\tfrac56,-\tfrac56\right) is correct.

Example 2. Find the minimum of f(x,y,z)=x2+y2+z2f(x,y,z)=x^2+y^2+z^2 subject to x+y+z=9x+y+z=9.

L=x2+y2+z2+λ(x+y+z−9)L=x^2+y^2+z^2+\lambda(x+y+z-9)

Lx=2x+λ=0L_x=2x+\lambda=0, Ly=2y+λ=0L_y=2y+\lambda=0, Lz=2z+λ=0L_z=2z+\lambda=0 give x=y=z=−λ2x=y=z=-\dfrac\lambda2. The constraint gives 3x=93x=9, so x=y=z=3x=y=z=3 and λ=−6\lambda=-6:

f(3,3,3)=9+9+9=27f(3,3,3)=9+9+9=\mathbf{27}

Note on the source. The question of this example was missing in the copied notes. Only the working "λ=−6\lambda=-6, x=y=z=3x=y=z=3, f=27f=27" was available. The constraint x+y+z=9x+y+z=9 gives exactly that working.

Example 3. Largest rectangle. A rectangle has perimeter 20 m20\ \text{m}. Find the dimensions that maximise its area.

Let the length be xx and the breadth be yy. Maximise f=xyf=xy subject to 2(x+y)=202(x+y)=20, that is g=x+y−10=0g=x+y-10=0.

L=xy+λ(x+y−10)L=xy+\lambda(x+y-10) Lx=y+λ=0,Ly=x+λ=0 ⇒ x=y=−λL_x=y+\lambda=0,\qquad L_y=x+\lambda=0\ \Rightarrow\ x=y=-\lambda

The constraint gives −2λ=10-2\lambda=10, so λ=−5\lambda=-5 and

x=y=5 m,area=25 m2x=y=5\ \text{m},\qquad\text{area}=25\ \text{m}^2

The best rectangle is a square.

Note on the source. One line of the notes read "x−x−10=0x-x-10=0". It should be x+x−10=0x+x-10=0 (the next line, −λ−λ−10=0-\lambda-\lambda-10=0, is correct).

Watch out. When the quantity to optimise is a distance, minimise d2d^2 instead of dd. The square root only makes the derivatives difficult and does not change the place where the minimum comes.

Page 5 of 14

Lagrange multipliers with two constraints

Method

To optimise f(x,y,z)f(x,y,z) subject to two constraints g(x,y,z)=0g(x,y,z)=0 and h(x,y,z)=0h(x,y,z)=0, use one multiplier for each:

L(x,y,z,λ,μ)=f+λg+μhL(x,y,z,\lambda,\mu)=f+\lambda g+\mu h

and solve the five equations

Lx=0,Ly=0,Lz=0,Lλ=0,Lμ=0L_x=0,\quad L_y=0,\quad L_z=0,\quad L_\lambda=0,\quad L_\mu=0

The last two are the constraints themselves.

Key idea. Each constraint takes away one degree of freedom. In three variables with two constraints, the allowed points form a curve (usually a line, where two planes meet), and we optimise ff along it.

Examples

Example 1. Find the extreme value of f(x,y)=x2+y2f(x,y)=x^2+y^2 subject to x+y=1x+y=1 and x−y=1x-y=1.

L=x2+y2+λ(x+y−1)+μ(x−y−1)L=x^2+y^2+\lambda(x+y-1)+\mu(x-y-1) Lx=2x+λ+μ=0  (1)Ly=2y+λ−μ=0  (2)L_x=2x+\lambda+\mu=0\ \ (1)\qquad L_y=2y+\lambda-\mu=0\ \ (2) Lλ=x+y−1=0  (3)Lμ=x−y−1=0  (4)L_\lambda=x+y-1=0\ \ (3)\qquad L_\mu=x-y-1=0\ \ (4)

Adding (3) and (4): 2x=22x=2, so x=1x=1, and then y=0y=0. From (1) and (2): 2+λ+μ=02+\lambda+\mu=0 and λ−μ=0\lambda-\mu=0, so λ=μ=−1\lambda=\mu=-1.

f(1,0)=1f(1,0)=\mathbf{1}

Two lines in the plane meet at a single point, so (1,0)(1,0) is the only point that satisfies both constraints, and 11 is the only value ff can take.

Example 2. Find the extreme value of f(x,y,z)=x2+y2+z2f(x,y,z)=x^2+y^2+z^2 subject to x+y+z=3x+y+z=3 and x−y+z=1x-y+z=1.

L=x2+y2+z2+λ(x+y+z−3)+μ(x−y+z−1)L=x^2+y^2+z^2+\lambda(x+y+z-3)+\mu(x-y+z-1) Lx=2x+λ+μ=0  (1)Ly=2y+λ−μ=0  (2)Lz=2z+λ+μ=0  (3)L_x=2x+\lambda+\mu=0\ \ (1)\qquad L_y=2y+\lambda-\mu=0\ \ (2)\qquad L_z=2z+\lambda+\mu=0\ \ (3) Lλ=x+y+z−3=0  (4)Lμ=x−y+z−1=0  (5)L_\lambda=x+y+z-3=0\ \ (4)\qquad L_\mu=x-y+z-1=0\ \ (5)
  • (4) −- (5): 2y−2=02y-2=0, so y=1y=1.
  • (1) and (3) give 2x=−(λ+μ)=2z2x=-(\lambda+\mu)=2z, so x=zx=z.
  • (4) then gives 2x+1=32x+1=3, so x=z=1x=z=1.

The critical point is (1,1,1)(1,1,1) with

f(1,1,1)=3f(1,1,1)=\mathbf{3}

This is the minimum: the two planes meet in a line, and (1,1,1)(1,1,1) is the point on that line nearest to the origin. There is no maximum, because the line goes to infinity.

Example 3. Find the extremum of f(x,y,z)=x2+y2+z2f(x,y,z)=x^2+y^2+z^2 subject to x+y+z=1x+y+z=1 and x−y=0x-y=0.

L=x2+y2+z2+λ(x+y+z−1)+μ(x−y)L=x^2+y^2+z^2+\lambda(x+y+z-1)+\mu(x-y) Lx=2x+λ+μ=0  (1)Ly=2y+λ−μ=0  (2)Lz=2z+λ=0  (3)L_x=2x+\lambda+\mu=0\ \ (1)\qquad L_y=2y+\lambda-\mu=0\ \ (2)\qquad L_z=2z+\lambda=0\ \ (3) Lλ=x+y+z−1=0  (4)Lμ=x−y=0  (5)L_\lambda=x+y+z-1=0\ \ (4)\qquad L_\mu=x-y=0\ \ (5)
  • (5): x=yx=y.
  • (1) −- (2): 2(x−y)+2μ=02(x-y)+2\mu=0, so μ=0\mu=0.
  • Then (1) and (3) give 2x=−λ=2z2x=-\lambda=2z, so x=zx=z.
  • (4): 3x=13x=1, so x=y=z=13x=y=z=\tfrac13.
f ⁣(13,13,13)=3⋅19=13(minimum)f\!\left(\tfrac13,\tfrac13,\tfrac13\right)=3\cdot\tfrac19=\mathbf{\tfrac13}\quad\text{(minimum)}

Note on the source. The copied page with Examples 2 and 3 was not clear. The working above is rebuilt from the equations that were readable, and both answers have been checked again: (1,1,1)(1,1,1) with value 33, and (13,13,13)\left(\tfrac13,\tfrac13,\tfrac13\right) with value 13\tfrac13.

Watch out. Number your equations and write which ones you are combining. With five equations it is easy to miss one, and a missing equation usually gives a wrong point.

Page 6 of 14

Linear programming: the terms

The idea

A linear programming problem (LPP) asks for the best value of a linear function when the variables must obey several linear inequalities. It models production planning, diets, staffing, transport and many other decisions.

The parts of an LPP

TermMeaningExample
Decision variablesthe unknown quantities that we choose; they are usually required to be ≥0\ge0x1x_1 = units of product 1, x2x_2 = units of product 2
Objective functionthe linear function to maximise or minimiseprofit z=3x1+5x2z=3x_1+5x_2
Constraintslinear equations or inequalities that the variables must satisfyresources: x1+2x2≤4x_1+2x_2\le4
Non-negativitythe variables cannot be negativex1≥0, x2≥0x_1\ge0,\ x_2\ge0

Constraints come in three types:

a1x1+a2x2≤b,a1x1+a2x2≥b,a1x1+a2x2=ba_1x_1+a_2x_2\le b,\qquad a_1x_1+a_2x_2\ge b,\qquad a_1x_1+a_2x_2=b

General form

Maximise (or minimise)z=c1x1+c2x2+⋯+cnxn\text{Maximise (or minimise)}\quad z=c_1x_1+c_2x_2+\dots+c_nx_n

subject to

a11x1+a12x2+⋯+a1nxn≤b1a21x1+a22x2+⋯+a2nxn≤b2  ⋮am1x1+am2x2+⋯+amnxn≤bmx1, x2, …, xn≥0\begin{aligned} a_{11}x_1+a_{12}x_2+\dots+a_{1n}x_n&\le b_1\\ a_{21}x_1+a_{22}x_2+\dots+a_{2n}x_n&\le b_2\\ &\ \,\vdots\\ a_{m1}x_1+a_{m2}x_2+\dots+a_{mn}x_n&\le b_m\\ x_1,\ x_2,\ \dots,\ x_n&\ge0 \end{aligned}

Kinds of solution

  • Feasible solution: any values of the variables that satisfy all the constraints, including non-negativity. The set of all feasible solutions is the feasible region.
  • Basic feasible solution: with nn variables and mm equality constraints, put n−mn-m of the variables equal to 00 and solve for the rest. If the result is feasible, it is a basic feasible solution. In the graph, these are the corner points of the feasible region.
  • Optimal solution: a feasible solution that gives the largest value (for maximise) or the smallest value (for minimise) of the objective.

Each inequality is a half-plane

A single linear inequality in two variables is satisfied on one side of its boundary line. To find which side, test a point not on the line, usually the origin: if (0,0)(0,0) satisfies the inequality, shade the side containing the origin; otherwise shade the other side. The feasible region is where all the shaded sides overlap.

A linear inequality defines a half-plane; the feasible region is the overlap of the half-planes

Watch out. "≤\le" does not always mean "shade below". For x1−3x2≥−6x_1-3x_2\ge-6, the origin gives 0≥−60\ge-6, which is true, so the side of the origin is shaded even though the line slopes upward. Always test a point.

Page 7 of 14

Formulating an LPP from a word problem

Method

  1. Name the decision variables: which quantities can we choose? Write what each one means.
  2. Write the objective function: the profit, cost or number to be maximised or minimised, in terms of the variables.
  3. Write one constraint for each limited resource or requirement. "Available" or "at most" gives ≤\le. "At least" or "required" gives ≥\ge.
  4. Add non-negativity: x1,x2,⋯≥0x_1,x_2,\dots\ge0.

Examples

Example 1. Manufacturing. A factory makes products P1P_1 and P2P_2, with profit Rs 3 and Rs 5 per unit. P1P_1 needs 1 unit of resource 1 and 2 units of resource 2; P2P_2 needs 2 units of resource 1 and 1 unit of resource 2. Only 4 units of resource 1 and 6 units of resource 2 are available. Write the LPP to maximise the profit.

Let x1x_1, x2x_2 be the numbers of units of P1P_1 and P2P_2 produced.

Maximisez=3x1+5x2\text{Maximise}\quad z=3x_1+5x_2

subject to

x1+2x2≤4(resource 1)2x1+x2≤6(resource 2)x1, x2≥0\begin{aligned} x_1+2x_2&\le4\qquad\text{(resource 1)}\\ 2x_1+x_2&\le6\qquad\text{(resource 2)}\\ x_1,\ x_2&\ge0 \end{aligned}

(It is solved on the practice page: the best profit is 343\tfrac{34}{3} at x1=83x_1=\tfrac83, x2=23x_2=\tfrac23.)

Example 2. Diet problem. A hospital diet must provide at least 2000 calories, 50 g of protein and 300 g of carbohydrate per day, at minimum cost. Food 1 costs Rs 3 per unit and gives 500 cal, 20 g protein and 30 g carbohydrate. Food 2 costs Rs 4 per unit and gives 600 cal, 30 g protein and 40 g carbohydrate. Write the LPP.

Let x1x_1, x2x_2 be the units of food 1 and food 2 per day.

Minimisez=3x1+4x2\text{Minimise}\quad z=3x_1+4x_2

subject to

500x1+600x2≥2000(calories)20x1+30x2≥50(protein)30x1+40x2≥300(carbohydrate)x1, x2≥0\begin{aligned} 500x_1+600x_2&\ge2000\qquad\text{(calories)}\\ 20x_1+30x_2&\ge50\qquad\text{(protein)}\\ 30x_1+40x_2&\ge300\qquad\text{(carbohydrate)}\\ x_1,\ x_2&\ge0 \end{aligned}

(It is solved graphically on the "word problems" page.)

Example 3. Staff scheduling. A company needs at least 5 employees from 8 am to 12 noon, 3 from 12 noon to 4 pm, and 4 from 4 pm to 8 pm. Each employee works an 8-hour shift starting at 8 am, 12 noon or 4 pm. Minimise the number of employees.

Let x1x_1, x2x_2, x3x_3 be the numbers starting at 8 am, 12 noon and 4 pm. A person starting at 8 am works from 8 am to 4 pm, so covers the first two periods. A person starting at noon covers the second and third periods. A person starting at 4 pm covers the third period.

Minimisez=x1+x2+x3\text{Minimise}\quad z=x_1+x_2+x_3

subject to

x1≥5(8 am to 12 noon)x1+x2≥3(12 noon to 4 pm)x2+x3≥4(4 pm to 8 pm)x1, x2, x3≥0\begin{aligned} x_1&\ge5\qquad\text{(8 am to 12 noon)}\\ x_1+x_2&\ge3\qquad\text{(12 noon to 4 pm)}\\ x_2+x_3&\ge4\qquad\text{(4 pm to 8 pm)}\\ x_1,\ x_2,\ x_3&\ge0 \end{aligned}

The minimum is 99 employees, for example x1=5x_1=5, x2=0x_2=0, x3=4x_3=4: the first constraint forces x1≥5x_1\ge5 and the third forces x2+x3≥4x_2+x_3\ge4.

Note on the source. The handwritten question said employees "can't start" at 8 am, 12 noon or 4 pm, and named x1,x2,x3x_1,x_2,x_3 by the four-hour periods. The constraints in the notes make sense only if shifts start at those times, so we have used that meaning here.

Watch out. Write what each variable means, with units. Most mistakes in writing the LPP come from a variable whose meaning changes in the middle of the working.

Page 8 of 14

The graphical method

The idea

With two decision variables, we can draw the feasible region. For a linear objective, the lines z=constantz=\text{constant} are parallel. If we move them in the direction in which zz increases, the last point of the region that they touch is a corner.

The objective lines z = constant slide across the feasible region; the optimum is at a corner

Key idea (corner-point theorem). If an LPP has an optimal solution, then one occurs at a corner point (vertex) of the feasible region. So we only need to find zz at the corners.

Method

  1. Change each inequality to an equation and draw the line, using its two intercepts (put x1=0x_1=0, and then x2=0x_2=0).
  2. Shade the side of each line that satisfies the inequality (test the origin). Also include x1,x2≥0x_1,x_2\ge0.
  3. The common part is the feasible region. Write its corner points. Find each one by solving the equations of the two lines that meet there.
  4. Find zz at every corner. The largest (or smallest) value is the optimum.

Examples

Example 1. Maximise z=3x1+4x2z=3x_1+4x_2 subject to 4x1+2x2≤804x_1+2x_2\le80, 2x1+5x2≤1802x_1+5x_2\le180, x1,x2≥0x_1,x_2\ge0.

Intercepts: 4x1+2x2=804x_1+2x_2=80 passes through (20,0)(20,0) and (0,40)(0,40); 2x1+5x2=1802x_1+5x_2=180 passes through (90,0)(90,0) and (0,36)(0,36).

The two lines meet where 4x1+2x2=804x_1+2x_2=80 and 2x1+5x2=1802x_1+5x_2=180. Multiply the second by 2 to get 4x1+10x2=3604x_1+10x_2=360. Subtracting the first, 8x2=2808x_2=280, so x2=35x_2=35 and x1=52x_1=\tfrac52.

{ "boundingBox": [-4, 46, 30, -4], "axis": true, "points": [ { "id": "A", "x": 0, "y": 0, "label": "A(0,0)" }, { "id": "B", "x": 20, "y": 0, "label": "B(20,0)" }, { "id": "C", "x": 2.5, "y": 35, "label": "C(2.5,35)" }, { "id": "D", "x": 0, "y": 36, "label": "D" }, { "id": "P", "x": 0, "y": 40, "label": "" }, { "id": "Q", "x": 10, "y": 32, "label": "2x₁+5x₂=180" } ], "polygons": [{ "points": ["A", "B", "C", "D"] }], "segments": [ { "from": "P", "to": "B" }, { "from": "D", "to": "Q" } ], "circles": [], "functions": [], "title": "Feasible region ABCD; the steep line is 4x₁ + 2x₂ = 80" }
Cornerz=3x1+4x2z=3x_1+4x_2
A(0,0)A(0,0)00
B(20,0)B(20,0)6060
C(52,35)C\left(\tfrac52,35\right)7.5+140=147.57.5+140=147.5
D(0,36)D(0,36)144144

Maximum z=147.5z=147.5 at x1=2.5x_1=2.5, x2=35x_2=35.

Example 2. Maximise z=3x+2yz=3x+2y subject to x+2y≤10x+2y\le10, 3x+y≤153x+y\le15, x,y≥0x,y\ge0.

Intercepts: x+2y=10x+2y=10 through (10,0)(10,0) and (0,5)(0,5); 3x+y=153x+y=15 through (5,0)(5,0) and (0,15)(0,15). They meet where 6x+2y=306x+2y=30 and x+2y=10x+2y=10. Subtracting, 5x=205x=20, so x=4x=4, y=3y=3.

Feasible region for x + 2y ≤ 10 and 3x + y ≤ 15 with corners (0,0), (5,0), (4,3), (0,5)

Cornerz=3x+2yz=3x+2y
(0,0)(0,0)00
(5,0)(5,0)1515
(4,3)(4,3)1818
(0,5)(0,5)1010

Maximum z=18z=18 at (4,3)(4,3).

Watch out. An intercept of a constraint line is a corner only if it satisfies every other constraint. In Example 2, (10,0)(10,0) is on x+2y=10x+2y=10 but does not satisfy 3x+y≤153x+y\le15, so it is not a corner.

Page 9 of 14

Graphical method: more examples

Example 1. Maximise z=15x1+10x2z=15x_1+10x_2 subject to 4x1+6x2≤3604x_1+6x_2\le360, 3x1≤1803x_1\le180, 5x2≤5005x_2\le500, x1,x2≥0x_1,x_2\ge0.

The constraints say 4x1+6x2≤3604x_1+6x_2\le360 (through (90,0)(90,0) and (0,60)(0,60)), x1≤60x_1\le60, and x2≤100x_2\le100. The last one is never the deciding one, because 4x1+6x2≤3604x_1+6x_2\le360 already forces x2≤60x_2\le60.

The line x1=60x_1=60 meets 4x1+6x2=3604x_1+6x_2=360 at 240+6x2=360240+6x_2=360, so x2=20x_2=20.

{ "boundingBox": [-8, 75, 100, -8], "axis": true, "points": [ { "id": "A", "x": 0, "y": 0, "label": "A(0,0)" }, { "id": "B", "x": 60, "y": 0, "label": "B(60,0)" }, { "id": "C", "x": 60, "y": 20, "label": "C(60,20)" }, { "id": "D", "x": 0, "y": 60, "label": "D(0,60)" }, { "id": "P", "x": 90, "y": 0, "label": "(90,0)" }, { "id": "Q", "x": 60, "y": 70, "label": "x₁ = 60" } ], "polygons": [{ "points": ["A", "B", "C", "D"] }], "segments": [ { "from": "D", "to": "P" }, { "from": "B", "to": "Q" } ], "circles": [], "functions": [], "title": "Feasible region ABCD for 4x₁ + 6x₂ ≤ 360 and x₁ ≤ 60" }
Cornerz=15x1+10x2z=15x_1+10x_2
(0,0)(0,0)00
(60,0)(60,0)900900
(60,20)(60,20)900+200=1100900+200=1100
(0,60)(0,60)600600

Maximum z=1100z=1100 at x1=60x_1=60, x2=20x_2=20.

Note on the source. The class notes listed the corners as (0,0)(0,0), (90,0)(90,0), (60,20)(60,20), (40,30)(40,30), (0,40)(0,40) and chose 13501350 at (90,0)(90,0). But (90,0)(90,0) does not satisfy 3x1≤1803x_1\le180, the point (40,30)(40,30) is not where any two constraint lines meet, and (0,40)(0,40) is not on any boundary. The correct corners are those in the table, and the maximum is 11001100.

Example 2. Maximise z=2x+3yz=2x+3y subject to x+y≤30x+y\le30, 3≤y≤123\le y\le12, x−y≥0x-y\ge0, 0≤x≤200\le x\le20.

The region lies between the horizontal lines y=3y=3 and y=12y=12, to the right of the line y=xy=x (because x≥yx\ge y), to the left of x=20x=20, and below x+y=30x+y=30. Its corners are:

  • y=3y=3 meets y=xy=x at A(3,3)A(3,3) and meets x=20x=20 at B(20,3)B(20,3).
  • x=20x=20 meets x+y=30x+y=30 at C(20,10)C(20,10).
  • x+y=30x+y=30 meets y=12y=12 at D(18,12)D(18,12).
  • y=12y=12 meets y=xy=x at E(12,12)E(12,12).
{ "boundingBox": [-2, 33, 33, -2], "axis": true, "points": [ { "id": "A", "x": 3, "y": 3, "label": "A" }, { "id": "B", "x": 20, "y": 3, "label": "B" }, { "id": "C", "x": 20, "y": 10, "label": "C" }, { "id": "D", "x": 18, "y": 12, "label": "D" }, { "id": "E", "x": 12, "y": 12, "label": "E" }, { "id": "L1", "x": 0, "y": 30, "label": "x+y=30" }, { "id": "L2", "x": 30, "y": 0, "label": "" }, { "id": "M1", "x": 0, "y": 0, "label": "" }, { "id": "M2", "x": 28, "y": 28, "label": "y = x" }, { "id": "V1", "x": 20, "y": 0, "label": "" }, { "id": "V2", "x": 20, "y": 30, "label": "x = 20" } ], "polygons": [{ "points": ["A", "B", "C", "D", "E"] }], "segments": [ { "from": "L1", "to": "L2" }, { "from": "M1", "to": "M2" }, { "from": "V1", "to": "V2" }, { "from": "A", "to": "B" }, { "from": "E", "to": "D" } ], "circles": [], "functions": [], "title": "Feasible region ABCDE between y = 3 and y = 12" }
Cornerz=2x+3yz=2x+3y
A(3,3)A(3,3)1515
B(20,3)B(20,3)4949
C(20,10)C(20,10)7070
D(18,12)D(18,12)7272
E(12,12)E(12,12)6060

Maximum z=72z=72 at (18,12)(18,12). (The minimum, if asked, is 1515 at (3,3)(3,3).)

Note on the source. The notes used E(3,12)E(3,12) as a corner, with z=42z=42. That point does not satisfy x≥yx\ge y. The correct corner is E(12,12)E(12,12) with z=60z=60. The maximum does not change.

Example 3. Maximise f=5x1+25x2f=5x_1+25x_2 subject to x1−3x2≥−6x_1-3x_2\ge-6, x1+x2≤6x_1+x_2\le6, x1,x2≥0x_1,x_2\ge0.

The line x1−3x2=−6x_1-3x_2=-6 passes through (0,2)(0,2) and (−6,0)(-6,0), and the origin satisfies 0≥−60\ge-6, so the feasible side is below this line that goes up. The line x1+x2=6x_1+x_2=6 passes through (6,0)(6,0) and (0,6)(0,6). The two lines meet where x1=3x2−6x_1=3x_2-6 and x1+x2=6x_1+x_2=6: 4x2=124x_2=12, so x2=3x_2=3, x1=3x_1=3.

{ "boundingBox": [-1, 7, 7.5, -1], "axis": true, "points": [ { "id": "A", "x": 0, "y": 0, "label": "A(0,0)" }, { "id": "B", "x": 6, "y": 0, "label": "B(6,0)" }, { "id": "C", "x": 3, "y": 3, "label": "C(3,3)" }, { "id": "D", "x": 0, "y": 2, "label": "D(0,2)" }, { "id": "P", "x": 0, "y": 6, "label": "(0,6)" }, { "id": "Q", "x": 4.5, "y": 3.5, "label": "x₁ − 3x₂ = −6" } ], "polygons": [{ "points": ["A", "B", "C", "D"] }], "segments": [ { "from": "P", "to": "B" }, { "from": "D", "to": "Q" } ], "circles": [], "functions": [], "title": "Feasible region ABCD" }
Cornerf=5x1+25x2f=5x_1+25x_2
(0,0)(0,0)00
(6,0)(6,0)3030
(3,3)(3,3)15+75=9015+75=90
(0,2)(0,2)5050

Maximum f=90f=90 at (3,3)(3,3).

Note on the source. The notes gave the x2x_2-intercept of x1−3x2=−6x_1-3x_2=-6 as (0,−2)(0,-2). It is (0,2)(0,2) (put x1=0x_1=0: −3x2=−6-3x_2=-6). The corner D(0,2)D(0,2) in the notes was correct.

Page 10 of 14

Word problems solved graphically

Example 1. Chairs and tables. A manufacturer makes chairs and tables on machines AA and BB. A chair needs 2 hours on AA and 6 hours on BB; a table needs 5 hours on AA and 1 hour on BB. Machine AA is available 16 hours a day and machine BB 30 hours. The profit is Rs 2 per chair and Rs 10 per table. Write the LPP and solve it.

Let x1x_1 chairs and x2x_2 tables be made per day.

Maximisez=2x1+10x2\text{Maximise}\quad z=2x_1+10x_2

subject to

2x1+5x2≤16(machine A)6x1+x2≤30(machine B)x1, x2≥0\begin{aligned} 2x_1+5x_2&\le16\qquad\text{(machine A)}\\ 6x_1+x_2&\le30\qquad\text{(machine B)}\\ x_1,\ x_2&\ge0 \end{aligned}

Intercepts: 2x1+5x2=162x_1+5x_2=16 through (8,0)(8,0) and (0,165)\left(0,\tfrac{16}5\right); 6x1+x2=306x_1+x_2=30 through (5,0)(5,0) and (0,30)(0,30).

The two lines meet here: from the second, x2=30−6x1x_2=30-6x_1; then 2x1+150−30x1=162x_1+150-30x_1=16, so x1=13428=6714≈4.79x_1=\tfrac{134}{28}=\tfrac{67}{14}\approx4.79 and x2=97≈1.29x_2=\tfrac97\approx1.29.

{ "boundingBox": [-0.8, 5.5, 9, -0.8], "axis": true, "points": [ { "id": "A", "x": 0, "y": 0, "label": "A(0,0)" }, { "id": "B", "x": 5, "y": 0, "label": "B(5,0)" }, { "id": "C", "x": 4.786, "y": 1.286, "label": "C(4.79,1.29)" }, { "id": "D", "x": 0, "y": 3.2, "label": "D(0,3.2)" }, { "id": "P", "x": 8, "y": 0, "label": "(8,0)" }, { "id": "Q", "x": 4.25, "y": 4.5, "label": "6x₁+x₂=30" } ], "polygons": [{ "points": ["A", "B", "C", "D"] }], "segments": [ { "from": "D", "to": "P" }, { "from": "B", "to": "Q" } ], "circles": [], "functions": [], "title": "Feasible region ABCD; the shallow line is 2x₁ + 5x₂ = 16" }
Cornerz=2x1+10x2z=2x_1+10x_2
(0,0)(0,0)00
(5,0)(5,0)1010
(6714,97)\left(\tfrac{67}{14},\tfrac97\right)677+907=1577≈22.43\tfrac{67}{7}+\tfrac{90}{7}=\tfrac{157}7\approx22.43
(0,165)\left(0,\tfrac{16}5\right)10×165=3210\times\tfrac{16}5=32

Maximum profit is Rs 32, by making no chairs and 3.23.2 tables a day (that is, 16 tables in five days).

Note on the source. The notes wrote the value at DD as "2×165=325=322\times\frac{16}{5}=\frac{32}{5}=32". The correct working is z=2(0)+10(165)=32z=2(0)+10\left(\tfrac{16}5\right)=32. They also rounded CC to (4.78,1.28)(4.78,1.28) with z=22.36z=22.36, but the exact value is 1577≈22.43\tfrac{157}{7}\approx22.43. The conclusion (maximum 3232) is correct.

Example 2. The diet problem, solved. Minimise z=3x1+4x2z=3x_1+4x_2 subject to 500x1+600x2≥2000500x_1+600x_2\ge2000, 20x1+30x2≥5020x_1+30x_2\ge50, 30x1+40x2≥30030x_1+40x_2\ge300, x1,x2≥0x_1,x_2\ge0 (from the formulation page).

The carbohydrate line 30x1+40x2=30030x_1+40x_2=300 passes through (10,0)(10,0) and (0,7.5)(0,7.5). Every point on or above it automatically satisfies the calorie line (through (4,0)(4,0) and (0,3.3‾)(0,3.\overline{3})) and the protein line (through (2.5,0)(2.5,0) and (0,1.6‾)(0,1.\overline{6})), which lie below it. So the feasible region is everything on or above the carbohydrate line. It is an unbounded region.

{ "boundingBox": [-1, 10, 13, -1], "axis": true, "points": [ { "id": "P", "x": 0, "y": 7.5, "label": "(0,7.5)" }, { "id": "Q", "x": 10, "y": 0, "label": "(10,0)" }, { "id": "R", "x": 18, "y": 0, "label": "" }, { "id": "S", "x": 18, "y": 15, "label": "" }, { "id": "T", "x": 0, "y": 15, "label": "" }, { "id": "C1", "x": 0, "y": 3.333, "label": "calories" }, { "id": "C2", "x": 4, "y": 0, "label": "" }, { "id": "P1", "x": 0, "y": 1.667, "label": "protein" }, { "id": "P2", "x": 2.5, "y": 0, "label": "" } ], "polygons": [{ "points": ["P", "Q", "R", "S", "T"] }], "segments": [ { "from": "P", "to": "Q" }, { "from": "C1", "to": "C2" }, { "from": "P1", "to": "P2" } ], "circles": [], "functions": [], "title": "Feasible region (shaded, continuing upwards) on or above 30x₁ + 40x₂ = 300" }
Cornerz=3x1+4x2z=3x_1+4x_2
(0,7.5)(0,7.5)3030
(10,0)(10,0)3030

Both corners give 3030. Notice that z=3x1+4x2=110(30x1+40x2)≥30010=30z=3x_1+4x_2=\tfrac1{10}(30x_1+40x_2)\ge\tfrac{300}{10}=30 everywhere in the region, and it is equal to 3030 along the whole carbohydrate line. So the minimum cost is Rs 30, and it is reached at every point of the segment from (10,0)(10,0) to (0,7.5)(0,7.5). This LPP has multiple optimal solutions.

Watch out. For a minimisation over an unbounded region, a minimum can still exist (as here), because the cost increases as you go further into the region. It is a maximisation over an unbounded region that may have no answer.

Page 11 of 14

Special cases of the graphical method

Not every LPP has one single answer.

CaseWhat the graph showsWhat to say
Unique optimumone corner gives the best value"the optimum is z∗z^* at (x1,x2)(x_1,x_2)"
Multiple optimatwo neighbouring corners give the same best value: the objective lines are parallel to an edgeevery point of that edge is optimal (diet problem)
Unboundedthe region goes on forever in the direction in which zz improvesno finite optimum
Infeasiblethe constraints have no common point, so there is no feasible region at allthe LPP has no feasible solution

Example 1. An infeasible problem. Maximise z=6x1−4x2z=6x_1-4x_2 subject to 2x1+4x2≤42x_1+4x_2\le4, 4x1+8x2≥154x_1+8x_2\ge15, x1,x2≥0x_1,x_2\ge0.

Divide the constraints by 2 and 4:

x1+2x2≤2andx1+2x2≥3.75x_1+2x_2\le2\qquad\text{and}\qquad x_1+2x_2\ge3.75

No pair (x1,x2)(x_1,x_2) can make x1+2x2x_1+2x_2 both at most 22 and at least 3.753.75. The boundary lines are parallel (through (2,0)(2,0), (0,1)(0,1) and through (3.75,0)(3.75,0), (0,1.875)(0,1.875)). The first constraint allows only the triangle below the lower line, and the second allows only the region above the upper line.

{ "boundingBox": [-0.4, 2.4, 4.4, -0.4], "axis": true, "points": [ { "id": "O", "x": 0, "y": 0, "label": "" }, { "id": "A", "x": 2, "y": 0, "label": "(2,0)" }, { "id": "B", "x": 0, "y": 1, "label": "(0,1)" }, { "id": "C", "x": 3.75, "y": 0, "label": "(3.75,0)" }, { "id": "D", "x": 0, "y": 1.875, "label": "(0,1.875)" } ], "polygons": [{ "points": ["O", "A", "B"] }], "segments": [ { "from": "A", "to": "B" }, { "from": "C", "to": "D" } ], "circles": [], "functions": [], "title": "Shaded: 2x₁ + 4x₂ ≤ 4. The second constraint needs points above the upper line, so the regions never meet" }

The LPP is infeasible: it has no solution.

Note on the source. The class notes concluded "there is no bounded region". The correct statement is stronger: there is no feasible region at all, so the problem is infeasible (not just unbounded).

Watch out. "Unbounded" and "infeasible" are different. Unbounded means feasible points exist but zz can be made as large as we like. Infeasible means there are no feasible points.

Page 12 of 14

Gradient descent (method of steepest descent)

The idea

From Module 3, ∇f\nabla f points in the direction in which ff increases fastest, so −∇f-\nabla f points in the direction in which it decreases fastest. To find a minimum, start at any point and keep taking small steps downhill.

∇f=(∂f∂x, ∂f∂y)\nabla f=\left(\frac{\partial f}{\partial x},\ \frac{\partial f}{\partial y}\right)

Update rule. From the current point (xk,yk)(x_k,y_k),

(xk+1,yk+1)=(xk,yk)−α ∇f(xk,yk)(x_{k+1},y_{k+1})=(x_k,y_k)-\alpha\,\nabla f(x_k,y_k)

where α>0\alpha>0 is the step size (also called the learning rate).

Method

  1. Find ∇f(x,y)\nabla f(x,y) as a formula.
  2. Start at the given (x0,y0)(x_0,y_0).
  3. At each step, find ∇f\nabla f at the current point, multiply by α\alpha, and subtract.
  4. Repeat for the required number of iterations, or until the steps become very small.

Write the work in a table: point, gradient, new point.

Examples

Example 1. Find the minimum of f(x,y)=x2+3y2f(x,y)=x^2+3y^2 by steepest descent from (x0,y0)=(6,3)(x_0,y_0)=(6,3), with α=0.1\alpha=0.1, for five iterations.

∇f=(2x, 6y)\nabla f=(2x,\ 6y). Each update is

xk+1=xk−0.1(2xk)=0.8 xk,yk+1=yk−0.1(6yk)=0.4 ykx_{k+1}=x_k-0.1(2x_k)=0.8\,x_k,\qquad y_{k+1}=y_k-0.1(6y_k)=0.4\,y_k
kk(xk,yk)(x_k,y_k)∇f(xk,yk)\nabla f(x_k,y_k)
0(6, 3)(6,\ 3)(12, 18)(12,\ 18)
1(4.8, 1.2)(4.8,\ 1.2)(9.6, 7.2)(9.6,\ 7.2)
2(3.84, 0.48)(3.84,\ 0.48)(7.68, 2.88)(7.68,\ 2.88)
3(3.072, 0.192)(3.072,\ 0.192)(6.144, 1.152)(6.144,\ 1.152)
4(2.4576, 0.0768)(2.4576,\ 0.0768)(4.9152, 0.4608)(4.9152,\ 0.4608)
5(1.96608, 0.03072)(1.96608,\ 0.03072)

The points move towards the true minimum (0,0)(0,0), where f=0f=0. The yy-coordinate decreases faster because ff is steeper in the yy-direction.

Note on the source. No step size was given in this question. The class notes took α=0.1\alpha=0.1, and we have kept that assumption. One line of the notes copied y4y_4 as 0.07610.0761, but it is 0.07680.0768. The value y5=0.03072y_5=0.03072 is correct.

Example 2. Minimise f(x,y)=x2+y2f(x,y)=x^2+y^2 from (1,1)(1,1) with α=0.1\alpha=0.1, for three iterations.

∇f=(2x, 2y)\nabla f=(2x,\ 2y), so each step multiplies both coordinates by 1−0.2=0.81-0.2=0.8:

(1,1) → (0.8, 0.8) → (0.64, 0.64) → (0.512, 0.512)(1,1)\ \to\ (0.8,\ 0.8)\ \to\ (0.64,\ 0.64)\ \to\ (0.512,\ 0.512)

approaching the minimum at the origin.

Watch out. Find the gradient at the current point in every step. A common mistake is to keep using ∇f(x0,y0)\nabla f(x_0,y_0), or to write the new point in place of the gradient.

Page 13 of 14

Gradient descent: more examples

Example 1. Minimise f(x,y)=3x2+4y2f(x,y)=3x^2+4y^2 from (x0,y0)=(1,1)(x_0,y_0)=(1,1) with fixed step α=0.01\alpha=0.01, for five iterations.

∇f=(6x, 8y)\nabla f=(6x,\ 8y). So xk+1=xk−0.06xk=0.94 xkx_{k+1}=x_k-0.06x_k=0.94\,x_k and yk+1=yk−0.08yk=0.92 yky_{k+1}=y_k-0.08y_k=0.92\,y_k.

kk(xk,yk)(x_k,y_k)∇f(xk,yk)\nabla f(x_k,y_k)
0(1, 1)(1,\ 1)(6, 8)(6,\ 8)
1(0.94, 0.92)(0.94,\ 0.92)(5.64, 7.36)(5.64,\ 7.36)
2(0.8836, 0.8464)(0.8836,\ 0.8464)(5.3016, 6.7712)(5.3016,\ 6.7712)
3(0.830584, 0.778688)(0.830584,\ 0.778688)(4.983504, 6.229504)(4.983504,\ 6.229504)
4(0.780749, 0.716393)(0.780749,\ 0.716393)(4.684494, 5.731144)(4.684494,\ 5.731144)
5(0.733904, 0.659082)(0.733904,\ 0.659082)

With such a small step, the progress towards (0,0)(0,0) is slow.

Note on the source. At step 3 the notes used 4.6721284.672128 for the yy-component of the gradient, but it is 8×0.778688=6.2295048\times0.778688=6.229504. This mistake made y4y_4 and y5y_5 wrong (0.731966720.73196672 and 0.67330.6733 in the notes). The corrected values are in the table.

Example 2. Minimise f(x,y)=(x−2)2+(y+3)2f(x,y)=(x-2)^2+(y+3)^2 from (0,0)(0,0) with learning rate 0.10.1.

∇f=(2(x−2), 2(y+3))=(2x−4, 2y+6)\nabla f=\big(2(x-2),\ 2(y+3)\big)=(2x-4,\ 2y+6).

kk(xk,yk)(x_k,y_k)∇f(xk,yk)\nabla f(x_k,y_k)
0(0, 0)(0,\ 0)(−4, 6)(-4,\ 6)
1(0.4, −0.6)(0.4,\ -0.6)(−3.2, 4.8)(-3.2,\ 4.8)
2(0.72, −1.08)(0.72,\ -1.08)(−2.56, 3.84)(-2.56,\ 3.84)
3(0.976, −1.464)(0.976,\ -1.464)(−2.048, 3.072)(-2.048,\ 3.072)
4(1.1808, −1.7712)(1.1808,\ -1.7712)

The points come closer to the true minimum (2,−3)(2,-3), where f=0f=0. Each step reduces the remaining gap by 20 %, since xk+1−2=0.8 (xk−2)x_{k+1}-2=0.8\,(x_k-2) and yk+1+3=0.8 (yk+3)y_{k+1}+3=0.8\,(y_k+3).

Note on the source. The notes wrote the second step as (0.4,−0.6)−0.1(0.72,−1.08)(0.4,-0.6)-0.1(0.72,-1.08), where the next point was written in the place of the gradient. The gradient at (0.4,−0.6)(0.4,-0.6) is (−3.2,4.8)(-3.2,4.8), which gives the point (0.72,−1.08)(0.72,-1.08).

Watch out. The step size is important. If it is too small, the method is slow (Example 1). If it is too large, the points go beyond the minimum: for f=x2f=x^2, any α>1\alpha>1 makes ∣xk∣|x_k| increase instead of decrease.

Page 14 of 14

Practice questions and formula sheet

Practice questions

Try these without looking at the answers. The answers are given below.

A. Lagrange multipliers

  1. Find the maximum and minimum of f(x,y)=x+yf(x,y)=x+y on the circle x2+y2=8x^2+y^2=8.
  2. Find the point of the line 2x+3y=132x+3y=13 closest to the origin.
  3. Three positive numbers add up to 1212. Use Lagrange multipliers to find the largest product.
  4. Minimise x2+y2+z2x^2+y^2+z^2 subject to x+y=2x+y=2 and y+z=2y+z=2.

B. Linear programming

  1. Solve the manufacturing problem: maximise z=3x1+5x2z=3x_1+5x_2 subject to x1+2x2≤4x_1+2x_2\le4, 2x1+x2≤62x_1+x_2\le6, x1,x2≥0x_1,x_2\ge0.
  2. Minimise z=2x+3yz=2x+3y subject to x+y≥6x+y\ge6, x+3y≥12x+3y\ge12, x,y≥0x,y\ge0.
  3. Show that the LPP "maximise x+yx+y subject to x+y≤2x+y\le2, x+y≥5x+y\ge5, x,y≥0x,y\ge0" has no solution.

C. Gradient descent

  1. Take two steps of steepest descent for f(x,y)=(x−1)2+2y2f(x,y)=(x-1)^2+2y^2 from (0,1)(0,1) with α=0.1\alpha=0.1.

Answers

  1. Lx=1+2λx=0L_x=1+2\lambda x=0, Ly=1+2λy=0L_y=1+2\lambda y=0 give x=yx=y; then 2x2=82x^2=8. Maximum 44 at (2,2)(2,2), minimum −4-4 at (−2,−2)(-2,-2).
  2. Minimise x2+y2x^2+y^2: 2x+2λ=02x+2\lambda=0, 2y+3λ=02y+3\lambda=0 give x=2tx=2t, y=3ty=3t; the line gives 13t=1313t=13. The point is (2,3)(2,3), at distance 13\sqrt{13}.
  3. L=xyz+λ(x+y+z−12)L=xyz+\lambda(x+y+z-12): yz=xz=xyyz=xz=xy gives x=y=z=4x=y=z=4. Maximum product 6464.
  4. 2x+λ=02x+\lambda=0, 2y+λ+μ=02y+\lambda+\mu=0, 2z+μ=02z+\mu=0 give y=x+zy=x+z; with x+y=2x+y=2, y+z=2y+z=2: x=z=23x=z=\tfrac23, y=43y=\tfrac43. Minimum 83\tfrac83 at (23,43,23)\left(\tfrac23,\tfrac43,\tfrac23\right).
  5. Corners (0,0)(0,0), (3,0)(3,0), (83,23)\left(\tfrac83,\tfrac23\right), (0,2)(0,2) with z=0, 9, 343, 10z=0,\ 9,\ \tfrac{34}{3},\ 10. Maximum 343≈11.33\tfrac{34}{3}\approx11.33 at (83,23)\left(\tfrac83,\tfrac23\right).
  6. The region is unbounded above, with corners (0,6)(0,6), (3,3)(3,3), (12,0)(12,0) and z=18, 15, 24z=18,\ 15,\ 24. Minimum 1515 at (3,3)(3,3).
  7. The constraints require x+y≤2x+y\le2 and x+y≥5x+y\ge5 at once, which is impossible: the LPP is infeasible.
  8. ∇f=(2(x−1), 4y)\nabla f=(2(x-1),\ 4y). From (0,1)(0,1): gradient (−2,4)(-2,4), new point (0.2, 0.6)(0.2,\ 0.6). Then gradient (−1.6, 2.4)(-1.6,\ 2.4), new point (0.36, 0.36)\mathbf{(0.36,\ 0.36)}. (The minimum is at (1,0)(1,0).)

Study tip. For LPPs, always make the corner table: corner, how you found it (which two lines), and value of zz. This makes the answer easy to check and easy to mark.


Formula sheet

Lagrange multipliers

One constraintL=f+λgL=f+\lambda g; solve Lx=Ly=Lλ=0L_x=L_y=L_\lambda=0
Condition∇f=−λ∇g\nabla f=-\lambda\nabla g at the optimum
Three variablesadd Lz=0L_z=0
Two constraintsL=f+λg+μhL=f+\lambda g+\mu h; solve Lx=Ly=Lz=Lλ=Lμ=0L_x=L_y=L_z=L_\lambda=L_\mu=0
Distance problemsminimise d2=x2+y2+z2d^2=x^2+y^2+z^2, not dd

Linear programming

General formoptimise z=∑cjxjz=\sum c_jx_j subject to ∑aijxj≤bi\sum a_{ij}x_j\le b_i (or ≥\ge, ==), xj≥0x_j\ge0
Feasible regionintersection of the half-planes of all constraints
Corner-point theoremif an optimum exists, one occurs at a corner of the feasible region
Graphical methoddraw lines by intercepts, test the origin, list corners, evaluate zz at each
Special casesmultiple optima, unbounded, infeasible

Gradient descent

(xk+1,yk+1)=(xk,yk)−α ∇f(xk,yk),∇f=(fx, fy)(x_{k+1},y_{k+1})=(x_k,y_k)-\alpha\,\nabla f(x_k,y_k),\qquad\nabla f=(f_x,\ f_y)
Direction of steepest descent−∇f-\nabla f
Step size (learning rate)α>0\alpha>0: small is slow, too large overshoots
For f=ax2+by2f=ax^2+by^2xk+1=(1−2aα)xkx_{k+1}=(1-2a\alpha)x_k,  yk+1=(1−2bα)yk\ y_{k+1}=(1-2b\alpha)y_k

You’ve reached the end of S1 CSE Maths · Module 4.

Source: ktunotes.in · GAMAT101, Module 4. Reorganised and rewritten from the class notes, with every worked example re-checked. Check the original material if a step looks unclear.