How to resolve the algorithm Cumulative standard deviation step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Cumulative standard deviation step by step in the J 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 J programming language

Source code in the j programming language

   mean=: +/ % #
   dev=: - mean
   stddevP=: [: %:@mean *:@dev          NB. A) 3 equivalent defs for stddevP
   stddevP=: [: mean&.:*: dev           NB. B) uses Under (&.:) to apply inverse of *: after mean
   stddevP=: %:@(mean@:*: - *:@mean)    NB. C) sqrt of ((mean of squares) - (square of mean))


   stddevP\ 2 4 4 4 5 5 7 9
0 1 0.942809 0.866025 0.979796 1 1.39971 2


   of     =: @:
   sqrt   =: %:         
   sum    =: +/
   squares=: *:
   data   =: ]
   mean   =: sum % #

   stddevP=: sqrt of mean of squares of (data-mean)

   stddevP\ 2 4 4 4 5 5 7 9
0 1 0.942809 0.866025 0.979796 1 1.39971 2


   require'stats'
   (%:@:(%~<:)@:# * stddev)\ 2 4 4 4 5 5 7 9
0 1 0.942809 0.866025 0.979796 1 1.39971 2


  

You may also check:How to resolve the algorithm Date manipulation step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Fantom programming language
You may also check:How to resolve the algorithm Determine if a string is numeric step by step in the COBOL programming language
You may also check:How to resolve the algorithm Infinity step by step in the Io programming language
You may also check:How to resolve the algorithm Truncate a file step by step in the J programming language