This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
avgAngleD=: (_1 { [: (**|)&.+.@(+/ % #)&.(*.inv) 1,.])&.(1r180p1&*)

View file

@ -0,0 +1,6 @@
rfd=: 1r180p1&* NB. convert angle to radians from degrees
toComplex=: *.inv NB. maps integer pairs as length, complex angle (in radians)
mean=: +/ % # NB. calculate arithmetic mean
roundComplex=: (* * |)&.+. NB. discard an extraneous least significant bit of precision from a complex value whose magnitude is in the vicinity of 1
avgAngleR=: _1 { [: roundComplex@mean&.toComplex 1 ,. ] NB. calculate average angle in radians
avgAngleD=: avgAngleR&.rfd

View file

@ -0,0 +1,6 @@
avgAngleD 10 350
0
avgAngleD 90 180 270 360 NB. result not meaningful
0
avgAngleD 10 20 30
20

View file

@ -0,0 +1,42 @@
global Pi
Pi =3.1415926535
print "Mean Angle( "; chr$( 34); "350,10"; chr$( 34); ") = "; using( "###.#", meanAngle( "350,10")); " degrees." ' 0
print "Mean Angle( "; chr$( 34); "90,180,270,360"; chr$( 34); ") = "; using( "###.#", meanAngle( "90,180,270,360")); " degrees." ' -90
print "Mean Angle( "; chr$( 34); "10,20,30"; chr$( 34); ") = "; using( "###.#", meanAngle( "10,20,30")); " degrees." ' 20
end
function meanAngle( angles$)
term =1
while word$( angles$, term, ",") <>""
angle =val( word$( angles$, term, ","))
sumSin = sumSin +sin( degRad( angle))
sumCos = sumCos +cos( degRad( angle))
term =term +1
wend
meanAngle= radDeg( atan2( sumSin, sumCos))
if abs( sumSin) +abs( sumCos) <0.001 then notice "Not Available." +_
chr$( 13) +"(" +angles$ +")" +_
chr$( 13) +"Result nearly equals zero vector." +_
chr$( 13) +"Displaying '666'.": meanAngle =666
end function
function degRad( theta)
degRad =theta *Pi /180
end function
function radDeg( theta)
radDeg =theta *180 /Pi
end function
function atan2( y, x)
if x >0 then at =atn( y /x)
if y >=0 and x <0 then at =atn( y /x) +pi
if y <0 and x <0 then at =atn( y /x) -pi
if y >0 and x =0 then at = pi /2
if y <0 and x =0 then at = 0 -pi /2
if y =0 and x =0 then notice "undefined": end
atan2 =at
end function

View file

@ -0,0 +1,2 @@
> [ 350, 10 ] *~ Unit(arcdeg);
[350 [arcdeg], 10 [arcdeg]]

View file

@ -0,0 +1,5 @@
MeanAngle := proc( L )
uses Units:-Standard; # for unit-awareness
local u;
evalf( convert( argument( add( u, u = exp~( I *~ L ) ) ), 'units', 'radian', 'degree' ) )
end proc:

View file

@ -0,0 +1,8 @@
> MeanAngle( [ 350, 10 ] *~ Unit(arcdeg) );
0.
> MeanAngle( [ 90, 180, 270, 360 ] *~ Unit(arcdeg) );
0.
> MeanAngle( [ 10, 20, 30 ] *~ Unit(arcdeg) );
20.00000000

View file

@ -0,0 +1 @@
meanAngle[data_List] := N@Arg[Mean[Exp[I data Degree]]]/Degree