RosettaCodeData/Task/Cumulative-standard-deviation/Run-BASIC/cumulative-standard-deviation.basic

13 lines
585 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
dim sdSave$(100) 'can call up to 100 versions
'holds (space-separated) number of data , sum of values and sum of squares
sd$ = "2,4,4,4,5,5,7,9"
for num = 1 to 8
2026-02-01 16:33:20 -08:00
stdData = val(word$(sd$,num,","))
2023-07-01 11:58:00 -04:00
sumVal = sumVal + stdData
sumSqs = sumSqs + stdData^2
2026-02-01 16:33:20 -08:00
' standard deviation = square root of (the average of the squares less the square of the average)
2023-07-01 11:58:00 -04:00
standDev =((sumSqs / num) - (sumVal /num) ^ 2) ^ 0.5
sdSave$(num) = str$(num);" ";str$(sumVal);" ";str$(sumSqs)
print num;" value in = ";stdData; " Stand Dev = "; using("###.######", standDev)
next num