Vector normsΒΆ
Given the vector \(\mathbf{x}= \bigl[ 2 ,\, -3 ,\, 1 ,\, -1 \bigr]^T\), we have \begin{align*} | \mathbf{x} |2 &= \sqrt{ 4 + 9 + 1 + 1 } = \sqrt{15}, \ | \mathbf{x} |\infty &= \max{ 2,3,1,1 } = 3,\ | \mathbf{x} |_1 &= 2 + 3 + 1 + 1 = 7. \end{align*}
In Julia the standard LinearAlgebra
package has a norm
command for vector norms.
using LinearAlgebra
x = [2,-3,1,-1]
twonorm = norm(x) # or norm(x,2)
3.872983346207417
infnorm = norm(x,Inf)
3.0
onenorm = norm(x,1)
7.0