Professional Documents
Culture Documents
PROYECTO 2
Integrantes del Equipo: Del Ro Cruz Vania Padilla Resendiz Nabila Isabel Rayo Velzquez Csar Daro Ruz Mrquez Juan Pedro N.L. 8 N.L. 31
Private Sub Command6_Click() Text1.Text = "ln(x)" Text1.SetFocus End Sub Private Sub Command7_Click() Text1.Text = "log(x)" Text1.SetFocus End Sub Private Sub Command8_Click() Text1.Text = "abs(x)" Text1.SetFocus End Sub Private Sub Command9_Click() Text1.Text = "atn(x)" Text1.SetFocus End Sub Private Sub cos_Click() Text1.Text = "cos(x)" Text1.SetFocus End Sub Private Sub Exp_Click() Text1.Text = "exp(x)" Text1.SetFocus End Sub Private Sub Form_Load() Text2.Enabled = False Text3.Enabled = False Text4.Enabled = False Inf.Enabled = False Sup.Enabled = False Text5.Enabled = False Command1.Enabled = False End Sub Private Sub Inf_Change() List1.Clear List2.Clear End Sub Private Sub Inf_KeyPress(KeyAscii As Integer)
Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub ln_Click() Text1.Text = "ln(x)" Text1.SetFocus End Sub Private Sub log_Click() Text1.Text = "log(x)" Text1.SetFocus End Sub Private Sub Nueva_Click() Text1.Text = "" Inf.Text = "" Sup.Text = "" Text5.Text = "" List1.Clear List2.Clear Text2.Text = "" Text3.Text = "" Label1.Caption = "" Text4.Text = "" End Sub Private Sub Prueba5_Click() End Sub Private Sub Sal_Click() FormBiseccion.Visible = False FormPrincipal.Show
End Sub Private Sub Sen_Click() Text1.Text = "sin(x)" Text1.SetFocus End Sub Private Sub Sup_Change() List1.Clear List2.Clear End Sub
Inf.SetFocus
Private Sub Sup_KeyPress(KeyAscii As Integer) Sup.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Tan_Click() Text1.Text = "tan(x)" Text1.SetFocus End Sub Private Sub Text1_Change()
Case 8, 33, 124, 105, 108 To 116, 97 To 101, 120, 94, 40 To 43, 44 To 46, 48 To 57, 78 Case Else KeyAscii = 0 End Select End Sub Private Sub Text2_Change() Label1.Caption = "" If Text2.Text <> "" Then If Text3.Text <> "" Then If Text4.Text <> "" Then Command1.Enabled = True Else Command1.Enabled = False End If Else Command1.Enabled = False End If Else Command1.Enabled = False End If End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) Text2.SetFocus
If Text1.Text <> "" Then Inf.Enabled = True Sup.Enabled = True Text5.Enabled = True Text2.Enabled = True Text3.Enabled = True Text4.Enabled = True Else Inf.Enabled = False Sup.Enabled = False Text5.Enabled = False End If Inf.Text = "" Sup.Text = "" Text5.Text = "" List1.Clear List2.Clear Text2.Text = "" Text3.Text = "" Label1.Caption = "" Text4.Text = "" End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 13 KeyAscii = 0
Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub
Label1.Caption = "" If Text2.Text <> "" Then If Text3.Text <> "" Then If Text4.Text <> "" Then Command1.Enabled = True Else Command1.Enabled = False End If Else Command1.Enabled = False
End If Else Command1.Enabled = False End If End Sub Private Sub Text3_KeyPress(KeyAscii As Integer) Text3.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Text4_Change() Label1.Caption = "" If Text2.Text <> "" Then If Text3.Text <> "" Then If Text4.Text <> "" Then Command1.Enabled = True Else Command1.Enabled = False End If Else Command1.Enabled = False End If Else Command1.Enabled = False End If End Sub Private Sub Text4_KeyPress(KeyAscii As Integer) Text4.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Text5_Change() List1.Clear List2.Clear
End Sub Private Sub Text5_KeyPress(KeyAscii As Integer) Text5.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub
Text1.Text = "ln(x)" Text1.SetFocus End Sub Private Sub Command7_Click() Text1.Text = "log(x)" Text1.SetFocus End Sub Private Sub Command8_Click() Text1.Text = "abs(x)" Text1.SetFocus End Sub Private Sub Command9_Click() Text1.Text = "atn(x)" Text1.SetFocus End Sub Private Sub cos_Click() Text1.Text = "cos(x)" Text1.SetFocus End Sub Private Sub Exp_Click() Text1.Text = "exp(x)" Text1.SetFocus End Sub Private Sub Form_Load() Text2.Enabled = False Text3.Enabled = False Text4.Enabled = False Inf.Enabled = False Sup.Enabled = False Text5.Enabled = False Command1.Enabled = False End Sub Private Sub Inf_Change() List1.Clear List2.Clear End Sub Private Sub Inf_KeyPress(KeyAscii As Integer)
Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub ln_Click() Text1.Text = "ln(x)" Text1.SetFocus End Sub Private Sub log_Click() Text1.Text = "log(x)" Text1.SetFocus End Sub Private Sub Nueva_Click() Text1.Text = "" Inf.Text = "" Sup.Text = "" Text5.Text = "" List1.Clear List2.Clear Text2.Text = "" Text3.Text = "" Label1.Caption = "" Text4.Text = "" End Sub Private Sub Prueba5_Click() End Sub Private Sub Sal_Click() FormBiseccion.Visible = False FormPrincipal.Show
End Sub Private Sub Sen_Click() Text1.Text = "sin(x)" Text1.SetFocus End Sub Private Sub Sup_Change() List1.Clear List2.Clear End Sub Private Sub Sup_KeyPress(KeyAscii As Integer)
Sup.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Tan_Click() Text1.Text = "tan(x)" Text1.SetFocus End Sub Private Sub Text1_Change()
KeyAscii = 0 End Select End Sub Private Sub Text2_Change() Label1.Caption = "" If Text2.Text <> "" Then If Text3.Text <> "" Then If Text4.Text <> "" Then Command1.Enabled = True Else Command1.Enabled = False End If Else Command1.Enabled = False End If Else Command1.Enabled = False End If End Sub
If Text1.Text <> "" Then Inf.Enabled = True Sup.Enabled = True Text5.Enabled = True Text2.Enabled = True Text3.Enabled = True Text4.Enabled = True Else Inf.Enabled = False Sup.Enabled = False Text5.Enabled = False End If Inf.Text = "" Sup.Text = "" Text5.Text = "" List1.Clear List2.Clear Text2.Text = "" Text3.Text = "" Label1.Caption = "" Text4.Text = "" End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 13 KeyAscii = 0 Case 8, 33, 124, 105, 108 To 116, 97 To 101, 120, 94, 40 To 43, 44 To 46, 48 To 57, 78 Case Else
Private Sub Text2_KeyPress(KeyAscii As Integer) Text2.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub
Label1.Caption = "" If Text2.Text <> "" Then If Text3.Text <> "" Then If Text4.Text <> "" Then Command1.Enabled = True Else Command1.Enabled = False End If Else Command1.Enabled = False End If Else Command1.Enabled = False
End If End Sub Private Sub Text3_KeyPress(KeyAscii As Integer) Text3.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Text4_Change() Label1.Caption = "" If Text2.Text <> "" Then If Text3.Text <> "" Then If Text4.Text <> "" Then Command1.Enabled = True Else Command1.Enabled = False End If Else Command1.Enabled = False End If Else Command1.Enabled = False End If End Sub Private Sub Text4_KeyPress(KeyAscii As Integer) Text4.SetFocus Select Case KeyAscii Case 8, 46, 45
Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Text5_Change() List1.Clear List2.Clear End Sub Private Sub Text5_KeyPress(KeyAscii As Integer) Text5.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub
End Sub Private Sub a0_KeyPress(KeyAscii As Integer) a0.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub a1_Change()
If a1.Text <> "" Then If a2.Text <> "" Then If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True Command2.Enabled = True Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else
Private Sub a2_KeyPress(KeyAscii As Integer) a2.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub a3_Change() If a1.Text <> "" Then If a2.Text <> "" Then If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True Command2.Enabled = True Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If
End Sub Private Sub a1_KeyPress(KeyAscii As Integer) a1.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub a2_Change() If a1.Text <> "" Then If a2.Text <> "" Then If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True Command2.Enabled = True Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If
End Sub Private Sub a3_KeyPress(KeyAscii As Integer) a3.SetFocus Select Case KeyAscii Case 8, 46, 45
End Sub
Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub a4_Change() If a1.Text <> "" Then If a2.Text <> "" Then If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True Command2.Enabled = True Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If
If Iteraciones.Text <> "" Then If a1.Text <> "" Then If a2.Text <> "" And a2.Text <> "0" Then
If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True End If End If End If End If Else MsgBox "Aplica la formula", "0", "Aviso"
End If Else MsgBox "Faltan datos", "0", "Aviso" Exit Sub End If
p(0) = Val(p1.Text) Q(0) = Val(q1.Text) n = Val(Iteraciones.Text) For i = 0 To Val(n) B1(i) = Val(a1.Text) - (Val(p(i)) * Val(a0.Text)) b2(i) = Val(a2.Text) - ((Val(p(i))) * (Val(B1(i)))) ((Val(Q(i))) * Val(a0.Text)) r(i) = (a3.Text) - ((p(i)) * (b2(i))) - ((Q(i)) * (B1(i))) s(i) = (a4.Text) - ((Q(i)) * (b2(i)))
End Sub Private Sub a4_KeyPress(KeyAscii As Integer) a4.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Calc_Click()
p(i + 1) = ((a3.Text) - (Q(i)) * (B1(i))) / ((b2(i))) Q(i + 1) = (a4.Text) / (b2(i)) deltap(i) = r(i) / b2(i) deltaq(i) = s(i) / b2(i)
y(i) = Val(((a3.Text) - (Q(i)) * (B1(i))) / ((b2(i)))) + Val((r(i) / b2(i))) Y1(i) = Val((a4.Text) / (b2(i))) + Val(s(i) / b2(i)) Next i Valp.Text = Round(p(Val(Iteraciones.Text)), 2) Valq.Text = Round(Q(Val(Iteraciones.Text)), 2) Valb0.Text = Round(Val(a0.Text), 2) Valb1.Text = Round(B1(Val(Iteraciones.Text)), 2) Valb2.Text = Round(b2(Val(Iteraciones.Text)), 2) ValR.Text = Round(r(Val(Iteraciones.Text)), 2) ValS.Text = Round(s(Val(Iteraciones.Text)), 2) Else Valp.Text = "" Valq.Text = "" Valb0.Text = "" Valb1.Text = "" Valb2.Text = "" ValR.Text = "" ValS.Text = "" End If Else Valp.Text = "" Valq.Text = "" Valb0.Text = "" Valb1.Text = "" Valb2.Text = "" ValR.Text = "" ValS.Text = "" MsgBox "Limite de iteraciones maximo exedido", "1", "Aviso" End If Else Valp.Text = "" Valq.Text = "" Valb0.Text = "" Valb1.Text = "" Valb2.Text = "" ValR.Text = "" ValS.Text = "" End If End Sub Private Sub Command2_Click() If Iteraciones.Text <> "" Then If a1.Text <> "" Then If a2.Text <> "" Then If a3.Text <> "" Then
If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True If ((Valp.Text * Valp.Text) - 4 * Valq.Text) > 0 Then Raiz1.Caption = Round((-Valp.Text + Sqr((Valp.Text * Valp.Text) - 4 * Valq.Text)) / 2, 3) Raiz2.Caption = Round((-Valp.Text Sqr((Valp.Text * Valp.Text) - 4 * Valq.Text)) / 2, 3) Else Raiz1.Caption = "" Raiz2.Caption = "" MsgBox "Algunar raices son complejas", "1", "Aviso" End If If Valb0.Text <> 0 Then If ((Valb1.Text * Valb1.Text) - 4 * (Valb0.Text * Valb2.Text)) > 0 Then Raiz3.Caption = Round((-Valb1.Text + Sqr((Valb1.Text * Valb1.Text) - 4 * Valb0.Text * Valb2.Text)) / 2, 3) Raiz4.Caption = Round((-Valb1.Text Sqr((Valb1.Text * Valb1.Text) - 4 * Valb0.Text * Valb2.Text)) / 2, 3) Else Raiz3.Caption = "" Raiz4.Caption = "" MsgBox "Algunar raices son complejas", "1", "Aviso" End If Else If Val(Valb1.Text) = "0" Then Raiz3.Caption = "" Else Raiz3.Caption = -Val(Valb2.Text) / Val(Valb1.Text) End If Raiz4.Caption = "" End If End If End If End If End If End If Else Iteraciones.Enabled = False MsgBox "Faltan datos", "1", "Aviso"
End If Else MsgBox "Introduce el nmero de iteraciones", "1", "Aviso" End If End Sub Private Sub Form_Load() Command2.Enabled = False Iteraciones.Enabled = False Valp.Enabled = False Valq.Enabled = False Valb0.Enabled = False Valb1.Enabled = False Valb2.Enabled = False ValR.Enabled = False ValS.Enabled = False End Sub Private Sub Iteraciones_Change() If Iteraciones.Text <> "" Then If a1.Text <> "" Then If a2.Text <> "" And a2.Text <> "0" Then If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True End If End If End If End If Else MsgBox "Aplica la formula", "0", "Aviso" End If Else MsgBox "Faltan datos", "0", "Aviso" Exit Sub End If If Iteraciones.Text < 1000000 Then If Iteraciones.Text <> "" Then p(0) = Val(p1.Text) Q(0) = Val(q1.Text) n = Val(Iteraciones.Text)
B1(i) = Val(a1.Text) - (Val(p(i)) * Val(a0.Text)) b2(i) = Val(a2.Text) - ((Val(p(i))) * (Val(B1(i)))) ((Val(Q(i))) * Val(a0.Text)) r(i) = (a3.Text) - ((p(i)) * (b2(i))) - ((Q(i)) * (B1(i))) s(i) = (a4.Text) - ((Q(i)) * (b2(i)))
p(i + 1) = ((a3.Text) - (Q(i)) * (B1(i))) / ((b2(i))) Q(i + 1) = (a4.Text) / (b2(i)) deltap(i) = r(i) / b2(i) deltaq(i) = s(i) / b2(i) y(i) = Val(((a3.Text) - (Q(i)) * (B1(i))) / ((b2(i)))) + Val((r(i) / b2(i))) Y1(i) = Val((a4.Text) / (b2(i))) + Val(s(i) / b2(i)) Next i Valp.Text = Round(p(Val(Iteraciones.Text)), 2) Valq.Text = Round(Q(Val(Iteraciones.Text)), 2) Valb0.Text = Round(Val(a0.Text), 2) Valb1.Text = Round(B1(Val(Iteraciones.Text)), 2) Valb2.Text = Round(b2(Val(Iteraciones.Text)), 2) ValR.Text = Round(r(Val(Iteraciones.Text)), 2) ValS.Text = Round(s(Val(Iteraciones.Text)), 2) Else Valp.Text = "" Valq.Text = "" Valb0.Text = "" Valb1.Text = "" Valb2.Text = "" ValR.Text = "" ValS.Text = "" End If Else Valp.Text = "" Valq.Text = "" Valb0.Text = "" Valb1.Text = "" Valb2.Text = "" ValR.Text = "" ValS.Text = "" MsgBox "Limite de iteraciones maximo exedido", "1", "Aviso" End If Else
Valq.Text = "" Valb0.Text = "" Valb1.Text = "" Valb2.Text = "" ValR.Text = "" ValS.Text = "" End If End Sub Private Sub p1_Change() If a1.Text <> "" Then If a2.Text <> "" Then If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True Command2.Enabled = True Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If End Sub Private Sub p1_KeyPress(KeyAscii As Integer) p1.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0
End Select End Sub Private Sub q1_Change() If a1.Text <> "" Then If a2.Text <> "" Then If a3.Text <> "" Then If a4.Text <> "" Then If p1.Text <> "" Then If q1.Text <> "" Then Iteraciones.Enabled = True Command2.Enabled = True Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If Else Iteraciones.Enabled = False Command2.Enabled = False End If End Sub Private Sub q1_KeyPress(KeyAscii As Integer) q1.SetFocus Select Case KeyAscii Case 8, 46, 45 Case Is < 48, Is > 57 KeyAscii = 0 End Select End Sub Private Sub Salir_Click() FormLin.Visible = False FormPrincipal.Show End Sub
METODOLOGA.- Primero iniciamos el programa con la opcin EXE Estndar, luego pusimos los objetos en el formulario necesarios para el funcionamiento del mtodo y comenzamos a programar a partir de la declaracin de varios arreglos que iban cambiando su valor conforme al mtodo y el nmero de iteraciones, para el mtodo de regla falsa empleamos la misma programacin solo que cambiamos la frmula para dividir el intervalo.
Mientras que para el mtodo de Factores cuadrticos se definieron muchos arreglos que igual como es un mtodo iterativo iban cambiando su valor, por ejemplo en este mtodo se lo que iba cambiando era el valor de p que al aumentar el contador se le sumaba un incremento delta p y as sucesivamente, esto hacia que haca que el programa encontrara la raz. En el Mtodo de Newton-Raphson para calcular la derivada utilizamos la definicin de la que es:
.
Para que h tendiera a 0 este fue lo suficientemente pequeo para que el valor fuera preciso y exacto. El programa est como DeltaX = 0.000001 . Despus aplicaba el Mtodo enseado en clase tantas veces como el usuario haya puesto en su nmero de iteraciones. En esta aplicacin agregamos el plus de que el usuario ya no necesita calcular la derivada para aplicar el programa.
RESULTADOS.- El programa funciono correctamente, incluso le agregamos dos tablas para que tabulara la funcin en un intervalo que el usuario poda poner. Tambin pusimos en el programa de factores cuadrticos adems de que determinara estos factores y los mostrara una opcin que calcula las races aplicando la formula cuadrtica.
CONCLUSIONES.- Pudimos darnos cuenta que el mtodo de regla falsa algunas veces converge al valor de la raz ms rpido que el mtodo de biseccin sin embargo no siempre es as. Tambin que son muy tiles estos programas pero que tienen sus limitaciones, por ejemplo el de factores cuadrticos es muy bueno pero solo funcional para polinomios, y para los de regla falsa y biseccin debes de conocer un intervalo que encierre a la raz si no obtienes un valor errneo. Para el Mtodo de Newton-Raphson necesitas un valor de inicio estratgico para que la derivada converja a la raz, sino es as este dar valores errneos. Pero ms all de estas limitaciones los programas hacen los clculos en fracciones de segundo algo que sera muy difcil y tardado de hacer a mano. Al realizar estos programas reafirmamos los conocimientos que tenemos de la asignatura y desarrollamos nuestras habilidades para programar y resolver problemas ligadas a Visual Basic. Le agradecemos la constancia y el tiempo que nos dedic para ensearnos Anlisis Numrico y del Software Visual Basic.