Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,34 @@
with Ada.Text_IO, Ada.Numerics.Generic_Elementary_Functions;
procedure Mean_Angles is
type X_Real is digits 4; -- or more digits for improved precision
subtype Real is X_Real range 0.0 .. 360.0; -- the range of interest
type Angles is array(Positive range <>) of Real;
procedure Put(R: Real) is
package IO is new Ada.Text_IO.Float_IO(Real);
begin
IO.Put(R, Fore => 3, Aft => 2, Exp => 0);
end Put;
function Mean_Angle(A: Angles) return Real is
Sin_Sum, Cos_Sum: X_Real := 0.0; -- X_Real since sums might exceed 360.0
package Math is new Ada.Numerics.Generic_Elementary_Functions(Real);
use Math;
begin
for I in A'Range loop
Sin_Sum := Sin_Sum + Sin(A(I), Cycle => 360.0);
Cos_Sum := Cos_Sum + Cos(A(I), Cycle => 360.0);
end loop;
return Arctan(Sin_Sum / X_Real(A'Length), Cos_Sum / X_Real(A'Length),
Cycle => 360.0);
-- may raise Ada.Numerics.Argument_Error if inputs are
-- numerically instable, e.g., when Cos_Sum is 0.0
end Mean_Angle;
begin
Put(Mean_Angle((10.0, 20.0, 30.0))); Ada.Text_IO.New_Line; -- 20.00
Put(Mean_Angle((10.0, 350.0))); Ada.Text_IO.New_Line; -- 0.00
Put(Mean_Angle((90.0, 180.0, 270.0, 360.0))); -- Ada.Numerics.Argument_Error!
end Mean_Angles;

View file

@ -0,0 +1,17 @@
require "complex"
def deg_to_rad (d)
d * Math::PI / 180
end
def rad_to_deg (r)
r * 180 / Math::PI
end
def mean_angle (angles)
rad_to_deg(angles.sum {|deg| deg_to_rad(deg).cis }.phase)
end
[[350, 10], [90, 180, 270, 360], [10, 20, 30]].each do |angles|
puts "The mean angle of %s is: %.2f°." % [angles, mean_angle(angles)]
end

View file

@ -0,0 +1,26 @@
include std/console.e
include std/mathcons.e
sequence AngleList = {{350,10},{90,180,270,360},{10,20,30}}
function atan2(atom y, atom x)
return 2*arctan((sqrt(power(x,2)+power(y,2)) - x)/y)
end function
function MeanAngle(sequence angles)
atom x = 0, y = 0
integer l = length(angles)
for i = 1 to length(angles) do
x += cos(angles[i] * PI / 180)
y += sin(angles[i] * PI / 180)
end for
return atan2(y / l, x / l) * 180 / PI
end function
for i = 1 to length(AngleList) do
printf(1,"Mean Angle for set %d: %3.5f\n",{i,MeanAngle(AngleList[i])})
end for
if getc(0) then end if

View file

@ -0,0 +1,20 @@
local fmt = require "fmt"
local function mean_angle(angles)
local n = #angles
local sin_sum = 0
local cos_sum = 0
for angles as angle do
sin_sum += math.sin(angle * math.pi / 180.0)
cos_sum += math.cos(angle * math.pi / 180.0)
end
return math.atan(sin_sum / n, cos_sum / n) * 180.0 / math.pi
end
local angles1 = {350, 10}
local angles2 = {90, 180, 270, 360}
local angles3 = {10, 20, 30}
for i, angles in {angles1, angles2, angles3} do
fmt.print("Mean for angles %d is : %6.2f", i, mean_angle(angles))
end

View file

@ -0,0 +1,7 @@
function Get-MeanAngle ([double[]]$Angles)
{
$x = ($Angles | ForEach-Object {[Math]::Cos($_ * [Math]::PI / 180)} | Measure-Object -Average).Average
$y = ($Angles | ForEach-Object {[Math]::Sin($_ * [Math]::PI / 180)} | Measure-Object -Average).Average
[Math]::Atan2($y, $x) * 180 / [Math]::PI
}

View file

@ -0,0 +1 @@
@(350, 10), @(90, 180, 270, 360), @(10, 20, 30) | ForEach-Object {Get-MeanAngle $_}

View file

@ -1,55 +1,39 @@
/*REXX program computes the mean angle for a group of angles (expressed in degrees). */
call pi /*define the value of pi to some accuracy.*/
numeric digits length(pi) - 1; /*use PI width decimal digits of precision,*/
showDig= 10 /*only display ten decimal digits. */
#= 350 10 ; say show(#, meanAngleD(#)) /*display mean angle (in degrees), 1st case.*/
#= 90 180 270 360 ; say show(#, meanAngleD(#)) /* " " " " " 2nd " */
#= 10 20 30 ; say show(#, meanAngleD(#)) /* " " " " " 3rd " */
exit /*stick a fork in it, we're all done with it*/
/*───────────────────────────────────────────────────────────────────────────────────────────*/
.sinCos: arg z,_,i; x=x*x; do k=2 by 2 until p=z; p=z; _=-_*x/(k*(k+i)); z=z+_; end; return z
$fuzz: return min(arg(1), max(1, digits() - arg(2) ) )
Acos: procedure; parse arg x; return pi() * .5 - Asin(x)
Atan: parse arg x; if abs(x)=1 then return pi()*.25 * sign(x); return Asin(x/sqrt(1 + x*x))
d2d: return arg(1) // 360
d2r: return r2r(d2d(arg(1)) / 180 * pi() )
r2d: return d2d((r2r(arg(1)) / pi()) * 180)
r2r: return arg(1) // (pi() * 2)
pi: pi=3.1415926535897932384626433832795028841971693993751058209749445923078164062862;return pi
/*───────────────────────────────────────────────────────────────────────────────────────────*/
Asin: procedure; parse arg x 1 z 1 o 1 p; a= abs(x); aa= a * a
if a>1 then call AsinErr x /*argument X is out of range.*/
if a >= sqrt(2) * .5 then return sign(x) * acos( sqrt(1 - aa), '-ASIN')
do j=2 by 2 until p=z; p= z; o= o * aa * (j-1) / j; z= z +o / (j+1); end
return z /* [↑] compute until no noise*/
/*───────────────────────────────────────────────────────────────────────────────────────────*/
Atan2: procedure; parse arg y,x; call pi; s= sign(y)
select
when x=0 then z= s * pi * .5
when x<0 then if y=0 then z= pi; else z= s * (pi - abs( Atan(y/x) ) )
otherwise z= s * Atan(y / x)
end /*select*/; return z
/*───────────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x; x= r2r(x); numeric fuzz $fuzz(6, 3)
a= abs(x); if a=0 then return 1; if a=pi then return -1
if a=pi*.5 | a= pi*1.5 then return 0; if a=pi/3 then return .5
if a= pi*2/3 then return -.5; return .sinCos(1, 1, -1)
/*───────────────────────────────────────────────────────────────────────────────────────────*/
meanAngleD: procedure; parse arg x; numeric digits digits() + digits() % 4
n= words(x); _sin= 0; _cos= 0
do j=1 for n; != d2r( word(x, j)); _sin= _sin + sin(!); _cos= _cos + cos(!)
end /*j*/
return r2d( Atan2( _sin/n, _cos/n) )
/*───────────────────────────────────────────────────────────────────────────────────────────*/
show: parse arg a,mA; _= format(ma, , showDig, 0) / 1
return left('angles='a, 30) "mean angle=" right(_, max(4, length(_) ) )
/*───────────────────────────────────────────────────────────────────────────────────────────*/
sin: procedure; parse arg x; x= r2r(x); numeric fuzz $fuzz(5, 3)
if x=pi * .5 then return 1; if x==pi * 1.5 then return -1
if abs(x)=pi | x=0 then return 0; return .sinCos(x, x, +1)
/*───────────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); m.=9; numeric form; h= d+6
numeric digits; 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*/
return g
-- 21 Feb 2026
include Setting
say 'MEAN ANGLE'
say version
say
numeric digits 11
say 'Meaningful...'
call Task '350;10'
call Task '10;20;30'
call Task '180'
say
say 'Mathematically undefined...'
call Task '90;180;270;360'
call Task '0;180'
call Task '45;225'
call Task '90;270'
call Task '135;305'
exit
Task:
procedure expose Memo.
arg xx
say 'Mean angle of list {'xx'} =' DegL(CmeanL(RadL(xx)))/1
return
CmeanL:
-- Returns circular mean of a list
procedure expose Memo.
arg xx
ss=0; sc=0
do while xx<>''
parse var xx xw';'xx
ss+=Sin(xw); sc+=Cos(xw)
end
return Arctan2(sc,ss)
-- CmeanL (full); DegL; RadL; Sin; Cos; Arctan2
include Math

View file

@ -0,0 +1,23 @@
(import (srfi 1 lists)) ;; use 'fold' from library
(define (average l)
(/ (fold + 0 l) (length l)))
(define pi 3.14159265358979323846264338327950288419716939937510582097)
(define (radians a)
(* pi 1/180 a))
(define (degrees a)
(* 180 (/ 1 pi) a))
(define (mean-angle angles)
(let* ((angles (map radians angles))
(cosines (map cos angles))
(sines (map sin angles)))
(degrees (atan (average sines) (average cosines)))))
(for-each (lambda (angles)
(display "The mean angle of ") (display angles)
(display " is ") (display (mean-angle angles)) (newline))
'((350 10) (90 180 270 360) (10 20 30)))

View file

@ -0,0 +1,24 @@
(define pi (* 4 (atan 1)))
(define (->radians d) (* d (/ pi 180)))
(define (->degrees r) (* r (/ 180 pi)))
(define (average-direction angles)
(->degrees
;; find the angle of the sum in radians
(angle
(apply + (map (lambda (d)
;; a complex number on the unit circle
(make-polar 1 (->radians d)))
angles)))))
(for-each (lambda (l)
(for-each display
(list "The mean angle of "
l
" is "
(average-direction l)
#\newline)))
'((350 10)
(90 180 270 360)
(10 20 30)))