(71B) Population Derivation - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (71B) Population Derivation (/thread-14138.html) (71B) Population Derivation - Eddie W. Shore - 12-09-2019 08:27 PM Link: http://edspi31415.blogspot.com/2019/12/hp-71b-population-deviation-derivation.html Derivation The standard formula for the population deviation for a set of statistical data is given by: σx = √( Σ(x - μ)^2 / n) where μ is the mean, where μ = Σx / n Σx = the sum of all the data points n = the number of data points If this function needs to be programmed, using the definition as will probably require the use of two FOR structures: one for the mean, and one for the deviation. Is there a way to use a formula where a FOR structure can be saved? Turns out, the answer is yes. σx = √( Σ(x - μ)^2 / n) = √( Σ(x^2 - 2*x*μ + μ^2) / n) Note that: Σ( f(x) + g(x) ) = Σ f(x) + Σ g(x) For a constant, a: Σ( a * f(x) ) = a * Σ f(x) And: Σ a = a * n (sum from 1 to n) Then: σx = √( Σ(x - μ)^2 / n) = √( Σ(x^2 - 2*x*μ + μ^2) / n) = √( (Σ(x^2) - 2*μ*Σx + Σ( μ^2 )) / n) = √( (Σ(x^2) - 2*μ*Σx + n*μ^2) / n) = √( (Σ(x^2) - 2*Σx*Σx/n + n*(Σx)^2/n^2 ) / n) = √( (Σ(x^2) - 2*(Σx)^2/n + (Σx)^2/n) / n) = √( (Σ(x^2) - (Σx)^2/n ) / n) The above formula allows to use a sum and sum of square of data points in calculating population deviation, eliminating the need for an additional FOR structure. Standard deviation follows a similar formula: sx = √( (Σ(x^2) - (Σx)^2/n ) / (n - 1)) HP 71B Program: Population Deviation File: PDEV Code: ```20 N=0 22 A=0 24 B=0 30 INPUT "X? ";X 40 N=N+1 50 A=A+X 60 B=B+X^2 70 INPUT "DONE? NO=0"; C 80 IF C=0 THEN 30 90 M=A/N 95 S=SQR((B-A^2/N)/N) 100 DISP "MEAN= ";M 105 PAUSE 110 DISP "PDEV= ";S 120 END``` Example Data Set: 150, 178, 293, 426, 508, 793, 1024 MEAN = 481.7142857 PDEV = 300.6320553