Cumulative standard deviation: Difference between revisions
Content deleted Content added
moved ooRexx to it's proper place. -- ~~~~ |
→{{header|REXX}}: added the REXX language. -- ~~~~ |
||
Line 1,723: | Line 1,723: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program to find the standard deviation of a given set of numbers.*/ |
|||
<lang rexx> |
|||
parse arg # /*let the user specify numbers. */ |
|||
⚫ | |||
if #='' then #=2 4 4 4 5 5 7 9 /*None given? Then use default.*/ |
|||
w=words(#); s=0; ss=0 /*define: #items, a couple sums. */ |
|||
do j=1 for w; _=word(#,j); s=s+_; ss=ss+_*_ |
|||
say ' item' right(j,length(w))":" right(_,4), |
|||
' average=' left(s/j,12), |
|||
' standard deviation=' left(sqrt( ss/j - (s/j)**2 ),15) |
|||
end /*j*/ |
|||
exit /*stick a fork in it, we're done.*/ |
|||
/*──────────────────────────────────SQRT subroutine─────────────────────*/ |
|||
sqrt: procedure;parse arg x; if x=0 then return 0; d=digits(); numeric digits 11; g=.sqrtGuess() |
|||
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; numeric digits d; return g/1 |
|||
.sqrtGuess: numeric form; m.=11; p=d+d%4+2 |
|||
parse value format(x,2,1,,0) 'E0' with g 'E' _ .; return g*.5'E'_%2</lang> |
|||
'''output''' using the default input |
|||
<pre style="overflow:scroll"> |
|||
item 1: 2 average= 2 standard deviation= 0 |
|||
item 2: 4 average= 3 standard deviation= 1 |
|||
item 3: 4 average= 3.33333333 standard deviation= 0.942809047 |
|||
item 4: 4 average= 3.5 standard deviation= 0.866025404 |
|||
item 5: 5 average= 3.8 standard deviation= 0.979795897 |
|||
item 6: 5 average= 4 standard deviation= 1 |
|||
item 7: 7 average= 4.42857143 standard deviation= 1.39970843 |
|||
item 8: 9 average= 5 standard deviation= 2 |
|||
⚫ | |||
=={{header|Ruby}}== |
=={{header|Ruby}}== |