Cumulative standard deviation: Difference between revisions
Content added Content deleted
(→[[Standard_Deviation#ALGOL 68]]: add a code sample in an object oriented style) |
(→[[Standard_Deviation#ALGOL 68]]: A simple - but "unpackaged" - code example) |
||
Line 186: | Line 186: | ||
variance = 4.000000 |
variance = 4.000000 |
||
count = 8.000000 |
count = 8.000000 |
||
</pre> |
|||
{{trans|python}} |
|||
{{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) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8.8d.fc9.i386]}} --> |
|||
A simple - but "unpackaged" - code example, useful if the standard deviation is required on only one set of concurrent data: |
|||
<lang Algol68>LONG REAL sum, sum2; |
|||
INT n; |
|||
PROC sd = (LONG REAL x)LONG REAL:( |
|||
sum +:= x; |
|||
sum2 +:= x*x; |
|||
n +:= 1; |
|||
IF n = 0 THEN 0 ELSE long sqrt(sum2/n - sum*sum/n/n) FI |
|||
); |
|||
sum := sum2 := n := 0; |
|||
[]LONG REAL values = (2,4,4,4,5,5,7,9); |
|||
FOR i TO UPB values DO |
|||
LONG REAL value = values[i]; |
|||
printf(($2(xg(0,6))l$, value, sd(value))) |
|||
OD</lang>Output: |
|||
<pre> |
|||
2.000000 .000000 |
|||
4.000000 1.000000 |
|||
4.000000 .942809 |
|||
4.000000 .866025 |
|||
5.000000 .979796 |
|||
5.000000 1.000000 |
|||
7.000000 1.399708 |
|||
9.000000 2.000000 |
|||
</pre> |
</pre> |
||