Logo

Programming-Idioms

  • D
  • Perl

Idiom #201 Euclidean norm

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

use Math::GSL::Vector qw();
use Math::GSL::BLAS qw(gsl_blas_dnrm2);
my $data = [5.0, 4.0, 3.0, 2.0, 1.0];
my $n = gsl_blas_dnrm2(Math::GSL::Vector->new($data)->raw);
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