Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15524

Can someone check my algorithms? (cubic mean and power mean)

$
0
0
I'm working on an averages app.
I have some algorithms, that i haven't found any online calculators to test with

Cubic mean
Code:

Dim sum As Decimal
For x As Integer = 0 To numbersAsInteger.GetUpperBound(0)
    sum += CDec(numbersAsInteger(x) * (3 / (x + 1)))
Next
Return Math.Pow((sum / numbersAsInteger.Count), 1 / 3)

Power mean
Code:

If frm.ShowDialog = DialogResult.OK Then
    Dim p As Integer = CInt(frm.NumericUpDown1.Value)
    Dim sum As Decimal
    For x As Integer = 0 To numbersAsInteger.GetUpperBound(0)
        sum += CDec(numbersAsInteger(x) * (p / (x + 1)))
    Next
    Return Math.Pow((sum / numbersAsInteger.Count), 1 / p)
End If

Are my calculations correct?
Thanks for any help

Viewing all articles
Browse latest Browse all 15524

Trending Articles