All formulas

Linear algebra

Euclidean (L2) norm

linalg.l2-normAlso called l2 norm, euclidean norm, norm, vector norm

∥x∥2=∑i=1nxi2\|x\|_2 = \sqrt{\sum_{i=1}^{n} x_i^2}

Length of a vector: the square root of the sum of its squared entries.

Notation

xx

vector

x ∈ ℝn

nn

vector length

Size, at least 1

∥x∥2\|x\|_2

Result: the norm

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=[3,4]x = [3, 4]

    Result

    ∥x∥2=5\displaystyle \|x\|_2 = 5
  2. Given

    x=[1,1,1,1]x = [1, 1, 1, 1]

    Result

    ∥x∥2=2\displaystyle \|x\|_2 = 2
  3. Given

    x=[1,−2,2]x = [1, -2, 2]

    Result

    ∥x∥2=3\displaystyle \|x\|_2 = 3

Common mistakes

  • Returns the squared norm

    The final square root is missing.

    Fix: Take the square root of the sum of squares.

  • Returns the L1 norm

    The result is the sum of absolute values.

    Fix: Sum the squares and take the square root.

Source

  • Golub and Van Loan 2013

    Golub, Gene H.; Van Loan, Charles F. Matrix Computations. 4th ed. Johns Hopkins University Press, 2013.