Averages/Arithmetic mean: Difference between revisions

(1-based index)
Line 3,199:
</syntaxhighlight>
 
=={{header|RPL}}==
===Hard-working approach===
≪ DUP SIZE SWAP OVER
0 1 ROT FOR j
OVER j GET +
NEXT
ROT / SWAP DROP
===Hard-working approach with local variables===
No significant impact on program size or speed, but much more readable
≪ DUP SIZE → vector n
≪ 0 1 n FOR j
vector j GET +
NEXT
n /
≫ ≫
===Straightforward approach===
The dot product of any vector with [1 1 ... 1] gives the sum of its elements.
≪ SIZE LAST DUP 1 CON DOT SWAP / ≫
'AMEAN' STO
 
[ 1 5 0 -4 6 ] AMEAN
{{out}}
<pre>
1: 1.6
</pre>
===Titre===
{{works with|Halcyon Calc|4.2.7}}
=={{header|RPL/2}}==
 
This is a simple rewrite of the dc version above. This works on an HP 48. "->" is a single right arrow character on the 48. Feel free to alter this code as necessary to work on RPL/2.
 
<syntaxhighlight lang="rpl/2">1 2 3 5 7
AMEAN
<< DEPTH DUP 'N' STO ->LIST→LIST ΣLIST N / >>
3.6</syntaxhighlight>
 
1,150

edits