Salta al contenuto
Note per Studenti Hessian Matrix and Taylor Formula Report

Hessian Matrix and Taylor Formula

In questa pagina 5

This note builds on Differentiability and the Gradientf is differentiable at x0 if f(x) = f(x0) + grad f(x0)·(x - x0) + o(‖x - x0‖), i.e. near x0 the graph is indistinguishable from the tangent plane z = f(x0) + grad f(x0)·(x - x0). Differentiable implies continuous, with partial derivatives and D_v f = grad f · v; continuous partial derivatives imply differentiable. The gradient gives the direction of steepest increase (slope ‖grad f‖) and is orthogonal to level curves.Differentiability and the Gradient →.

In one variable the sign of f′′(x0)f''(x_0) tells whether a stationary point is a maximum or a minimum. In several variables the second derivatives are n2n^2 in number and must be organized in a matrix; their "sign" becomes the sign of a quadratic form.

Higher-order derivatives and Schwarz's theorem

Consider a function f:D⊆Rn→Rf: D \subseteq \mathbb{R}^n \to \mathbb{R}. If the first partial derivatives ∂f∂xi\frac{\partial f}{\partial x_i} are in turn differentiable, we obtain the second-order partial derivativesderivatives of the partial derivatives, defined by: ∂2f∂xj∂xi=∂∂xj(∂f∂xi)\frac{\partial^2 f}{\partial x_j \partial x_i} = \frac{\partial}{\partial x_j} \left( \frac{\partial f}{\partial x_i} \right) When i≠ji \neq j they are called mixed derivatives. A function is said to be of class C2C^2a function whose second partial derivatives are continuous on an open set DD.

Schwarz's theorem. Let f:D⊆Rn→Rf: D \subseteq \mathbb{R}^n \to \mathbb{R} be a function of class C2C^2 in a neighbourhood of x0∈Dx_0 \in D. Then the mixed derivatives are equal at x0x_0: ∂2f∂xi∂xj(x0)=∂2f∂xj∂xi(x0)\frac{\partial^2 f}{\partial x_i \partial x_j}(x_0) = \frac{\partial^2 f}{\partial x_j \partial x_i}(x_0)

This theorem guarantees that, for sufficiently regular functions, the order of differentiation does not affect the result. In fact it suffices that the two mixed derivatives exist near x0x_0 and are continuous at x0x_0. Without continuity it can fail: the classic counterexample is f(x,y)=xy(x2−y2)x2+y2f(x,y) = \frac{xy(x^2 - y^2)}{x^2 + y^2}, f(0,0)=0f(0,0) = 0, for which fxy(0,0)=−1f_{xy}(0,0) = -1 and fyx(0,0)=1f_{yx}(0,0) = 1.

Example. f(x,y)=sin⁡(x2y)+4x3y2f(x, y) = \sin(x^2y) + 4x^3y^2.

  • fx=2xycos⁡(x2y)+12x2y2f_x = 2xy\cos(x^2y) + 12x^2y^2, fy=x2cos⁡(x2y)+8x3y\quad f_y = x^2\cos(x^2y) + 8x^3y.
  • fxy=∂∂yfx=2xcos⁡(x2y)−2xy⋅x2sin⁡(x2y)+24x2y=2xcos⁡(x2y)−2x3ysin⁡(x2y)+24x2yf_{xy} = \frac{\partial}{\partial y}f_x = 2x\cos(x^2y) - 2xy\cdot x^2\sin(x^2y) + 24x^2y = 2x\cos(x^2y) - 2x^3y\sin(x^2y) + 24x^2y (product 2xy⋅cos⁡(x2y)2xy \cdot \cos(x^2y) differentiated in yy: the derivative of cos⁡(x2y)\cos(x^2y) with respect to yy is −x2sin⁡(x2y)-x^2\sin(x^2y)).
  • fyx=∂∂xfy=2xcos⁡(x2y)−x2⋅2xysin⁡(x2y)+24x2yf_{yx} = \frac{\partial}{\partial x}f_y = 2x\cos(x^2y) - x^2\cdot 2xy\sin(x^2y) + 24x^2y: equal to fxyf_{xy}, as Schwarz predicts.
  • fxx=2ycos⁡(x2y)−4x2y2sin⁡(x2y)+24xy2f_{xx} = 2y\cos(x^2y) - 4x^2y^2\sin(x^2y) + 24xy^2, fyy=−x4sin⁡(x2y)+8x3\quad f_{yy} = -x^4\sin(x^2y) + 8x^3.

Hessian matrix

The Hessian matrix is the main tool for analysing the local curvature of a function.

Definition. Given f∈C2(D)f \in C^2(D), the Hessian matrix Hf(x0)H_f(x_0) is the n×nn \times n square matrix defined by: Hf(x0)=(fx1x1…fx1xn⋮⋱⋮fxnx1…fxnxn)H_f(x_0) = \begin{pmatrix} f_{x_1x_1} & \dots & f_{x_1x_n} \\ \vdots & \ddots & \vdots \\ f_{x_nx_1} & \dots & f_{x_nx_n} \end{pmatrix} By Schwarz's theorem, the Hessian matrix is symmetric (Hf=HfTH_f = H_f^T).

Example: let f(x,y)=ex2+yf(x,y) = e^{x^2+y}.

  1. Compute the gradient: ∇f=(2xex2+y,ex2+y)\nabla f = (2x e^{x^2+y}, e^{x^2+y}).
  2. Differentiate with respect to xx and yy to obtain the entries of HfH_f: fxx=2ex2+y+4x2ex2+yf_{xx} = 2e^{x^2+y} + 4x^2e^{x^2+y}, fxy=2xex2+yf_{xy} = 2xe^{x^2+y}, fyy=ex2+yf_{yy} = e^{x^2+y}. Hf(x,y)=ex2+y(2+4x22x2x1)H_f(x,y) = e^{x^2+y} \begin{pmatrix} 2+4x^2 & 2x \\ 2x & 1 \end{pmatrix}

Second-order Taylor formula

Differentiability (Differentiability and the Gradientf is differentiable at x0 if f(x) = f(x0) + grad f(x0)·(x - x0) + o(‖x - x0‖), i.e. near x0 the graph is indistinguishable from the tangent plane z = f(x0) + grad f(x0)·(x - x0). Differentiable implies continuous, with partial derivatives and D_v f = grad f · v; continuous partial derivatives imply differentiable. The gradient gives the direction of steepest increase (slope ‖grad f‖) and is orthogonal to level curves.Differentiability and the Gradient →) lets us approximate a function by the tangent plane, with error o(∥h∥)o(\|h\|). Adding a second-degree term the error becomes o(∥h∥2)o(\|h\|^2):

Taylor formula. Let f∈C2f \in C^2 in a neighbourhood of x0x_0. For hh sufficiently small, f(x0+h)=f(x0)+∇f(x0)⋅h+12hTHf(x0)h+o(∥h∥2)f(x_0+h) = f(x_0) + \nabla f(x_0) \cdot h + \frac{1}{2} h^T H_f(x_0) h + o(\|h\|^2) where hTHfhh^T H_f h is the quadratic formthe sum of the terms a_ij h_i h_j: a homogeneous polynomial of degree two in the components of h associated with the Hessian.

In two variables, with h=(h,k)h = (h, k) and the derivatives evaluated at (x0,y0)(x_0, y_0): f(x0+h,y0+k)=f+fxh+fyk+12(fxxh2+2fxyhk+fyyk2)+o(h2+k2)f(x_0 + h, y_0 + k) = f + f_x h + f_y k + \frac12\left(f_{xx}h^2 + 2f_{xy}hk + f_{yy}k^2\right) + o(h^2 + k^2) The 22 in front of fxyf_{xy} comes from the two equal terms fxyhkf_{xy}hk and fyxkhf_{yx}kh in the product hTHhh^T H h.

Example. f(x,y)=ex2+yf(x, y) = e^{x^2 + y} at (0,0)(0, 0): f=1f = 1, ∇f=(0,1)\nabla f = (0, 1), Hf(0,0)=(2001)H_f(0,0) = \begin{pmatrix} 2 & 0 \\ 0 & 1\end{pmatrix} (from the formula above with x=y=0x = y = 0). Hence ex2+y=1+y+12(2x2+y2)+o(x2+y2)=1+y+x2+y22+o(x2+y2)e^{x^2+y} = 1 + y + \frac12(2x^2 + y^2) + o(x^2+y^2) = 1 + y + x^2 + \frac{y^2}{2} + o(x^2 + y^2) Check: with u=x2+yu = x^2 + y, eu=1+u+u22+⋯=1+x2+y+y22+…e^u = 1 + u + \frac{u^2}{2} + \dots = 1 + x^2 + y + \frac{y^2}{2} + \dots (the terms x4x^4, x2yx^2y are of order higher than two).

Definite, semidefinite and indefinite symmetric matrices

At a critical point (∇f(x0)=0\nabla f(x_0) = 0) the Taylor formula becomes f(x0+h)−f(x0)=12hTHf(x0)h+o(∥h∥2)f(x_0 + h) - f(x_0) = \frac12 h^T H_f(x_0) h + o(\|h\|^2): the sign of f(x0+h)−f(x0)f(x_0+h) - f(x_0) near x0x_0 is that of the quadratic form q(h)=hTAhq(h) = h^T A h with A=Hf(x0)A = H_f(x_0). For this reason we need to classify symmetric matrices.

Definition. A symmetric n×nn \times n matrix AA is:

  • positive definite if hTAh>0h^T A h > 0 for every h≠0h \neq 0;
  • negative definite if hTAh<0h^T A h < 0 for every h≠0h \neq 0;
  • positive (negative) semidefinite if hTAh≥0h^T A h \geq 0 (≤0\leq 0) for every hh, and vanishes for some h≠0h \neq 0;
  • indefinite if there exist h1,h2h_1, h_2 with h1TAh1>0h_1^T A h_1 > 0 and h2TAh2<0h_2^T A h_2 < 0.

Example. A=(2003)A = \begin{pmatrix} 2 & 0 \\ 0 & 3 \end{pmatrix} is positive definite (hTAh=2h12+3h22>0h^T A h = 2h_1^2 + 3h_2^2 > 0); B=(100−1)B = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} is indefinite (hTBh=h12−h22h^T B h = h_1^2 - h_2^2 changes sign).

Eigenvalue criterion. A symmetric matrix has nn real eigenvalues λ1,…,λn\lambda_1, \dots, \lambda_n (see Linear Algebra). It is positive definite if they are all >0> 0, negative definite if all <0< 0, semidefinite if they are all ≥0\geq 0 (or all ≤0\leq 0) and at least one is zero, indefinite if there are some of opposite sign.

Leading principal minors criterion (Sylvester). Let AkA_k be the submatrices formed by the first kk rows and kk columns:

  • Positive definite: det⁡Ak>0\det A_k > 0 for every k=1,…,nk=1, \dots, n.
  • Negative definite: the signs alternate starting from negative: det⁡A1<0,det⁡A2>0,det⁡A3<0,…\det A_1 < 0, \det A_2 > 0, \det A_3 < 0, \dots (i.e. (−1)kdet⁡Ak>0(-1)^k \det A_k > 0).

The criterion works only for definite matrices: if some minor is zero it does not say anything precise.

The 2×22 \times 2 case. For A=(abbc)A = \begin{pmatrix} a & b \\ b & c \end{pmatrix}, the eigenvalues have product det⁡A=ac−b2\det A = ac - b^2 and sum a+ca + c. Therefore:

  • det⁡A>0\det A > 0: eigenvalues of the same sign; if a>0a > 0 positive definite, if a<0a < 0 negative definite (aa and cc have the same sign, because ac>b2≥0ac > b^2 \geq 0).
  • det⁡A<0\det A < 0: eigenvalues of opposite sign, indefinite.
  • det⁡A=0\det A = 0: one eigenvalue is zero, semidefinite (or null).

Examples. (2113)\begin{pmatrix} 2 & 1 \\ 1 & 3 \end{pmatrix}: det⁡=5>0\det = 5 > 0 and a=2>0a = 2 > 0, positive definite. (1221)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}: det⁡=−3<0\det = -3 < 0, indefinite (indeed q(1,−1)=1−4+1=−2<0q(1, -1) = 1 - 4 + 1 = -2 < 0 and q(1,0)=1>0q(1, 0) = 1 > 0). (−444−4)\begin{pmatrix} -4 & 4 \\ 4 & -4 \end{pmatrix}: det⁡=0\det = 0, negative semidefinite (q(h,k)=−4(h−k)2≤0q(h,k) = -4(h - k)^2 \leq 0).

The use for classifying critical points is in Free Extrema in Several VariablesIf f is differentiable and has a relative extremum at an interior point x0, then grad f(x0) = 0 (Fermat): interior extrema are found among the critical points. If f is C^2, at a critical point: Hessian positive definite gives a minimum, negative definite a maximum, indefinite a saddle, semidefinite means the test is inconclusive and one studies the sign of f(x) - f(x0). In two variables: det H > 0 and f_xx > 0 minimum, det H > 0 and f_xx < 0 maximum, det H < 0 saddle.Free Extrema in Several Variables →.

Common mistakes

  • Forgetting the factor 1/2: in the Taylor formula the quadratic term must always be multiplied by 1/21/2.
  • Applying Schwarz without its hypotheses: for piecewise-defined functions the mixed derivatives at the junction point must be computed from the definition and can be different.
  • Confusion in the signs of the minors criterion: for negative definite the first minor (det⁡A1=a11\det A_1 = a_{11}) must be negative, the second positive; "all negative" is wrong.
  • Forgetting the 2 of the mixed term when writing Taylor in two variables: it is 2fxyhk2f_{xy}hk.

Versione ripasso

Schwarz's theorem. If f∈C2f \in C^2 in a neighbourhood of x0x_0, the mixed derivatives coincide: fxixj(x0)=fxjxi(x0)f_{x_ix_j}(x_0) = f_{x_jx_i}(x_0). It suffices that the mixed ones exist near x0x_0 and are continuous at x0x_0. Without this hypothesis it can fail: for f=xy(x2−y2)x2+y2f = \frac{xy(x^2-y^2)}{x^2+y^2} we have fxy(0,0)=−1f_{xy}(0,0) = -1 and fyx(0,0)=1f_{yx}(0,0) = 1.

Hessian. Hf(x0)=(fxixj(x0))ijH_f(x_0) = \left(f_{x_ix_j}(x_0)\right)_{ij} is symmetric by Schwarz. Example: f=ex2+yf = e^{x^2+y} has Hf(x,y)=ex2+y(2+4x22x2x1)H_f(x,y) = e^{x^2+y}\begin{pmatrix}2+4x^2 & 2x\\ 2x & 1\end{pmatrix}.

Second-order Taylor (f∈C2f \in C^2). f(x0+h)=f(x0)+∇f(x0)⋅h+12 hTHf(x0) h+o(∥h∥2)f(x_0+h) = f(x_0) + \nabla f(x_0)\cdot h + \frac12\,h^T H_f(x_0)\,h + o(\|h\|^2) In two variables: f(x0+h,y0+k)=f+fxh+fyk+12(fxxh2+2fxyhk+fyyk2)+o(h2+k2)f(x_0+h, y_0+k) = f + f_xh + f_yk + \frac12(f_{xx}h^2 + 2f_{xy}hk + f_{yy}k^2) + o(h^2+k^2). The 22 in front of fxyf_{xy} comes from the two equal terms hkhk and khkh.

  • Example: f=ex2+yf = e^{x^2+y} at (0,0)(0,0), with H=(2001)H = \begin{pmatrix}2&0\\0&1\end{pmatrix}, gives ex2+y=1+y+x2+y22+o(x2+y2)e^{x^2+y} = 1 + y + x^2 + \frac{y^2}{2} + o(x^2+y^2). Check: with u=x2+yu = x^2+y, eu=1+u+u22+…e^u = 1 + u + \frac{u^2}{2} + \dots.

Quadratic forms. A symmetric matrix AA is:

  • positive definite if hTAh>0h^TAh > 0 for h≠0h \neq 0; negative definite if <0< 0;
  • positive (negative) semidefinite if ≥0\ge 0 (≤0\le 0) everywhere and vanishes for some h≠0h \neq 0;
  • indefinite if it takes values of both signs.

Examples: diag⁡(2,3)\operatorname{diag}(2,3) is positive definite; diag⁡(1,−1)\operatorname{diag}(1,-1) is indefinite.

Criteria.

  • Eigenvalues: positive definite if all >0> 0, negative definite if all <0< 0, indefinite if of mixed sign, semidefinite if one is zero and the others have the same sign.
  • Leading principal minors (Sylvester): positive definite if det⁡Ak>0\det A_k > 0 for every kk; negative definite if det⁡A1<0\det A_1 < 0, det⁡A2>0\det A_2 > 0, det⁡A3<0\det A_3 < 0, ... The criterion decides only for definite matrices.
  • 2×22\times2 case, A=(abbc)A = \begin{pmatrix}a&b\\b&c\end{pmatrix}: det⁡>0\det > 0 and a>0a > 0 gives positive definite; det⁡>0\det > 0 and a<0a < 0 gives negative definite; det⁡<0\det < 0 gives indefinite; det⁡=0\det = 0 gives semidefinite.
  • Examples: (2113)\begin{pmatrix}2&1\\1&3\end{pmatrix} has det⁡=5\det = 5, positive definite; (1221)\begin{pmatrix}1&2\\2&1\end{pmatrix} has det⁡=−3\det = -3, indefinite; (−444−4)\begin{pmatrix}-4&4\\4&-4\end{pmatrix} is negative semidefinite, with q(h,k)=−4(h−k)2q(h,k) = -4(h-k)^2.

At a critical point the sign of f(x0+h)−f(x0)f(x_0+h) - f(x_0) is that of 12hTHfh\frac12 h^T H_f h: this is how the Hessian classifies critical points (Free Extrema in Several VariablesIf f is differentiable and has a relative extremum at an interior point x0, then grad f(x0) = 0 (Fermat): interior extrema are found among the critical points. If f is C^2, at a critical point: Hessian positive definite gives a minimum, negative definite a maximum, indefinite a saddle, semidefinite means the test is inconclusive and one studies the sign of f(x) - f(x0). In two variables: det H > 0 and f_xx > 0 minimum, det H > 0 and f_xx < 0 maximum, det H < 0 saddle.Free Extrema in Several Variables →).

Typical mistakes.

  • Forgetting the factor 12\frac12 in the quadratic term.
  • Writing the mixed term without the 22: it is 2fxyhk2f_{xy}hk.
  • Applying Schwarz to piecewise-defined functions at junction points, where the mixed derivatives must be computed from the definition.
  • In the minors criterion for negative definite, reversing the signs: the first minor must be negative, the second positive.

Teoria collegata