Anonymous user
Statistics/Normal distribution: Difference between revisions
m
→{{header|REXX}}: added whitespace, changed some comments, optimized the COSine function.
m (→{{header|R}}: first part was not done) |
m (→{{header|REXX}}: added whitespace, changed some comments, optimized the COSine function.) |
||
Line 2,515:
<br>so we hoi polloi programmers have to roll our own.
<lang rexx>/*REXX program generates 10,000 normally distributed numbers (Gaussian distribution).*/
numeric digits 20 /*use
parse arg n seed . /*obtain optional arguments from the CL*/
if n=='' | n=="," then n= 10000 /*Not specified? Then use the default.*/
Line 2,525:
mn= #.1; mx= mn; noise= n * .0005 /*calculate the noise: 1/20th % of N.*/
ss= 0
do j=1 for n; _= #.j
s= s + _; ss= ss + _ * _ /*the sum, and the sum of squares. */
mn= min(mn, _); mx= max(mx, _) /*find the minimum and the maximum. */
end /*j*/
!.= 0
say 'number of data points = '
say ' minimum = '
say ' maximum = '
say ' arithmetic mean = '
say ' standard deviation = '
?mn= !.1; ?mx= ?mn /*define minimum & maximum value so far*/
parse value scrSize() with sd sw . /*obtain the (true) screen size of term*/ /*◄──not all REXXes have this BIF*/
sdE= sd - 4 /*the effective (
swE= sw - 1 /* " " " " width.*/
$= 1 / max(1, mx-mn) * sdE /*$ is used for scaling depth of histo*/
do i=1 for n;
!.?= !.? + 1 /*bump the counter.
?mn= min(?mn, !.?)
?mx= max(?mx, !.?) /* " " maximum. */
end /*i*/
f= swE/?mx
do h=0 for sdE;
if _>noise then say copies('─', trunc(_*f) ) /*display a bar of histogram. */
end /*h*/ /*[↑] use a hyphen for histo.*/
exit /*stick a fork in it, we're all done. */
/*───────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
e:
pi:
r2r:
rand:
/*───────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
ln: procedure; parse arg x,f; call e; ig= x>1.5; is= 1 -2*(ig\==1); ii= 0; xx= x; do while ig & xx>1.5 | \ig & xx<.5
ii= ii +is*2**k;
/*───────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x; x=r2r(x); a=abs(x); hpi= pi*.5; numeric fuzz min(6, digits()-3); if a=pi then return -1
x= x*x;
/*───────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
sqrt:
This REXX program makes use of '''scrsize''' REXX program (or BIF) which is used to determine the screen size of the terminal (console); this is to aid in maximizing the width of the horizontal histogram.
|