Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-03 - decus/20-0078/libsim/sigma2.sim
There is 1 other file named sigma2.sim in the archive. Click here to see a list.
OPTIONS(/E/C/-A/-Q/-I/-D);
COMMENT Real procedure SIGMA2 calculates the variance, mean value and sum
of a REAL ARRAY A, from A[1] to A[N].
Array A must be declared before calling SIGMA2 and have a lower
bound <= 1 and a upper bound >= N.
Results are returned in -

SIGMA2		Variance
MEAN		Mean value
SUM		Sum
;
REAL PROCEDURE sigma2(mean,sum,a,n);   NAME mean,sum;   REAL mean,sum;
ARRAY a;   INTEGER n;
BEGIN   REAL s,s2,x;   INTEGER i;

    OPTIONS(/A);   s:= a[1];   a[n]:= a[n];;  OPTIONS(/-A);
    s2:= s^2;
    FOR i:= 2 STEP 1 UNTIL n DO
    BEGIN   x:= a[i];
	s:= s + x;
	s2:= s2 + x^2;
    END;

    x:= 1/n;
    sigma2:= (s2 - s^2*x)*x;
    mean:= s*x;
    sum:= s;
END of sigma2;