Averages/Root mean square: Difference between revisions

No edit summary
Line 9:
C.f. [[Averages/Pythagorean means]]
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Standard - no extensions to language used}}
 
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
 
{{works with|ELLA ALGOL 68|Any (with appropriate job cards)}}
<lang algol68># Define the rms PROCedure & ABS OPerators for LONG... REAL #
MODE RMSFIELD = #LONG...# REAL;
PROC (RMSFIELD)RMSFIELD rms field sqrt = #long...# sqrt;
INT rms field width = #long...# real width;
 
PROC crude rms = ([]RMSFIELD v)RMSFIELD: (
RMSFIELD sum := 0;
FOR i FROM LWB v TO UPB v DO sum +:= v[i]**2 OD;
rms field sqrt(sum / (UPB v - LWB v + 1))
);
PROC rms = ([]RMSFIELD v)RMSFIELD: (
# round off error accumulated at standard precision #
RMSFIELD sum := 0, round off error:= 0;
FOR i FROM LWB v TO UPB v DO
RMSFIELD org = sum, prod = v[i]**2;
sum +:= prod;
round off error +:= sum - org - prod
OD;
rms field sqrt((sum - round off error)/(UPB v - LWB v + 1))
);
 
# define an ABS OPerator similar to ABS of COMPLex numbers #
OP ([]RMSFIELD)RMSFIELD ABS = rms;
 
main: (
[]RMSFIELD one to ten = (1,2,3,4,5,6,7,8,9,10);
 
print(("crude rms(one to ten): ", crude rms(one to ten), new line));
print(("rms(one to ten): ", rms(one to ten), new line));
print(("ABS one to ten: ", ABS one to ten, new line))
)</lang>
Output:
<pre>
crude rms(one to ten): +6.20483682299543e +0
rms(one to ten): +6.20483682299543e +0
ABS one to ten: +6.20483682299543e +0
</pre>
=={{header|AutoHotkey}}==
===Using a loop===