September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,46 @@
|
|||
-- 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
|
||||
|
|
@ -0,0 +1 @@
|
|||
fun rootMeanSq(l): sqrt(mean(l²))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
10 FAST
|
||||
20 LET RMS=0
|
||||
30 FOR X=1 TO 10
|
||||
40 LET RMS=RMS+X**2
|
||||
50 NEXT X
|
||||
60 LET RMS=SQR (RMS/10)
|
||||
70 SLOW
|
||||
80 PRINT RMS
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
(use '[clojure.contrib.math :only (sqrt)])
|
||||
|
||||
(defn rms [xs]
|
||||
(sqrt (/ (reduce + (map #(* % %) xs))
|
||||
(Math/sqrt (/ (reduce + (map #(* % %) xs))
|
||||
(count xs))))
|
||||
|
||||
(println (rms (range 1 11)))
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
import "futlib/math"
|
||||
|
||||
fun main(as: [n]f64): f64 =
|
||||
sqrt64 ((reduce (+) 0.0 (map (**2.0) as)) / f64(n))
|
||||
f64.sqrt ((reduce (+) 0.0 (map (**2.0) as)) / f64(n))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
import Data.List (genericLength)
|
||||
|
||||
rootMeanSquare :: [Double] -> Double
|
||||
rootMeanSquare = sqrt . (((/) . foldr ((+) . (^ 2)) 0) <*> genericLength)
|
||||
|
||||
main :: IO ()
|
||||
main = print $ rootMeanSquare [1 .. 10]
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
public class RMS {
|
||||
public static double rms(double[] nums){
|
||||
double ms = 0;
|
||||
for (int i = 0; i < nums.length; i++)
|
||||
ms += nums[i] * nums[i];
|
||||
ms /= nums.length;
|
||||
return Math.sqrt(ms);
|
||||
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){
|
||||
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 " + rms(nums));
|
||||
System.out.println("The RMS of the numbers from 1 to 10 is " + rootMeanSquare(nums));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
(lst => {
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
|
||||
// rootMeanSquare :: [Num] -> Real
|
||||
let rootMeanSquare = lst =>
|
||||
Math.sqrt(
|
||||
lst.reduce(
|
||||
const rootMeanSquare = xs =>
|
||||
Math.sqrt(
|
||||
xs.reduce(
|
||||
(a, x) => (a + x * x),
|
||||
0
|
||||
) / lst.length
|
||||
) / xs.length
|
||||
);
|
||||
|
||||
|
||||
return rootMeanSquare(lst);
|
||||
return rootMeanSquare([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
|
||||
|
||||
})([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
// -> 6.2048368229954285
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -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)}")
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import math
|
||||
from math import sqrt, sum
|
||||
from sequtils import mapIt
|
||||
|
||||
proc qmean(num): float =
|
||||
for n in num:
|
||||
result += n*n
|
||||
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])
|
||||
echo qmean(@[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0])
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
call testAverage .array~of(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
|
||||
call testAverage .array~of(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, .11)
|
||||
call testAverage .array~of(30, 10, 20, 30, 40, 50, -100, 4.7, -11e2)
|
||||
|
||||
::routine testAverage
|
||||
use arg list
|
||||
say "list =" list~toString("l", ", ")
|
||||
say "root mean square =" rootmeansquare(list)
|
||||
say
|
||||
|
||||
::routine rootmeansquare
|
||||
use arg numbers
|
||||
-- return zero for an empty list
|
||||
if numbers~isempty then return 0
|
||||
|
||||
sum = 0
|
||||
do number over numbers
|
||||
sum += number * number
|
||||
end
|
||||
return rxcalcsqrt(sum/numbers~items)
|
||||
|
||||
::requires rxmath LIBRARY
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
func rms(a) {
|
||||
Math.sqrt(a.map{.**2}.sum / a.len);
|
||||
sqrt(a.map{.**2}.sum / a.len)
|
||||
}
|
||||
|
||||
say rms(1..10);
|
||||
say rms(1..10)
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
fcn rms(z){ ( z.reduce(fcn(p,n){ p + n*n },0.0) /z.len() ).sqrt() }
|
||||
Loading…
Add table
Add a link
Reference in a new issue