Foundations to Frontier
Tests
A. Mathematical Foundations › A3 Calculus and Analysis › Multivariable calculus

Functions of Several Variables, Level Sets and Contour Plots

Most real quantities depend on many inputs. A loss depends on millions of weights, and a robot's cost on its position. Level sets and contour plots make these functions visible, show where minima and narrow valleys are, and give robots signed distance fields for collision avoidance.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Maps of mountains

A hiking map can’t show height directly, because paper is flat. Instead it draws contour lines: each line joins points at the same height, such as 100 m, 200 m or 300 m. Where the lines crowd together, the ground is steep. Where they spread out, it’s gentle. A ring of rings is a hilltop or a hollow.

Height depends on two inputs, east–west and north–south position. A function with several inputs is a function of several variables. Each contour line is a level set: all the places where the function equals one value.

Contour maps: a 3-D surface drawn on flat paper
probe (click the map): (0.80, 0.50) → f = 0.8900 · range of f on the box: 0.00 to 8.00
Blue = low, orange = high; white curves are level sets f = c. Level sets are circles; equal spacing in f gives contours that crowd together further out (steeper).
Why engineers care

A Mars rover plans its drive on a “cost map”: a function of position that is high near rocks and steep slopes and low on safe ground. Planners read this map like contour lines, steering along low ground and away from the crowded high contours around hazards.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Contour lines packed close together mean the ground is…
  2. 2. All points on one contour line have the same…
  3. 3. Which is higher, the 200 m line or the 100 m line?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Notation and pictures

A function f:R2→Rf:\mathbb R^2\to\mathbb R takes (x,y)(x,y) to a number. Its graph z=f(x,y)z = f(x,y) is a surface in 3-D. Its level sets are

Lc={(x,y):f(x,y)=c}L_c = \{(x,y) : f(x,y) = c\}
f(x,y)f(x,y) Level sets Picture
x2+y2x^2 + y^2 circles of radius c\sqrt c a bowl
x2+4y2x^2 + 4y^2 ellipses an elongated bowl
x2−y2x^2 - y^2 hyperbolas a saddle
xyxy hyperbolas y=c/xy = c/x a saddle rotated 45°
x+yx + y parallel lines a tilted plane

For three inputs, the level sets are surfaces, like the “isosurfaces” of temperature in a room. In nn dimensions, you can’t draw the function, but level sets still make sense.

📝 Quick check (Level 1)
0/3 answered
  1. 1. f(x, y) = x² + y² at (3, 4)?
  2. 2. The level set x² + y² = 9 is a circle of radius…
  3. 3. The level sets of x² − y² are…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Limits and continuity need every direction

lim⁡(x,y)→(a,b)f=L\lim_{(x,y)\to(a,b)}f = L means ff gets close to LL however (x,y)(x,y) approaches, from every direction and along every curve. For f=xyx2+y2f = \frac{xy}{x^2+y^2}, the line y=mxy = mx gives m1+m2\frac m{1+m^2}. That’s 0 along the axes and ½ along y=xy = x, so the limit at the origin does not exist.

Sublevel sets and convexity

The sublevel set {f≤c}\{f\le c\} is the region inside a contour. If ff is convex, every sublevel set is convex. The converse fails, and functions with convex sublevel sets are called quasi-convex. Non-convex losses like Himmelblau’s have sublevel sets made of separate islands. Those islands are the multiple minima that make optimization hard.

Where several-variable functions appear

Field Function
ML loss L(w)L(\mathbf w) over all weights; contour slices show the valleys optimizers must navigate
robotics cost maps, potential fields, signed distance to obstacles
physics temperature T(x,y,z)T(x,y,z), potential energy, pressure fields
statistics likelihoods and densities, e.g. a 2-D Gaussian with elliptical contours
🐍 Exercise 1: tabulating functions and finding level sets
Evaluate f on a grid, and find where a horizontal line crosses the level set f = c (circles, ellipses, hyperbolas) by sign changes.
📝 Quick check (Level 2)
0/3 answered
  1. 1. xy/(x² + y²) along y = x tends to…
  2. 2. Sublevel sets of a convex function are…
  3. 3. x² + 4y² = 4 crosses the y-axis at y = …

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

The precise definition, and a trap

lim⁡x→af(x)=L\lim_{\mathbf x\to\mathbf a}f(\mathbf x) = L iff for all ε>0\varepsilon>0 there is δ>0\delta>0 with 0<∥x−a∥<δ⇒∣f(x)−L∣<ε0<\lVert\mathbf x - \mathbf a\rVert<\delta\Rightarrow\lvert f(\mathbf x) - L\rvert<\varepsilon. Here the distance is any norm on Rn\mathbb R^n; they are all equivalent (A2.1-2).

Trap. g(x,y)=xy2x2+y4g(x,y) = \frac{xy^2}{x^2+y^4} tends to 0 along every straight line through the origin. Along the parabola x=y2x = y^2, however, g=y42y4=12g = \frac{y^4}{2y^4} = \frac12. So the limit doesn’t exist, even though every line suggests 0. One counterexample path settles non-existence. Proving existence needs an estimate valid in every direction, such as polar coordinates or a squeeze.

Proof: convex functions have convex sublevel sets

If f(p)≤cf(\mathbf p)\le c and f(q)≤cf(\mathbf q)\le c, convexity gives f(λp+(1−λ)q)≤λf(p)+(1−λ)f(q)≤cf(\lambda\mathbf p + (1-\lambda)\mathbf q)\le\lambda f(\mathbf p) + (1-\lambda)f(\mathbf q)\le c. ∎

When is a level set a nice curve?

If ff is smooth and its gradient (A3.2-3) is nonzero at a point of LcL_c, the implicit function theorem says that near that point LcL_c is a smooth curve (a surface, in higher dimensions). Where the gradient vanishes, at critical points, level sets can cross or collapse to a point. The 0-level of x2−y2x^2 - y^2 is an X.

Exercise 3.1: Show that xy/(x² + y²) is bounded even though it has no limit at 0

∣xy∣≤12(x2+y2)\lvert xy\rvert\le\frac12(x^2 + y^2) (from (∣x∣−∣y∣)2≥0(\lvert x\rvert - \lvert y\rvert)^2\ge0), so ∣f∣≤12\lvert f\rvert\le\frac12. It is bounded but direction-dependent, so it has no limit.

📝 Quick check (Level 3)
0/3 answered
  1. 1. xy²/(x² + y⁴) along x = y² →
  2. 2. Limits along all straight lines agree. Does the limit exist?
  3. 3. A level set may fail to be a smooth curve where…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Signed distance fields

The signed distance function d(p)d(\mathbf p) to an obstacle set is positive outside, zero on the boundary and negative inside. Its zero level set is the obstacle’s surface, and it satisfies ∥∇d∥=1\lVert\nabla d\rVert = 1 (the eikonal equation). Motion planners like CHOMP (Ratliff et al., 2009) and TrajOpt push trajectories toward larger dd. Neural networks learn SDFs of whole scenes for mapping and grasping (DeepSDF, Park et al., 2019; iSDF, Ortiz et al., 2022).

🐍 Exercise 2 (research): a signed distance field for a robot's workspace
Build the SDF of three disc obstacles. Show the straight path collides (negative clearance) while a weaving path stays clear, and check |∇d| = 1 numerically.

More research uses of level sets

  • Loss-landscape visualization. Plotting a 2-D slice L(w∗+αu+βv)L(\mathbf w^* + \alpha\mathbf u + \beta\mathbf v) through random, filter-normalized directions showed why skip connections make landscapes smoother (Li et al., 2018).
  • Artificial potential fields (Khatib, 1986) navigate robots downhill on attractive-plus-repulsive functions, like the “robot cost map” in the demo. Spurious local minima, islands in the sublevel sets, are their known weakness.
  • Level-set methods (Osher and Sethian, 1988) represent moving boundaries as the zero level set of an evolving function. They are used for fluid interfaces, image segmentation and shape optimization of aerospace structures.
  • Probability. The contours of a 2-D Gaussian are ellipses set by the covariance (A2.3-3). Confidence regions in robot localization are drawn exactly this way.

References

  1. O. Khatib (1986). “Real-time obstacle avoidance for manipulators and mobile robots.” International Journal of Robotics Research, 5(1).
  2. S. Osher, J. Sethian (1988). “Fronts propagating with curvature-dependent speed.” Journal of Computational Physics, 79(1).
  3. N. Ratliff, M. Zucker, J. A. Bagnell, S. Srinivasa (2009). “CHOMP: Gradient optimization techniques for efficient motion planning.” ICRA.
  4. H. Li, Z. Xu, G. Taylor, C. Studer, T. Goldstein (2018). “Visualizing the loss landscape of neural nets.” NeurIPS.
  5. J. J. Park, P. Florence, J. Straub, R. Newcombe, S. Lovegrove (2019). “DeepSDF: Learning continuous signed distance functions for shape representation.” CVPR.
  6. J. Ortiz, A. Clegg, J. Dong, E. Sucar, D. Novotny, M. Zollhoefer, M. Mukadam (2022). “iSDF: Real-time neural signed distance fields for robot perception.” RSS.
  7. J. Stewart (2015). Calculus: Early Transcendentals, 8th ed. Chapter 14.