You are on page 1of 7

METODO DE CUADRADO MEDIO

BUTTON _SIMULAR: BOTON EJECUTAR

Dim i, n As Integer

Dim x, k, w, y, z, v, t, nlimp As Double

Randomize()

k = Val(TextBox1.Text) REM número de simulaciones

x = Val(TextBox2.Text) REM primer número tomado al azar de "N


cifras

n = Val(TextBox3.Text) REM número de dígitos

nlimp = 0

i=0

TextBox4.Text = TextBox4.Text & "X [" & i & "] = " & x & Chr(13) &
Chr(10)

For i = 1 To k

y=x*x

z = Int(y / 100)

v = Int(z / 10 ^ (2 * n))

t = v * (10 ^ (2 * n))
w=z-t

TextBox5.Text = TextBox5.Text & "Y [" & i & "] = " & y & Chr(13) &
Chr(10)

If i < nlimp * 10 + 10 Then

TextBox6.Text = TextBox6.Text & "W [" & i & "] = " & w & Chr(13) &
Chr(10)

End If

If i = nlimp * 10 + 10 Then

nlimp = nlimp + 1

TextBox6.Text = TextBox6.Text & "W [" & i & "] = " & w & Chr(13) &
Chr(10)

End If

x=w

TextBox4.Text = TextBox4.Text & "X [" & i & "] = " & x & Chr(13) &
Chr(10)

Next

BOTON NUEVO

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click

TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

TextBox5.Text = ""

TextBox6.Text = ""

TextBox1.Focus() End Sub

BOTON SALIR

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
End End Sub

BOTON EJECUTAR
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim I, S, R, A, B, M As Integer

Dim X1 As Double

S = Val(TextBox1.Text) REM ingresa numero semilla

A = Val(TextBox2.Text) REM ingresa valor de a numero primo

B = Val(TextBox3.Text) REM ingresa valor de b numero primo <>b


M = Val(TextBox4.Text) REM igreso del modulo

R = Val(TextBox5.Text) REM ingrese veces a generar el n°


aleatorio For I = 1 To R

X1 = (A ^ I * S + B * (A ^ I - 1) / (A - 1)) Mod M

TextBox6.Text = TextBox6.Text & "NA[" & I & "] = " & X1 & Chr(13)
& Chr(10)

Next End Sub

BOTON NUEVO

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button2.Click

TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

TextBox5.Text = ""

TextBox6.Text = ""

TextBox1.Focus()

End Sub

BOTON SALIR
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click

End End Sub

METODO MONTECARLO
BOTON SIMULAR

Dim np, i, j, m As Integer Dim ph(0 To 100), ptp(0 To 100), pv(0 To


100), pld(0 To 100) As Double Dim sp(0 To 100) As Double Dim t As
Double Dim sph, sptp, spv, splp, spld As Double Randomize() np =
Val(TextBox1.Text) t = Val(TextBox2.Text) For i = 0 To np - 1

ph(i) = (Rnd() * (100000 - 10000) + 10000) * (1 + t / 100) ^ ((Rnd() * (10 -


0.5) + 0.5)) sph = sph + ph(i) ptp(i) = (Rnd() * (50000 - 10000) + 10000) *
(1 + t / 100) ^ ((Rnd() * (10 - 0.5) + 0.5)) sptp = sptp + ptp(i) pv(i) =
(Rnd() * (30000 - 5000) + 5000) * (1 + t / 100) ^ ((Rnd() * (10 - 0.5) +
0.5)) spv = spv + pv(i) pld(i) = (Rnd() * (10000 - 5000) + 5000) * (1 + t /
100) ^ ((Rnd() * (10 - 0.5) + 0.5)) splp = spld + pld(i)

Next REM pone sumas a un vector sp(1) = sph : sp(2) = sptp : sp(3) =
spv : sp(4) = splp For i = 0 To np - 1 tabla.Rows.Add(np) Next For i = 0
To np - 1 tabla.Rows(i).Cells(0).Value = i + 1
tabla.Rows(i).Cells(1).Value = Format(ph(i), "#####.00")
tabla.Rows(i).Cells(2).Value = Format(ptp(i), "#####.00")
tabla.Rows(i).Cells(3).Value = Format(pv(i), "#####.00")
tabla.Rows(i).Cells(4).Value = Format(pld(i), "#####.00") Next

BOTON NUEVO

Private Sub Command2_Click() Dim k As Integer k = tabla.Rows.Count


For i = 0 To k tabla.Rows.Clear() Next TextBox1.Text = ""
TextBox2.Text = "" TextBox1.Focus() End Sub

BOTON SALIR

Private Sub Command3_Click() Me.Close() End Sub

PROGRAMAR TAMBIEN EVENTO FORM LOAD PARA CENTRAR EL


FORMULARIO
Private Sub Form_Load() Dim k As Integer 'Sitúa el formulario en el
centro de la pantalla Move (Screen.Width - Width) / 2, (Screen.Height -
Height) / 2 End Sub

You might also like