Skip to main content

Norm

Norm (Function)​

Format​

norm ( vector )

returns float_expression.

Description​

Returns the length of a vector held in an array — the square root of the sum of the squares of its elements, which is the same as the square root of v dot v.

Any number of elements will do, and the shape does not matter: the elements are read in the order they are stored, so a row, a column, or whatever Mat Trn hands back all count as vectors.

The answer is always a decimal number, even where it comes out whole, because a square root is not a whole number except by accident.

norm gives the length; unit gives the direction.

Example​

print norm({3,4})
print norm({2,3,6})
print norm({0,0,0})

# a length is the square root of the dot product of a vector with itself
v = {1,2,3}
print norm(v)
print sqr(v dot v)

will print

5.0
7.0
0.0
3.74165738677
3.74165738677

Errors​

ErrorCause
136The value passed is not an array.
139An element of the vector has never been given a value.

See Also​

Arrays, Cross, Dot, Sqr, Unit, Vector Operators

History​

2.2New To Version