SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 4.1.1 Functions of two variables: surfaces and level curvesConcept · 30 min
      2. 4.1.2 Partial derivativesConcept · 35 min
      3. 4.1.3 Practice set: partial derivativesPractice set · 20 min
      4. 4.1.4 Case study: the Greeks as partial derivativesCase study · 35 min

Level 4, Multivariable calculus and optimisation 4.1 Functions of several variables Lesson 1 of 4

ConceptLesson 4.1.1 in Level 4, Multivariable calculus and optimisation. About 30 minutes.

Functions of two variables: surfaces and level curves

A rule with two inputs

A function of two variables takes two numbers, xx and yy, and returns one number, written f(x,y)f(x, y). The pair (x,y)(x, y) is a point of the plane, as in lesson 3.1.1. So ff gives a number for each point.

You already know some. A rectangle ww cm wide and hh cm tall has area A(w,h)=whA(w, h) = wh cm². Both inputs matter, and neither can be left out.

Take f(x,y)=x2+2y2f(x, y) = x^2 + 2y^2. At the point (1,2)(1, 2) it gives 1+8=91 + 8 = 9, and at (2,1)(2, 1) it gives 4+2=64 + 2 = 6. The order of the inputs matters: xx always comes first.

Rule: Function of two variables

(x,y)↦f(x,y)(x, y) \mapsto f(x, y)

A rule that gives exactly one number f(x,y)f(x, y) for each point (x,y)(x, y) where it is defined. The output is in its own units, such as cm² for an area.

A function of one variable fits in a row of values. A function of two variables needs a grid: one column for each xx and one row for each yy. Here is x2+2y2x^2 + 2y^2 on a grid of 25 points.

x=−2x = -2−1-1012
y=1y = 163236
y=0.5y = 0.54.51.50.51.54.5
y=0y = 041014
y=−0.5y = -0.54.51.50.51.54.5
y=−1y = -163236

The smallest value, 0, is at the centre (0,0)(0, 0). The values grow in every direction from there, faster in yy than in xx. From the centre, a step of 1 in yy climbs to 2, a step of 1 in xx only to 1.

Try it

np.meshgrid turns a list of xx values and a list of yy values into two grids, X and Y. Entry by entry, they hold the coordinates of every point.

f(X, Y) then computes all 25 values at once, row by row as in the table. The first line checks that the order of the inputs matters.

⌘/Ctrl + Enter runs the cell

The domain

The domain of ff is the set of points where the rule gives a real number (lesson 1.1.1). For x2+2y2x^2 + 2y^2 it is the whole plane.

The same two traps as in one variable can shrink it: a square root of a negative number, and division by zero. Logarithms need a positive input too.

  • x−y\sqrt{x - y} needs x−y≥0x - y \ge 0, so y≤xy \le x. The domain is the half of the plane on or below the line y=xy = x. At (3,1)(3, 1) the value is 2≈1.4142\sqrt{2} \approx 1.4142; at (1,2)(1, 2) there is none.
  • ln⁡(x+y)\ln(x + y) needs x+y>0x + y > 0: the points above the line y=−xy = -x, not on it. At (3,−2)(3, -2) it is ln⁡1=0\ln 1 = 0.
  • 1x2+y2\frac{1}{x^2 + y^2} needs x2+y2≠0x^2 + y^2 \neq 0. That rules out one point, the origin (0,0)(0, 0).

So a domain is a region of the plane, often bounded by a line or a curve. Check whether the boundary itself is in it, as with ≤\le against << in lesson 1.1.1.

Try it

math.sqrt and math.log raise ValueError outside their domains. The cell tries points inside, on the edge and outside.

(2,2)(2, 2) is on the edge of the first domain, where 0=0\sqrt{0} = 0 is allowed.

⌘/Ctrl + Enter runs the cell

The graph is a surface

The graph of a function of one variable is a curve: above each xx, a point at height f(x)f(x). With two inputs, put the point (x,y)(x, y) on a floor and raise a point above it to the height z=f(x,y)z = f(x, y). Together these points form a surface.

For x2+2y2x^2 + 2y^2 the surface is a bowl. Its bottom sits on the floor at (0,0)(0, 0), where f=0f = 0, and its sides rise in every direction, more steeply in yy.

The bowl z=x2+2y2z = x^2 + 2y^2, as a surface and as a map of level curves. The cut at height 4 casts the ellipse f=4f = 4 on the floor. The slice y=1y = 1 is the parabola x2+2x^2 + 2.

A surface is hard to draw and harder to read off exactly. Two simpler pictures carry the same information: slices, which are curves you know from Level 2, and level curves, which are flat maps.

Slices

Hold yy fixed at a number bb, and f(x,b)f(x, b) is a function of xx alone. Its graph is a slice: the curve where the upright plane y=by = b cuts the surface. Holding xx fixed instead gives a slice in the yy direction.

For x2+2y2x^2 + 2y^2, the slice y=1y = 1 is x2+2x^2 + 2: a parabola (lesson 1.2.2) with its lowest point 2 at x=0x = 0. The slice x=1x = 1 is 1+2y21 + 2y^2, a narrower parabola.

moving input−2-2−1-1012
slice y=1y = 1: f(x,1)f(x, 1)63236
slice x=1x = 1: f(1,y)f(1, y)93139

In the first row xx moves, and the values are the row y=1y = 1 of the grid above. In the second row yy moves.

Rule: A slice

g(x)=f(x,b)h(y)=f(a,y)\begin{gathered} g(x) = f(x, b) \\[4pt] h(y) = f(a, y) \end{gathered}

Fix one input at a number and let the other move. The result is a function of one variable, and everything in Level 2 applies to it.

Every slice of the bowl in the xx direction is the same parabola x2x^2, lifted by 2b22b^2. Lesson 4.1.2 takes the slopes of slices: those are the partial derivatives.

Try it

across is the slice y=1y = 1 and along the slice x=1x = 1. Each line compares a slice with its formula, x2+2x^2 + 2 or 1+2y21 + 2y^2.

⌘/Ctrl + Enter runs the cell

Level curves and the contour map

Cut the surface with a flat plane at height cc and look straight down. The cut is a level curve: every point (x,y)(x, y) where f(x,y)=cf(x, y) = c.

Draw level curves for several heights, each labelled with its cc, and you have a contour map. It works like the contour lines of a hiking map.

For the bowl, x2+2y2=cx^2 + 2y^2 = c is an ellipse. Setting y=0y = 0 gives x=±cx = \pm\sqrt{c}, and setting x=0x = 0 gives y=±c/2y = \pm\sqrt{c/2}. So f=4f = 4 crosses the xx-axis at ±2\pm 2 and the yy-axis at ±2≈±1.4142\pm\sqrt{2} \approx \pm 1.4142.

The level c=0c = 0 is the single point (0,0)(0, 0), and a negative cc gives no curve at all: the bowl never goes below the floor.

Rule: Level curve

{(x,y):f(x,y)=c}\{(x, y) : f(x, y) = c\}

All the points where ff has the height cc. Moving along a level curve leaves ff unchanged. Curves for different heights never cross, because each point has only one height.

Reading steepness from the spacing

Walk out along the positive xx-axis. The curves f=1,2,3,4f = 1, 2, 3, 4 cross it at 1, 1.4142, 1.7321 and 2, with gaps 0.4142, 0.3178 and 0.2679 between them. Each gap is one unit of height, and the gaps shrink, so the climb gets steeper.

Along the yy-axis the crossings are at 0.7071, 1, 1.2247 and 1.4142, with gaps 0.2929, 0.2247 and 0.1895. They are closer than along xx: the bowl is steeper in the yy direction, as the table showed.

So curves close together mean a steep surface, and curves far apart a gentle one. The labels say whether it rises or falls.

Quadratic forms

Lesson 3.7.1 drew level curves of quadratic forms and found that their eigenvalues decide the shape. x2+2y2x^2 + 2y^2 is the form of the matrix with diagonal entries 1 and 2, whose eigenvalues are 1 and 2. Both are positive, so the curves are ellipses, with semi-axes c/1\sqrt{c/1} and c/2\sqrt{c/2}.

A contour map works for any function of two variables, quadratic or not. Lessons 4.3.2 and 4.4.2 use these maps to find and reach the lowest points of more general functions.

Set a point with the sliders and read its height; the bold curve through it is its level curve. Move the point along that curve and the height stays the same. Then switch to x2−y2x^2 - y^2, a saddle met in the next section.

Explore

Each curve joins the points where the function has the same height, like the contour lines of a map. Pick a point and read its height; where the curves crowd together, the surface is steep.

−202−2−1012
Point
(2, 1), f = 6

Try it

The loop takes five points of the form (2cos⁡t,2sin⁡t)(2\cos t, \sqrt{2}\sin t), which trace the ellipse f=4f = 4. Each gives height 4.

The last two lines print where f=1,2,3,4f = 1, 2, 3, 4 cross each axis, and the gaps between neighbours.

⌘/Ctrl + Enter runs the cell

Four shapes

Four simple shapes come up again and again in this level. The bowl is the first.

A saddle: x2−y2x^2 - y^2. Its slice y=0y = 0 is x2x^2, which rises both ways, and its slice x=0x = 0 is −y2-y^2, which falls both ways. So the surface is shaped like a horse's saddle, or a mountain pass. Its level curves are hyperbolas: f=3f = 3 at (2,1)(2, 1), f=−3f = -3 at (1,2)(1, 2), and f=0f = 0 on the two crossing lines y=xy = x and y=−xy = -x.

A plane: 6−2x−3y6 - 2x - 3y. Every slice is a straight line: 6−2x6 - 2x along y=0y = 0, 6−3y6 - 3y along x=0x = 0. The level curves 2x+3y=6−c2x + 3y = 6 - c are parallel straight lines. Equal steps in height give equal gaps: along y=0y = 0 the height falls by 1 every 0.5.

A product: xyxy. The slice y=2y = 2 is the line 2x2x, and in general the slice y=by = b is the line bxbx, with slope bb. The level curves xy=cxy = c are hyperbolas, such as (2,3)(2, 3) and (4,1.5)(4, 1.5) on f=6f = 6. They lie in the quadrants where xx and yy have the same sign when c>0c > 0, and in the others when c<0c < 0.

Level curves of a saddle, a plane and the product xyxy. Labels give the heights; the dashed lines are where f=0f = 0, with positive and negative heights in different colours.

The product xyxy is the saddle turned by 45°. Algebra shows it: xy=14((x+y)2−(x−y)2)xy = \frac{1}{4}\big((x + y)^2 - (x - y)^2\big), a square minus a square.

As a quadratic form, xyxy has the matrix (012120)\begin{pmatrix} 0 & \frac{1}{2} \\ \frac{1}{2} & 0 \end{pmatrix}. Its eigenvalues, 12\frac{1}{2} and −12-\frac{1}{2}, have both signs, so lesson 3.7.1 predicts hyperbolas.

functionsliceslevel curvessurface
x2+2y2x^2 + 2y^2parabolas opening upellipsesbowl
x2−y2x^2 - y^2parabolas, up in xx and down in yyhyperbolassaddle
6−2x−3y6 - 2x - 3ystraight linesparallel, evenly spaced linestilted plane
xyxystraight lines through the originhyperbolas in the quadrantssaddle turned 45°

Try it

The first line checks the saddle: 3 at (2,1)(2, 1), −3-3 at (1,2)(1, 2), 0 on the line y=xy = x, then the slices y=0y = 0 and x=0x = 0.

Then the plane along y=0y = 0, falling by 1 every 0.5, and the product. The last lines check that xyxy is a difference of squares, and print the eigenvalues of both quadratic forms.

⌘/Ctrl + Enter runs the cell

The same ideas reach functions of three or more variables, such as the volume xyzxyz of a box. Their graphs need more dimensions than paper has, but slices and partial derivatives (lesson 4.1.2) still work.

Common mistakes

  1. The order of the inputs matters. For x2+2y2x^2 + 2y^2, f(1,2)=9f(1, 2) = 9 but f(2,1)=6f(2, 1) = 6.
  2. A level curve's label is a height, not a distance. x2+2y2=4x^2 + 2y^2 = 4 crosses the xx-axis at 2, not at 4.
  3. Close curves mean steep, not high. The bowl's crowded outer curves are steep sides; the height is in the labels.
  4. Level curves of different heights never cross. One point has one height. The saddle's two lines where f=0f = 0 cross, but they are the same level.
  5. Check the domain. x−y\sqrt{x - y} has no value at (1,2)(1, 2), and ln⁡(x+y)\ln(x + y) none on the line y=−xy = -x.
  6. A slice fixes the other input at a number. The slice y=1y = 1 of x2+2y2x^2 + 2y^2 is x2+2x^2 + 2, a function of xx alone.

Functions of two variables

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • A function of two variables gives one number f(x,y)f(x, y) for each point (x,y)(x, y) of its domain, the region where the rule makes sense. A grid of values is its table.
  • Its graph is a surface, at height z=f(x,y)z = f(x, y) above each point.
  • A slice fixes one input: f(x,b)f(x, b) is a function of xx alone, the curve cut by the plane y=by = b.
  • A level curve is f(x,y)=cf(x, y) = c, all points at height cc; a contour map shows several. Close curves mean steep, and curves of different heights never cross.
  • Bowl x2+2y2x^2 + 2y^2: ellipses. Saddle x2−y2x^2 - y^2: hyperbolas. Plane: parallel, evenly spaced lines. xyxy: hyperbolas, the saddle turned 45°.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.