RosettaCodeData/Task/Statistics-Basic/J/statistics-basic-3.j

25 lines
678 B
Text
Raw Permalink Normal View History

2015-02-20 09:02:09 -05:00
histogram=: <: @ (#/.~) @ (i.@#@[ , I.)
2016-12-05 22:15:40 +01:00
meanstddevP=: 3 :0
2015-02-20 09:02:09 -05:00
NB. compute mean and std dev of y random numbers
NB. picked from even distribution between 0 and 1
NB. and display a normalized ascii histogram for this sample
2016-12-05 22:15:40 +01:00
NB. note: uses population mean (0.5), not sample mean, for stddev
2015-02-20 09:02:09 -05:00
NB. given the equation specified for this task.
h=.s=.t=. 0
2016-12-05 22:15:40 +01:00
chunk=. 1e6
bins=. (%~ 1 + i.) 10
for. i. <.y%chunk do.
data=. chunk ?@$ 0
h=. h+ bins histogram data
s=. s+ +/ data
t=. t+ +/ *: data-0.5
2015-02-20 09:02:09 -05:00
end.
2016-12-05 22:15:40 +01:00
data=. (chunk|y) ?@$ 0
h=. h+ bins histogram data
s=. s+ +/ data
t=. t+ +/ *: data - 0.5
smoutput (<.300*h%y) #"0 '#'
(s%y) , %:t%y
2015-02-20 09:02:09 -05:00
)