Vous êtes sur la page 1sur 4

PROBLEMA 2. En la tabla de valores siguientes algunos datos de sin(x) pueden tener errores.

Elabore un programa que calcule diferencias finitas y que a partir de los valores calculados el programa indique qu valores son incorrectos. Este mtodo podr servir para filtrar datos incorrectos en trminos generales? Justifique su respuesta.

Dim matriz() As Double Dim b() As Double Dim x As Integer Dim y As Integer Dim ec As String Dim ex As String Dim tp As Integer Dim n As Integer Dim i As Integer Private Sub cmdload_Click() i=0 List1.Clear List2.Clear Open "sin.dat" For Input As #1 While Not EOF(1) Line Input #1, linea If EOF(1) = True Then pos1 = InStr(1, linea, Chr(9), vbTextCompare) List1.List(i) = Mid(linea, 1, pos1 - 1) List2.List(i) = Mid(linea, pos1 + 1, Len(linea)) Else pos1 = InStr(1, linea, Chr(9), vbTextCompare) List1.List(i) = Mid(linea, 1, pos1 - 1) List2.List(i) = Mid(linea, pos1 + 1, Len(linea))

End If i=i+1 Wend Close #1 Command1.Enabled = True End Sub Private Sub Command1_Click() Dim h As Integer ReDim matriz(7, 5) ReDim b(List1.ListCount) For w = 0 To List1.ListCount - 1 Step 3 matriz(h, 0) = List1.List(w) matriz(h, 1) = List2.List(w) h=h+1 Next b(0) = matriz(0, 1) tp = 3 For l = 1 To 4 For n = 0 To tp matriz(n, 1) = (matriz(n + 1, 1) - matriz(n, 1)) / (matriz(n + l, 0) - matriz(n, 0)) Next tp = tp - 1 b(l) = matriz(0, 1) Next For i = 0 To 4 List4.List(i) = b(i) Next Command3.Enabled = True End Sub Private Sub Command2_Click() Unload Me End Sub Private Sub Command3_Click() Dim lista(13) As Double For r = 0 To List1.ListCount - 1 lista(r) = List1.List(r) Next For i = 0 To List1.ListCount - 1 List5.List(i) = b(0) + b(1) * (lista(i) - lista(0)) + b(2) * (lista(i) - lista(1)) * (lista(i) - lista(0)) + b(3) * (lista(i) - lista(0)) * (lista(i) - lista(1)) * (lista(i) - lista(2)) + b(4) * (lista(i) - lista(0)) * (lista(i) lista(1)) * (lista(i) - lista(2)) * (lista(i) - lista(3)) Next For i = 0 To List1.ListCount - 1 List3.List(i) = Abs((List5.List(i) - List2.List(i)) / List5.List(i)) Next End Sub Private Sub Command4_Click() End End Sub

PROBLEMA 4 Redacte un programa en Visual Basic para aplicar la integracin de Simpson. Luego transforme este programa en una funcin. El programa deber ingresar los datos de lmite inferior de integracin, lmite superior de integracin y nmero de puntos de integracin (impar). El programa deber estar asociado a una funcin que defina la frmula a integrar. Por ejemplo haremos la integracin de Simpson para el funcin: ( )

Option Explicit Function f(ByVal x As Double) As Double f=x*x+2*x+3 End Function Function Par(ByVal i As Integer) As Boolean If (i Mod 2 = 0) Then Par = True Else Par = False End If End Function Function Simpson(ByVal a As Double, ByVal b As Double, ByVal N As Integer) As Double Dim x, x0, x1, x2, h As Double Dim i As Integer h = (b - a) / N

x0 = f(a) + f(b) x1 = 0 x2 = 0 For i = 1 To (N - 1) x=a+i*h If Par(i) Then x2 = x2 + f(x) Else x1 = x1 + f(x) End If Next i Simpson = h * (x0 + 2 * x2 + 4 * x1) / 3 End Function Private Sub Command1_Click() Dim a, b As Double Dim N, r As Integer a = Val(Text1.Text) b = Val(Text2.Text) N = Val(Text3.Text) If Par(N) Then r = MsgBox("Ingrese nmero impar de intervalos", 48, "Dato no vlido") Else Text4.Text = Simpson(a, b, N + 1) End If End Sub Private Sub Command2_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" End Sub Private Sub Command3_Click() End End Sub

Vous aimerez peut-être aussi