Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
(→Joy: add) |
(Merge RPL/2 and RPL, CLEAR added to first implementation to make it always work) |
||
Line 3,220: | Line 3,220: | ||
=={{header|RPL}}== |
=={{header|RPL}}== |
||
⚫ | |||
{{works with|Halcyon Calc|4.2.7}} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
===Hard-working approach=== |
===Hard-working approach=== |
||
Works for all RPL versions. |
|||
≪ DUP SIZE SWAP OVER |
≪ DUP SIZE SWAP OVER |
||
0 1 ROT FOR j |
0 1 ROT '''FOR''' j |
||
OVER j GET + |
OVER j GET + '''NEXT''' |
||
NEXT |
|||
ROT / SWAP DROP |
ROT / SWAP DROP |
||
≫ |
≫ |
||
Line 3,231: | Line 3,237: | ||
No significant impact on program size or speed, but much more readable |
No significant impact on program size or speed, but much more readable |
||
≪ DUP SIZE → vector n |
≪ DUP SIZE → vector n |
||
≪ 0 1 n FOR j |
≪ 0 1 n '''FOR''' j |
||
vector j GET + |
vector j GET + '''NEXT''' |
||
NEXT |
|||
n / |
n / |
||
≫ ≫ |
≫ ≫ |
||
Line 3,239: | Line 3,244: | ||
The dot product of any vector with [1 1 ... 1] gives the sum of its elements. |
The dot product of any vector with [1 1 ... 1] gives the sum of its elements. |
||
≪ SIZE LAST DUP 1 CON DOT SWAP / ≫ |
≪ SIZE LAST DUP 1 CON DOT SWAP / ≫ |
||
'AMEAN' STO |
''''AMEAN'''' STO |
||
===Using built-in statistics features=== |
===Using built-in statistics features=== |
||
Most of the code is dedicated to store the input array according to built-in statistics requirements, which requires a matrix with one line per record. Main benefit of this approach is that you can then easily calculate standard deviation and variance by calling resp. <code>SDEV</code> and <code>VAR</code> functions. |
Most of the code is dedicated to store the input array according to built-in statistics requirements, which requires a matrix with one line per record. Main benefit of this approach is that you can then easily calculate standard deviation and variance by calling resp. <code>SDEV</code> and <code>VAR</code> functions. |
||
≪ { 1 } OVER SIZE + RDM TRN '∑DAT' STO MEAN ≫ |
≪ { 1 } OVER SIZE + RDM TRN '∑DAT' STO MEAN ≫ ''''AMEAN'''' STO |
||
'AMEAN' STO |
|||
[ 1 5 0 -4 6 ] AMEAN |
[ 1 5 0 -4 6 ] '''AMEAN''' |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
1: 1.6 |
1: 1.6 |
||
</pre> |
</pre> |
||
=={{header|RPL/2}}== |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Ruby}}== |
=={{header|Ruby}}== |