Documentos de Académico
Documentos de Profesional
Documentos de Cultura
1 0 2 1
2 1 1 0
2
2 0
( ) ( ) ( ) ( ) f x f x f x f x
x x x x
b
x x
6 6 6
2
1 1 1
7 5.52380952x 0.97619048x dx dx dx
+
[ ]
6 6
2 3
6
1
1 1
7 5.52380952 0.97619048
2 3
x x
x
1 1
+
1 1
] ]
( )
2 2 3 3
6 -(-1) 6 -(-1)
7 7 5.52380952 0.97619048
2 3
_ _
+
, ,
35 217
49 5.52380952 0.97619048
2 3
_ _
+
, ,
75.05555521333
Option Explicit
Private Function f(ByVal x As Double) As
Double
Dim x1, x2, x3, y1, y2, y3 As Double
x1 = Val(txtx1.Text)
x2 = Val(txtx2.Text)
x3 = Val(txtx3.Text)
y1 = Val(txty1.Text)
y2 = Val(txty2.Text)
y3 = Val(txty3.Text)
f = (x - x2) * (x - x3) * y1 / (x1 - x2) / (x1 -
x3) + (x - x1) * (x - x3) * y2 / (x2 - x1) / (x2 -
x3) + (x - x1) * (x - x2) * y3 / (x3 - x1) / (x3 -
x2)
End Function
Private Function Par(ByVal i As Integer) As
Boolean
If (i Mod 2 = 0) Then
Par = True
Else
Par = False
End If
End Function
Private Function Simpson(ByVal a As Double,
ByVal b As Double, ByVal N As Integer) As
Double
Dim x, x0, s1, s2, h As Double
Dim i As Integer
h = (b - a) / N
x0 = f(a) + f(b)
s1 = 0
s2 = 0
For i = 1 To (N - 1)
x = a + i * h
If Par(i) Then
s2 = s2 + f(x)
Else
s1 = s1 + f(x)
End If
Next i
Simpson = h * (x0 + 2 * s2 + 4 * s1) / 3
End Function
Private Sub cmdEjecutar_Click()
Dim x1, x3 As Double
Dim N As Integer
x1 = txtx1.Text
x3 = txtx3.Text
N = Val(txtn.Text)
If Par(N) Then
txtr.Text = Simpson(x1, x3, N)
Else
txtr.Text = Simpson(x1, x3, N + 1)
End If
End Sub
Private Sub cmdSalir_Click()
End
End Sub
PROBLEMA 11 Aplique el programa anterior para determinar la fugacidad del metano a -70C
Problema 11
Option Explicit
Private Function f(ByVal xint As Double) As
Double
Dim L, pxint, P As Double
Dim i, j, N As Integer
N = Val(TxtIngreso.Text)
P = Val(TxtP.Text)
ReDim Data(0 To N - 1, 1 To 2) As Double
For i = 1 To N
Data(i - 1, 1) = Val(matriz.TextMatrix(i,
1))
Data(i - 1, 2) = Val(matriz.TextMatrix(i,
2))
Next i
pxint = 0
i = 0
Do While i < N
L = 1
j = 0
Do While j < N
If j <> i Then
L = L * (xint - Data(j, 1)) / (Data(i,
1) - Data(j, 1))
End If
j = j + 1
Loop
pxint = pxint + L * Data(i, 2)
i = i + 1
Loop
f = (pxint - 1) / P
End Function
Private Function Par(ByVal i As Integer) As
Boolean
If (i Mod 2 = 0) Then
Par = True
Else
Par = False
End If
End Function
Private Function Simpson(ByVal a As Double,
ByVal b As Double, ByVal N As Integer) As
Double
Dim x, x0, s1, s2, h As Double
Dim i As Integer
h = (b - a) / N
x0 = f(a) + f(b)
s1 = 0
s2 = 0
For i = 1 To (N - 1)
x = a + i * h
If Par(i) Then
s2 = s2 + f(x)
Else
s1 = s1 + f(x)
End If
Next i
Simpson = h * (x0 + 2 * s2 + 4 * s1) / 3
End Function
Private Sub Calcular_Click()
Dim Nint, i As Integer
Dim lnfp, P As Double
P = Val(TxtP.Text)
Nint = Val(TxtN.Text)
If Par(Nint) Then
lnfp = Simpson(0, P, Nint)
Else
lnfp = Simpson(0, P, Nint + 1)
End If
txtr.Text = Exp(lnfp) * P
End Sub
Private Sub Form_Load()
matriz.ColWidth(0) = 1000
matriz.ColWidth(1) = 1800
matriz.ColWidth(2) = 1800
matriz.TextMatrix(0, 0) = " i"
matriz.TextMatrix(0, 1) = " P"
matriz.TextMatrix(0, 2) = " Z"
matriz.TextMatrix(1, 0) = " 1"
matriz.TextMatrix(2, 0) = " 2"
TxtIngreso.Text = 2
End Sub
Private Sub matriz_KeyPress(KeyAscii As
Integer)
If KeyAscii >= 46 And KeyAscii <= 57 Or
KeyAscii = 45 Then
matriz.Text = matriz.Text &
Chr(KeyAscii)
End If
End Sub
Private Sub matriz_KeyUp(KeyCode As
Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDelete
matriz.Text = ""
Case vbKeyBack
If Len(matriz.Text) > 0 Then
matriz.Text = Left(matriz.Text,
Len(matriz.Text) - 1)
End If
End Select
End Sub
Private Sub txtingreso_KeyPress(KeyAscii As
Integer)
Dim N, i As Integer
N = Val(TxtIngreso.Text)
If KeyAscii = 13 Then
matriz.Rows = N + 1
For i = 1 To N
matriz.TextMatrix(i, 0) = " " & (i)
Next i
End If
End Sub
Private Sub txtingreso_LostFocus()
Dim N, i As Integer
If TxtIngreso.Text = Empty Or
Val(TxtIngreso.Text) <= 1 Then
TxtIngreso.Text = 2
End If
N = Val(TxtIngreso.Text)
matriz.Rows = N + 1
For i = 1 To N
matriz.TextMatrix(i, 0) = " " & (i)
Next i
End Sub
Private Sub Borrar_Click()
Dim N, i As Integer
N = Val(TxtIngreso.Text)
For i = 1 To N
matriz.TextMatrix(i, 1) = ""
matriz.TextMatrix(i, 2) = ""
Next
TxtIngreso.Text = ""
TxtP.Text = ""
TxtN.Text = ""
txtr.Text = ""
TxtIngreso.SetFocus
End Sub
Private Sub Salir_Click()
End
End Sub