Averages/Root mean square: Difference between revisions

no edit summary
No edit summary
Line 94:
rms(one to ten): +6.20483682299543e +0
</pre>
=={{header|ALGOL-M}}==
Because ALGOL-M lacks a built-in square root function, we have to supply our own.
<lang algol>
BEGIN
 
DECIMAL FUNCTION SQRT(X);
DECIMAL X;
BEGIN
DECIMAL R1, R2, TOL;
TOL := .00001; % reasonable for most purposes %
IF X >= 1.0 THEN
BEGIN
R1 := X;
R2 := 1.0;
END
ELSE
BEGIN
R1 := 1.0;
R2 := X;
END;
WHILE (R1-R2) > TOL DO
BEGIN
R1 := (R1+R2) / 2.0;
R2 := X / R1;
END;
SQRT := R1;
END;
 
COMMENT - MAIN PROGRAM BEGINS HERE;
 
DECIMAL N, SQSUM, SQMEAN;
 
SQSUM := 0.0;
FOR N := 1.0 STEP 1.0 UNTIL 10.0 DO
SQSUM := SQSUM + (N * N);
SQMEAN := SQSUM / (N - 1.0);
WRITE("RMS OF WHOLE NUMBERS 1.0 THROUGH 10.0 =", SQRT(SQMEAN));
 
END</lang>
{{out}}
Based on the finite tolerance of the square root function, only the first six decimal places of the output can actually be relied on (but that's probably more than sufficient for real world use).
<pre>
RMS OF WHOLE NUMBERS 1.0 THROUGH 10.0 = 6.20483683432
</pre>
 
 
=={{header|ALGOL W}}==
211

edits