norm
.. norm(A, [p])
Compute the ``p``norm of a vector or the operator norm of a matrix ``A``, defaulting to the ``p=2``norm.
For vectors, ``p`` can assume any numeric value (even though not all values produce a mathematically valid vector norm). In particular, ``norm(A, Inf)`` returns the largest value in ``abs(A)``, whereas ``norm(A, Inf)`` returns the smallest.
For matrices, the matrix norm induced by the vector ``p``norm is used, where valid values of ``p`` are ``1``, ``2``, or ``Inf``. (Note that for sparse matrices, ``p=2`` is currently not implemented.) Use :func:`vecnorm` to compute the Frobenius norm.
Examples
The norm
function in Julia calculates the p
norm of a vector or the operator norm of a matrix A
. By default, it computes the p=2
norm.
norm(A, [p])
For vectors, the parameter p
can take any numeric value, although not all values produce a mathematically valid vector norm. The norm(A, Inf)
returns the largest value in abs(A)
, while norm(A, Inf)
returns the smallest.
For matrices, the p
norm used is the matrix norm induced by the vector p
norm. Valid values for p
are 1
, 2
, or Inf
. Note that for sparse matrices, p=2
is currently not implemented. To compute the Frobenius norm, use the vecnorm
function.
Here are some examples of using the norm
function:

Compute the Euclidean norm of a vector:
julia> v = [3, 4]; julia> norm(v) 5.0

Compute the
p=1
norm of a vector:julia> w = [1, 2, 3]; julia> norm(w, 1) 6.0

Compute the
p=Inf
norm of a matrix:julia> A = [1 2; 3 4]; julia> norm(A, Inf) 7.0
 Compute the Frobenius norm of a matrix using
vecnorm
:julia> B = [1 2; 3 4; 5 6]; julia> vecnorm(B) 9.539392014169456
Please note that these examples assume that the necessary variables are defined before using the norm
function.
See Also
Ac_ldiv_B, Ac_ldiv_Bc, Ac_mul_B, Ac_mul_Bc, Ac_rdiv_B, Ac_rdiv_Bc, At_ldiv_B, At_ldiv_Bt, At_mul_B, At_mul_Bt, At_rdiv_B, At_rdiv_Bt, A_ldiv_Bc, A_ldiv_Bt, A_mul_B!, A_mul_Bc, A_mul_Bt, A_rdiv_Bc, A_rdiv_Bt, Bidiagonal, cond, conv2, det, diag, diagind, diagm, diff, eig, eigvals, eigvecs, expm, eye, full, inv, isdiag, ishermitian, isposdef, isposdef!, issym, istril, istriu, logabsdet, logdet, lyap, norm, qrfact, rank, repmat, rot180, rotl90, rotr90, sortrows, sqrtm, SymTridiagonal, trace, Tridiagonal, tril, tril!, triu, triu!, writedlm,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.