Cumulative standard deviation: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(5 intermediate revisions by 3 users not shown)
Line 904:
No attempt to handle different types -- standard deviation is intrinsically a real number.
<syntaxhighlight lang="cpp">
#include <assert.hcassert>
#include <cmath>
#include <vector>
Line 1,348:
1.3997084244475297
2.0</syntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|Pascal}}
<syntaxhighlight lang="easylang">
global sum sum2 n .
proc sd x . r .
sum += x
sum2 += x * x
n += 1
r = sqrt (sum2 / n - sum * sum / n / n)
.
v[] = [ 2 4 4 4 5 5 7 9 ]
for v in v[]
sd v r
print v & " " & r
.
</syntaxhighlight>
 
=={{header|Elixir}}==
Line 3,746 ⟶ 3,763:
7 value in = 7 Stand Dev = 1.399708
8 value in = 9 Stand Dev = 2
</pre>
 
=={{header|RPL}}==
===Basic RPL===
≪ CL∑ { } SWAP
1 OVER SIZE '''FOR''' j
DUP j GET ∑+
'''IF''' j 1 > '''THEN'''
SDEV ∑DAT SIZE 1 GET DUP 1 - SWAP / √ *
ROT SWAP + SWAP '''END'''
'''NEXT'''
DROP CL∑
≫ '<span style="color:blue>CSDEV</span>' STO
===RPL 1993===
≪ CL∑
1 ≪ ∑+ PSDEV ≫ DOSUBS CL∑
≫ '<span style="color:blue>CSDEV</span>' STO
{{out}}
<pre>
1: { 0 1 0.942809041582 0.866025403784 0.979795897113 1 1.39970842445 2 }
</pre>
 
Line 4,405 ⟶ 4,442:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./math" for Nums
 
var cumStdDev = Fiber.new { |a|
Line 4,420 ⟶ 4,457:
var sd = cumStdDev.call(a)
if (cumStdDev.isDone) return
SystemFmt.print("Std Dev : %(Fmt$10.f(108f\n", sd, 8))\n")
}</syntaxhighlight>
 
9,476

edits