Averages/Arithmetic mean: Difference between revisions

Content added Content deleted
m (→‎{{header|AutoHotkey}}: Minor indentation and casing edit)
No edit summary
Line 456: Line 456:
`rmean($1, eval($2+$3), shift(shift(shift($@))))')')dnl</lang>
`rmean($1, eval($2+$3), shift(shift(shift($@))))')')dnl</lang>
<lang m4>mean(0,100,200,300,400,500,600,700,800,900,1000)</lang>
<lang m4>mean(0,100,200,300,400,500,600,700,800,900,1000)</lang>

=={{header|Mathematica}}==
Modify the built-in Mean function to give 0 for empty vectors (lists in Mathematica):
<lang Mathematica >
Unprotect[Mean];
Mean[{}] := 0
</lang>
Examples:
<lang Mathematica >
Mean[{3,4,5}]
Mean[{3.2,4.5,5.9}]
Mean[{-4, 1.233}]
Mean[{}]
Mean[{1/2,1/3,1/4,1/5}]
Mean[{a,c,Pi,-3,a}]
</lang>
gives (a set of integers gives back an integer or a rational, a set of floats gives back a float, a set of rationals gives a rational back, a list of symbols and numbers keeps the symbols exact and a mix of exact and approximate numbers gives back an approximate number):
<lang Mathematica >
4
4.53333
-1.3835
0
77/240
1/5 (-3+2 a+c+Pi)
</lang>




=={{header|MAXScript}}==
=={{header|MAXScript}}==