Statistics/Normal distribution: Difference between revisions

m
→‎{{header|REXX}}: changed comments, somplified some functions.
(Added FreeBASIC)
m (→‎{{header|REXX}}: changed comments, somplified some functions.)
Line 1,761:
end /*j*/
!.=0
say 'number of data points = ' aa(n )
say ' minimum = ' aa(mn )
say ' maximum = ' aa(mx )
say ' arithmetic mean = ' aa(s/n)
say ' standard deviation = ' aa(sqrt(ss/n - (s/n)**2) )
r?mn=!.1; ?mx-=?mn /*isdefine usedminimum for& scaling the histogram.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 (useable) screen depth.*/
swE=sw-1 /* " " " " width.*/
$=1 / max(1,mx-mn) * sdE /*$ is used for scaling depth of histo*/
?mn=; ?mx=
do i=1 for n; ?=trunc((#.i-mn) * $) /*calculate the relative line.*/
 
do i !.?=!.?+1 for n; ?=trunc((#.i-mn) /r*sdE)bump the counter. */
!. ?mn=min(?mn, !.?+1 ); ?mx=max(?mx, !.?) /*bumpfind the counter. minimum and maximum*/
if ?mn=='' then do; ?mn=!.j; ?mx=!.j; end /*define min, max (1st).i*/
f=swE/?mx ?mn=min(?mn, !.?); ?mx=max(?mx, !.?) /*find thelimit mingraph andto max.1 full screen*/
f=swE/?mx do h=0 for sdE; _=!.h /*obtain a data point. /*limit graph to 1 screen*/
end /*i*/
if _>noise then say copies('─', trunc(_*f)) /*display thea bar of histogram. */
f=swE/?mx /*limit graph to 1 screen*/
do end /*h=0*/ for sdE; _=!.h /*obtain[↑] a datause point.a hyphen for histo.*/
if _>noise then say copies('─', trunc(_*f)) /*display the histogram. */
end /*h*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
Line 1,786 ⟶ 1,784:
e: e =2.7182818284590452353602874713526624977572470936999595749669676277240766303535; return e
pi: pi=3.1415926535897932384626433832795028841971693993751058209749445923078164062862; return pi
rand: return random(0, 1e5) / 1e5 /*REXX generates uniform random postive integers.*/
r2r: return arg(1) // (2*pi()*2) /*normalize the given angle (in radians) to ±2pi.*/
.sincos: parse arg z,_,i; x=x*x; p=z; do k=2 by 2; _=-_*x/(k*(k+i)); z=z+_; if z=p then leave; p=z; end; return z
ln: procedure; parse arg x,f; call e; ig=x>1.5; is=1-2*(ig\==1); ii=0; xx=x; return .ln_compln()
.ln_compln: do while ig&xx>1.5|\ig&xx<.5;_=e; do k=-1;iz=xx*_**-is;if k>=0&(ig&iz<1|\ig&iz>.5) then leave; _=_*_;izz=iz; end
xx=izz;ii=ii+is*2**k;end; x=x*e**-ii-1;z=0;_=-1;p=z; do k=1;_=-_*x;z=z+_/k;if z=p then leave;p=z;end; return z+ii