BCX Console Demonstration Program s125.bas |
'------------------------------------------------------------------ ' BCX Implementation of the Standard Deviation Function '------------------------------------------------------------------ SET A[] AS DOUBLE 1, 5, 9, 3, 10, 4 ' Small Set Of Sample Data END SET DIM Result AS DOUBLE ' The answer = 3.502380149323707 Result = StDev(&A[0], 6) : PRINT "The Standard Deviation = ", Result# FUNCTION StDev(Sample[] AS DOUBLE, Elements) AS DOUBLE DIM Total AS DOUBLE DIM Mean AS DOUBLE DIM Srs AS DOUBLE DIM Tmp AS INTEGER FOR Tmp = 0 TO Elements - 1 Total = Total + Sample[Tmp] NEXT Mean = Total / Elements FOR Tmp= 0 TO Elements - 1 Srs = Srs + POW(ABS(Sample[Tmp] - Mean), 2) NEXT FUNCTION = SQRT(Srs / (Elements - 1)) END FUNCTION
Result:
The Standard Deviation = 3.50238014308365