Videos

.

lunes, 25 de mayo de 2009

Varianza de la distribucion - Visual Basic 6

Agregamos un CommandButton y 3 TextBox; en la primera caja tecleamos el numero de elemento total del conjunto de datos por ejemplo:

{5, 8, 2} el numero total de elementos es 3
{3, 9, 3, 7, 5, 48} el numero total de elementos es 6

En la segunda caja nos mostrara la media aritmetica o promedio y en la tercer caja no mostrara la varianza de la distribucion.

Y en el boton agregamos el siguiente codigo:

Private Sub Command1_Click()
Dim x() As String 'Declaro el array
ReDim Preserve x(1 To Val(Text1.Text)) ' y con ReDim Preserve le
'digo que es un arreglo dinamico
For i = 1 To Val(Text1.Text)
x(i) = InputBox("Introduce el dato: " & i)
tmp = Val(x(i))
suma = suma + tmp
tmp = 0
Next i
Text2.Text = suma / Val(Text1.Text) ' media aritmetica o promedio
For j = 1 To Val(Text1.Text)
tmp2 = (x(j) - Val(Text2.Text)) * (x(j) - Val(Text2.Text))
sumatoria_x = sumatoria_x + tmp2
tmp2 = 0
Next j
Text3.Text = sumatoria_x / Val(Text1.Text)
End Sub

Si desean la Varianza muestral vean el comentario jojo

1 comentarios:

si queremos la varianza muestral solo modificamos la penultima linea XD

Text3.Text = sumatoria_x / (Val(Text1.Text) - 1)

Insertar

Twitter Delicious Facebook Digg Stumbleupon Favorites More