Sei sulla pagina 1di 13

Interface de Ingreso de Datos

Programa del formulario


Private Sub bton_algo1_Click()
Dim valor_ini As Single
Dim val_tol As Single
Dim intia As Single
Dim intib As Single
valor_ini = validar_ini(Str(frm_numerico.txt_ini))
val_tol = validar_ini(Str(frm_numerico.txt_tol))
intia = validar_ini(Str(frm_numerico.txt_inita))
intib = validar_ini(Str(frm_numerico.txt_initb))

Call algoritmo(valor_ini, val_tol, intia, intib, 1, Val(txt_corte))


End Sub
Private Sub bton_algo2_Click()
Dim valor_ini As Single
Dim val_tol As Single
Dim intia As Single

Dim intib As Single


valor_ini = validar_ini(Str(frm_numerico.txt_ini))
val_tol = validar_ini(Str(frm_numerico.txt_tol))
intia = validar_ini(Str(frm_numerico.txt_inita))
intib = validar_ini(Str(frm_numerico.txt_initb))

Call algoritmo(valor_ini, val_tol, intia, intib, 2, Val(txt_corte))


End Sub
Private Sub bton_algo3_Click()
Dim valor_ini As Single
Dim val_tol As Single
Dim intia As Single
Dim intib As Single
valor_ini = validar_ini(Str(frm_numerico.txt_ini))
val_tol = validar_ini(Str(frm_numerico.txt_tol))
intia = validar_ini(Str(frm_numerico.txt_inita))
intib = validar_ini(Str(frm_numerico.txt_initb))

Call algoritmo(valor_ini, val_tol, intia, intib, 3, Val(txt_corte))


End Sub
Private Sub bton_algo4_Click()
Dim valor_ini As Single
Dim val_tol As Single
Dim intia As Single
Dim intib As Single
valor_ini = validar_ini(Str(frm_numerico.txt_ini))
val_tol = validar_ini(Str(frm_numerico.txt_tol))
intia = validar_ini(Str(frm_numerico.txt_inita))
intib = validar_ini(Str(frm_numerico.txt_initb))

Call algoritmo(valor_ini, val_tol, intia, intib, 4, Val(txt_corte))


End Sub
Private Sub bton_algo5_Click()
Dim valor_ini As Single
Dim val_tol As Single
Dim intia As Single
Dim intib As Single
valor_ini = validar_ini(Str(frm_numerico.txt_ini))
val_tol = validar_ini(Str(frm_numerico.txt_tol))
intia = validar_ini(Str(frm_numerico.txt_inita))
intib = validar_ini(Str(frm_numerico.txt_initb))

Call algoritmo(valor_ini, val_tol, intia, intib, 5, Val(txt_corte))


End Sub

Function validar_ini(ini As String)


Dim numero As Single
ini = Replace(ini, ".", ",")
If IsNumeric(ini) Then
numero = CDbl(ini)
Else
numero = 999
End If
validar_ini = numero
End Function
Sub algoritmo(ini As Single, tol As Single, inita As Single, initb As Single, numero As Integer,
maximo As Integer)

Dim xn As Single
Dim xn1 As Single
Dim paso As Integer

Dim fin As Boolean


fin = False
paso = 0
maximo = 300
xn = ini

Do While Not fin


paso = paso + 1
xn1 = algo(xn, numero)
Call imprimir(xn, xn1, Abs(Abs(xn) - Abs(xn1)), paso, numero)
If (Abs(tol) > Abs(Abs(xn) - Abs(xn1))) Or (paso > maximo) Then

fin = True
xn = xn1
Else
xn = xn1
End If
Loop
Call mensaje(xn, paso, numero)

End Sub
Sub mensaje(xn As Single, pasos As Integer, numero As Integer)
Select Case numero
Case 1
lb_raiz1 = xn

lb_pasos1 = pasos
Case 2
lb_raiz2 = xn
lb_pasos2 = pasos
Case 3
lb_raiz3 = xn
lb_pasos3 = pasos
Case 4
lb_raiz4 = xn
lb_pasos4 = pasos
Case 5
lb_raiz5 = xn
lb_pasos5 = pasos
End Select
End Sub
Function algo(x As Single, nalgo As Integer)
Select Case nalgo
Case 1
algo = -x ^ 4 - 2 * x ^ 2 + 2 * x + 4 * 0.67491
Case 2
algo = (-2 * x ^ 2 + x + 4 * 0.67491) ^ 0.25
Case 3
algo = (-1 * x ^ 4 + x + 4 * 0.67491) ^ 0.25
Case 4
algo = ((x + 4 * 0.67491) / (x ^ 2 + 2)) ^ 0.5
Case 5
algo = 3 * x ^ 4 + 2 * x ^ 2 + 4 * 0.67491
End Select
End Function

Private Sub UserForm_Initialize()


txt_ini = "0,6"
txt_corte = "300"
txt_inita = "0,5451"
txt_initb = "2.1804"
txt_tol = "0,00001"

End Sub
Sub imprimir(xn As Single, xn1 As Single, dif, paso As Integer, numero As Integer)
Dim columna As Integer
columna = ActiveWorkbook.ActiveSheet.Range("B" & paso + 10).Column
columna = columna + numero * 5

If paso = 1 Then
ActiveWorkbook.ActiveSheet.Cells(8, columna) = "Algoritmo N " & numero
ActiveWorkbook.ActiveSheet.Cells(9, columna) = "Numero de Paso"
ActiveWorkbook.ActiveSheet.Cells(9, columna + 1) = "xn"
ActiveWorkbook.ActiveSheet.Cells(9, columna + 2) = "xn+1"
ActiveWorkbook.ActiveSheet.Cells(9, columna + 3) = "Diferencia entre xn y xn+a < " &
frm_numerico.txt_tol
Else
ActiveWorkbook.ActiveSheet.Cells(paso + 10, columna) = paso
ActiveWorkbook.ActiveSheet.Cells(paso + 10, columna + 1) = xn
ActiveWorkbook.ActiveSheet.Cells(paso + 10, columna + 2) = xn1
ActiveWorkbook.ActiveSheet.Cells(paso + 10, columna + 3) = dif
End If

End Sub

Corrida

Planilla de excel
Algoritmo
N 1

Numero de
Paso
xn

xn+1

Diferenci
a entre
xn y
xn+a <
0,00001

3,050040 96,34681 93,29677


2
01
7
58
96,34681 8618744 8618735
3
7
8
2
8618744 5,5179E 5,5179E
4
8
+31
+31
Algoritmo
N 2
Diferenci
a entre
xn y
Numero de
xn+a <
Paso
xn
xn+1
0,00001
2 1,267330 0,932065 0,335265

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Algoritmo
N 3

17
0,932065
13
1,173160
08
1,028781
18
1,126722
57
1,065183
88
1,105867
74
1,079827
67
1,096852
06
1,085872
77
1,093016
74
1,088394
88
1,091396
21
1,089451
91
1,090713
5
1,089895
73
1,090426
09
1,090082
29
1,090305
21
1,090160
73
1,090254
43
1,090193
63
1,090233
09
1,090207
46
1,090224
15
1,090213
3

13
1,173160
08
1,028781
18
1,126722
57
1,065183
88
1,105867
74
1,079827
67
1,096852
06
1,085872
77
1,093016
74
1,088394
88
1,091396
21
1,089451
91
1,090713
5
1,089895
73
1,090426
09
1,090082
29
1,090305
21
1,090160
73
1,090254
43
1,090193
63
1,090233
09
1,090207
46
1,090224
15
1,090213
3
1,090220
33

04
0,241094
95
0,144378
9
0,097941
4
0,061538
7
0,040683
87
0,026040
08
0,017024
4
0,010979
29
0,007143
97
0,004621
86
0,003001
33
0,001944
3
0,001261
59
0,000817
78
0,000530
36
0,000343
8
0,000222
92
0,000144
48
9,3699E05
6,0797E05
3,9458E05
2,563E05
1,6689E05
1,0848E05
7,0333E06

Numero de
Paso
xn
1,334339
2
02
0,964097
3
08
1,293545
4
37
1,045190
5
33
1,263852
6
72
1,090090
7
39
1,241762
8
04
1,118252
9
4
1,225312
10
11
1,136919
11
86
1,213119
12
39
1,149666
13
79
1,204134
14
7
1,158524
15
99
1,197550
16
06
1,164748
17
91
1,192746
18
52
1,169153
19
45
1,189255
20
24
1,172285
21
44
1,186724
22
9
1,174519
23
78
1,184894
24
92
1,176117
25
42
1,183573
26
6

xn+1
0,964097
08
1,293545
37
1,045190
33
1,263852
72
1,090090
39
1,241762
04
1,118252
4
1,225312
11
1,136919
86
1,213119
39
1,149666
79
1,204134
7
1,158524
99
1,197550
06
1,164748
91
1,192746
52
1,169153
45
1,189255
24
1,172285
44
1,186724
9
1,174519
78
1,184894
92
1,176117
42
1,183573
6
1,177261
59

Diferenci
a entre
xn y
xn+a <
0,00001
0,370241
94
0,329448
28
0,248355
03
0,218662
38
0,173762
32
0,151671
65
0,123509
65
0,107059
72
0,088392
26
0,076199
53
0,063452
6
0,054467
92
0,045609
71
0,039025
07
0,032801
15
0,027997
61
0,023593
07
0,020101
79
0,016969
8
0,014439
46
0,012205
12
0,010375
14
0,008777
5
0,007456
18
0,006312
01

1,177261 1,182620 0,005359


59
64
05
1,182620 1,178081 0,004538
28
64
87
77
1,178081
0,003852
29
87 1,181934
13
1,178670 0,003263
30 1,181934
41
59
1,178670 1,181439 0,002769
31
41
52
11
1,181439
0,002346
32
52 1,179093
52
1,181083 0,001990
33 1,179093
68
68
1,181083 1,179396 0,001687
34
68
39
29
1,179396 1,180827 0,001431
35
39
62
23
1,180827 1,179614 0,001213
36
62
42
19
1,179614 1,180643 0,001028
37
42
32
9
1,180643 1,179771 0,000872
38
32
18
14
1,179771 1,180510 0,000739
39
18
76
57
1,180510 1,179883 0,000627
40
76
72
04
1,179883 1,180415 0,000531
41
72
51
79
1,180415 1,179964 0,000450
42
51
66
85
1,179964 1,180346 0,000382
43
66
97
3
1,180346 1,180022 0,000324
44
97
84
13
1,180022 1,180297 0,000274
45
84
73
9
1,180297 1,180064 0,000233
46
73
68
05
1,180064 1,180262 0,000197
47
68
21
53
1,180262 1,180094 0,000167
48
21
72
49
1,180094 1,180236 0,000142
49
72
82
1
1,180236 1,180116 0,000120
50
82
3
52
1,180116 1,180218 0,000102
51
3
46
16
1,180218 1,180131 8,6546E52
46
91
05
1,180131 1,180205 7,3314E53
91
23
05
27

54
55
56
57
58
59
60

1,180205
23
1,180143
12
1,180195
81
1,180151
1
1,180189
01
1,180156
83
1,180184
13

61 1,180161
1,180180
62
55
1,180163
63
98
1,180178
64
05
1,180166
65
13
1,180176
66
26

1,180143
12
1,180195
81
1,180151
1
1,180189
01
1,180156
83
1,180184
13
1,180161
1,180180
55
1,180163
98
1,180178
05
1,180166
13
1,180176
26
1,180167
68

6,2108E05
5,2691E05
4,4703E05
3,7909E05
3,2187E05
2,7299E05
2,3127E05
1,955E05
1,657E05
1,4067E05
1,1921E05
1,0133E05
8,5831E06

Algoritmo
N 4

Numero de
Paso
2
3
4
5
6

xn
1,182435
04
1,068834
66
1,095094
32
1,089100
24
1,090473
29
1,090159
7
06
1,090230
8
94
1,090214
9
49

xn+1
1,068834
66
1,095094
32
1,089100
24
1,090473
29
1,090159
06
1,090230
94
1,090214
49
1,090218
31

Diferenci
a entre
xn y
xn+a <
0,00001
0,113600
37
0,026259
66
0,005994
08
0,001373
05
0,000314
24
7,1883E05
1,6451E05
3,8147E06

Algoritmo
N 5
Diferenci
a entre
xn y
Numero de
xn+a <
Paso
xn
xn+1 0,00001
3,808440 662,8250 659,0166
2
21
12
02
662,8250 5,7905E 5,7905E
3
12
+11
+11