Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Averages/Root_mean_square

View file

@ -0,0 +1,19 @@
;Task
Compute the   [[wp:Root mean square|Root mean square]]   of the numbers 1..10.
The   ''root mean square''   is also known by its initials RMS (or rms), and as the '''quadratic mean'''.
The RMS is calculated as the mean of the squares of the numbers, square-rooted:
::: <big><math>x_{\mathrm{rms}} = \sqrt {{{x_1}^2 + {x_2}^2 + \cdots + {x_n}^2} \over n}. </math></big>
;See also
{{Related tasks/Statistical measures}}
<br><hr>

View file

@ -0,0 +1,4 @@
F qmean(num)
R sqrt(sum(num.map(n -> n * n)) / Float(num.len))
print(qmean(1..10))

View file

@ -0,0 +1,28 @@
# Define the rms PROCedure & ABS OPerators for LONG... REAL #
MODE RMSFIELD = #LONG...# REAL;
PROC (RMSFIELD)RMSFIELD rms field sqrt = #long...# sqrt;
INT rms field width = #long...# real width;
PROC crude rms = ([]RMSFIELD v)RMSFIELD: (
RMSFIELD sum := 0;
FOR i FROM LWB v TO UPB v DO sum +:= v[i]**2 OD;
rms field sqrt(sum / (UPB v - LWB v + 1))
);
PROC rms = ([]RMSFIELD v)RMSFIELD: (
# round off error accumulated at standard precision #
RMSFIELD sum := 0, round off error:= 0;
FOR i FROM LWB v TO UPB v DO
RMSFIELD org = sum, prod = v[i]**2;
sum +:= prod;
round off error +:= sum - org - prod
OD;
rms field sqrt((sum - round off error)/(UPB v - LWB v + 1))
);
main: (
[]RMSFIELD one to ten = (1,2,3,4,5,6,7,8,9,10);
print(("crude rms(one to ten): ", crude rms(one to ten), new line));
print(("rms(one to ten): ", rms(one to ten), new line))
)

View file

@ -0,0 +1,36 @@
BEGIN
DECIMAL FUNCTION SQRT(X);
DECIMAL X;
BEGIN
DECIMAL R1, R2, TOL;
TOL := .00001; % reasonable for most purposes %
IF X >= 1.0 THEN
BEGIN
R1 := X;
R2 := 1.0;
END
ELSE
BEGIN
R1 := 1.0;
R2 := X;
END;
WHILE (R1-R2) > TOL DO
BEGIN
R1 := (R1+R2) / 2.0;
R2 := X / R1;
END;
SQRT := R1;
END;
COMMENT - MAIN PROGRAM BEGINS HERE;
DECIMAL N, SQSUM, SQMEAN;
SQSUM := 0.0;
FOR N := 1.0 STEP 1.0 UNTIL 10.0 DO
SQSUM := SQSUM + (N * N);
SQMEAN := SQSUM / (N - 1.0);
WRITE("RMS OF WHOLE NUMBERS 1.0 THROUGH 10.0 =", SQRT(SQMEAN));
END

View file

@ -0,0 +1,21 @@
begin
% computes the root-mean-square of an array of numbers with %
% the specified lower bound (lb) and upper bound (ub) %
real procedure rms( real array numbers ( * )
; integer value lb
; integer value ub
) ;
begin
real sum;
sum := 0;
for i := lb until ub do sum := sum + ( numbers(i) * numbers(i) );
sqrt( sum / ( ( ub - lb ) + 1 ) )
end rms ;
% test the rms procedure with the numbers 1 to 10 %
real array testNumbers( 1 :: 10 );
for i := 1 until 10 do testNumbers(i) := i;
r_format := "A"; r_w := 10; r_d := 4; % set fixed point output %
write( "rms of 1 .. 10: ", rms( testNumbers, 1, 10 ) );
end.

View file

@ -0,0 +1,5 @@
rms{((+/*2)÷)*0.5}
x10
rms x
6.204836823

View file

@ -0,0 +1,11 @@
#!/usr/bin/awk -f
# computes RMS of the 1st column of a data file
{
x = $1; # value of 1st column
S += x*x;
N++;
}
END {
print "RMS: ",sqrt(S/N);
}

View file

@ -0,0 +1,44 @@
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
BYTE FUNC Equal(REAL POINTER a,b)
BYTE ARRAY x,y
x=a y=b
IF x(0)=y(0) AND x(1)=y(1) AND x(2)=y(2) THEN
RETURN (1)
FI
RETURN (0)
PROC Sqrt(REAL POINTER a,b)
REAL z,half
IntToReal(0,z)
ValR("0.5",half)
IF Equal(a,z) THEN
RealAssign(z,b)
ELSE
Power(a,half,b)
FI
RETURN
PROC Main()
BYTE i
REAL x,x2,sum,tmp
IntToReal(0,sum)
FOR i=1 TO 10
DO
IntToReal(i,x)
RealMult(x,x,x2)
RealAdd(sum,x2,tmp)
RealAssign(tmp,sum)
OD
IntToReal(10,x)
RealDiv(sum,x,tmp)
Sqrt(tmp,x)
Put(125) PutE() ;clear screen
Print("RMS of 1..10 is ")
PrintRE(x)
RETURN

View file

@ -0,0 +1,20 @@
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
procedure calcrms is
type float_arr is array(1..10) of Float;
function rms(nums : float_arr) return Float is
sum : Float := 0.0;
begin
for p in nums'Range loop
sum := sum + nums(p)**2;
end loop;
return sqrt(sum/Float(nums'Length));
end rms;
list : float_arr;
begin
list := (1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0);
put( rms(list) , Exp=>0);
end calcrms;

View file

@ -0,0 +1,48 @@
--------------------- ROOT MEAN SQUARE -------------------
-- rootMeanSquare :: [Num] -> Real
on rootMeanSquare(xs)
script
on |λ|(a, x)
a + x * x
end |λ|
end script
(foldl(result, 0, xs) / (length of xs)) ^ (1 / 2)
end rootMeanSquare
--------------------------- TEST -------------------------
on run
rootMeanSquare({1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
-- > 6.204836822995
end run
-------------------- GENERIC FUNCTIONS -------------------
-- foldl :: (a -> b -> a) -> a -> [b] -> a
on foldl(f, startValue, xs)
tell mReturn(f)
set v to startValue
set lng to length of xs
repeat with i from 1 to lng
set v to |λ|(v, item i of xs, i, xs)
end repeat
return v
end tell
end foldl
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn

View file

@ -0,0 +1,13 @@
on rootMeanSquare(listOfNumbers)
script o
property lst : listOfNumbers
end script
set r to 0.0
repeat with n in o's lst
set r to r + (n ^ 2)
end repeat
return (r / (count o's lst)) ^ 0.5
end rootMeanSquare
rootMeanSquare({1, 2, 3, 4, 5, 6, 7, 8, 9, 10})

View file

@ -0,0 +1 @@
6.204836822995

View file

@ -0,0 +1,6 @@
-- RMS of integer range a to b.
on rootMeanSquare(a, b)
return ((b * (b + 1) * (2 * b + 1) - a * (a - 1) * (2 * a - 1)) / 6 / (b - a + 1)) ^ 0.5
end rootMeanSquare
rootMeanSquare(1, 10)

View file

@ -0,0 +1 @@
6.204836822995

View file

@ -0,0 +1,6 @@
10 N = 10
20 FOR I = 1 TO N
30 S = S + I * I
40 NEXT
50 X = SQR (S / N)
60 PRINT X

View file

@ -0,0 +1,4 @@
rootMeanSquare: function [arr]->
sqrt (sum map arr 'i -> i^2) // size arr
print rootMeanSquare 1..10

View file

@ -0,0 +1 @@
sqrt(mean(x²))

View file

@ -0,0 +1,11 @@
MsgBox, % RMS(1, 10)
;---------------------------------------------------------------------------
RMS(a, b) { ; Root Mean Square of integers a through b
;---------------------------------------------------------------------------
n := b - a + 1
Loop, %n%
Sum += (a + A_Index - 1) ** 2
Return, Sqrt(Sum / n)
}

View file

@ -0,0 +1,8 @@
MsgBox, % RMS(1, 10)
;---------------------------------------------------------------------------
RMS(a, b) { ; Root Mean Square of integers a through b
;---------------------------------------------------------------------------
Return, Sqrt((b*(b+1)*(2*b+1)-a*(a-1)*(2*a-1))/6/(b-a+1))
}

View file

@ -0,0 +1,14 @@
DIM i(1 TO 10) AS DOUBLE, L0 AS LONG
FOR L0 = 1 TO 10
i(L0) = L0
NEXT
PRINT STR$(rms#(i()))
FUNCTION rms# (what() AS DOUBLE)
DIM L0 AS LONG, tmp AS DOUBLE, rt AS DOUBLE
FOR L0 = LBOUND(what) TO UBOUND(what)
rt = rt + (what(L0) ^ 2)
NEXT
tmp = UBOUND(what) - LBOUND(what) + 1
rms# = SQR(rt / tmp)
END FUNCTION

View file

@ -0,0 +1,7 @@
DIM array(9)
array() = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
PRINT FNrms(array())
END
DEF FNrms(a()) = MOD(a()) / SQR(DIM(a(),1)+1)

View file

@ -0,0 +1,3 @@
RMS +´×˜÷
RMS 1+10

View file

@ -0,0 +1 @@
6.2048368229954285

View file

@ -0,0 +1 @@
RMS (+´÷)(ט)

View file

@ -0,0 +1,13 @@
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
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 ) ) / 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,23 @@
using System;
namespace rms
{
class Program
{
static void Main(string[] args)
{
int[] x = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Console.WriteLine(rootMeanSquare(x));
}
private static double rootMeanSquare(int[] x)
{
double sum = 0;
for (int i = 0; i < x.Length; i++)
{
sum += (x[i]*x[i]);
}
return Math.Sqrt(sum / x.Length);
}
}
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace rms
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(rootMeanSquare(Enumerable.Range(1, 10)));
}
private static double rootMeanSquare(IEnumerable<int> x)
{
return Math.Sqrt(x.Average(i => (double)i * i));
}
}
}

View file

@ -0,0 +1,18 @@
#include <stdio.h>
#include <math.h>
double rms(double *v, int n)
{
int i;
double sum = 0.0;
for(i = 0; i < n; i++)
sum += v[i] * v[i];
return sqrt(sum / n);
}
int main(void)
{
double v[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
printf("%f\n", rms(v, sizeof(v)/sizeof(double)));
return 0;
}

View file

@ -0,0 +1,21 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. QUADRATIC-MEAN-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 QUADRATIC-MEAN-VARS.
05 N PIC 99 VALUE 0.
05 N-SQUARED PIC 999.
05 RUNNING-TOTAL PIC 999 VALUE 0.
05 MEAN-OF-SQUARES PIC 99V9(16).
05 QUADRATIC-MEAN PIC 9V9(15).
PROCEDURE DIVISION.
CONTROL-PARAGRAPH.
PERFORM MULTIPLICATION-PARAGRAPH 10 TIMES.
DIVIDE RUNNING-TOTAL BY 10 GIVING MEAN-OF-SQUARES.
COMPUTE QUADRATIC-MEAN = FUNCTION SQRT(MEAN-OF-SQUARES).
DISPLAY QUADRATIC-MEAN UPON CONSOLE.
STOP RUN.
MULTIPLICATION-PARAGRAPH.
ADD 1 TO N.
MULTIPLY N BY N GIVING N-SQUARED.
ADD N-SQUARED TO RUNNING-TOTAL.

View file

@ -0,0 +1,5 @@
(defn rms [xs]
(Math/sqrt (/ (reduce + (map #(* % %) xs))
(count xs))))
(println (rms (range 1 11)))

View file

@ -0,0 +1,5 @@
root_mean_square = (ary) ->
sum_of_squares = ary.reduce ((s,x) -> s + x*x), 0
return Math.sqrt(sum_of_squares / ary.length)
alert root_mean_square([1..10])

View file

@ -0,0 +1,5 @@
(loop for x from 1 to 10
for xx = (* x x)
for n from 1
summing xx into xx-sum
finally (return (sqrt (/ xx-sum n))))

View file

@ -0,0 +1,7 @@
(defun root-mean-square (numbers)
"Takes a list of numbers, returns their quadratic mean."
(sqrt
(/ (apply #'+ (mapcar #'(lambda (x) (* x x)) numbers))
(length numbers))))
(root-mean-square (loop for i from 1 to 10 collect i))

View file

@ -0,0 +1,11 @@
precision 8
let n = 10
for i = 1 to n
let s = s + i * i
next i
print sqrt(s / n)

View file

@ -0,0 +1,5 @@
def rms(seq)
Math.sqrt(seq.sum { |x| x*x } / seq.size)
end
puts rms (1..10).to_a

View file

@ -0,0 +1,9 @@
import std.stdio, std.math, std.algorithm, std.range;
real rms(R)(R d) pure {
return sqrt(d.reduce!((a, b) => a + b * b) / real(d.length));
}
void main() {
writefln("%.19f", iota(1, 11).rms);
}

View file

@ -0,0 +1,22 @@
program AveragesMeanSquare;
{$APPTYPE CONSOLE}
uses Types;
function MeanSquare(aArray: TDoubleDynArray): Double;
var
lValue: Double;
begin
Result := 0;
for lValue in aArray do
Result := Result + (lValue * lValue);
if Result > 0 then
Result := Sqrt(Result / Length(aArray));
end;
begin
Writeln(MeanSquare(TDoubleDynArray.Create()));
Writeln(MeanSquare(TDoubleDynArray.Create(1,2,3,4,5,6,7,8,9,10)));
end.

View file

@ -0,0 +1,13 @@
def makeMean(base, include, finish) {
return def mean(numbers) {
var count := 0
var acc := base
for x in numbers {
acc := include(acc, x)
count += 1
}
return finish(acc, count)
}
}
def RMS := makeMean(0, fn b,x { b+x**2 }, fn acc,n { (acc/n).sqrt() })

View file

@ -0,0 +1,2 @@
? RMS(1..10)
# value: 6.2048368229954285

View file

@ -0,0 +1,9 @@
PROGRAM ROOT_MEAN_SQUARE
BEGIN
N=10
FOR I=1 TO N DO
S=S+I*I
END FOR
X=SQR(S/N)
PRINT("Root mean square is";X)
END PROGRAM

View file

@ -0,0 +1,5 @@
(define (rms xs)
(sqrt (// (for/sum ((x xs)) (* x x)) (length xs))))
(rms (range 1 11))
→ 6.2048368229954285

View file

@ -0,0 +1,14 @@
import extensions;
import system'routines;
import system'math;
extension op
{
get RootMeanSquare()
= (self.selectBy:(x => x * x).summarize(Real.new()) / self.Length).sqrt();
}
public program()
{
console.printLine(new Range(1, 10).RootMeanSquare)
}

View file

@ -0,0 +1,14 @@
defmodule RC do
def root_mean_square(enum) do
enum
|> square
|> mean
|> :math.sqrt
end
defp mean(enum), do: Enum.sum(enum) / Enum.count(enum)
defp square(enum), do: (for x <- enum, do: x * x)
end
IO.puts RC.root_mean_square(1..10)

View file

@ -0,0 +1,5 @@
(defun rms (nums)
(sqrt (/ (apply '+ (mapcar (lambda (x) (* x x)) nums))
(float (length nums)))))
(rms (number-sequence 1 10))

View file

@ -0,0 +1,4 @@
rms(Nums) ->
math:sqrt(lists:foldl(fun(E,S) -> S+E*E end, 0, Nums) / length(Nums)).
rms([1,2,3,4,5,6,7,8,9,10]).

View file

@ -0,0 +1,14 @@
function rms(sequence s)
atom sum
if length(s) = 0 then
return 0
end if
sum = 0
for i = 1 to length(s) do
sum += power(s[i],2)
end for
return sqrt(sum/length(s))
end function
constant s = {1,2,3,4,5,6,7,8,9,10}
? rms(s)

View file

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

View file

@ -0,0 +1,4 @@
ROOTMEANSQR
=LAMBDA(xs,
SQRT(SUMSQ(xs)/COUNT(xs))
)

View file

@ -0,0 +1,6 @@
ENUMFROMTO
=LAMBDA(a,
LAMBDA(z,
SEQUENCE(1 + z - a, 1, a, 1)
)
)

View file

@ -0,0 +1,3 @@
let RMS (x:float list) : float = List.map (fun y -> y**2.0) x |> List.average |> System.Math.Sqrt
let res = RMS [1.0..10.0]

View file

@ -0,0 +1,2 @@
: root-mean-square ( seq -- mean )
[ [ sq ] map-sum ] [ length ] bi / sqrt ;

View file

@ -0,0 +1,16 @@
class Main
{
static Float averageRms (Float[] nums)
{
if (nums.size == 0) return 0.0f
Float sum := 0f
nums.each { sum += it * it }
return (sum / nums.size.toFloat).sqrt
}
public static Void main ()
{
a := [1f,2f,3f,4f,5f,6f,7f,8f,9f,10f]
echo ("RMS Average of $a is: " + averageRms(a))
}
}

View file

@ -0,0 +1,9 @@
: rms ( faddr len -- frms )
dup >r 0e
floats bounds do
i f@ fdup f* f+
float +loop
r> s>f f/ fsqrt ;
create test 1e f, 2e f, 3e f, 4e f, 5e f, 6e f, 7e f, 8e f, 9e f, 10e f,
test 10 rms f. \ 6.20483682299543

View file

@ -0,0 +1 @@
print *,sqrt( sum(x**2)/size(x) )

View file

@ -0,0 +1,20 @@
' FB 1.05.0 Win64
Function QuadraticMean(array() As Double) As Double
Dim length As Integer = Ubound(array) - Lbound(array) + 1
Dim As Double sum = 0.0
For i As Integer = LBound(array) To UBound(array)
sum += array(i) * array(i)
Next
Return Sqr(sum/length)
End Function
Dim vector(1 To 10) As Double
For i As Integer = 1 To 10
vector(i) = i
Next
Print "Quadratic mean (or RMS) is :"; QuadraticMean(vector())
Print
Print "Press any key to quit the program"
Sleep

View file

@ -0,0 +1,4 @@
import "futlib/math"
fun main(as: [n]f64): f64 =
f64.sqrt ((reduce (+) 0.0 (map (**2.0) as)) / f64(n))

View file

@ -0,0 +1,9 @@
1, 10 rep (i)
i i | (v) ;
0
1, 10 rep (i)
i dup mult +
]
10 div
sqrt
print

View file

@ -0,0 +1,15 @@
package main
import (
"fmt"
"math"
)
func main() {
const n = 10
sum := 0.
for x := 1.; x <= n; x++ {
sum += x * x
}
fmt.Println(math.Sqrt(sum / n))
}

View file

@ -0,0 +1,7 @@
def quadMean = { list ->
list == null \
? null \
: list.empty \
? 0 \
: ((list.collect { it*it }.sum()) / list.size()) ** 0.5
}

View file

@ -0,0 +1,6 @@
def list = 1..10
def Q = quadMean(list)
println """
list: ${list}
Q: ${Q}
"""

View file

@ -0,0 +1 @@
main = print $ mean 2 [1 .. 10]

View file

@ -0,0 +1,7 @@
import Data.List (genericLength)
rootMeanSquare :: [Double] -> Double
rootMeanSquare = sqrt . (((/) . foldr ((+) . (^ 2)) 0) <*> genericLength)
main :: IO ()
main = print $ rootMeanSquare [1 .. 10]

View file

@ -0,0 +1,5 @@
sum = 0
DO i = 1, 10
sum = sum + i^2
ENDDO
WRITE(ClipBoard) "RMS(1..10) = ", (sum/10)^0.5

View file

@ -0,0 +1,8 @@
100 PRINT RMS(10)
110 DEF RMS(N)
120 LET R=0
130 FOR X=1 TO N
140 LET R=R+X^2
150 NEXT
160 LET RMS=SQR(R/N)
170 END DEF

View file

@ -0,0 +1,5 @@
procedure main()
every put(x := [], 1 to 10)
writes("x := [ "); every writes(!x," "); write("]")
write("Quadratic mean:",q := qmean!x)
end

View file

@ -0,0 +1,6 @@
procedure qmean(L[]) #: quadratic mean
local m
if *L = 0 then fail
every (m := 0.0) +:= !L^2
return sqrt(m / *L)
end

View file

@ -0,0 +1,3 @@
rms := method (figs, (figs map(** 2) reduce(+) / figs size) sqrt)
rms( Range 1 to(10) asList ) println

View file

@ -0,0 +1 @@
rms=: (+/ % #)&.:*:

View file

@ -0,0 +1,2 @@
rms 1 + i. 10
6.20484

View file

@ -0,0 +1,14 @@
public class RootMeanSquare {
public static double rootMeanSquare(double... nums) {
double sum = 0.0;
for (double num : nums)
sum += num * num;
return Math.sqrt(sum / nums.length);
}
public static void main(String[] args) {
double[] nums = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
System.out.println("The RMS of the numbers from 1 to 10 is " + rootMeanSquare(nums));
}
}

View file

@ -0,0 +1,6 @@
function root_mean_square(ary) {
var sum_of_squares = ary.reduce(function(s,x) {return (s + x*x)}, 0);
return Math.sqrt(sum_of_squares / ary.length);
}
print( root_mean_square([1,2,3,4,5,6,7,8,9,10]) ); // ==> 6.2048368229954285

View file

@ -0,0 +1,18 @@
(() => {
'use strict';
// rootMeanSquare :: [Num] -> Real
const rootMeanSquare = xs =>
Math.sqrt(
xs.reduce(
(a, x) => (a + x * x),
0
) / xs.length
);
return rootMeanSquare([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// -> 6.2048368229954285
})();

View file

@ -0,0 +1,4 @@
def rms: length as $length
| if $length == 0 then null
else map(. * .) | add | sqrt / $length
end ;

View file

@ -0,0 +1 @@
rms

View file

@ -0,0 +1 @@
sqrt(sum(A.^2.) / length(A))

View file

@ -0,0 +1 @@
sqrt(mean(A.^2.))

View file

@ -0,0 +1 @@
sqrt(sum(x -> x*x, A) / length(A))

View file

@ -0,0 +1,7 @@
function rms(A)
s = 0.0
for a in A
s += a*a
end
return sqrt(s / length(A))
end

View file

@ -0,0 +1 @@
norm(A) / sqrt(length(A))

View file

@ -0,0 +1,3 @@
rms:{_sqrt (+/x^2)%#x}
rms 1+!10
6.204837

View file

@ -0,0 +1,11 @@
// version 1.0.5-2
fun quadraticMean(vector: Array<Double>) : Double {
val sum = vector.sumByDouble { it * it }
return Math.sqrt(sum / vector.size)
}
fun main(args: Array<String>) {
val vector = Array(10, { (it + 1).toDouble() })
print("Quadratic mean of numbers 1 to 10 is ${quadraticMean(vector)}")
}

View file

@ -0,0 +1,10 @@
{def rms
{lambda {:n}
{sqrt
{/ {+ {S.map {lambda {:i} {* :i :i}}
{S.serie 1 :n}}}
:n}}}}
-> rms
{rms 10}
-> 6.2048368229954285

View file

@ -0,0 +1,4 @@
define rms(a::staticarray)::decimal => {
return math_sqrt((with n in #a sum #n*#n) / decimal(#a->size))
}
rms(generateSeries(1,10)->asStaticArray)

View file

@ -0,0 +1,26 @@
' [RC] Averages/Root mean square
SourceList$ ="1 2 3 4 5 6 7 8 9 10"
' If saved as an array we'd have to have a flag for last data.
' LB has the very useful word$() to read from delimited strings.
' The default delimiter is a space character, " ".
SumOfSquares =0
n =0 ' This holds index to number, and counts number of data.
data$ ="666" ' temporary dummy to enter the loop.
while data$ <>"" ' we loop until no data left.
data$ =word$( SourceList$, n +1) ' first data, as a string
NewVal =val( data$) ' convert string to number
SumOfSquares =SumOfSquares +NewVal^2 ' add to existing sum of squares
n =n +1 ' increment number of data items found
wend
n =n -1
print "Supplied data was "; SourceList$
print "This contained "; n; " numbers."
print "R.M.S. value is "; ( SumOfSquares /n)^0.5
end

View file

@ -0,0 +1,5 @@
to rms :v
output sqrt quotient (apply "sum map [? * ?] :v) count :v
end
show rms iseq 1 10

View file

@ -0,0 +1,4 @@
function sumsq(a, ...) return a and a^2 + sumsq(...) or 0 end
function rms(t) return (sumsq(unpack(t)) / #t)^.5 end
print(rms{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})

View file

@ -0,0 +1,3 @@
function rms = quadraticMean(list)
rms = sqrt(mean(list.^2));
end

View file

@ -0,0 +1,5 @@
>> quadraticMean((1:10))
ans =
6.204836822995429

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

@ -0,0 +1 @@
RootMeanSquare@Range[10]

View file

@ -0,0 +1,5 @@
L: makelist(i, i, 10)$
rms(L) := sqrt(lsum(x^2, x, L)/length(L))$
rms(L), numer; /* 6.204836822995429 */

View file

@ -0,0 +1,3 @@
(((dup *) map sum) keep size / sqrt) ^rms
(1 2 3 4 5 6 7 8 9 10) rms puts!

View file

@ -0,0 +1,14 @@
import morfa.base;
import morfa.functional.base;
template <TRange>
func rms(d: TRange): float
{
var count = 1;
return sqrt(reduce( (a: float, b: float) { count += 1; return a + b * b; }, d) / count);
}
func main(): void
{
println(rms(1 .. 11));
}

View file

@ -0,0 +1,17 @@
using System;
using System.Console;
using System.Math;
module RMS
{
RMS(x : list[int]) : double
{
def sum = x.Map(fun (x) {x*x}).FoldLeft(0, _+_);
Sqrt((sum :> double) / x.Length)
}
Main() : void
{
WriteLine("RMS of [1 .. 10]: {0:g6}", RMS($[1 .. 10]));
}
}

View file

@ -0,0 +1,15 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
parse arg maxV .
if maxV = '' | maxV = '.' then maxV = 10
sum = 0
loop nr = 1 for maxV
sum = sum + nr ** 2
end nr
rmsD = Math.sqrt(sum / maxV)
say 'RMS of values from 1 to' maxV':' rmsD
return

View file

@ -0,0 +1,8 @@
from math import sqrt, sum
from sequtils import mapIt
proc qmean(num: seq[float]): float =
result = num.mapIt(it * it).sum
result = sqrt(result / float(num.len))
echo qmean(@[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0])

View file

@ -0,0 +1,7 @@
let rms a =
sqrt (Array.fold_left (fun s x -> s +. x*.x) 0.0 a /.
float_of_int (Array.length a))
;;
rms (Array.init 10 (fun i -> float_of_int (i+1))) ;;
(* 6.2048368229954285 *)

Some files were not shown because too many files have changed in this diff Show more