The equation for the gradient of a **linear** function mapped
in a two dimensional, Cartesian coordinate space is as follows.

The easiest way is to either derive the function you use the
gradient formula

(y2 - y1) / (x2 - x1)

were one co-ordinate is (x1, y1) and a second co-ordinate is
(x2, y2)

This, however, is almost **always** referred to as the
**slope** of the function and is a **very** specific example
of a gradient. When one talks about the gradient of a scalar
function, they are almost **always** referring to the vector
field that results from taking the spacial partial derivatives of a
scalar function, as shown below.

___________________________________________________________

The equation for the gradient of a function, symbolized
∇*f*, depends on the coordinate system being used.

For the Cartesian coordinate system:

∇*f*(x,y,z) = ∂*f*/∂x **i** + ∂*f*/∂y
**j** + ∂*f*/∂z *k* where ∂*f*/(∂x,
∂y, ∂z) is the partial derivative of *f* with respect to (x,
y, z) and **i**, **j**, and **k** are
the unit vectors in the x, y, and z directions, respectively.

For the cylindrical coordinate system:

∇*f*(ρ,θ,z) = ∂*f*/∂ρ **i***ρ* +
(1/ρ)∂*f*/∂θ **j***θ* + ∂*f*/∂z
*k**z* where ∂*f*/(∂ρ, ∂θ, ∂z) is the
partial derivative of *f* with respect to (ρ, θ, z) and
**i***ρ*, **j***θ*, and
*k**z* are the unit vectors in the ρ, θ,
and z directions, respectively.

For the spherical coordinate system:

∇*f*(r,θ,φ) = ∂*f*/∂r **i***r* +
(1/r)∂*f*/∂θ **j***θ* + [1/(r
sin(θ))]∂*f*/∂φ *k**φ* where
∂*f*/(∂r, ∂θ, ∂φ) is the partial derivative of *f* with
respect to (r, θ, φ) and **i***r*,
**j***θ*, and *k**φ*
are the unit vectors in the r, θ, and φ directions,
respectively.

Of course, the equation for ∇*f* can be generalized to any
coordinate system in any *n*-dimensional space, but that is
beyond the scope of this answer.