Averages/Root mean square: Difference between revisions

m
imported>Arakov
 
(10 intermediate revisions by 7 users not shown)
Line 406:
{{out}}
<pre>6.20483683</pre>
 
==={{header|Craft Basic}}===
<syntaxhighlight lang="basic">precision 8
 
let n = 10
 
for i = 1 to n
 
let s = s + i * i
 
next i
 
print sqrt(s / n)</syntaxhighlight>
{{out| Output}}<pre>6.20483682</pre>
 
==={{header|IS-BASIC}}===
Line 668 ⟶ 682:
<syntaxhighlight lang="e">? RMS(1..10)
# value: 6.2048368229954285</syntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|C}}
<syntaxhighlight lang=easylang>
func rms v[] .
for v in v[]
sum += v * v
.
return sqrt (sum / len v[])
.
v[] = [ 1 2 3 4 5 6 7 8 9 10 ]
print rms v[]
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 680 ⟶ 707:
=={{header|Elena}}==
{{trans|C#}}
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
import system'routines;
Line 688 ⟶ 715:
{
get RootMeanSquare()
= (self.selectBy::(x => x * x).summarize(Real.new()) / self.Length).sqrt();
}
Line 1,125 ⟶ 1,152:
Quadratic mean of numbers 1 to 10 is 6.2048368229954285
</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def rms
{lambda {:n}
{sqrt
{/ {+ {S.map {lambda {:i} {* :i :i}}
{S.serie 1 :n}}}
:n}}}}
-> rms
 
{rms 10}
-> 6.2048368229954285
</syntaxhighlight>
 
=={{header|Lasso}}==
Line 1,225 ⟶ 1,266:
 
=={{header|min}}==
{{works with|min|0.1937.60}}
<syntaxhighlight lang="min">(((dup *) :sqmap sum) keep size / sqrt) ^rms
('sq map sum) :sum-sq
(('sum-sq 'size) => cleave / sqrt) :rms
 
(1 2 3 4 5 6 7 8 9 10) rms puts!</syntaxhighlight>
{{out}}
<pre>6.204836822995428</pre>
<pre>
6.204836822995429
</pre>
 
=={{header|МК-61/52}}==
Line 1,864 ⟶ 1,901:
return x
</syntaxhighlight>
 
=={{header|RPL}}==
≪ LIST→ → n
≪ 0 1 n '''START''' SWAP SQ + '''NEXT'''
n / √
≫ ≫ '<span style="color:blue">RMS</span>' STO
 
{ 1 2 3 4 5 6 7 8 9 10 } <span style="color:blue">RMS</span>
{{out}}
<pre>
1: 6.204836823
</pre>
{{works with|HP|48G}}
≪ DUP ≪ SQ + ≫ STREAM SWAP SIZE / √
≫ '<span style="color:blue">RMS</span>' STO
 
=={{header|Ruby}}==
Line 2,066 ⟶ 2,118:
{{out}}
<pre>1 2 3 4 5 6 7 8 9 10 -> 6.20483682</pre>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "calcrms" )
@( description, "Compute the Root mean square of the numbers 1..10." )
@( description, "The root mean square is also known by its initial RMS (or rms), and as the" )
@( description, "quadratic mean. The RMS is calculated as the mean of the squares of the" )
@( description, "numbers, square-rooted" )
@( see_also, "http://rosettacode.org/wiki/Averages/Root_mean_square" )
@( author, "Ken O. Burtch" );
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure calcrms is
type float_arr is array(1..10) of float;
list : constant float_arr := (1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0);
total: float := 0.0;
rms : float;
begin
for p in arrays.first(list)..arrays.last(list) loop
total := @ + list(p)**2;
end loop;
rms := numerics.sqrt( total / float(arrays.length(list)));
? rms;
end calcrms;</syntaxhighlight>
 
=={{header|Standard ML}}==
Line 2,244 ⟶ 2,323:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var rms = ((1..10).reduce(0) { |acc, i| acc + i*i }/10).sqrt
System.print(rms)</syntaxhighlight>
 
Anonymous user