Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -7,7 +7,7 @@ int main( ) {
std::vector<int> numbers ;
for ( int i = 1 ; i < 11 ; i++ )
numbers.push_back( i ) ;
double meansquare = sqrt ( ( std::inner_product( numbers.begin(), numbers.end(), numbers.begin(), 0 ))/10.0 );
std::cout << "The quadratic mean of the numbers 1 .. 10 is " << meansquare << " !\n" ;
double meansquare = sqrt( ( std::inner_product( numbers.begin(), numbers.end(), numbers.begin(), 0 ) ) / static_cast<double>( numbers.size() ) );
std::cout << "The quadratic mean of the numbers 1 .. " << numbers.size() << " is " << meansquare << " !\n" ;
return 0 ;
}

View file

@ -0,0 +1,7 @@
defmodule RC do
def root_mean_square(list) do
:math.sqrt(Enum.reduce(list, 0, &(&2 + &1 * &1)) / Enum.count(list))
end
end
IO.puts RC.root_mean_square(1..10)

View file

@ -0,0 +1,5 @@
(defun rms (nums)
;; `/' returns a float only when given floats
(setq nums (mapcar 'float nums))
(sqrt (/ (apply '+ (mapcar (lambda (x) (* x x)) nums))
(length nums))))

View file

@ -0,0 +1,6 @@
(defun rms (nums)
(setq nums (mapcar 'float nums))
(sqrt (/ (apply '+ (cl-map 'list '* nums nums))
(length nums))))
(rms '(1 2 3 4 5 6 7 8 9 10))

View file

@ -0,0 +1 @@
=SQRT(SUMSQ($A1:$A10)/COUNT($A1:$A10))

View file

@ -0,0 +1,6 @@
fn RMS arr =
(
local sumSquared = 0
for i in arr do sumSquared += i^2
return (sqrt (sumSquared/arr.count as float))
)

View file

@ -0,0 +1,2 @@
rms #{1..10}
6.20484

View file

@ -0,0 +1,5 @@
y := [ seq(1..10) ]:
RMS := proc( x )
return sqrt( Statistics:-Mean( x ^~ 2 ) );
end proc:
RMS( y );

View file

@ -1,3 +1,7 @@
declare A(10) fixed decimal static initial (1,2,3,4,5,6,7,8,9,10);
n = hbound(A,1);
RMS = sqrt(sum(A**2)/n);
atest: Proc Options(main);
declare A(10) Dec Float(15) static initial (1,2,3,4,5,6,7,8,9,10);
declare (n,RMS) Dec Float(15);
n = hbound(A,1);
RMS = sqrt(sum(A**2)/n);
put Skip Data(rms);
End;

View file

@ -0,0 +1 @@
sub rms { sqrt @_ R/ [+] @_ X** 2 }

View file

@ -1,19 +1,16 @@
/*REXX program to compute the root mean square of a series of numbers.*/
/*REXX program computes the root mean square of a series of numbers. */
parse arg n . /*get the argument (maybe). */
if n=='' then n=10 /*Not specified? Then assume 10.*/
if n=='' then n=10 /*Not specified? Then assume 10.*/
numeric digits 50 /*let's go a little overboard. */
sum=0 /*sum of numbers squared (so far)*/
do j=1 for n /*step through N integers. */
do j=1 for n /*step through N integers. */
sum=sum+j**2 /*sum the squares of the integers*/
end /*j*/
rms=sqrt(sum/n) /*divide by N, then get SQRT. */
say 'root mean square for 1'n "is" rms /*show & tell.*/
say 'root mean square for 1'n "is" rms /*display it.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SQRT subroutine─────────────────────────*/
sqrt: procedure; parse arg x;if x=0 then return 0;d=digits();numeric digits 11
g=.sqrtGuess(); do j=0 while p>9; m.j=p; p=p%2+1; end; do k=j+5 to 0 by -1
numeric form; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'E'_%2
p=d+d%4+2; m.=11; do j=0 while p>9; m.j=p; p=p%2+1; end; do k=j+5 to 0 by -1
if m.k>11 then numeric digits m.k;g=.5*(g+x/g);end;numeric digits d;return g/1
.sqrtGuess: if x<0 then say 'negative number' x; numeric form; m.=11
p=d+d%4+2; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; return g*.5'E'_%2

View file

@ -1,6 +1,6 @@
class Array
def quadratic_mean
Math.sqrt( self.inject(0) {|s, y| s += y*y}.to_f / self.length )
Math.sqrt( self.inject(0.0) {|s, y| s + y*y} / self.length )
end
end
@ -10,4 +10,4 @@ class Range
end
end
(1..10).quadratic_mean # => 6.20483682299543
(1..10).quadratic_mean # => 6.2048368229954285

View file

@ -1,4 +1,4 @@
def rms(seq)
Math.sqrt(seq.inject(0.0) {|sum, x| sum += x*x} / seq.length)
Math.sqrt(seq.inject(0.0) {|sum, x| sum + x*x} / seq.length)
end
puts rms (1..10).to_a # => 6.2048368229954285
puts rms (1..10).to_a # => 6.2048368229954285

View file

@ -0,0 +1 @@
Sqrt(Add((1 .. 10)^2)/10)