Está en la página 1de 31

UNIVERSIDAD NACIONAL DE SAN AGUSTN

ESCUELA PROFESIONAL DE INGENIERA QUMICA


CURSO DE DISEO Y EVALUACIN DE PROCESOS
INFORME DE LABORATORIO 7
PROGRAMAS EN VISUAL BASIC.
Luis Felipe Miranda Z.
PROGRAMA 1
Desarrolle un programa en Visual Basic en el que se ingresen tres pares ordenados de temperatura y
constante de equilibrio de fases. Se deber calcular las constantes de Antoine correspondientes y
verificar si dichas constantes permiten calcular los datos originales con precisin. Para esto podrn
emplear el documento denominado Constantes de Antoine que se ha colgado en el dominio de
SCRIBD.COM.
Dim a As Double
Dim b As Double
Dim c As Double

Private Sub Salir_Click()
End
End Sub
Private Sub calcular_Click()
Dim t1 As Double
Dim t2 As Double
Dim t3 As Double
Dim k1 As Double
Dim k2 As Double
Dim k3 As Double
t1 = Val(Txt1.Text)
t2 = Val(Txt2.Text)
t3 = Val(Txt3.Text)
k1 = Val(Txk1.Text)
k2 = Val(Txk2.Text)
k3 = Val(Txk3.Text)
Call Constantes(t1, t2, t3, k1, k2, k3)

TxA.Text = a
TxB.Text = b
TxC.Text = c

End Sub
Public Sub Constantes(t1 As Double, t2 As
Double, t3 As Double, k1 As Double, k2 As
Double, k3 As Double)
Dim alpha As Double
alpha = (Log(k2 / k1) / Log(k3 / k2) * (t3 -
t2) / (t2 - t1))
c = (alpha * t1 - t3) / (1 - alpha)
b = Log(k3 / k1) / ((1 / (t1 - c)) - (1 / (t3 -
c)))
a = Log(k2) + b / (t2 + c)

End Sub
PROGRAMA 2
Estime las propiedades del vapor de agua
saturado empleando la ecuacin propuesta por
Virgilio Gonzlez Pozo. Dicha ecuacin es:
Y = A x + B/x + Cx
1/2
+ D ln x + E x
2
+ F x
3
+ G
Problema 2
private Sub Command1_Click()

P = Val(Text1.Text)

Text2.Text = fy(P, -0.17724, 3.83986,
11.48345, 31.1311, 0.00008762969,
-0.0000000278794, 86.594)
Text3.Text = fy(P, -0.0000005280126,
0.0000299481, 0.0001521874,
0.0000662512, 8.408856E-10, 1.86401E-14,
0.01596)
If P < 200 Then
Text4.Text = fy(P, -0.48799,
304.717614, 9.8299035, -16.455274,
0.0009474745, -0.00001363366, 19.53953)
Else
Text4.Text = fy(P, 0.002862, 457.5802,
-0.176959, 0.826862, -0.0000004801876,
0.000000000063181, -2.3928)
End If
Text5.Text = fy(P, -0.15115567, 3.671404,
11.622558, 30.832667, 0.0000874117,
-0.0000000262306, 54.55)
Text6.Text = fy(P, 0.008676153,
-1.3049844, -8.1237368, -16.37649,
-0.000043043, 0.000000009763, 1045.81)
Text7.Text = fy(P, -0.14129, 2.258225,
3.4014802, 14.438078, 0.00004222624,
-0.00000001569916, 1100.5)
Text8.Text = fy(P, -0.000167772,
0.004272688, 0.01048048, 0.05801509,
0.00000009101291, -0.000000000027592,
0.11801)
Text9.Text = fy(P, 0.00003454439,
-0.00275287, -0.00733044, -0.14263733,
-0.0000000349366, 7.433711E-12, 1.85565)
Text10.Text = fy(P, -0.0001476933,
0.0012617946, 0.00344201, -0.08494128,
0.0000000689138, -0.000000000024941,
1.97364)
Text11.Text = fy(P, -0.1549439, 3.662121,
11.632628, 30.82137, 0.0000876248,
-0.00000002646533, 5456)
Text12.Text = fy(P, -0.0993951, 1.93961,
2.428354, 10.9818864, 0.00002737201,
-0.00000001057475, 1040.03)

End Sub
Function fy(ByVal x As Double, ByVal a As
Double, ByVal b As Double, ByVal c As Double,
ByVal d As Double, ByVal e As Double, ByVal f
As Double, ByVal g As Double) As Double

fy = a * x + b / x + c * x ^ (1 / 2) + d *
Log(x) + e * x ^ 2 + f * x ^ 3 + g

End Function
Private Sub Command2_Click()
End
End Sub
INFORME DE LABORATORIO 8
1. En la tabla adjunta se presentan datos correspondientes a la conductividad del dixido de
carbono, en BTU/hr.ft.F, y a la viscosidad del etilen glicol, en lb/ft.hr, siendo la
temperatura expresada en grados Fahrenheit
Temp Conductividad Temp Viscosidad
32 0,085 0 242
212 0,0133 50 82,1
392 0,0181 100 30,5
572 0,0228 150 12,6
200 5,57
Para cada propiedad determine el polinomio ms sencillo para interpolar. Con este polinomio,
formule un programa en Visual Basic que genere datos calculados y estime el error cometido en
cada punto. Asimismo, presente una tabla con intervalos regulares de 25 F partiendo desde las
temperaturas iniciales sealadas para cada caso. Genere un archivo donde registre estos
resultados y grafique en Excel los resultados.
Problema 1
ivate Sub Command1_Click()
Form2.Show
Unload Form1

End Sub
Private Sub Form_Load()
Option1.Value = True
End Sub
Private Sub Command1_Click()
If Grid1.Rows = 5 Then
n = 4
Else
If Grid1.Rows = 6 Then
n = 5
End If
End If

For i = 1 To n
Grid2.TextMatrix(i, 0) =
Round(f(Val(Grid1.TextMatrix(i, 0))), 6)
Grid2.TextMatrix(i, 1) =
Abs(Round((Val(Grid2.TextMatrix(i, 0)) -
Val(Grid1.TextMatrix(i, 1))) /
Val(Grid2.TextMatrix(i, 0)), 10))
Next

End Sub
Private Sub Command2_Click()

h = Val(Text1.Text)
n = Val(Text2.Text)

Grid3.Rows = n + 1
x = Val(Grid1.TextMatrix(1, 0))

For i = 1 To n
Grid3.TextMatrix(i, 0) = x + (i - 1) * h
Grid3.TextMatrix(i, 1) =
f(Val(Grid3.TextMatrix(i, 0)))
Next

End Sub
Private Sub Command3_Click()
Form2.Enabled = False
Form3.Show
End Sub
Private Sub Command4_Click()
Unload Form2
Form1.Show
End Sub
Private Sub Command5_Click()
End
End Sub
' Formato de los componentes al cargarse
Form2
' Se introducen los titulos de la ventana y las
cabeceras de las tablas
Private Sub Form_Load()
Grid1.ColWidth(0) = 1050
Grid1.ColWidth(1) = 1210
Grid2.ColWidth(0) = 1200
Grid2.ColWidth(1) = 1200
Grid3.ColWidth(0) = 1000
Grid3.ColWidth(1) = 1600

If Form1.Option1.Value Then
Label1.Caption = "Conductividad del
Dixido de Carbono"
Else
If Form1.Option2.Value Then
Label1.Caption = "Viscosidad del
Etilenglicol"
End If
End If

Grid1.TextMatrix(0, 0) = "Temperatura"
Grid3.TextMatrix(0, 0) = "Temperatura"
If Form1.Option1.Value Then
Grid1.TextMatrix(0, 1) = "
Conductividad"
Grid2.TextMatrix(0, 0) = "
Conductividad"
Grid3.TextMatrix(0, 1) = "
Conductividad"
Grid2.TextMatrix(0, 1) = " Error"
Grid1.Rows = 5
Grid2.Rows = 5
Grid1.TextMatrix(1, 0) = "32"
Grid1.TextMatrix(2, 0) = "212"
Grid1.TextMatrix(3, 0) = "392"
Grid1.TextMatrix(4, 0) = "572"
Grid1.TextMatrix(1, 1) = "0.085"
Grid1.TextMatrix(2, 1) = "0.0133"
Grid1.TextMatrix(3, 1) = "0.0181"
Grid1.TextMatrix(4, 1) = "0.0228"
Else
If Form1.Option2.Value Then
Grid1.TextMatrix(0, 1) = "
Viscosidad"
Grid2.TextMatrix(0, 0) = "
Viscosidad"
Grid3.TextMatrix(0, 1) = "
Viscosidad"
Grid2.TextMatrix(0, 1) = " Error"
Grid1.Rows = 6
Grid2.Rows = 6
Grid1.TextMatrix(1, 0) = "0"
Grid1.TextMatrix(2, 0) = "50"
Grid1.TextMatrix(3, 0) = "100"
Grid1.TextMatrix(4, 0) = "150"
Grid1.TextMatrix(5, 0) = "200"
Grid1.TextMatrix(1, 1) = "242"
Grid1.TextMatrix(2, 1) = "82.1"
Grid1.TextMatrix(3, 1) = "30.5"
Grid1.TextMatrix(4, 1) = "12.6"
Grid1.TextMatrix(5, 1) = "5.57"
End If
End If

End Sub
rivate Sub Command2_Click()

h = Val(Text1.Text)
n = Val(Text2.Text)

Grid3.Rows = n + 1
x = Val(Grid1.TextMatrix(1, 0))

For i = 1 To n
Grid3.TextMatrix(i, 0) = x + (i - 1) * h
Grid3.TextMatrix(i, 1) =
f(Val(Grid3.TextMatrix(i, 0)))
Next

End Sub
Private Sub Command3_Click()
Form2.Enabled = False
Form3.Show
End Sub
Private Sub Command4_Click()
Unload Form2
Form1.Show
End Sub
Private Sub Command5_Click()
End
End Sub
' Formato de los componentes al cargarse
Form2
' Se introducen los titulos de la ventana y las
cabeceras de las tablas
Private Sub Form_Load()
Grid1.ColWidth(0) = 1050
Grid1.ColWidth(1) = 1210
Grid2.ColWidth(0) = 1200
Grid2.ColWidth(1) = 1200
Grid3.ColWidth(0) = 1000
Grid3.ColWidth(1) = 1600

If Form1.Option1.Value Then
Label1.Caption = "Conductividad del
Dixido de Carbono"
Else
If Form1.Option2.Value Then
Label1.Caption = "Viscosidad del
Etilenglicol"
End If
End If

Grid1.TextMatrix(0, 0) = "Temperatura"
Grid3.TextMatrix(0, 0) = "Temperatura"
If Form1.Option1.Value Then
Grid1.TextMatrix(0, 1) = "
Conductividad"
Grid2.TextMatrix(0, 0) = "
Conductividad"
Grid3.TextMatrix(0, 1) = "
Conductividad"
Grid2.TextMatrix(0, 1) = " Error"
Grid1.Rows = 5
Grid2.Rows = 5
Grid1.TextMatrix(1, 0) = "32"
Grid1.TextMatrix(2, 0) = "212"
Grid1.TextMatrix(3, 0) = "392"
Grid1.TextMatrix(4, 0) = "572"
Grid1.TextMatrix(1, 1) = "0.085"
Grid1.TextMatrix(2, 1) = "0.0133"
Grid1.TextMatrix(3, 1) = "0.0181"
Grid1.TextMatrix(4, 1) = "0.0228"
Else
If Form1.Option2.Value Then
Grid1.TextMatrix(0, 1) = "
Viscosidad"
Grid2.TextMatrix(0, 0) = "
Viscosidad"
Grid3.TextMatrix(0, 1) = "
Viscosidad"
Grid2.TextMatrix(0, 1) = " Error"
Grid1.Rows = 6
Grid2.Rows = 6
Grid1.TextMatrix(1, 0) = "0"
Grid1.TextMatrix(2, 0) = "50"
Grid1.TextMatrix(3, 0) = "100"
Grid1.TextMatrix(4, 0) = "150"
Grid1.TextMatrix(5, 0) = "200"
Grid1.TextMatrix(1, 1) = "242"
Grid1.TextMatrix(2, 1) = "82.1"
Grid1.TextMatrix(3, 1) = "30.5"
Grid1.TextMatrix(4, 1) = "12.6"
Grid1.TextMatrix(5, 1) = "5.57"
End If
End If

End Sub
private Sub Command3_Click()
Form2.Enabled = False
Form3.Show
End Sub
Private Sub Command4_Click()
Unload Form2
Form1.Show
End Sub
Private Sub Command5_Click()
End
End Sub
' Formato de los componentes al cargarse
Form2
' Se introducen los titulos de la ventana y las
cabeceras de las tablas
Private Sub Form_Load()
Grid1.ColWidth(0) = 1050
Grid1.ColWidth(1) = 1210
Grid2.ColWidth(0) = 1200
Grid2.ColWidth(1) = 1200
Grid3.ColWidth(0) = 1000
Grid3.ColWidth(1) = 1600

If Form1.Option1.Value Then
Label1.Caption = "Conductividad del
Dixido de Carbono"
Else
If Form1.Option2.Value Then
Label1.Caption = "Viscosidad del
Etilenglicol"
End If
End If

Grid1.TextMatrix(0, 0) = "Temperatura"
Grid3.TextMatrix(0, 0) = "Temperatura"
If Form1.Option1.Value Then
Grid1.TextMatrix(0, 1) = "
Conductividad"
Grid2.TextMatrix(0, 0) = "
Conductividad"
Grid3.TextMatrix(0, 1) = "
Conductividad"
Grid2.TextMatrix(0, 1) = " Error"
Grid1.Rows = 5
Grid2.Rows = 5
Grid1.TextMatrix(1, 0) = "32"
Grid1.TextMatrix(2, 0) = "212"
Grid1.TextMatrix(3, 0) = "392"
Grid1.TextMatrix(4, 0) = "572"
Grid1.TextMatrix(1, 1) = "0.085"
Grid1.TextMatrix(2, 1) = "0.0133"
Grid1.TextMatrix(3, 1) = "0.0181"
Grid1.TextMatrix(4, 1) = "0.0228"
Else
If Form1.Option2.Value Then
Grid1.TextMatrix(0, 1) = "
Viscosidad"
Grid2.TextMatrix(0, 0) = "
Viscosidad"
Grid3.TextMatrix(0, 1) = "
Viscosidad"
Grid2.TextMatrix(0, 1) = " Error"
Grid1.Rows = 6
Grid2.Rows = 6
Grid1.TextMatrix(1, 0) = "0"
Grid1.TextMatrix(2, 0) = "50"
Grid1.TextMatrix(3, 0) = "100"
Grid1.TextMatrix(4, 0) = "150"
Grid1.TextMatrix(5, 0) = "200"
Grid1.TextMatrix(1, 1) = "242"
Grid1.TextMatrix(2, 1) = "82.1"
Grid1.TextMatrix(3, 1) = "30.5"
Grid1.TextMatrix(4, 1) = "12.6"
Grid1.TextMatrix(5, 1) = "5.57"
End If
End If

End Sub
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.
X SIN(X)
0,2 0,19867
0,25 0,24740
0,30 0,29552
0,35 0,34920
0,40 0,38492
0,45 0,43497
0,50 0,47943
0,55 0,52269
0,60 0,56464
0,65 0,60529
0,70 0,64422
0,75 0,68164
0,80 0,72736
Problema 2
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
INFORME DE LABORATORIO 9
PROGRAMA 1
Desarrolle un programa en VB que calcule la velocidad de reaccin en funcin de las concentraciones
de los componentes A y B. A su vez, estas concentraciones tienen como variables a la conversin y la
concentracin inicial del componente A. Pruebe este programa bajo las siguientes condiciones:
La reaccin qumica tiene la forma A + 2 B 2 C. La cintica del proceso est dada por la expresin:
-rA = k [A] [B]. Se alcanza una conversin del reactante A de 0,75. La reaccin ocurre a 60 C,
siendo el correspondiente valor de k = 1 m3/(mol.s). La concentracin inicial del reactante A es 6
mol/m3.
Problema 1
Private Sub Command1_Click()
Dim CAo As Single 'Concentracion inicial del
reactante mol/m3
Dim CB As Single
Dim FAo As Single
Dim K As Single 'Constante de velocidad
m3/mol.s
Dim X As Single
Dim Vel As Single
Dim Vol As Single 'Volumen m3
'Valores de Texto
FAo = Val(Text1.Text)
CAo = Val(Text2.Text)
K = Val(Text3.Text)
X = Val(Text4.Text)
'Calculos
CA = CAo * (1 - X)
CB = CAo * (0.3 - 2 * X)
Vel = -K * CA * CB
Vol = FAo * X / Vel
'Resultados
Text5.Text = Str(Vel)
Text6.Text = Str(Vol)
End Sub
Private Sub Command2_Click()
End
End Sub
INFORME DE LABORATORIO 9
PROGRAMA
Calcule el rea de transferencia de calor de un intercambiador de calor de tubos concntricos, el
calor transferido , la diferencia media logartmica y la temperatura de salida del agua de
enfriamiento, dadas las siguientes condiciones conocidas:
Propiedad Fluido Caliente Fluido Fro
Nombre Etanol Agua
Temperatura de ingreso, C 60 28
Temperatura de salida, C 30 Por calcular
Flujo msico, kg/s 0,5 0,9
Calor especfico, J/kg/C Busque en tablas Busque en tablas
El coeficiente global de transferencia de calor (U) es conocido.
Problema
'Decalracion de variables
Dim T1, T2, T3, T4, m, w, Cp, Cpw, U, A, Q,
DTlog As Single
Private Sub Command1_Click()
'Valores de las Cajas de Texto
T1 = Val(Text1.Text)
T2 = Val(Text2.Text)
T3 = Val(Text6.Text)
T4 = Val(Text9.Text)
m = Val(Text3.Text)
w = Val(Text7.Text)
Cp = Val(Text4.Text)
Cpw = Val(Text8.Text)
U = Val(Text5.Text)
DTlog = Val(Text10.Text)
A = Val(Text11.Text)
'Calculos
Q = m * Cp * (T1 - T2)
T4 = T3 + Q / (w * Cpw)
DTlog = ((T1 - T4) - (T2 - T3)) / Log((T1 -
T4) / (T2 - T3))
A = Q / (U * DTlog)
'Resultados
Text9.Text = Str(T4)
Text10.Text = Str(DTlog)
Text11.Text = Str(A)
End Sub
Private Sub Command2_Click()
End
End Sub
DISEO Y EVALUACIN DE PROCESOS INFORME DE LABORATORIO
INFORME 10
PROBLEMA 1 Elabore un Programa en Visual Basic para implementar el mtodo de Newton Raphson
para la determinacin de races de una funcin. Pruebe el programa con la funcin Y = (x-1)(x-3)(x-4).
Problema 1
Const zero = 0.00000001
Private Sub CmdBorra_Click()
Borrar
TxtX0.Text = ""
TxtTol.Text = ""
TxtMax.Text = ""
End Sub
Private Sub CmdCalcular_Click()
Dim x0 As Double
Dim X1 As Double
'--------------------------Asignacin de
variables--------------------------
x0 = Val(TxtX0.Text)
tol = Val(TxtTol.Text)
maxit = Val(TxtMax.Text)

Borrar
'-------------------------------Rutina
Principal------------------------------
For i = 1 To maxit 'Inicia e incrementa el
contador

X1 = x0 - F(x0) / dF(x0) 'Frmula
iterativa

'----------------------Evaluacin de
tolerancia----------------------
If Abs(F(X1)) >= tol Then
x0 = X1
Else
Exit For
End If

'-------------------Muestra resultados en
el flexgrid------------------
MsgResult.TextMatrix(i, 0) = i
MsgResult.TextMatrix(i, 1) = Round(x0,
4)
List1.AddItem Round(x0, 7)
MsgResult.TextMatrix(i, 2) =
Round(F(x0), 4)
MsgResult.TextMatrix(i, 3) =
Round(dF(x0), 4)
MsgResult.TextMatrix(i, 4) = Round(X1,
4)
MsgResult.TextMatrix(i, 5) =
Round(dF(X1), 4)

Next
'-------------------------Mensaje de no
convergencia-----------------------
If Abs(F(X1)) > tol Then
R = MsgBox("Mtodo no converge para
nmero de interaciones especificadas", 16)
Else
TxtResult.Text = Round(x0, 4)
End If

End Sub
Private Sub CmdSalir_Click()
End
End Sub
Public Function F(x As Double) As Double
F = (x - 1) * (x - 3) * (x - 4)
End Function
Public Function dF(x As Double) As Double
dF = (F(x + zero) - F(x)) / zero
End Function
Private Sub Form_Load()
MsgResult.TextMatrix(0, 0) = "Num Iter"
MsgResult.TextMatrix(0, 1) = "X0"
MsgResult.TextMatrix(0, 2) = "F(X0)"
MsgResult.TextMatrix(0, 3) = "F'(X0)"
MsgResult.TextMatrix(0, 4) = "X1"
MsgResult.TextMatrix(0, 5) = "F(X1)"

End Sub
Private Sub Borrar()
'------------------------------Borra
Resultados----------------------------
TxtResult.Text = ""
List1.Clear
For k = 1 To 99
MsgResult.TextMatrix(k, 0) = ""
MsgResult.TextMatrix(k, 1) = ""
MsgResult.TextMatrix(k, 2) = ""
MsgResult.TextMatrix(k, 3) = ""
MsgResult.TextMatrix(k, 4) = ""
MsgResult.TextMatrix(k, 5) = ""
Next k
End Sub
PROBLEMA 2 Transforme el programa del Problema 1 en una funcin. Emplea esta funcin para
calcular el factor de friccin mediante iteraciones por medio de la ecuacin de Colebrook:
Un buen estimado inicial para esta ecuacin puede ser encontrado a partir de la ecuacin de Blasius:
adecuado para flujo turbulento en tuberas lisas
Problema 2
Const zero = 0.000000000001
Dim E As Double
Dim D As Double
Dim Re As Double
Dim maxit As Integer
Dim tol As Double
Static Function Log10(x)
Log10 = Log(x) / Log(10#)
End Function
Private Sub CmdBorra_Click()
Borrar
TxtX0.Text = ""
TxtD.Text = ""
TxtE.Text = ""
TxtRe.Text = ""
TxtTol.Text = ""
TxtMax.Text = ""
End Sub
Public Sub CmdCalcular_Click()
Dim f0 As Double
'--------------------------Asignacin de
variables--------------------------
D = Val(TxtD.Text)
E = Val(TxtE.Text)
Re = Val(TxtRe.Text)
tol = Val(TxtTol.Text)
maxit = Val(TxtMax.Text)

Borrar

'Utilizando estimacin inicial

f0 = 0.316 * Re ^ (-0.25)
TxtX0.Text = f0

TxtResult.Text = Newton(f0)

End Sub
Private Function Newton(x0 As Double) As
Double
Dim X1 As Double

For i = 1 To maxit 'Inicia e incrementa
el contador

X1 = x0 - F(x0) / dF(x0) 'Frmula
iterativa

'----------------------Evaluacin de
tolerancia----------------------
If Abs(F(X1)) >= tol Then
x0 = X1
Newton = x0
Else
Exit For
End If

'-------------------Muestra resultados
en el flexgrid------------------
MsgResult.TextMatrix(i, 0) = i
MsgResult.TextMatrix(i, 1) =
Round(x0, 4)
List1.AddItem Round(x0, 7)
MsgResult.TextMatrix(i, 2) =
Round(F(x0), 4)
MsgResult.TextMatrix(i, 3) =
Round(dF(x0), 4)
MsgResult.TextMatrix(i, 4) =
Round(X1, 4)
MsgResult.TextMatrix(i, 5) =
Round(dF(X1), 4)

Next

End Function
Private Sub CmdSalir_Click()
End
End Sub
Private Function F(x As Double) As Double
F = 1 / Sqr(x) + 2 * Log10(E / (3.7 * D) +
2.51 / (Re * Sqr(x)))
End Function
Private Function dF(x As Double) As Double
dF = (F(x + zero) - F(x)) / zero
End Function
Private Sub Form_Load()
MsgResult.TextMatrix(0, 0) = "Num Iter"
MsgResult.TextMatrix(0, 1) = "X0"
MsgResult.TextMatrix(0, 2) = "F(X0)"
MsgResult.TextMatrix(0, 3) = "F'(X0)"
MsgResult.TextMatrix(0, 4) = "X1"
MsgResult.TextMatrix(0, 5) = "F(X1)"

End Sub
Private Sub Borrar()
'------------------------------Borra
Resultados----------------------------
TxtResult.Text = ""
List1.Clear
For k = 1 To 99
MsgResult.TextMatrix(k, 0) = ""
MsgResult.TextMatrix(k, 1) = ""
MsgResult.TextMatrix(k, 2) = ""
MsgResult.TextMatrix(k, 3) = ""
MsgResult.TextMatrix(k, 4) = ""
MsgResult.TextMatrix(k, 5) = ""
Next k

End Sub
PROBLEMA 3 Transforme el Programa del Problema 2 en una funcin que calcule el factor de friccin
por medio de la ecuacin de Colebrook. Recordar que para un rgimen laminar de flujo, cuando el
nmero de Reynolds es inferior a 2100, es vlida la expresin . Escriba un programa en el que se
ingresan los valores de flujo volumtrico, dimetro de tubera, longitud de tubera, densidad y
viscosidad del fluido, as como rugosidad relativa de la tubera y se calcule lo siguiente: velocidad del
fluido, nmero de Reynolds, factor de friccin y prdidas por friccin en la tubera. Ponga especial
atencin en la consistencia de las unidades empleadas.
Problema 3
Const zero = 0.000000000001
Const pi = 3.14159265358979
Dim E As Double
Dim D As Double
Dim L As Double
Dim Re As Double
Dim p As Double
Dim v As Double
Dim u As Double
Dim Q As Double
Dim dp As Double
Dim maxit As Integer
Dim tol As Double
Dim fm As Double
Static Function Log10(x)
Log10 = Log(x) / Log(10#)
End Function
Private Sub CmdBorra_Click()
Borrar
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Label18.Caption = ""

End Sub
Public Sub CmdCalcular_Click()
Dim f0 As Double
'--------------------------Asignacin de
variables--------------------------
Q = Val(Text1.Text)
D = Val(Text2.Text)
L = Val(Text3.Text)
E = Val(Text4.Text)
p = Val(Text5.Text)
u = Val(Text6.Text)
tol = Val(Text7.Text)
maxit = Val(Text8.Text)

Borrar

v = 4 * Q / pi / (D ^ 2) ' Calculando
velocidad media
Re = D * p * v / u
'calculando estimacin inicial
If Re <= 2100 Then
Label18.Caption = "Laminar"
fm = 64 / Re
Text11.Text = fm
Else
Label18.Caption = "Turbulento"
f0 = 0.316 * Re ^ (-0.25) ' Ecuacin de
Blasius
fm = Newton(f0)
Text11.Text = fm
End If

dp = fm * p * (v ^ 2) * L / 2 / D

Text9.Text = v
Text10.Text = Re
Text12.Text = dp

End Sub
Private Function Newton(x0 As Double) As
Double
Dim X1 As Double

For i = 1 To maxit 'Inicia e incrementa
el contador

X1 = x0 - F(x0) / dF(x0) 'Frmula
iterativa

'----------------------Evaluacin de
tolerancia----------------------
If Abs(F(X1)) >= tol Then
x0 = X1
Newton = x0
Else
Exit For
End If

'-------------------Muestra resultados
en el flexgrid------------------
MsgResult.TextMatrix(i, 0) = i
MsgResult.TextMatrix(i, 1) =
Round(x0, 4)
List1.AddItem Round(x0, 7)
MsgResult.TextMatrix(i, 2) =
Round(F(x0), 4)
MsgResult.TextMatrix(i, 3) =
Round(dF(x0), 4)
MsgResult.TextMatrix(i, 4) =
Round(X1, 4)
MsgResult.TextMatrix(i, 5) =
Round(dF(X1), 4)

Next

End Function
Private Sub CmdSalir_Click()
End
End Sub
Private Function F(x As Double) As Double
F = 1 / Sqr(x) + 2 * Log10(E / (3.7 * D) +
2.51 / (Re * Sqr(x)))
End Function
Private Function dF(x As Double) As Double
dF = (F(x + zero) - F(x)) / zero
End Function
Private Sub Form_Load()
MsgResult.TextMatrix(0, 0) = "Num Iter"
MsgResult.TextMatrix(0, 1) = "X0"
MsgResult.TextMatrix(0, 2) = "F(X0)"
MsgResult.TextMatrix(0, 3) = "F'(X0)"
MsgResult.TextMatrix(0, 4) = "X1"
MsgResult.TextMatrix(0, 5) = "F(X1)"

End Sub
Private Sub Borrar()
'------------------------------Borra
Resultados----------------------------
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
List1.Clear
For k = 1 To 99
MsgResult.TextMatrix(k, 0) = ""
MsgResult.TextMatrix(k, 1) = ""
MsgResult.TextMatrix(k, 2) = ""
MsgResult.TextMatrix(k, 3) = ""
MsgResult.TextMatrix(k, 4) = ""
MsgResult.TextMatrix(k, 5) = ""
Next k

End Sub
PROBLEMA 4 Desarrolle un Programa en Visual Basic para determinar los clculos de vaporizacin
instantnea (Flash) isotrmico, empleando para la iteracin el mtodo de Newton Raphson, es decir,
el programa desarrollado en el Problema 1. Este programa deber ingresar los siguientes valores:
nmero de componentes de la mezcla, conjunto de fracciones molares en la alimentacin, conjunto de
valores de las constantes de equilibrio. El programa calcular: flujo molar del vapor as como el
conjunto de fracciones molares del lquido y del vapor.
Evale su programa con el siguiente grupo de valores correspondiente a una corriente de gas natural
que se encuentra a 1600 psia y 120 F: Nmero 1 2 3 4 5 6 7 8 9 Componente Dixido de carbono
Metano Etano Propano Isobutano n-Butano Pentanos Hexanos Heptanos Fraccin molar
Problema 4
Const zero = 0.0000000000001
Const tol = 0.0000001
Const maxit = 100
Dim n As Integer
Private Sub Calcular_Click()
Dim x0 As Double
Dim X1 As Double
Dim Q As Double
n = Val(TextN.Text)
Q = Val(TextQ.Text)

ReDim A(1 To n, 1 To 2) As Double

For i = 1 To n
A(i, 1) = matriz.TextMatrix(i, 1)
A(i, 2) = matriz.TextMatrix(i, 2)
Next i

x0 = 0.5 'punto inicial para la iteracin

'-------------------------------Rutina
Principal------------------------------
For i = 1 To maxit 'Inicia e incrementa el
contador

X1 = x0 - f(x0, A()) / dF(x0, A())
'Frmula iterativa

'----------------------Evaluacin de
tolerancia----------------------
If Abs(f(X1, A())) >= tol Then
x0 = X1
Else
Exit For
End If

Next

'-------------------------Mensaje de no
convergencia-----------------------
If Abs(f(X1, A())) > tol Then
R = MsgBox("Mtodo no converge para
nmero de interaciones especificadas", 16)
End If

For i = 1 To n

z = A(i, 1)
k = A(i, 2)
fracciones.TextMatrix(i, 1) = Round((z /
(x0 * (k - 1) + 1)), 4)
fracciones.TextMatrix(i, 2) = Round((z *
k / (x0 * (k - 1) + 1)), 4)

Next

Text1.Text = Q * x0
Text2.Text = Q - Val(Text1.Text)


End Sub
Private Sub Form_Load()
matriz.ColWidth(0) = 900
matriz.ColWidth(1) = 1520
matriz.ColWidth(2) = 1520
fracciones.ColWidth(0) = 900
fracciones.ColWidth(1) = 1680
fracciones.ColWidth(2) = 1680
TextN.Text = 1
matriz.TextMatrix(0, 0) = " N Comp."
matriz.TextMatrix(0, 1) = " Fraccin
Molar"
matriz.TextMatrix(0, 2) = " Const.
Equilibrio"
matriz.TextMatrix(1, 0) = " C1"
fracciones.TextMatrix(0, 0) = " N Comp."
fracciones.TextMatrix(0, 1) = "Fracc. Molar
Lquido"
fracciones.TextMatrix(0, 2) = " Fracc.
Molar vapor"
fracciones.TextMatrix(1, 0) = " C1"

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 TextN_KeyPress(KeyAscii As
Integer)
n = Val(TextN.Text)

If KeyAscii = 13 Then
matriz.Rows = n + 1
fracciones.Rows = n + 1
For i = 1 To n
matriz.TextMatrix(i, 0) = " C" & (i)
fracciones.TextMatrix(i, 0) = " C"
& (i)
Next i
End If
End Sub
Private Sub TextN_LostFocus()
If TextN.Text = Empty Or
Val(TextN.Text) <= 0 Then
TextN.Text = 1
End If
n = Val(TextN.Text)
matriz.Rows = n + 1
fracciones.Rows = n + 1

For i = 1 To n
matriz.TextMatrix(i, 0) = " C" & (i)
fracciones.TextMatrix(i, 0) = " C" &
(i)
Next i

End Sub
Private Sub Borrar_Click()
TextN.Text = ""
TextQ.Text = ""
Text1.Text = ""
Text2.Text = ""

For i = 1 To n
matriz.TextMatrix(i, 1) = ""
matriz.TextMatrix(i, 2) = ""
fracciones.TextMatrix(i, 1) = ""
fracciones.TextMatrix(i, 2) = ""
Next i
TextN.SetFocus

End Sub
Private Sub Salir_Click()
End
End Sub
Private Function f(x As Double, ByRef A() As
Double) As Double
f = 0

For i = 1 To n
z = A(i, 1)
k = A(i, 2)
f = f + ((k - 1) * z / (x * (k - 1) + 1))
Next

End Function
Private Function dF(x As Double, ByRef A()
As Double) As Double
dF = (f(x + zero, A()) - f(x, A())) / zero

End Function
PROBLEMA 5 Elabore un programa en Visual Basic, que a partir de tres pares ordenados de
temperatura y constante de equilibrio de fases, calcule las constantes del modelo de Antoine.
Asimismo, transforme este programa en una subrutina de Visual Basic.
Problema 5
Dim a As Double
Dim b As Double
Dim c As Double

Private Sub Salir_Click()
End
End Sub
Private Sub calcular_Click()
Dim t1 As Double
Dim t2 As Double
Dim t3 As Double
Dim k1 As Double
Dim k2 As Double
Dim k3 As Double
t1 = Val(Txt1.Text)
t2 = Val(Txt2.Text)
t3 = Val(Txt3.Text)
k1 = Val(Txk1.Text)
k2 = Val(Txk2.Text)
k3 = Val(Txk3.Text)
Constantes(t1, t2, t3, k1, k2, k3)

TxA.Text = a
TxB.Text = b
TxC.Text = c

End Sub
Public Sub Constantes(t1 As Double, t2 As
Double, t3 As Double, k1 As Double, k2 As
Double, k3 As Double)
Dim alpha As Double

alpha = (Log(k2 / k1) / Log(k3 / k2) * (t3 -
t2) / (t2 - t1))
c = (alpha * t1 - t3) / (1 - alpha)
b = Log(k3 / k1) / ((1 / (t1 - c)) - (1 / (t3 -
c)))
a = Log(k2) + b / (t2 + c)

End Sub
PROBLEMA 7 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.
Problema 7
Option Explicit
Function f(ByVal x As Double) As Double
f = Cos(x) * x + 3 * x

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 cmdEjecutar_Click()
Dim a, b As Double
Dim N, r As Integer

a = Val(txta.Text)
b = Val(txtb.Text)
N = Val(txtn.Text)

If Par(N) Then
r = MsgBox("Ingrese nmero impar de
intervalos", 48, "Dato no vlido")
Else
txtr.Text = Simpson(a, b, N + 1)
End If

End Sub
Private Sub cmdSalir_Click()
End
End Sub
PROBLEMA 8 Haciendo uso del Excel determine una funcin de correlacin para los siguientes datos
de conductividad trmica, correspondientes al dixido de carbono, expresados en BTU/h/Ft/F
Temperatura
Problema 8
Private Sub Calcular_Click()
Dim n As Integer
Dim xint As Double

n = Val(TxtIngreso.Text)
xint = Val(TxtXInt.Text)

ReDim X(1 To n) As Double
ReDim Y(1 To n) As Double

For i = 1 To n
X(i) = matriz.TextMatrix(i, 1)
Y(i) = matriz.TextMatrix(i, 2)
Next

Label7.Caption = TxtXInt.Text
Text1.Text = newtint(X, Y, xint, n)

End Sub
Private Function newtint(ByRef X() As Double,
ByRef Y() As Double, ByVal p As Double,
ByVal n As Integer) As Double
ReDim a(1 To n) As Double
ReDim d(1 To n, 1 To n) As Double
ReDim c(1 To n) As Double
ReDim df(1 To n) As Double

a(1) = Y(1)

For k = 1 To n - 1
d(k, 1) = (Y(k + 1) - Y(k)) / (X(k + 1) -
X(k))
Next k

For j = 2 To n - 1
For k = 1 To n - j
d(k, j) = (d(k + 1, j - 1) - d(k, j - 1)) /
(X(k + j) - X(k))
Next k
Next j

For j = 2 To n
a(j) = d(1, j - 1)
Next j

df(1) = 1
c(1) = a(1)

For j = 2 To n
df(j) = (p - X(j - 1)) * df(j - 1)
c(j) = a(j) * df(j)
Next j

newtint = 0

For j = 1 To n
newtint = newtint + c(j)
Next j

End Function
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) = " xi"
matriz.TextMatrix(0, 2) = " yi"
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)
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()
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()
n = Val(TxtIngreso.Text)
For i = 1 To n
matriz.TextMatrix(i, 1) = ""
matriz.TextMatrix(i, 2) = ""
Next
TxtIngreso.Text = ""
Text1.Text = ""
TxtXInt.Text = ""
Label7.Caption = ""
TxtIngreso.SetFocus

End Sub
Private Sub Salir_Click()
End
End Sub
Problema 10
Utilizando el polinomio de Interpolacin de Newton por Diferencias divididas calculamos un polinomio
interpolante para tres puntos arbitrarios:
x -1 0 6
y 0.5 7 5
Utilizando la interpolacin de Newton:
f
2
(x) = a
0
+ a
1
x + a
2
x
2
donde :
a
0
= b
0
b
1
x
0
+ b
2
x
0
x
1
a
1
= b
1
b
2
x
0
b
2
x
1
a
2
= b
2
donde :
( )
0 0
b f x
1 0
1
1 0
( ) ( ) f x f x
b
x x

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

Son las Diferencias divididas de Newton.


Reemplazando valores obtenemos las diferencias divididas:
b
0
= 0.5
b
1
= 6.5
b
2
= -0.97619048
Y calculamos los coeficientes del polinomio interpolante de 2do. Grado:
a
0
= 0.5 - (6.5)(-1)+(-0.97619048)(-1)(0) = 7
a
1
= 6.5 -(-0.97619048)(-1)-( -0.97619048)(0) = 5.52380952
a
0
= -0.97619048
Entonces el polinomio por diferencias divididas de Newton de segundo grado para tres puntos es:
f
2
(x) = 7 + 5.52380952x - 0.97619048x
2
145.6666666
Luego integramos el polinomio:
( )
6
2
1
7 5.52380952x-0.97619048x dx

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

También podría gustarte