Cumulative standard deviation: Difference between revisions
Content added Content deleted
(→{{header|Perl}}: shorter perl version) |
m (→show running sums: added/changed whitespace.) |
||
Line 3,458: | Line 3,458: | ||
<lang rexx>/*REXX program calculates and displays the standard deviation of a given set of numbers.*/ |
<lang rexx>/*REXX program calculates and displays the standard deviation of a given set of numbers.*/ |
||
parse arg # /*obtain optional arguments from the CL*/ |
parse arg # /*obtain optional arguments from the CL*/ |
||
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*/ |
||
n=words(#); |
n= words(#); $= 0; $$= 0; L= length(n) /*N: # items; $,$$: sums to be zeroed*/ |
||
/* [↓] process each number in the list*/ |
/* [↓] process each number in the list*/ |
||
do j=1 for n |
|||
_= word(#, j); $= $ + _ |
|||
$$= $$ + _**2 |
|||
say ' item' right(j, L)":" right(_, 4) ' average=' left($/j, 12), |
|||
' standard deviation=' sqrt($$/j - ($/j)**2) |
|||
end /*j*/ /* [↑] prettify output with whitespace*/ |
|||
say 'standard deviation: ' sqrt($$/n - ($/n)**2) /*calculate & display the std deviation*/ |
say 'standard deviation: ' sqrt($$/n - ($/n)**2) /*calculate & display the std deviation*/ |
||
exit |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); h=d+6; m.=9; numeric form |
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); h=d+6; m.=9; numeric form |