home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
352_01
/
vecnorm.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-24
|
642b
|
32 lines
// vecnorm.cpp - take norm (=sum of squares of elements) of vector
// between 2 endpoints.
#include <stdlib.h>
#include <alloc.h>
#include <string.h>
#include "wtwg.h"
#include "dblib.h"
#include "vector.h"
float norm (Vector& vec, int n1, int n2 )
// norm between point1 and point2 (friend function of Vector)
// if point2 == -1, sums to end of V.
{
float s=0, xv;
if ( n2<0 ) n2 = vec.n;
float *vv = vec.v;
for ( int i=n1; i<n2; ++i )
{
xv = vv[i];
s+= xv*xv; // sum of squares.
}
return (s);
}
//---------------------- end VECNORM.CPP ----------------------------