Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -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.
|
||||
|
|
@ -2,4 +2,4 @@
|
|||
for xx = (* x x)
|
||||
for n from 1
|
||||
summing xx into xx-sum
|
||||
finally (return (sqrt (/ xx-sum n)))))
|
||||
finally (return (sqrt (/ xx-sum n))))
|
||||
|
|
@ -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))
|
||||
|
|
@ -3,4 +3,4 @@
|
|||
(sqrt (/ (apply '+ (cl-map 'list '* nums nums))
|
||||
(length nums))))
|
||||
|
||||
(rms '(1 2 3 4 5 6 7 8 9 10))
|
||||
(rms (number-sequence 1 10))
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
sqrt(sum(x -> x*x, A) / length(A))
|
||||
sqrt(mean(A.^2.))
|
||||
|
|
|
|||
|
|
@ -1,7 +1 @@
|
|||
function rms(A)
|
||||
s = 0.0
|
||||
for a in A
|
||||
s += a*a
|
||||
end
|
||||
return sqrt(s / length(A))
|
||||
end
|
||||
sqrt(sum(x -> x*x, A) / length(A))
|
||||
|
|
|
|||
|
|
@ -1 +1,7 @@
|
|||
norm(A) / sqrt(length(A))
|
||||
function rms(A)
|
||||
s = 0.0
|
||||
for a in A
|
||||
s += a*a
|
||||
end
|
||||
return sqrt(s / length(A))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
norm(A) / sqrt(length(A))
|
||||
|
|
@ -1,16 +1,18 @@
|
|||
/*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.*/
|
||||
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. */
|
||||
sum=sum+j**2 /*sum the squares of the integers*/
|
||||
/*REXX program computes and displays the root mean square of a number sequence*/
|
||||
parse arg n . /*obtain the optional argument from CL.*/
|
||||
if n=='' then n=10 /*Not specified? Then use the default.*/
|
||||
numeric digits 50 /*go a little overboard on decimal digs*/
|
||||
sum=0 /*the sum of numbers squared (so far).*/
|
||||
do j=1 for n /*process each of the 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 /*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
|
||||
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
|
||||
rms=sqrt(sum/n) /*divide by N, then calculate the SQRT.*/
|
||||
say 'root mean square for 1──►'n "is" rms /*display the RMS. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); i=; m.=9
|
||||
numeric digits 9; numeric form; h=d+6; if x<0 then do; x=-x; i='i'; end
|
||||
parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'e'_%2
|
||||
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
|
||||
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
|
||||
numeric digits d; return (g/1)i /*make complex if X < 0.*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue