A rule with two inputs
A function of two variables takes two numbers, and , and returns one number, written . The pair is a point of the plane, as in lesson 3.1.1. So gives a number for each point.
You already know some. A rectangle cm wide and cm tall has area cm². Both inputs matter, and neither can be left out.
Take . At the point it gives , and at it gives . The order of the inputs matters: always comes first.
Rule: Function of two variables
A rule that gives exactly one number for each point 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 and one row for each . Here is on a grid of 25 points.
| 0 | 1 | 2 | |||
|---|---|---|---|---|---|
| 6 | 3 | 2 | 3 | 6 | |
| 4.5 | 1.5 | 0.5 | 1.5 | 4.5 | |
| 4 | 1 | 0 | 1 | 4 | |
| 4.5 | 1.5 | 0.5 | 1.5 | 4.5 | |
| 6 | 3 | 2 | 3 | 6 |
The smallest value, 0, is at the centre . The values grow in every direction from there, faster in than in . From the centre, a step of 1 in climbs to 2, a step of 1 in only to 1.
Try it
np.meshgrid turns a list of values and a list of 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.
The domain
The domain of is the set of points where the rule gives a real number (lesson 1.1.1). For 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.
- needs , so . The domain is the half of the plane on or below the line . At the value is ; at there is none.
- needs : the points above the line , not on it. At it is .
- needs . That rules out one point, the origin .
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 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.
is on the edge of the first domain, where is allowed.
The graph is a surface
The graph of a function of one variable is a curve: above each , a point at height . With two inputs, put the point on a floor and raise a point above it to the height . Together these points form a surface.
For the surface is a bowl. Its bottom sits on the floor at , where , and its sides rise in every direction, more steeply in .
The bowl , as a surface and as a map of level curves. The cut at height 4 casts the ellipse on the floor. The slice is the parabola .
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 fixed at a number , and is a function of alone. Its graph is a slice: the curve where the upright plane cuts the surface. Holding fixed instead gives a slice in the direction.
For , the slice is : a parabola (lesson 1.2.2) with its lowest point 2 at . The slice is , a narrower parabola.
| moving input | 0 | 1 | 2 | ||
|---|---|---|---|---|---|
| slice : | 6 | 3 | 2 | 3 | 6 |
| slice : | 9 | 3 | 1 | 3 | 9 |
In the first row moves, and the values are the row of the grid above. In the second row moves.
Rule: A slice
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 direction is the same parabola , lifted by . Lesson 4.1.2 takes the slopes of slices: those are the partial derivatives.
Try it
across is the slice and along the slice . Each line compares a slice with its formula, or .
Level curves and the contour map
Cut the surface with a flat plane at height and look straight down. The cut is a level curve: every point where .
Draw level curves for several heights, each labelled with its , and you have a contour map. It works like the contour lines of a hiking map.
For the bowl, is an ellipse. Setting gives , and setting gives . So crosses the -axis at and the -axis at .
The level is the single point , and a negative gives no curve at all: the bowl never goes below the floor.
Rule: Level curve
All the points where has the height . Moving along a level curve leaves unchanged. Curves for different heights never cross, because each point has only one height.
Reading steepness from the spacing
Walk out along the positive -axis. The curves 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 -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 : the bowl is steeper in the 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. 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 and .
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 , 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.
- Point
- (2, 1), f = 6
Try it
The loop takes five points of the form , which trace the ellipse . Each gives height 4.
The last two lines print where cross each axis, and the gaps between neighbours.
Four shapes
Four simple shapes come up again and again in this level. The bowl is the first.
A saddle: . Its slice is , which rises both ways, and its slice is , which falls both ways. So the surface is shaped like a horse's saddle, or a mountain pass. Its level curves are hyperbolas: at , at , and on the two crossing lines and .
A plane: . Every slice is a straight line: along , along . The level curves are parallel straight lines. Equal steps in height give equal gaps: along the height falls by 1 every 0.5.
A product: . The slice is the line , and in general the slice is the line , with slope . The level curves are hyperbolas, such as and on . They lie in the quadrants where and have the same sign when , and in the others when .
Level curves of a saddle, a plane and the product . Labels give the heights; the dashed lines are where , with positive and negative heights in different colours.
The product is the saddle turned by 45°. Algebra shows it: , a square minus a square.
As a quadratic form, has the matrix . Its eigenvalues, and , have both signs, so lesson 3.7.1 predicts hyperbolas.
| function | slices | level curves | surface |
|---|---|---|---|
| parabolas opening up | ellipses | bowl | |
| parabolas, up in and down in | hyperbolas | saddle | |
| straight lines | parallel, evenly spaced lines | tilted plane | |
| straight lines through the origin | hyperbolas in the quadrants | saddle turned 45° |
Try it
The first line checks the saddle: 3 at , at , 0 on the line , then the slices and .
Then the plane along , falling by 1 every 0.5, and the product. The last lines check that is a difference of squares, and print the eigenvalues of both quadratic forms.
The same ideas reach functions of three or more variables, such as the volume of a box. Their graphs need more dimensions than paper has, but slices and partial derivatives (lesson 4.1.2) still work.
Common mistakes
- The order of the inputs matters. For , but .
- A level curve's label is a height, not a distance. crosses the -axis at 2, not at 4.
- Close curves mean steep, not high. The bowl's crowded outer curves are steep sides; the height is in the labels.
- Level curves of different heights never cross. One point has one height. The saddle's two lines where cross, but they are the same level.
- Check the domain. has no value at , and none on the line .
- A slice fixes the other input at a number. The slice of is , a function of alone.
Functions of two variables
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 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,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for 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 for each point of its domain, the region where the rule makes sense. A grid of values is its table.
- Its graph is a surface, at height above each point.
- A slice fixes one input: is a function of alone, the curve cut by the plane .
- A level curve is , all points at height ; a contour map shows several. Close curves mean steep, and curves of different heights never cross.
- Bowl : ellipses. Saddle : hyperbolas. Plane: parallel, evenly spaced lines. : hyperbolas, the saddle turned 45°.