Mathwords logoMathwords

Affine Function — Definition, Formula & Example

An affine function is a linear function shifted by a constant: it scales and combines its inputs, then adds a fixed offset. Its graph is a line, a plane, or a higher-dimensional flat surface. That surface does not have to pass through the origin.

A function f:Rn→Rmf:\mathbb{R}^n \to \mathbb{R}^m is affine if there exist an m×nm \times n matrix AA and a vector b∈Rm\mathbf{b} \in \mathbb{R}^m such that f(x)=Ax+bf(\mathbf{x}) = A\mathbf{x} + \mathbf{b} for all x\mathbf{x}. An equivalent condition is that f(tx+(1−t)y)=tf(x)+(1−t)f(y)f(t\mathbf{x} + (1-t)\mathbf{y}) = t f(\mathbf{x}) + (1-t) f(\mathbf{y}) for all x,y\mathbf{x}, \mathbf{y} and all real tt. The map x↦Ax\mathbf{x} \mapsto A\mathbf{x} is the linear part, and b=f(0)\mathbf{b} = f(\mathbf{0}) is the translation.

Key Formula

f(x)=Ax+bf(\mathbf{x}) = A\mathbf{x} + \mathbf{b}
Where:
  • x\mathbf{x} = Input vector in Rn\mathbb{R}^n
  • AA = An m×nm \times n matrix that gives the linear part of the function
  • b\mathbf{b} = Constant vector in Rm\mathbb{R}^m, equal to f(0)f(\mathbf{0})

Worked Example

Problem: Let f(x,y)=3x−2y+5f(x, y) = 3x - 2y + 5. Find the linear part and the translation of ff, then show that ff is affine but not linear.
Step 1: Find the translation by evaluating at the origin.
b=f(0,0)=3(0)−2(0)+5=5b = f(0, 0) = 3(0) - 2(0) + 5 = 5
Step 2: Subtract bb to get the linear part. It is multiplication by the 1×21 \times 2 matrix A=(3−2)A = \begin{pmatrix} 3 & -2 \end{pmatrix}, so f(x)=Ax+5f(\mathbf{x}) = A\mathbf{x} + 5 has the affine form. Its graph z=3x−2y+5z = 3x - 2y + 5 is a plane that crosses the zz-axis at 55.
L(x,y)=f(x,y)−5=3x−2y=(3−2)(xy)L(x, y) = f(x, y) - 5 = 3x - 2y = \begin{pmatrix} 3 & -2 \end{pmatrix}\begin{pmatrix} x \\ y \end{pmatrix}
Step 3: Test additivity with (1,0)(1, 0) and (0,1)(0, 1). The two sides disagree, so ff is not linear. The constant 55 gets counted twice on the left side but only once on the right.
f(1,0)+f(0,1)=8+3=11≠6=f(1,1)f(1,0) + f(0,1) = 8 + 3 = 11 \neq 6 = f(1, 1)
Answer: The linear part is L(x,y)=3x−2yL(x, y) = 3x - 2y and the translation is b=5b = 5. So ff is affine. Since f(0,0)=5≠0f(0,0) = 5 \neq 0 and additivity fails, ff is not linear.

Why It Matters

Each fully connected layer of a neural network applies an affine function Wx+bW\mathbf{x} + \mathbf{b} before its nonlinearity. In multivariable calculus, the tangent-plane approximation f(a)+∇f(a)⋅(x−a)f(\mathbf{a}) + \nabla f(\mathbf{a}) \cdot (\mathbf{x} - \mathbf{a}) is an affine function. Linear programming optimizes affine objectives subject to affine constraints.

Common Mistakes

Mistake: Calling f(x)=mx+bf(x) = mx + b with b≠0b \neq 0 a linear map because its graph is a straight line.
Correction: In linear algebra, a map is linear only if f(x+y)=f(x)+f(y)f(\mathbf{x} + \mathbf{y}) = f(\mathbf{x}) + f(\mathbf{y}) and f(cx)=cf(x)f(c\mathbf{x}) = c f(\mathbf{x}) for all vectors and scalars. These conditions force f(0)=0f(\mathbf{0}) = \mathbf{0}. When b≠0b \neq 0, the function is affine, not linear. Algebra courses often say "linear function" loosely for mx+bmx + b, so check which meaning your course uses.

Related Terms