langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -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]));
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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 *)
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
MODULE QM;
|
||||
IMPORT ML := MathL, Out;
|
||||
VAR
|
||||
nums: ARRAY 10 OF LONGREAL;
|
||||
i: INTEGER;
|
||||
|
||||
PROCEDURE Rms(a: ARRAY OF LONGREAL): LONGREAL;
|
||||
VAR
|
||||
i: INTEGER;
|
||||
s: LONGREAL;
|
||||
BEGIN
|
||||
s := 0.0;
|
||||
FOR i := 0 TO LEN(a) - 1 DO
|
||||
s := s + (a[i] * a[i])
|
||||
END;
|
||||
RETURN ML.Sqrt(s / LEN(a))
|
||||
END Rms;
|
||||
|
||||
BEGIN
|
||||
FOR i := 0 TO LEN(nums) - 1 DO
|
||||
nums[i] := i + 1
|
||||
END;
|
||||
Out.String("Quadratic Mean: ");Out.LongReal(Rms(nums));Out.Ln
|
||||
END QM.
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
bundle Default {
|
||||
class Hello {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
values := [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
|
||||
RootSquareMean(values)->PrintLine();
|
||||
}
|
||||
|
||||
function : native : RootSquareMean(values : Float[]) ~ Float {
|
||||
sum := 0.0;
|
||||
each(i : values) {
|
||||
x := values[i]->Power(2.0);
|
||||
sum += values[i]->Power(2.0);
|
||||
};
|
||||
|
||||
return (sum / values->Size())->SquareRoot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
declare
|
||||
fun {Square X} X*X end
|
||||
|
||||
fun {RMS Xs}
|
||||
{Sqrt
|
||||
{Int.toFloat {FoldL {Map Xs Square} Number.'+' 0}}
|
||||
/
|
||||
{Int.toFloat {Length Xs}}}
|
||||
end
|
||||
in
|
||||
{Show {RMS {List.number 1 10 1}}}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
RMS(v)={
|
||||
sqrt(sum(i=1,#v,v[i]^2)/#v)
|
||||
};
|
||||
|
||||
RMS(vector(10,i,i))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
RMS_first(n)={
|
||||
sqrt((n+1)*(2*n+1)/6)
|
||||
};
|
||||
|
||||
RMS_first(10)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
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);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
sub rms(*@nums) { sqrt [+](@nums X** 2) / @nums }
|
||||
|
||||
say rms 1..10;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/findrms{
|
||||
/x exch def
|
||||
/sum 0 def
|
||||
/i 0 def
|
||||
x length 0 eq{}
|
||||
{
|
||||
x length{
|
||||
/sum x i get 2 exp sum add def
|
||||
/i i 1 add def
|
||||
}repeat
|
||||
/sum sum x length div sqrt def
|
||||
}ifelse
|
||||
sum ==
|
||||
}def
|
||||
|
||||
[1 2 3 4 5 6 7 8 9 10] findrms
|
||||
|
|
@ -0,0 +1 @@
|
|||
[1 10] 1 range dup 0 {dup * +} fold exch length div sqrt
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
function get-rms([float[]]$nums){
|
||||
$sqsum=$nums | foreach-object { $_*$_} | measure-object -sum | select-object -expand Sum
|
||||
return [math]::sqrt($sqsum/$nums.count)
|
||||
}
|
||||
|
||||
get-rms @(1..10)
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
NewList MyList() ; To hold a unknown amount of numbers to calculate
|
||||
|
||||
If OpenConsole()
|
||||
Define.d result
|
||||
Define i, sum_of_squares
|
||||
|
||||
;Populate a random amounts of numbers to calculate
|
||||
For i=0 To (Random(45)+5) ; max elements is unknown to the program
|
||||
AddElement(MyList())
|
||||
MyList()=Random(15) ; Put in a random number
|
||||
Next
|
||||
|
||||
Print("Averages/Root mean square"+#CRLF$+"of : ")
|
||||
|
||||
; Calculate square of each element, print each & add them together
|
||||
ForEach MyList()
|
||||
Print(Str(MyList())+" ") ; Present to our user
|
||||
sum_of_squares+MyList()*MyList() ; Sum the squares, e.g
|
||||
Next
|
||||
|
||||
;Present the result
|
||||
result=Sqr(sum_of_squares/ListSize(MyList()))
|
||||
PrintN(#CRLF$+"= "+StrD(result))
|
||||
|
||||
PrintN("Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(define rms
|
||||
R -> (sqrt (/ (APPLY + (MAPCAR * R R)) (length R))))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
valueList$ = "1 2 3 4 5 6 7 8 9 10"
|
||||
while word$(valueList$,i +1) <> "" ' grab values from list
|
||||
thisValue = val(word$(valueList$,i +1)) ' turn values into numbers
|
||||
sumSquares = sumSquares + thisValue ^ 2 ' sum up the squares
|
||||
i = i +1 '
|
||||
wend
|
||||
print "List of Values:";valueList$;" containing ";i;" values"
|
||||
print "Root Mean Square =";(sumSquares/i)^0.5
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
define('rms(a)i,ssq') :(rms_end)
|
||||
rms i = i + 1; ssq = ssq + (a<i> * a<i>) :s(rms)
|
||||
rms = sqrt(1.0 * ssq / prototype(a)) :(return)
|
||||
rms_end
|
||||
|
||||
* # Fill array, test and display
|
||||
str = '1 2 3 4 5 6 7 8 9 10'; a = array(10)
|
||||
loop i = i + 1; str len(p) span('0123456789') . a<i> @p :s(loop)
|
||||
output = str ' -> ' rms(a)
|
||||
end
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "float.s7i";
|
||||
include "math.s7i";
|
||||
|
||||
const array float: numbers is [] (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
|
||||
const func float: rms (in array float: numbers) is func
|
||||
result
|
||||
var float: rms is 0.0;
|
||||
local
|
||||
var float: number is 0.0;
|
||||
var float: sum is 0.0;
|
||||
begin
|
||||
for number range numbers do
|
||||
sum +:= number ** 2;
|
||||
end for;
|
||||
rms := sqrt(sum / flt(length(numbers)));
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln(rms(numbers) digits 7);
|
||||
end func;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#import nat
|
||||
#import flo
|
||||
|
||||
#cast %e
|
||||
|
||||
rms = sqrt mean sqr* float* nrange(1,10)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
double rms(double[] list){
|
||||
double sum_squares = 0;
|
||||
double mean;
|
||||
|
||||
foreach ( double number in list){
|
||||
sum_squares += (number * number);
|
||||
}
|
||||
|
||||
mean = Math.sqrt(sum_squares / (double) list.length);
|
||||
|
||||
return mean;
|
||||
} // end rms
|
||||
|
||||
public static void main(){
|
||||
double[] list = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
double mean = rms(list);
|
||||
|
||||
stdout.printf("%s\n", mean.to_string());
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
code CrLf=9;
|
||||
code real RlOut=48;
|
||||
int N;
|
||||
real S;
|
||||
[S:= 0.0;
|
||||
for N:= 1 to 10 do S:= S + sq(float(N));
|
||||
RlOut(0, sqrt(S/10.0));
|
||||
CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue