[RESOLVED] Mean And Standard Deviation
I seem to figure out why my code is not for finding mean and st dev because the code i wrote for finding the sum is working and mean = sum/N so im confused i think i might have the wrong formula/code for standard deviation tho..i just found it online.....:down:
Code:
Private Sub btnDisplayMean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayMean.Click
Dim Mean As Integer
Dim Sum As Integer
For J = 0 To MyArray.Count - 1
Sum = Sum + MyArray(J)
Mean = CInt(Sum / (MyArray.Count - 1))
Next
txtDisplayNumbers.Text = CStr(Mean)
End Sub
Private Sub btnDisplaySD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplaySD.Click
Dim Mean As Decimal
Dim Temp As Double
Dim Temp2 As Double
Dim StDev As Double
For J = 0 To MyArray.Count - 1
Temp2 = MyArray(J) - Mean
Temp = Temp + Temp2 * Temp2
StDev = Math.Sqrt(Temp / MyArray.Count - 1)
Next
txtDisplayNumbers.Text = CStr(StDev)
End Sub
Re: Mean And Standard Deviation
First up, why would you be calculating the mean inside a loop? The mean is just one value, right? So why would you calculate it more than once?
Also, you say one thing:yet you do something else:
Code:
Mean = CInt(Sum / (MyArray.Count - 1))
You're making the same two errors with your std dev as well.
Re: Mean And Standard Deviation
Quote:
Originally Posted by
jmcilhinney
First up, why would you be calculating the mean inside a loop? The mean is just one value, right? So why would you calculate it more than once?
Oh wow, im an idiot... I'm calculating it in a loop because of my professor(He's CRAZY) wants it that way...
Ok thank you for your help!
Re: Mean And Standard Deviation
Quote:
Originally Posted by
rosleenXOXO
I'm calculating it in a loop because of my professor(He's CRAZY) wants it that way...
It's possible that he would want the sum calculated in a loop. Then after the loop, calculate the mean from that sum.
Re: Mean And Standard Deviation
Quote:
Originally Posted by
Evil_Giraffe
It's possible that he would want the sum calculated in a loop. Then after the loop, calculate the mean from that sum.
I changed it to the way you said :) Thanks a bunch!