Gradient Vectors

Nerd Cafe

What is a Gradient?

The gradient of a scalar-valued function is a vector that points in the direction of the steepest increase of the function. It’s one of the most fundamental ideas in multivariable calculus.

For a function f(x,y), the gradient is defined as:

f(x,y)=(fx,fy)\bigtriangledown f(x,y)=\left( \frac{\partial f}{\partial x},\frac{\partial f}{\partial y} \right)

For a function 𝑓 ( 𝑥 , 𝑦 , 𝑧 ):

f(x,y,z)=(fx,fy,fz)\bigtriangledown f(x,y,z)=\left( \frac{\partial f}{\partial x},\frac{\partial f}{\partial y},\frac{\partial f}{\partial z} \right)

Why is the Gradient Important?

  • It tells us the direction of the fastest increase of the function.

  • It is perpendicular (normal) to level curves (in 2D) or level surfaces (in 3D).

  • It is used in optimization problems like gradient descent.

Step-by-Step Mathematical Explanation

Let’s say we have a scalar function:

f(x,y)=x2+y2f(x,y)=x^{2}+y^{2}

Step 1: Compute Partial Derivatives

fx=2x    and    fy=2y\frac{\partial f}{\partial x}=2x\;\;and\;\;\frac{\partial f}{\partial y}=2y

Step 2: Write the Gradient Vector

f(x,y)=(2x,2y)\bigtriangledown f(x,y)=(2x,2y)

At a point like ( 1 , 1 ) , the gradient becomes:

f(1,1)=(2,2)\bigtriangledown f(1,1)=(2,2)

This vector points in the direction of steepest ascent of the function.

Example 1

f(x,y)=x2+y2f(x,y)=x^{2}+y^{2}

Let’s compute and visualize gradient vectors on a 2D surface.

Output

Example 2

Let:

f(x,y)=x.ex2y2f(x,y)=x.e^{-x^{2}-y^{2}}

Using product and chain rules:

fx=ex2y22x2.ex2y2=(12x2)ex2y2\frac{\partial f}{\partial x}=e^{-x^{2}-y^{2}}-2x^{2}.e^{-x^{2}-y^{2}}=(1-2x^{2})e^{-x^{2}-y^{2}}

and

fy=2xy.ex2y2\frac{\partial f}{\partial y}=-2xy.e^{-x^{2}-y^{2}}

Python Visualization:

Output

Summary

Concept
Meaning

Gradient

Vector of partial derivatives

Direction

Steepest increase

Magnitude

Rate of increase

Applications

Optimization, physics, machine learning

Keywords

gradient vector, gradient descent, partial derivatives, optimization, scalar field, vector calculus, electric field, gravitational field, backpropagation, machine learning, neural networks, image processing, edge detection, sobel filter, heat equation, diffusion, potential function, motion planning, terrain slope, multivariable calculus, nerd cafe

Last updated