JPhrases/SumsMeans

From J Wiki
Jump to navigation Jump to search

10A. Sums & Means

m0=: A=: # %~ +/ Arithmetic mean
m1=: G=: # %: */ Geometric mean
m2=: H=: A&.(%"_) Harmonic mean
m3=: C=: [: {. (A,G)^:_ Common mean; arithmetic-geometric mean (de Kerf [2])
m4=: A&(^&3) Mean of cubes
a5=: (^&) (A&) Generalized x-mean
m6=: m4 -: 3 a5 Tautology
a7=: (^&) (A&.) L-x norm
m8=: (^&3)@(3 a7) -: (3 a5) Tautology
v9=: MA=: A\ x-period moving average of y
m10=: +/\ -: +/\.&.|. Tautology: invariance under reverse
m11=: +/\. -: +/\ &.|. Tautology: invariance under reverse
m12=: +/\^:(i.`($&1)) Figurate numbers
m13=: 1: #. ] Sum; +/"1
m14=: +/&.(*:"_)@:+."0 Magnitude |
m15=: - |.!.0 .+/\^:_1
d16=: psum=: ([:+/ [ ^~ i.@])"0 Sum of powers of integers; 2 sum 7
m17=: 0&psum -: [ Tautology: +/(i.n)^0
m18=: 1&psum -: 2&! Tautology: +/(i.n)^1
m19=: 2&psum -: 0 1r6 _1r2 1r3&p. Tautology: +/(i.n)^2
m20=: [ (psum %. ^/~@]) i.@(2&+) Polynomial coeff. of +/(i.n)^k