Skip to main content

Gradient and Multidimensional Optimization

Definition of Gradient​

For a differentiable function f(x,y)f(x, y) with two variables, using Euclidean coordinates, the gradient, denoted as ∇f\nabla f, is defined as the vector of its partial derivatives. Formally,

∇f=(∂f∂x,∂f∂y)\nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right)

For f(x,y)=x2+y2f(x, y) = x^2 + y^2, the gradient is ∇f=(2x,2y)\nabla f = (2x, 2y). This vector points in the direction of greatest local increase, and its magnitude gives that maximum directional rate of change. At a regular point, the gradient is perpendicular—not tangent—to the level curve through that point.

Directions of steepest ascent, steepest descent and zero first-order change on a surface and their projections onto the input plane.Open full-size image

Start with the arrows in the lower plane: the gradient lives in the input coordinates (x, y). Orange points toward steepest local increase, blue toward decrease, and green is tangent to a level curve. The surface above shows the corresponding changes in height; the gradient itself is not a three-dimensional arrow on that surface.

Gradient at a Specific Point​

To find the gradient of f(x,y)=x2+y2f(x, y) = x^2 + y^2 at a particular point, say (2,3)(2, 3), we substitute x=2x = 2 and y=3y = 3 into the gradient formula:

∇f=(2⋅2,2⋅3)=(4,6)\nabla f = (2 \cdot 2, 2 \cdot 3) = (4, 6)

This result signifies the gradient of ff at the point (2,3)(2, 3) and represents the vector pointing in the direction of greatest increase of ff from that point.

Why the negative gradient gives local descent​

Assume ff is differentiable at an interior point qq. For a unit vector uu in the Euclidean norm, the directional derivative is

Duf(q)=lim⁡t→0f(q+tu)−f(q)t=∇f(q)Tu.D_u f(q)=\lim_{t\to0}\frac{f(q+tu)-f(q)}t=\nabla f(q)^Tu.

Cauchy–Schwarz gives −∥∇f(q)∥2≤Duf(q)≤∥∇f(q)∥2-\|\nabla f(q)\|_2\le D_u f(q)\le\|\nabla f(q)\|_2. If the gradient is nonzero, the lower bound is attained at u=−∇f(q)/∥∇f(q)∥2u=-\nabla f(q)/\|\nabla f(q)\|_2. This is steepest descent among Euclidean unit directions, not a promise about a long step or differently scaled coordinates. In particular,

f(q−α∇f(q))=f(q)−α∥∇f(q)∥22+o(α),f(q-\alpha\nabla f(q))=f(q)-\alpha\|\nabla f(q)\|_2^2+o(\alpha),

so sufficiently small positive steps decrease ff. For the gradient (4,6)(4,6) above, the steepest unit direction is (−2,−3)/13(-2,-3)/\sqrt{13} and its rate is −213-2\sqrt{13}. A tangent vector vv to a regular level curve satisfies ∇f(q)Tv=0\nabla f(q)^Tv=0 by differentiating the constant value along that curve.

Hessian and directional curvature​

For a twice continuously differentiable function, the Hessian collects second partial derivatives, Hij(q)=∂2f(q)/∂xi∂xjH_{ij}(q)=\partial^2 f(q)/\partial x_i\partial x_j. Equality of mixed partials makes it symmetric. The second-order expansion is

f(q+v)=f(q)+∇f(q)Tv+12vTH(q)v+o(∥v∥22).f(q+v)=f(q)+\nabla f(q)^Tv+\tfrac12v^TH(q)v+o(\|v\|_2^2).

The quadratic form vTHvv^THv describes curvature along a displacement. A real symmetric matrix is positive definite if this is positive for every nonzero vv, and positive semidefinite if it is nonnegative. These correspond to all eigenvalues being positive or nonnegative, respectively. An indefinite matrix has directions with both signs. See Boyd and Vandenberghe, Appendix A and §3.1.4 for the matrix definitions and second-order convexity criterion.

For x2−y2x^2-y^2, H=diag⁡(2,−2)H=\operatorname{diag}(2,-2): curvature is positive along the x-axis and negative along the y-axis. For a symmetric 2×22\times2 matrix, positive definiteness is equivalent to H11>0H_{11}>0 and det⁡H>0\det H>0, the test used in the regression example below. A zero Hessian is inconclusive: x4+y4x^4+y^4, −x4−y4-x^4-y^4, and x4−y4x^4-y^4 all have one at the origin but give a minimum, maximum, and saddle. Positive semidefiniteness throughout an open convex domain, rather than at one point, underlies the global guarantee in convex optimization.

A stationary point has zero gradient; a local minimum is best among nearby feasible points; a global minimum is best over the entire feasible set. These differ: x2−y2x^2-y^2 has a stationary saddle at the origin, while minimizing xx on [0,1][0,1] gives the boundary solution 00 with derivative 11. At a stationary point of a twice continuously differentiable function, a positive-definite Hessian ensures a strict local minimum; an indefinite Hessian gives a saddle, and a singular positive-semidefinite Hessian needs further analysis.

Application in Optimization​

At an interior local extremum of a differentiable function, the derivative must vanish. The converse is not guaranteed. For f(x)=x2f(x)=x^2, solving f′(x)=2x=0f'(x)=2x=0 gives the candidate x=0x=0; the separate inequality x2≥0x^2\ge0 proves it is the global minimum. Boundary points and points where a derivative does not exist require separate consideration.

For functions of two or more variables, such as f(x,y)=x2+y2f(x, y) = x^2 + y^2, the optimization process seeks points where the gradient is zero, i.e., ∇f=0⃗\nabla f = \vec{0}. This condition implies that both partial derivatives, ∂f∂x\frac{\partial f}{\partial x} and ∂f∂y\frac{\partial f}{\partial y}, are zero. Solving the system of equations

∂f∂x=2x=0∂f∂y=2y=0\begin{align*} \frac{\partial f}{\partial x} = 2x &= 0 \\ \frac{\partial f}{\partial y} = 2y &= 0 \end{align*}

yields the point (0,0)(0, 0) as the location of the minimum. This search generalizes to functions of any number of variables, but a zero gradient identifies only a stationary candidate. The point may be a minimum, maximum, or saddle, so a second-order test or another argument is still needed.

Optimization in a Two-Dimensional Sauna​

Considering a sauna as a two-dimensional space allows for movement in any direction within a 5x5 room, aiming to find the coldest point based on the temperature distribution.

  • Temperature Function: For a given position (x,y)(x, y), the temperature is a function T(x,y)T(x, y) represented by the height in a three-dimensional plot. Hot areas are indicated by red (higher values) and cold areas by blue (lower values).

  • Objective: Minimize T(x,y)T(x,y) over the closed square [0,5]2[0,5]^2. A global minimizer need not be an interior point or have strictly higher values at every other point.

  • Mathematical Approach: The process involves calculating the partial derivatives ∂T∂x\frac{\partial T}{\partial x} and ∂T∂y\frac{\partial T}{\partial y}, setting them to zero, and solving for xx and yy to find potential minimum points.

  • Example Function: T(x,y)=85−190x2(x−6)y2(y−6)T(x, y) = 85 - \frac{1}{90}x^2(x - 6)y^2(y - 6).

  • Partial Derivatives:

    ∂T∂x=−190x(3x−12)y2(y−6)\frac{\partial T}{\partial x} = -\frac{1}{90}x(3x - 12)y^2(y - 6) ∂T∂y=−190x2(x−6)y(3y−12)\frac{\partial T}{\partial y} = -\frac{1}{90}x^2(x - 6)y(3y - 12)
  • Finding the Minimum: Solving ∂T∂x=0\frac{\partial T}{\partial x}=0 and ∂T∂y=0\frac{\partial T}{\partial y}=0 gives interior candidates only. Check the four edges and corners as well; the complete argument below includes the boundary.

For the sauna, declare the domain [0,5]2[0,5]^2. Put h(t)=t2(6−t)h(t)=t^2(6-t), so T=85−h(x)h(y)/90T=85-h(x)h(y)/90. On [0,5][0,5], h≥0h\ge0 and h′(t)=3t(4−t)h'(t)=3t(4-t): it increases to h(4)=32h(4)=32 and then decreases. Thus the unique global coldest point is (4,4)(4,4) with T=3313/45≈73.6222T=3313/45\approx73.6222. Edges with x=0x=0 or y=0y=0 have temperature 8585; edges at 55 have minimum 85−25⋅32/90≈76.111185-25\cdot32/90\approx76.1111. This checks the boundary, not just stationary points.

Linear Regression Optimization​

Linear regression, a fundamental machine learning model, is optimized through a similar multidimensional calculus approach but involves finding the best fit line to a set of data points.

  • Problem Statement: With given coordinates of power lines, the task is to minimize the total cost of connecting these to a main fiber line. In this illustrative model, cost is proportional to squared vertical residuals, not shortest distances to the line.
  • Mathematical Formulation: The line equation y=mx+by = mx + b represents the fiber line, with mm and bb being the slope and y-intercept, respectively. The optimization goal is to minimize the total cost function E(m,b)E(m, b), which depends on mm and bb.
  • Cost Function: Use the illustrative data (1,2),(2,5),(3,3)(1,2),(2,5),(3,3). Expanding the vertical residual sum E(m,b)=(m+b−2)2+(2m+b−5)2+(3m+b−3)2E(m,b)=(m+b-2)^2+(2m+b-5)^2+(3m+b-3)^2 gives 14m2+3b2+38+12mb−42m−20b14m^2+3b^2+38+12mb-42m-20b.
  • Partial Derivatives and Optimization:
    • ∂E∂m=28m+12b−42\frac{\partial E}{\partial m} = 28m + 12b - 42
    • ∂E∂b=6b+12m−20\frac{\partial E}{\partial b} = 6b + 12m - 20
  • Solution: Setting ∂E∂m=0\frac{\partial E}{\partial m} = 0 and ∂E∂b=0\frac{\partial E}{\partial b} = 0 and solving for mm and bb yields the optimal line parameters minimizing the cost.
  • Result: The optimal values m=12m = \frac{1}{2} and b=73b = \frac{7}{3} are found, with a minimum cost of 4.167.

For the regression quadratic, the Hessian is (2812126)\begin{pmatrix}28&12\\12&6\end{pmatrix}, with positive leading minor 2828 and determinant 2424. It is positive definite, so (1/2,7/3)(1/2,7/3) is the unique global minimizer and Emin⁡=25/6≈4.1667E_{\min}=25/6\approx4.1667. Here squared distance means a vertical residual yi−(mxi+b)y_i-(mx_i+b); perpendicular distance would also divide its square by 1+m21+m^2 and give a different optimization problem. For the statistical model, see Linear Regression.

Gradient Descent: An Efficient Optimization Method​

When solving stationary equations directly is impractical, gradient descent offers an iterative alternative. It is not always faster than a direct solver, and descent alone does not establish convergence or global optimality. The local descent property follows from differentiability as shown above; the one-variable guide supplies a domain-safe implementation.

Explore connectionsOpen network