Averages/Pythagorean means: Difference between revisions
Content added Content deleted
(→{{header|D}}: The output for the harmonic mean is wrong.) |
|||
Line 3,257: | Line 3,257: | ||
</pre> |
</pre> |
||
=={{header|VBA}}== |
|||
Uses Excel VBA. |
|||
<lang vb>Private Function arithmetic_mean(s() As Variant) As Double |
|||
arithmetic_mean = WorksheetFunction.sum(s) / UBound(s) |
|||
End Function |
|||
Private Function geometric_mean(s() As Variant) As Double |
|||
geometric_mean = WorksheetFunction.Power( _ |
|||
WorksheetFunction.Product(s), 1 / UBound(s)) |
|||
End Function |
|||
Private Function harmonic_mean(s() As Variant) As Double |
|||
For i = 1 To UBound(s) |
|||
s(i) = 1 / s(i) |
|||
Next i |
|||
harmonic_mean = UBound(s) / WorksheetFunction.sum(s) |
|||
End Function |
|||
Public Sub pythagorean_means() |
|||
Dim s() As Variant |
|||
s = [{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}] |
|||
Debug.Print "A ="; arithmetic_mean(s) |
|||
Debug.Print "G ="; geometric_mean(s) |
|||
Debug.Print "H ="; harmonic_mean(s) |
|||
End Sub</lang>{{out}} |
|||
<pre>A = 5,5 |
|||
G = 4,52872868811677 |
|||
H = 3,41417152147406 </pre> |
|||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
<lang vb> |
<lang vb> |