How to resolve the algorithm Cumulative standard deviation step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Cumulative standard deviation step by step in the Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
procedure main()
stddev() # reset state / empty
every s := stddev(![2,4,4,4,5,5,7,9]) do
write("stddev (so far) := ",s)
end
procedure stddev(x) # running standard deviation
static X,sumX,sum2X
if /x then { # reset state
X := []
sumX := sum2X := 0.
}
else { # accumulate
put(X,x)
sumX +:= x
sum2X +:= x^2
return sqrt( (sum2X / *X) - (sumX / *X)^2 )
}
end
You may also check:How to resolve the algorithm Assertions step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Tcl programming language
You may also check:How to resolve the algorithm Padovan sequence step by step in the Java programming language
You may also check:How to resolve the algorithm String concatenation step by step in the NS-HUBASIC programming language
You may also check:How to resolve the algorithm Elementary cellular automaton step by step in the Wren programming language