Search

Search papers and lessons

Multivariable Function

Level 1 · 8 min read

A multivariable function takes several numbers as input and returns one number, like a bill that depends on how many apples and pears you buy.

On this page

TL;DR

A multivariable function takes several numbers as input and returns a single number as output. Give it a position on a map and it can return the height of the ground there. Give it how many apples and pears you buy and it returns the total bill. The rule is still one rule; it just reads more than one input.

Where you'll see it: in cost and profit formulas with several choices, in height maps and temperature maps, and in the loss a neural network is trained to make small.

Intuition

One rule, several slots

A function of one variable is a machine with one slot. You feed in a number and it gives one back. A multivariable function is the same kind of machine with several slots, and it still gives back one number.

Take a shopping bill. Apples cost 2 each and pears cost 3 each. If you buy aa apples and pp pears, the total is 2a+3p2a + 3p. Two slots, one output.

flowchart LR
  A[apples a] --> F[rule]
  B[pears p] --> F
  F --> C[total bill]

Why it exists

Real quantities depend on several things at once. The temperature in a room depends on where you stand and when you measure. The height of a hill depends on how far east and how far north you are. A function of one variable cannot describe a map. A multivariable function can, and it lets you ask useful questions, such as which combination of purchases gives the lowest bill.

Freeze all but one

The most useful trick is to hold every input fixed except one. What is left is an ordinary function of one variable, which you can graph as a curve.

Take the height of a bowl, f(x,y)=x2+y2f(x,y) = x^2 + y^2, where xx and yy are positions on the floor. Freeze yy at 0, then at 1, then at 2. You get three ordinary curves: x2x^2, x2+1x^2 + 1 and x2+4x^2 + 4. Each one is a slice through the bowl. The same freezing idea is the seed of partial derivatives, which measure how fast a function changes when only one input moves.

−3−2−101230510xheight f(x, y)
  • y = 0
  • y = 1
  • y = 2
Three slices of the bowl f(x, y) = x^2 + y^2, each with y held fixed. Each slice is an ordinary curve in x. The markers show the height at x = 0.

The math

Definition

Definition: Multivariable function

A function of nn variables is a rule ff that assigns to each input (x1,x2,…,xn)(x_1, x_2, \dots, x_n) in a set D⊆RnD \subseteq \mathbb{R}^n, called the domain, exactly one real number f(x1,x2,…,xn)f(x_1, x_2, \dots, x_n), called the output. Writing x=(x1,…,xn)\mathbf{x} = (x_1, \dots, x_n) gives the short form f(x)f(\mathbf{x}).

Here Rn\mathbb{R}^n means the set of all lists of nn real numbers. R1\mathbb{R}^1 is the number line, R2\mathbb{R}^2 is the flat plane, and R3\mathbb{R}^3 is ordinary space. A function of two variables is written f(x,y)f(x,y) and takes a point of the plane as input. A function of three variables is written f(x,y,z)f(x,y,z).

Graph and level sets

The graph of f(x,y)f(x,y) is the set of points (x,y,f(x,y))(x, y, f(x,y)) in three-dimensional space. It is a surface that sits over the plane, the way a hill sits over its base.

A level set collects all inputs that give the same output cc:

{ x:f(x)=c }.\{\, \mathbf{x} : f(\mathbf{x}) = c \,\}.

On a topographic map, each contour line is a level set of the height function: every point on the line is at the same altitude.

Linear functions

The simplest multivariable function is f(x,y)=ax+byf(x,y) = ax + by, where aa and bb are fixed numbers. Write a=(a,b)\mathbf{a} = (a, b) and x=(x,y)\mathbf{x} = (x, y). Then f(x)=a⋅xf(\mathbf{x}) = \mathbf{a} \cdot \mathbf{x}, a dot product.

Domains

A formula may not make sense for every input. The set of inputs where it does make sense is the domain. For f(x,y)=1/(x−y)f(x,y) = 1/(x - y), the domain is every pair with x≠yx \neq y, because division by zero is not allowed. For g(x,y)=1−x2−y2g(x,y) = \sqrt{1 - x^2 - y^2}, the domain is the set of points with x2+y2≤1x^2 + y^2 \le 1, a filled disc of radius 1.

Worked examples

Example
Evaluating by substitution

Let f(x,y)=x2+3xy−yf(x,y) = x^2 + 3xy - y. Find f(2,−1)f(2,-1) and f(0,5)f(0,5).

  1. Substitute x=2x = 2 and y=−1y = -1: f(2,−1)=22+3⋅2⋅(−1)−(−1)f(2,-1) = 2^2 + 3 \cdot 2 \cdot (-1) - (-1).
  2. Evaluate each term: 4+(−6)−(−1)4 + (-6) - (-1).
  3. Simplify: 4−6+1=−14 - 6 + 1 = -1.
  4. Substitute x=0x = 0 and y=5y = 5: f(0,5)=0+0−5=−5f(0,5) = 0 + 0 - 5 = -5.

The rule never changed. Only the numbers plugged into the slots did.

Example
A shopping bill

Apples cost 2 each and pears cost 3 each, so the bill is C(a,p)=2a+3pC(a,p) = 2a + 3p.

  1. Buy 4 apples and 2 pears: C(4,2)=2⋅4+3⋅2C(4,2) = 2 \cdot 4 + 3 \cdot 2.
  2. Simplify: 8+6=148 + 6 = 14.
  3. Now buy one more pear: C(4,3)=8+9=17C(4,3) = 8 + 9 = 17.
  4. The extra pear raised the bill by 33, which is the price of one pear. The coefficient of pp is the pear price because changing pp alone shifts the total by exactly that amount.
Example
A circle as a level set

Which points lie on the level set f(x,y)=x2+y2=25f(x,y) = x^2 + y^2 = 25?

  1. Check (3,4)(3,4): 32+42=9+16=253^2 + 4^2 = 9 + 16 = 25. So (3,4)(3,4) is on the level set.
  2. Check (5,0)(5,0): 25+0=2525 + 0 = 25. So (5,0)(5,0) is on it too.
  3. Check (3,3)(3,3): 9+9=18<259 + 9 = 18 \lt 25. So (3,3)(3,3) is not on it, and it lies inside the circle.
  4. Interpretation: the level set is the circle of radius 5 around the origin. Every point on that circle has output 25, like a contour line at one height.
Example
Finding a domain

Let g(x,y)=1−x2−y2g(x,y) = \sqrt{1 - x^2 - y^2}. A square root needs a number that is zero or positive, so the domain requires 1−x2−y2≥01 - x^2 - y^2 \ge 0.

  1. Rearrange: x2+y2≤1x^2 + y^2 \le 1.
  2. The points with x2+y2≤1x^2 + y^2 \le 1 are the points within distance 1 of the origin.
  3. Check (0.6,0.6)(0.6, 0.6): 0.36+0.36=0.72≤10.36 + 0.36 = 0.72 \le 1, so it is in the domain. Check (1,1)(1,1): 2>12 \gt 1, so it is not.
  4. Interpretation: the domain is a filled disc of radius 1. Outside it, gg has no value.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Plugging in values without checking the domainYou divide by zero or take a root of a negative numberSolve the domain condition first, then evaluate
Reading exact values off a 3D picture of a surfacePictures are imprecise, and perspective hides detailUse slices, level sets, or a table of values
Looking at one input and forgetting the othersBehaviour changes when another input changesFreeze one input, vary another, and compare slices
Going past three inputsNo picture fits, and intuition from space stops workingRely on the algebra, level sets, and tables

Two practical warnings:

  • Units matter. If xx is metres and yy is seconds, the output of x2+y2x^2 + y^2 mixes units and means nothing. Check that every term in a formula has the same units.
  • Not every multivariable function is a formula. A temperature map may be a table of measurements. The definition still applies, but you cannot always simplify it by hand.

History

René Descartes, in La Géométrie (1637), tied pairs of numbers to points in a plane. That idea let an equation in two unknowns describe a curve, and it made x2+y2=25x^2 + y^2 = 25 a shape you can see. Functions of several variables followed from that picture. In the 18th century, Leonhard Euler and others worked out how to differentiate them one variable at a time, which later became the theory of partial derivatives.

Contour lines on maps, which are level sets of height, were in common use by the nineteenth century. The same idea spread to physics, where a function giving one number at each point of space is called a scalar field. In 1928, Charles Cobb and Paul Douglas used a two-input production function to model how labour and capital combine to produce output. Economists still use the form today.

It caught on because one function can describe a whole landscape of possibilities, and a level set or a slice turns that landscape into something you can read.

Check yourself

QuestionWhat is the difference between a function of one variable and a function of two variables?Show answer

A function of one variable takes one number and returns one number, so its graph is a curve in the plane. A function of two variables takes a pair of numbers (x,y)(x,y) and returns one number, so its graph is a surface in three-dimensional space.

QuestionLet f(x,y)=3x−2y+1f(x,y) = 3x - 2y + 1. Compute f(2,5)f(2,5).Show answer

Substitute: 3⋅2−2⋅5+1=6−10+1=−33 \cdot 2 - 2 \cdot 5 + 1 = 6 - 10 + 1 = -3. So f(2,5)=−3f(2,5) = -3.

QuestionWhy does the level set of x2+y2x^2 + y^2 at value 25 form a circle, and what happens if you change 25 to 9?Show answer

The condition x2+y2=25x^2 + y^2 = 25 says the distance from the origin is 25=5\sqrt{25} = 5. Every point at distance 5 is on the set, which is a circle of radius 5. With value 9 the distance is 3, so the circle has radius 3. A larger output value gives a larger circle.

QuestionA bakery's profit is P(c,b)=4c+6b−30P(c,b) = 4c + 6b - 30, where cc is cakes sold and bb is loaves of bread sold. Compute the profit when 10 cakes and 5 loaves are sold. Which product adds more profit per unit?Show answer

P(10,5)=40+30−30=40P(10,5) = 40 + 30 - 30 = 40. Each loaf adds 6 to the profit and each cake adds 4, so a loaf adds more profit per unit sold.

Sources