How to resolve the algorithm Cumulative standard deviation step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Cumulative standard deviation step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation language; the task must state which is being used. Do not apply Bessel's correction; the returned standard deviation should always be computed as if the sample seen so far is the entire population.
Use this to compute the standard deviation of this demonstration set,
{ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 }
{\displaystyle {2,4,4,4,5,5,7,9}}
, which is
2
{\displaystyle 2}
.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Cumulative standard deviation step by step in the FreeBASIC programming language
Source code in the freebasic programming language
' FB 1.05.0 Win64
Function calcStandardDeviation(number As Double) As Double
Static a() As Double
Redim Preserve a(0 To UBound(a) + 1)
Dim ub As UInteger = UBound(a)
a(ub) = number
Dim sum As Double = 0.0
For i As UInteger = 0 To ub
sum += a(i)
Next
Dim mean As Double = sum / (ub + 1)
Dim diff As Double
sum = 0.0
For i As UInteger = 0 To ub
diff = a(i) - mean
sum += diff * diff
Next
Return Sqr(sum/ (ub + 1))
End Function
Dim a(0 To 7) As Double = {2, 4, 4, 4, 5, 5, 7, 9}
For i As UInteger = 0 To 7
Print "Added"; a(i); " SD now : "; calcStandardDeviation(a(i))
Next
Print
Print "Press any key to quit"
Sleep
You may also check:How to resolve the algorithm Take notes on the command line step by step in the uBasic/4tH programming language
You may also check:How to resolve the algorithm Web scraping step by step in the Lua programming language
You may also check:How to resolve the algorithm Super-Poulet numbers step by step in the Phix programming language
You may also check:How to resolve the algorithm SEDOLs step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Arturo programming language