Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
56
Task/Statistics-Basic/PureBasic/statistics-basic.purebasic
Normal file
56
Task/Statistics-Basic/PureBasic/statistics-basic.purebasic
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
Procedure.f randomf()
|
||||
#RNG_max_resolution = 2147483647
|
||||
ProcedureReturn Random(#RNG_max_resolution) / #RNG_max_resolution
|
||||
EndProcedure
|
||||
|
||||
Procedure sample(n)
|
||||
Protected i, nBins, binNumber, tickMarks, maxBinValue
|
||||
Protected.f sum, sumSq, mean
|
||||
|
||||
Dim dat.f(n)
|
||||
For i = 1 To n
|
||||
dat(i) = randomf()
|
||||
Next
|
||||
|
||||
;show mean, standard deviation
|
||||
For i = 1 To n
|
||||
sum + dat(i)
|
||||
sumSq + dat(i) * dat(i)
|
||||
Next i
|
||||
|
||||
PrintN(Str(n) + " data terms used.")
|
||||
mean = sum / n
|
||||
PrintN("Mean =" + StrF(mean))
|
||||
PrintN("Stddev =" + StrF((sumSq / n) - Sqr(mean * mean)))
|
||||
|
||||
;show histogram
|
||||
nBins = 10
|
||||
Dim bins(nBins)
|
||||
For i = 1 To n
|
||||
binNumber = Int(nBins * dat(i))
|
||||
bins(binNumber) + 1
|
||||
Next
|
||||
|
||||
maxBinValue = 1
|
||||
For i = 0 To nBins
|
||||
If bins(i) > maxBinValue
|
||||
maxBinValue = bins(i)
|
||||
EndIf
|
||||
Next
|
||||
|
||||
#normalizedMaxValue = 70
|
||||
For binNumber = 0 To nBins
|
||||
tickMarks = Int(bins(binNumber) * #normalizedMaxValue / maxBinValue)
|
||||
PrintN(ReplaceString(Space(tickMarks), " ", "#"))
|
||||
Next
|
||||
PrintN("")
|
||||
EndProcedure
|
||||
|
||||
If OpenConsole()
|
||||
sample(100)
|
||||
sample(1000)
|
||||
sample(10000)
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
Loading…
Add table
Add a link
Reference in a new issue