$\newcommand{\ds}{\displaystyle}$ $\newcommand{\Rr}{\mathbb{R}}$ $\newcommand{\Qq}{\mathbb{Q}}$ $\newcommand{\Nn}{\mathbb{N}}$ $\newcommand{\lint}{\underline{\int}}$ $\newcommand{\uint}{\overline{\int}}$ $\newcommand{\sgn}{\mathrm{sgn}}$ $\newcommand{\ve}{\varepsilon}$ $\newcommand{\norm}[1]{\left\| #1 \right\|}$ $\newcommand{\mbf}{\mathbf}$ $\newcommand{\vx}{\mbf{x}}$ $\newcommand{\ve}{\mbf{e}}$ $\newcommand{\vh}{\mbf{h}}$ $\newcommand{\va}{\mbf{a}}$

Functions of several variables¶

Here are two referrence pages Part I Part II

Differentiability¶

Let $U$ be an open subset of $\Rr^n$, we say that $f \colon U \to \Rr$ is differentiable at $\vx_0 \in U$ if there exists a linear map $L \colon \Rr^n \to \Rr$ such that

$$\lim_{\vx \to \vx_0} \frac{f(\vx) - f(\vx_0) - L(\vx - \vx_0)}{\norm{\vx - \vx_0}} = 0 \tag{1}$$

The linear map $L$ depends on $\vx_0$ and is usually denoted by $\nabla f(\vx_0)$ (called the graident of $f$ at $\vx_0$)

Remark Here $\norm{\cdot}$ denotes the Euclidean norm not the sup norm $\norm{\cdot}_{\infty}$.

More generally, a function $f \colon \Rr \to \Rr^m$ is differentiable at $\vx_0 \in U$ if its $i$-th component function $f^i:=\pi^i \circ f$ is differentiable at $\vx_0$ for each $i$.

Recall $\pi^i \colon \Rr^m \to \Rr$ is the projection of $\Rr^m$ to its $i$-th coordinate.

We often write $f = (f^1, f^2, \cdots, f^m)$ for a function $f$ that takes values in $\Rr^m$.

Proposition 1 If $f \colon U \to \Rr^m$ is differentiable at $\vx_0$ then $f$ is continuous at $\vx_0$.

Proof. Note that $f$ is continuous at $\vx_0$ if and only if each $f^i$ is. Therefore, it sufficies to show the proposition for $m=1$. Clearly $\lim_{\vx \to \vx_0} \norm{\vx - \vx_0} = 0$. So the fact that $f$ is differentiable at $\vx_0$ implies

\begin{align*} 0 & = \lim_{\vx \to \vx_0} \norm{\vx \to \vx_0} \lim_{\vx \to \vx_0} \frac{f(\vx) - f(\vx_0) - \nabla f(\vx_0)(\vx - \vx_0)}{\norm{\vx - \vx_0}} \\ { }\\ & = \lim_{\vx \to \vx_0} f(\vx) - (f(\vx_0) + \nabla f(\vx_0)(\vx-\vx_0)) \end{align*}

Since linear functions are continuous, $\lim_{\vx \to \vx_0} \nabla f(\vx_0)(\vx - \vx_0) = 0$. Hence, we conclude that

$$ \lim_{\vx \to \vx_0} f(\vx) = f(\vx_0)$$

For each $1 \le j \le n$, let $\ve_j$ denote the vector $(0,\ldots 1, \ldots 0)$ (the '$1$' appears in the $j$-th coordinate). If $f$ is differentiable at $\vx_0$, then

\begin{align*} \lim_{t \to 0} \frac{f(\vx_0 + t\ve_j) - f(\vx_0) - \nabla f(\vx_0)(t\ve_j)}{\norm{t\ve_j}} &= 0 \\ \lim_{t\to 0} \frac{f(\vx_0 +t\ve_j) - f(\vx_0)}{t} - \frac{t\nabla f(\vx_0)(\ve_j)}{t} & = 0 \end{align*}

That means the limit $$\ds \lim_{t\to 0} \frac{f(\vx_0 +t\ve_j) - f(\vx_0)}{t} \tag{2}$$ exists and is the $j$-th component of $\nabla f(\vx_0)$.

The limit above, if exists, is the partial derivative of $f$ with respect to $x_j$ and is usually denoted by

$$ \frac{\partial f}{\partial x_j}(\vx_0),\ D_j f(\vx_0), \text{or}\ f_{x_j}(\vx_0). $$

Remark The partial derivative of $f$ wrt $x_j$ at $\vx_0$ exists exactly means the 1-variable function

$$t \mapsto f(\vx_0+t\ve_j)$$

is differentiable at $t=0$ and its derivative in that case is $D_j f(\vx_0)$.

Thus, we have just proved that

Proposition 2. If $f \colon U \to \Rr^m$ is differentiable at $\vx_0 \in U$, then each partial derivative of $f$

$$ \frac{\partial f^i}{\partial x_j}(\vx_0)\quad (1 \le i \le m, 1 \le j \le n)$$ exists.

Suppose all parital derivatives of $f$ at $\vx_0$ exist, the $m \times n$ matrix

$$\ds Df(\vx_0) = \left(\frac{\partial f^i}{\partial x_j}(\vx_0)\right)$$

is called the Jacobian matrix of $f$ at $\vx_0$.

If $f$ is differentiable at $\vx_0$, the linear map represented by $Df(\vx_0)$ with respect to the standard bases is called the derivative of $f$ at $\vx_0$.

The determinant of $Df(\vx_0)$ is often referred as the Jacobian of $f$ at $\vx_0$.

The converse of Proposition 2 is not true as the following example demonstrates.

A function that has partial derivatives in all directions but not differentiable.¶

Consider the function $f \colon \Rr^2 \to \Rr$ defined by $$ f(x,y) = \begin{cases} \dfrac{x^2y}{x^4 + y^2} & (x,y) \neq (0,0)\\ 0 & (x,y) = (0,0) \end{cases} $$

In [1]:
var('z,y'); f(x,y) = x^2*y/(x^4 + y^2)
In [2]:
G=implicit_plot3d(z-f(x,y),(x,-1,1),(y,-1,1),(z,-1,1),aspect_ratio=(1,1,1), plot_points=60); G
Out[2]:

Note that for any $\theta$ and $t \neq 0$, $$ \frac{f(t\cos(\theta),t\sin(\theta))-f(0,0)}{t-0} = \frac{\cos^2(\theta)\sin(\theta)}{t^2\cos^4(\theta) + \sin^2(\theta)}$$

Thus, the directional derivative of $f$ exists for any direction $(\cos(\theta),\sin(\theta))$ and is

$0$ is $\sin(\theta) = 0$ or $\ds \frac{\cos^2(\theta)}{\sin(\theta)}$ if $\sin(\theta) \neq 0$.

However, $\ds f(x,x^2) = \frac{1}{2}$ for all $x\neq 0$. So, $f(x,y)$ is not even continuous (let alone differentiable) at $(0,0)$.

Continuously Differentiable Functions¶

A function $f \colon U \to \Rr^m$ is continuously differentiable (or of class $C^1$) at $\vx_0 \in U$ if its partial derivatives at $\vx_0$ exist on a neighborhood of $\vx_0$ and are continuous.

Theorem 1. If $f$ is continuously differentiable at $\vx_0$ then $f$ is differentiable at $\vx_0$.

Proof. It suffices to establish the case $m=1$. In that case, we need to show that

$$ \lim_{\vh \to 0} \frac{|f(\vx_0 + \vh) - f(\vx_0) - \nabla f(\vx_0)\vh|}{\norm{\vh}} = 0 $$

So let $\vh = (h_1, \ldots, h_n) \neq \mbf{0}$ sufficiently close to $\mbf{0}$.

The key trick is to express the difference $f(\vx_0 + \vh) - f(\vx_0)$ as a telescopic sum:

$$ f(\vx_0 + \vh) - f(\vx_0) = \sum_{j=1}^{n} f(\vx_j) - f(\vx_{j+1}) \tag{3}$$

where $\vx_i = \vx_0 + (0,\ldots,0, h_i, \ldots, h_n)$. (Note that $\vx_1 = \vx_0 + \vh$ and $\vx_{n+1} = \vx_0$)

For each $1 \le j \le n$, since $\partial f/\partial x_j$ exist near $\vx_0$, by the Mean Value Theorem,

$$ f(\vx_j) - f(\vx_{j+1}) = \frac{\partial f}{\partial x_j}(\va_j)h_j$$

where $\va_j = \vx_0 + (0,\ldots,0,a_j,h_{j+1},\ldots,h_n)$ for some $a_j$ lies between $0$ and $h_j$.

So, it follows from $(3)$ that

$$ f(\vx_0 + \vh) -f(\vx_0) - \nabla f(\vx_0)(\vh) = \sum_{j=1}^n \left(\frac{\partial f}{\partial x_j}(\va_j) - \frac{\partial f}{\partial x_j}(\vx_0)\right) h_j $$

By the triangle inequality,

$$ \lvert f(\vx_0 + \vh) -f(\vx_0) - \nabla f(\vx_0)(\vh) \rvert \le \sum_{j=1}^n \left\vert \frac{\partial f}{\partial x_j}(\va_j) - \frac{\partial f}{\partial x_j}(\vx_0)\right\vert |h_j| \le \norm{\vh}\sum_{j=1}^n \left\vert \frac{\partial f}{\partial x_j}(\va_j) - \frac{\partial f}{\partial x_j}(\vx_0)\right\vert.$$

Thus,

$$ \frac{\lvert f(\vx_0 + \vh) -f(\vx_0) - \nabla f(\vx_0)(\vh) \rvert}{\norm{\vh}} \le \sum_{j=1}^n \left\vert \frac{\partial f}{\partial x_j}(\va_j) - \frac{\partial f}{\partial x_j}(\vx_0)\right\vert \to 0$$

as $\vh \to \mbf{0}$ by continuity of the partial derivatives of $f$ at $\vx_0$.

A differentiable function that in not continuously differentiable¶

Let $f \colon \Rr^2 \to \Rr$ be the function defined by

$$ f(x,y)=\begin{cases}(x^2+y^2)\sin\left(\dfrac{1}{\sqrt{x^2+y^2}}\right) & \text{ if } (x,y) \ne (0,0)\\ 0 & \text{ if }(x,y) = (0,0).\end{cases} $$

Clearly, this is the two dimensional analog of the function $f(x) = x^2\sin(1/x)$ for $x\neq 0$ and $f(0)=0$.

In [3]:
f(x,y)=(x^2+y^2)*sin(1/sqrt(x^2+y^2))
In [4]:
plot3d(f,(-0.1,0.1),(-0.1,0.1), aspect_ratio=(1,1,2))
Out[4]:

It is differentiable at the origin since

$$ \left\vert \frac{f(x,y) – f(0,0)}{\sqrt{x^2+y^2}} \right\vert \le \frac{x^2+y^2}{\sqrt{x^2+y^2}} = \Vert (x,y) \Vert \mathrel{\mathop{\longrightarrow}_{(x,y) \to (0,0)}} 0 $$

Its partial derivatives at the origin are both zeros:

\begin{align*} \frac{\partial f}{\partial x}(0,0) &= \lim_{h \to 0} \frac{f(h,0)-f(0,0)}{h}\\ &= \lim_{h \to 0}\frac{h^2 \sin (1/|h|)-0}{h} \\ &= \lim_{h \to 0}h \sin (1/|h|) =0. \end{align*}

A similar computation shows that $\ds \frac{\partial f}{\partial y}(0,0)=0$.

For $(x,y) \neq (0,0)$, the partial derivatives can be computed by the usual rules of differentiation:

\begin{align*} \frac{\partial f}{\partial x}(x,y) &= 2 x \sin \left(\frac{1}{\sqrt{x^2+y^2}}\right)-\frac{x \cos \left(\frac{1}{\sqrt{x^2+y^2}}\right)}{\sqrt{x^2+y^2}}\\ \frac{\partial f}{\partial y}(x,y) &= 2 y \sin \left(\frac{1}{\sqrt{x^2+y^2}}\right)-\frac{y \cos \left(\frac{1}{\sqrt{x^2+y^2}}\right)}{\sqrt{x^2+y^2}}. \end{align*}

To see that the partial derivatives are not continuous at the origin, we can for example approach $(0,0)$ from the positive $x$-axis. Note that for $h >0$,

$$ \frac{\partial f}{\partial x}(h,0) = 2h\sin(1/h) - \cos(1/h) $$

And $\ds \lim_{h \to 0^+} \frac{\partial f}{\partial x}(h,0)$ does not exist (as in the 1-dimensional case). This shows that $\ds \frac{\partial f}{\partial x}$ is not continuous at $(0,0)$.

By symmetry, $\ds \frac{\partial f}{\partial y}$ is not continuous at the origin either.

Higher Partial Derivatives¶

Let $f \colon U \to \Rr^m$. Suppose $\ds \frac{\partial f}{\partial x_j}(\vx)$ exists for each $\vx \in U$, then denote the function

$$ \vx \mapsto \frac{\partial f}{\partial x_j}(\vx) $$

by $\ds \frac{\partial f}{\partial x_j}$ and we call it a 1st order partial derivative of $f$.

For $n >1$, an $n$-th order partial derivative of $f$ is a (1st order) partial derivative of an $(n-1)$-th order partial derivative of $f$.

One can regard $f$ itself as the $0$-th order partial derivative of $f$.

In general the order of taking partial derivative matters as the following example demonstrates.

A function with $f_{xy}(0,0) \neq f_{yx}(0,0)$¶

The function $f \colon \Rr^2 \to \Rr$ defined by

$$ f(x,y) = \begin{cases} \dfrac{xy(x^2-y^2)}{x^2+y^2} & (x,y) \neq (0,0) \\ 0 & (x,y) = (0,0) \end{cases} $$

For $(x,y) \neq (0,0)$

\begin{align*} \left\vert \frac{f(x,y)-f(0,0)}{\sqrt{x^2+y^2}} \right\vert & = \left\vert \frac{xy(x^2-y^2)}{\sqrt{x^2+y^2}(x^2+y^2)} \right\vert\\ & \le \left\vert \frac{xy}{\sqrt{x^2+y^2}} \right\vert\\ & \le \frac{(\vert x \vert + \vert y \vert)^2}{2 \sqrt{x^2+y^2}}\\ & \le \sqrt{x^2+y^2}\end{align*}

The last two inequalities follow from the fact that for all $(x,y) \in \Rr^2$

$\vert xy \vert \le \dfrac{(\vert x \vert +\vert y \vert)^2}{2}$ and $(\vert x \vert +\vert y \vert)^2 \le 2 (x^2+y^2)$ respectively.

This shows that the derivative of $f$ at $(0,0)$ is the $0$ linear map.

And so $f_x(0,0) = 0 = f_y(0,0)$.

For $(x,y) \neq (0,0)$, we have

\begin{cases} \dfrac{\partial f}{\partial x}(x,y) = \dfrac{(x^2+y^2)(3x^2y-y^3)+2x^2y(y^2-x^2)}{(x^2+y^2)^2}\\ \dfrac{\partial f}{\partial y}(x,y) = \dfrac{(x^2+y^2)(x^3-3x y^2)+2xy^2(y^2-x^2)}{(x^2+y^2)^2} \end{cases}

In particular,

\begin{align*} \frac{\partial f}{\partial x}(0,y) &= -y \text{ for } y \neq 0\\ \frac{\partial f}{\partial y}(x,0) &= x \text{ for } x \neq 0 \end{align*}

And so,

$$ \frac{\partial^2 f}{\partial x \partial y}(0,0) =1 \neq -1 = \frac{\partial^2 f}{\partial y \partial x}(0,0) $$

However,

Theorem 3. Suppose the 2nd order partial derivatives of $f$ exist on some neighborhood of $\vx_0$ and are continuous at $\vx_0$. Then

$$ \frac{\partial^2 f}{\partial x_j \partial x_i}(\vx_0) = \frac{\partial^2 f}{\partial x_i \partial x_j}(\vx_0)$$

Proof. For notation simplicity, we prove the Theorem for functions of 2-variables but the proof can be easily extended to the general case.

Consider the expression

$$ f(x_0+h, y_0+k) - f(x_0+h,y_0) - f(x_0, y_0 + k) + f(x_0,y_0) \tag{*}$$

For a fixed $y_0$ and $k$, it follows from the differentiability assumption that the function

$$ g(t) = f(t,y_0+k) - f(t,y_0) $$

is continuous on the closed interval with endpoints $x_0$ and $x_0+h$ and differentiable on the open interval with the same endpoints.

Then expression $(*)$ can be rewritten as

$$ g(x_0+h) - g(x_0) $$

Hence, by the MVT, $(*)$ equals

$$g'(c_1)h = \left(\frac{\partial f}{\partial x}(c_1,y_0+k) - \frac{\partial f}{\partial x}(c_1,y_0)\right)h$$

for some $c_1$ that lies between $x_0$ and $x_0+h$

Now by a similar argument applying to the function

$$t \mapsto \frac{\partial f}{\partial x}(c_1,t) $$

We conclude that $(*)$ equals $\ds \frac{\partial^2 f}{\partial y\partial x}(c_1,c_2)hk$ for some $c_2$ between $y_0$ and $y_0+k$.

Thus, by continuous of the 2nd partial derivatives at $(x_0,y_0)$ we conclude that

$$ \frac{\partial^2 f}{\partial y \partial x}(x_0,y_0) = \lim_{(h,k) \to (0,0)} \frac{1}{hk}{(f(x_0+h, y_0+k) - f(x_0+h,y_0) -f(x_0, y_0 + k) + f(x_0,y_0))}$$

Likewise, one shows that $$\frac{\partial^2 f}{\partial x \partial y}(x_0,y_0)$$ equals to the same limit. So we are done.