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,4 @@
mean := proc( a :: indexable )
local i;
Normalizer( add( i, i in a ) / numelems( a ) )
end proc:

View file

@ -0,0 +1,21 @@
> mean( { 1/2, 2/3, 3/4, 4/5, 5/6 } ); # set
71
---
100
> mean( [ a, 2, c, 2.3, e ] ); # list
0.8600000000 + a/5 + c/5 + e/5
> mean( Array( [ 1, sin( s ), 3, exp( I*t ), 5 ] ) ); # array
9/5 + 1/5 sin(s) + 1/5 exp(t I)
> mean( [ sin(s)^2, cos(s)^2 ] );
2 2
1/2 sin(s) + 1/2 cos(s)
> Normalizer := simplify: # use a stronger normalizer than the default
> mean( [ sin(s)^2, cos(s)^2 ] );
1/2
> mean([]); # empty argument causes an exception to be raised.
Error, (in mean) numeric exception: division by zero

View file

@ -0,0 +1 @@
mean := () -> Normalizer( `+`( args ) / nargs ):

View file

@ -0,0 +1,10 @@
> mean( 1, 2, 3, 4, 5 );
3
> mean( a + b, b + c, c + d, d + e, e + a );
2 a 2 b 2 c 2 d 2 e
--- + --- + --- + --- + ---
5 5 5 5 5
> mean(); # again, an exception is raised
Error, (in mean) numeric exception: division by zero

View file

@ -0,0 +1 @@
mean := ( s :: seq(algebraic) ) -> Normalizer( `+`( args ) / nargs ):