norm
result = norm(x)
Input: x · Output: result
What it is
Euclidean (L2) norm; for a matrix this is the Frobenius norm (every element treated as one long vector), not a matrix operator norm. x is a scalar, Vec, or Mat (real, or CVec/CMat, which norm by magnitude).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = norm(x) | x matrix, vector, scalar, Vec, Mat, CVec, or CMatnot documented yet | result scalar or Num | Returns a scalar Num. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
a = [1, 2, 2]
print("dot(a,a) = {dot(a,a)}") # 9
print("norm(a) = {norm(a)}") # 3
output
dot(a,a) = 9 norm(a) = 3
from numerics-dsp
A = randn(60, 200, seed = 7) / sqrt(60)
x = zeros(200)
x[7] = 1.5
x[33] = -2.0
x[91] = 0.75
y = A * x
r = cs_recover(A, y, method = "omp", sparsity = 3)
print("{r.iterations} iterations, converged {r.converged}, error {norm(r.x - x):.2e}")
output
3 iterations, converged true, error 3.19e-12
from compressed-sensing
A = randn(60, 200, seed = 7) / sqrt(60)
x = zeros(200)
x[7] = 1.5
x[33] = -2.0
x[91] = 0.75
y = A * x
r = cs_recover(A, y, method = "fista", lambda = 1e-3)
print("{r.iterations} iterations, converged {r.converged}, error {norm(r.x - x):.2e}")
output
563 iterations, converged true, error 1.75e-3
from compressed-sensing
A = randn(60, 200, seed = 7) / sqrt(60)
x = zeros(200)
x[7] = 1.5
x[33] = -2.0
x[91] = 0.75
y = A * x
r = cs_recover(A, y, method = "cosamp", sparsity = 3)
print("{r.iterations} iterations, converged {r.converged}, error {norm(r.x - x):.2e}")
output
2 iterations, converged true, error 4.87e-12
from compressed-sensing