Cumulative standard deviation: Difference between revisions

m
→‎only show standard deviation: added/changed whitespace and comments.
m (→‎show running sums: added/changed whitespace.)
m (→‎only show standard deviation: added/changed whitespace and comments.)
Line 3,491:
<lang rexx>/*REXX program calculates and displays the standard deviation of a given set of numbers.*/
parse arg # /*obtain optional arguments from the CL*/
if #='' then #= 2 4 4 4 5 5 7 9 /*None specified? Then use the default*/
n= words(#); $= 0; $$= 0 /*N: # items; $,$$: sums to be zeroed*/
/* [↓] process each number in the list*/
do j=1 for n; _=word(#,j); $ =$ + _ /*perform summation on two sets of #'s.*/
_= word(#, j); $$=$ $ + _**2 + /*calculate the standard deviation. */_
$$= $$ + _**2
end /*j*/
say 'standard deviation: ' sqrt($$/n - ($/n)**2) /*calculate&display the std, deviation.*/
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