Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Smalltalk

Idiom #201 Euclidean norm

Calculate n, the Euclidean norm of data, where data is a list of floating point values.

data := #( 5 4 3 2 1 ).
n := data squared sum sqrt.

No builtin but this is pretty straight forward.
n = norm2( data )

data may be a multidimensional array (e.g. data(:,:)). n is the Frobenius norm if data is a 2-dimensional array (matrix).

New implementation...
< >
Bart