Cumulative standard deviation: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: changed/add comments and whitespace, changed section header comment. |
|||
Line 2,719: | Line 2,719: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
This REXX version uses running sums. |
|||
<lang rexx>/*REXX pgm finds & displays the standard deviation of a given set of |
<lang rexx>/*REXX pgm finds & displays the standard deviation of a given set of numbers.*/ |
||
parse arg # /*any optional |
parse arg # /*any optional arguments on the C.L. ? */ |
||
if #='' then #=2 4 4 4 5 5 7 9 |
if #='' then # = 2 4 4 4 5 5 7 9 /*None specified? Then use the default*/ |
||
w=words(#); |
w=words(#); L=length(w); $=0; $$=0 /*# items; item width; couple of sums*/ |
||
⚫ | |||
do j=1 for w; _=word(#,j); $=$+_; $$=$$+_**2 |
|||
say ' item' right(j,L)":" right(_,4) ' average=' left($/j,12), |
|||
' standard deviation=' left(sqrt( $$/j - ($/j)**2 ), 15) |
|||
end /*j*/ /* [↑] prettify output with whitespace*/ |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
/*──────────────────────────────────SQRT subroutine─────────────────────*/ |
|||
⚫ | |||
⚫ | |||
g=g*.5'E'_%2; p=d+d%4+2; do j=0 while p>9; m.j=p; p=p%2+1; end |
|||
⚫ | |||
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k; g=.5*(g+x/g); end |
|||
⚫ | |||
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k; g=.5*(g+x/g); end |
|||
'''output''' when using the default input of: <tt> 2 4 4 4 5 5 7 9 </tt> |
|||
⚫ | |||
{{out}} using the default input |
|||
<pre> |
<pre> |
||
item 1: 2 average= 2 standard deviation= 0 |
item 1: 2 average= 2 standard deviation= 0 |