21 Continuity and differentiability
Continuity and differentiability are fundamental concepts in calculus. For functions of several variables, the basic ideas are the same as for functions of one variable, but there are some important new features. In particular, a point in \(\mathbb{R}^n\) can be approached from infinitely many directions, and a function can have partial derivatives without being differentiable.
Continuity
Consider a function
\[ f:\mathbb{R}^n\to\mathbb{R}. \]
We say that \(f\) is continuous at \(\mathbf{a}\in\mathbb{R}^n\) if
\[ \lim_{\mathbf{x}\to\mathbf{a}}f(\mathbf{x})=f(\mathbf{a}). \]
More precisely, \(f\) is continuous at \(\mathbf{a}\) if, for every \(\epsilon>0\), there exists a \(\delta>0\) such that
\[ \|\mathbf{x}-\mathbf{a}\|<\delta \quad\Longrightarrow\quad |f(\mathbf{x})-f(\mathbf{a})|<\epsilon. \]
Here \(\|\mathbf{x}-\mathbf{a}\|\) denotes the Euclidean distance between \(\mathbf{x}\) and \(\mathbf{a}\). For a function of two variables, \(f(x,y)\), continuity at \((a,b)\) therefore means that \(f(x,y)\) approaches \(f(a,b)\) whenever \((x,y)\) approaches \((a,b)\).
An important difference from one-dimensional calculus is that \((x,y)\) can approach \((a,b)\) along infinitely many different paths. If different paths give different limiting values, the limit does not exist.
Partial derivatives
For a function of a single variable, the derivative is the slope, or rate of change, when that variable is increased by a small amount. For a function of several variables, however, we can study how the function changes when one variable is varied while all the other variables are held constant. This defines partial derivatives.
For a function \(f:\mathbb{R}^2\to\mathbb{R}\), the partial derivative with respect to \(x\) at \((a,b)\) is
\[ \frac{\partial f}{\partial x}(a,b) = \lim_{h\to0} \frac{f(a+h,b)-f(a,b)}{h}, \]
provided that the limit exists. Similarly,
\[ \frac{\partial f}{\partial y}(a,b) = \lim_{h\to0} \frac{f(a,b+h)-f(a,b)}{h}. \]
Thus, \(\partial f/\partial x\) measures the rate of change of \(f\) in the \(x\) direction, while \(\partial f/\partial y\) measures the rate of change in the \(y\) direction.
For a function \(f:\mathbb{R}^n\to\mathbb{R}\), the partial derivatives can be collected into the gradient
\[ \nabla f(\mathbf{x}) = \begin{pmatrix} \frac{\partial f}{\partial x_1}\\ \vdots\\ \frac{\partial f}{\partial x_n} \end{pmatrix}. \]
The gradient will play an important role throughout multivariable calculus. In quantum chemistry, for example, the gradient of an energy with respect to nuclear coordinates gives information about how the energy changes when the molecular geometry is displaced.
For functions \(f : \mathbb{R}^n \to \mathbb{R}^m\), the matrix of partial derivatives is called the Jacobian,
\[ J_f = \frac{\partial (f_1,\dots,f_m)}{\partial (x_1,\dots,x_n)} = \begin{pmatrix} \frac{\partial f_1}{\partial x_1} & \cdots & \frac{\partial f_1}{\partial x_n} \\ \vdots & \ddots & \vdots \\ \frac{\partial f_m}{\partial x_1} & \cdots & \frac{\partial f_m}{\partial x_n} \end{pmatrix}. \]
The function \(f\) is differentiable at \(\mathbf{x}_0\) if the Jacobian matrix exists and provides a good linear approximation to the function near that point:
\[ f(\mathbf{x}_0+\mathbf{h}) \approx f(\mathbf{x}_0) +J_f(\mathbf{x}_0)\mathbf{h}, \]
Differentiability
In single-variable calculus, differentiability means that sufficiently close to a point, a function is well approximated by a straight line. The same idea applies in several dimensions: a differentiable function is locally well approximated by a linear function.
For \(f:\mathbb{R}^n\to\mathbb{R}\), we say that \(f\) is differentiable at \(\mathbf{a}\) if
\[ f(\mathbf{a}+\mathbf{h}) = f(\mathbf{a}) + \nabla f(\mathbf{a})\cdot\mathbf{h} + r(\mathbf{h}), \]
where the remainder \(r(\mathbf{h})\) becomes negligible compared with \(\|\mathbf{h}\|\) as \(\mathbf{h}\to\mathbf{0}\):
\[ \lim_{\mathbf{h}\to\mathbf{0}} \frac{|r(\mathbf{h})|}{\|\mathbf{h}\|} =0. \]
Equivalently,
\[ f(\mathbf{a}+\mathbf{h}) = f(\mathbf{a}) + \nabla f(\mathbf{a})\cdot\mathbf{h} + o(\|\mathbf{h}\|). \]
For a function \(f(x,y)\), writing \(\mathbf{h}=(h,k)\) gives the perhaps more familiar expression
\[ f(a+h,b+k) \approx f(a,b) + \frac{\partial f}{\partial x}(a,b)h + \frac{\partial f}{\partial y}(a,b)k. \]
Geometrically, the graph \(z=f(x,y)\) is therefore approximated near \((a,b,f(a,b))\) by its tangent plane.
It is important to distinguish partial differentiability from differentiability. The existence of all partial derivatives at a point does not by itself imply that the function is differentiable there. Partial derivatives examine the function only along the coordinate directions, whereas differentiability requires a single linear approximation that works for small displacements in all directions.
There is, however, a very useful sufficient condition: if all the first partial derivatives exist and are continuous in a neighbourhood of a point, then the function is differentiable at that point. Thus, for the smooth functions encountered in most applications, differentiability can usually be established by computing the partial derivatives and checking that they are continuous.
Exercises: Continuity
Exercise 21.1 (A first discontinuity) Consider
\[f(x)=\begin{cases}1,&x>0,\\-1,&x\leq 0.\end{cases}\]
Compute \(f(-1)\), \(f(0)\), and \(f(1)\).
For \(x=1\), what value does \(f(x+h)\) have when \(h\) is sufficiently small? What is \(\lim_{h\to0}f(1+h)\)?
Approach \(x=0\) from the left and from the right. What values does \(f(h)\) take?
For which \(x\in\mathbb{R}\) does \(\lim_{h\to0}f(x+h)\) not exist? Explain in words.
Exercise 21.2 (Getting close in two dimensions) Let \(\mathbf{a}=(1,2)\) and \(\mathbf{x}=(x,y)\).
Write an expression for the Euclidean distance \(\|\mathbf{x}-\mathbf{a}\|\).
Compute this distance for \(\mathbf{x}=(1.1,2)\), \((1,1.9)\), and \((1.06,2.08)\).
Which of these points lie inside the disk \(\|\mathbf{x}-\mathbf{a}\|<0.1\)?
In your own words, explain what \(\mathbf{x}\to\mathbf{a}\) means.
Exercise 21.3 (Continuity by direct substitution) For each function below, evaluate the indicated limit by direct substitution. State briefly why this is allowed.
\(\displaystyle \lim_{(x,y)\to(1,2)}(x+2y)\).
\(\displaystyle \lim_{(x,y)\to(1,2)}x^2y\).
\(\displaystyle \lim_{(x,y)\to(0,0)}e^{-(x^2+y^2)}\).
\(\displaystyle \lim_{(x,y)\to(1,1)}\frac{x+y}{1+x^2+y^2}\).
Exercise 21.4 (Testing two paths) Consider
\[f(x,y)=\frac{x^2}{x^2+y^2},\qquad (x,y)\ne(0,0).\]
Set \(y=0\) and simplify \(f(x,0)\) for \(x\ne0\).
Set \(x=0\) and simplify \(f(0,y)\) for \(y\ne0\).
What value is approached along each axis as \((x,y)\to(0,0)\)?
Can \(\lim_{(x,y)\to(0,0)}f(x,y)\) exist? Why or why not?
Exercise 21.5 (Approaching a point with Python) Consider \(f(x,y)=x^2+y^2\).
By hand, compute \(f(0.1,0.1)\), \(f(0.01,0.01)\), and \(f(0.001,0.001)\).
Write a short Python loop that evaluates \(f(t,t)\) for \(t=10^{-1},10^{-2},\ldots,10^{-6}\).
What value do the results appear to approach?
Repeat for the path \((x,y)=(t,2t)\). Does the limiting value change?
Exercise 21.6 (Why polynomials are continuous) Use standard properties of continuous functions to show that every polynomial \(p:\mathbb{R}\to\mathbb{R}\) is continuous. Then explain briefly why a polynomial in two variables, such as \(p(x,y)=3x^2y-2xy+7\), is also continuous on \(\mathbb{R}^2\).
Exercise 21.7 (A radial limit) Consider
\[f(x,y)=\frac{\sin(x^2+y^2)}{x^2+y^2},\qquad (x,y)\ne(0,0).\]
Introduce \(r^2=x^2+y^2\) and rewrite the function in terms of \(r\).
Determine \(\lim_{(x,y)\to(0,0)}f(x,y)\) using the one-variable limit \(\lim_{t\to0}\sin t/t=1\).
How could \(f\) be defined at \((0,0)\) so that the resulting function is continuous there?
Exercise 21.8 (A path-dependent limit) Consider
\[f(x,y)=\frac{x^2}{x^2+y^2},\qquad (x,y)\ne(0,0).\]
Evaluate the limit along the line \(y=0\).
Evaluate the limit along the line \(x=0\).
Conclude whether \(\lim_{(x,y)\to(0,0)}f(x,y)\) exists.
As an optional visualization, make a surface plot or contour plot near the origin and relate what you see to parts a–c.
Exercise 21.9 (Bounding a function near the origin) Consider
\[f(x,y)=\frac{2x^2y}{x^2+y^2},\qquad (x,y)\ne(0,0).\]
Show that \(|f(x,y)|\leq2|y|\).
Use \(|y|\leq\sqrt{x^2+y^2}\) to obtain a bound in terms of \(\|(x,y)\|\).
Use the bound to prove with an \(\epsilon\)–\(\delta\) argument that \(\lim_{(x,y)\to(0,0)}f(x,y)=0\).
Exercise 21.10 (Making a function continuous) For \((x,y)\ne(0,0)\), define
\[f(x,y)=\frac{x^2y^2}{x^2+y^2}.\]
Show that \(0\leq f(x,y)\leq y^2\).
Determine \(\lim_{(x,y)\to(0,0)}f(x,y)\).
Choose a value for \(f(0,0)\) that makes \(f\) continuous at the origin.
Check your conclusion numerically along the paths \(y=x\) and \(y=x^2\).
Exercise 21.11 (Continuity of a model potential energy) A simple model potential energy is
\[E(x,y)=\frac12 k_xx^2+\frac12 k_yy^2+cxy,\]
where \(k_x,k_y,\) and \(c\) are constants.
Explain why \(E\) is continuous everywhere.
Evaluate \(\lim_{(x,y)\to(0,0)}E(x,y)\).
Let \(k_x=2\), \(k_y=3\), and \(c=1\). Compute \(E(0.1,0)\), \(E(0,0.1)\), and \(E(0.1,0.1)\).
What do these values suggest about the energy surface close to the origin?
Exercises: Differentiability
Exercise 21.12 (First partial derivatives) Let \(f(x,y)=x^2+3xy+y^2\).
To compute \(\partial f/\partial x\), treat \(y\) as a constant. Find \(\partial f/\partial x\).
To compute \(\partial f/\partial y\), treat \(x\) as a constant. Find \(\partial f/\partial y\).
Evaluate both partial derivatives at \((1,2)\).
Write the gradient \(\nabla f(1,2)\) as a column vector.
Exercise 21.13 (Partial derivatives as one-dimensional derivatives) Let \(f(x,y)=x^2y+y^3\) and consider the point \((1,2)\).
Hold \(y=2\) fixed and define \(g(x)=f(x,2)\). Write down \(g(x)\) and compute \(g'(1)\).
Hold \(x=1\) fixed and define \(h(y)=f(1,y)\). Write down \(h(y)\) and compute \(h'(2)\).
Compute \(\partial f/\partial x\) and \(\partial f/\partial y\) directly and check your answers from a and b.
Explain in one sentence what is held fixed when taking a partial derivative.
Exercise 21.14 (Using a gradient for a small displacement) Suppose an energy \(E(x,y)\) has
\[E(1,1)=5,\qquad \nabla E(1,1)=\begin{pmatrix}2\\-1\end{pmatrix}.\]
For a small displacement \(\mathbf{h}=(0.01,0)\), use the linear approximation to estimate the change in energy.
Repeat for \(\mathbf{h}=(0,0.01)\).
Repeat for \(\mathbf{h}=(0.01,0.01)\).
Estimate \(E(1.01,1.01)\).
Exercise 21.15 (A first Jacobian) Let \(F:\mathbb{R}^2\to\mathbb{R}^2\) be
\[F(x,y)=\begin{pmatrix}x+y\\xy\end{pmatrix}.\]
Identify the two component functions \(F_1\) and \(F_2\).
Compute \(\partial F_1/\partial x\) and \(\partial F_1/\partial y\).
Compute \(\partial F_2/\partial x\) and \(\partial F_2/\partial y\).
Assemble the four derivatives into the Jacobian matrix \(J_F(x,y)\) and evaluate it at \((1,2)\).
Exercise 21.16 (Partial derivatives of a radial quotient) For \((x,y)\ne(0,0)\), let
\[f(x,y)=\frac{xy}{\sqrt{x^2+y^2}}.\]
Compute \(\partial f/\partial x\).
Compute \(\partial f/\partial y\).
Evaluate the gradient at \((1,1)\).
Is the formula defined at the origin? What additional question would have to be answered before discussing differentiability there?
Exercise 21.17 (Linear approximation) Let \(f(x,y)=e^x\cos y\).
Compute \(\nabla f(x,y)\).
Find the linear approximation to \(f\) near \((0,0)\).
Use it to estimate \(f(0.02,0.03)\).
Compare with a Python evaluation of
exp(0.02)*cos(0.03).
Exercise 21.18 (Tangent plane to an energy surface) Consider \(E(x,y)=x^2+xy+2y^2\).
Compute \(\nabla E(x,y)\).
Find \(E(1,1)\) and \(\nabla E(1,1)\).
Write the tangent-plane approximation to \(E\) near \((1,1)\).
Use it to estimate \(E(1.02,0.99)\) and compare with the exact value.
Exercise 21.19 (Checking differentiability efficiently) Let
\[f(x,y)=x^3\sin y+e^{xy}.\]
Compute the two first partial derivatives.
Explain why these partial derivatives are continuous everywhere.
Use the sufficient condition from the text to conclude that \(f\) is differentiable everywhere.
Compute \(\nabla f(0,0)\) and write the linear approximation near the origin.
Exercise 21.20 (A numerical gradient with finite differences) Let \(f(x,y)=x^2+xy+3y^2\).
Compute \(\nabla f(1,2)\) analytically.
Approximate \(\partial f/\partial x\) at \((1,2)\) by
\[\frac{f(1+h,2)-f(1,2)}{h}\]
for \(h=10^{-1},10^{-2},10^{-3}\).
Do the same for \(\partial f/\partial y\).
Write a tiny Python script for b and c. How do the approximations behave as \(h\) becomes smaller?
Exercise 21.21 (Checking multivariable limits along different paths) Define
\[f(x,y)=\begin{cases}\dfrac{x^2y}{x^4+y^2},&(x,y)\ne(0,0),\\0,&(x,y)=(0,0).\end{cases}\]
Along a straight line \(y=mx\), show that \(f(x,mx)\to0\) as \(x\to0\).
Along the curved path \(y=x^2\), determine the limiting value.
Is \(f\) continuous at the origin?
What does this example teach you about checking multivariable limits using paths?
Exercise 21.22 (Partial derivatives without continuity) Define
\[f(x,y)=\begin{cases}\dfrac{xy}{\sqrt{x^2+y^2}},&(x,y)\ne(0,0),\\0,&(x,y)=(0,0).\end{cases}\]
Show that \(f\) is continuous at the origin by finding a useful bound for \(|f(x,y)|\).
Compute \(\partial f/\partial x(0,0)\) and \(\partial f/\partial y(0,0)\) directly from the definitions.
Test differentiability at the origin along the path \((x,y)=(t,t)\).
Reconcile your result with the statement that continuous first partial derivatives are sufficient for differentiability.
Exercise 21.23 (Explore a two-dimensional energy landscape) Consider the model energy
\[E(x,y)=(x^2-1)^2+y^2+\frac12xy.\]
Compute the gradient \(\nabla E(x,y)\).
Use Python to make a contour plot of \(E\) on \(-2\leq x\leq2\), \(-2\leq y\leq2\).
On the same grid, make a quiver plot of \(-\nabla E\), or plot a separate vector field if that is clearer.
Locate the stationary points numerically or analytically. Which appear to be minima, maxima, or saddle points? Describe how the gradient field reflects this.
Exercise 21.24 (A numerical experiment with the definition of differentiability) Let \(f(x,y)=\sin(xy)+x^2\) and let \(\mathbf{a}=(1,1)\).
Compute \(f(\mathbf{a})\) and \(\nabla f(\mathbf{a})\).
For a displacement \(\mathbf{h}\), define the linearization error
\[R(\mathbf{h})=f(\mathbf{a}+\mathbf{h})-f(\mathbf{a})-\nabla f(\mathbf{a})\cdot\mathbf{h}.\]
Write a short Python program that evaluates \(|R(\mathbf{h})|/\|\mathbf{h}\|\) for \(\mathbf{h}=t(1,2)\) and \(t=10^{-1},\ldots,10^{-7}\).
Repeat for a few random directions. What numerical behavior do you expect if \(f\) is differentiable at \(\mathbf{a}\)? Do you observe it?