Programación e Interpolación

8
UNIVERSIDAD NACIONAL DE SAN AGUSTÍN ESCUELA PROFESIONAL DE INGENIERÍA QUÍMICA CURSO DE DISEÑO Y EVALUACIÓN DE PROCESOS INFORME DE LABORATORIO 8 PROGRAMAS EN VISUAL BASIC. Luis Felipe Miranda Z. 1. En la tabla adjunta se presentan datos correspondientes a la conductividad del dióxido 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 Conductivid ad Temp Viscosid ad 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 más 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 señaladas para cada caso. Genere un archivo donde registre estos resultados y grafique en Excel los resultados. 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 método podrá servir para filtrar datos incorrectos en términos 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

description

Este documento contiene una tarea para programar en Visual Basic problemas de Interpolación por el método de Newton. Asimismo adjunta un ejemplo de Programa que trabaja con archivos e ilustra el uso de funciones

Transcript of Programación e Interpolación

Page 1: Programación e Interpolación

UNIVERSIDAD NACIONAL DE SAN AGUSTÍNESCUELA PROFESIONAL DE INGENIERÍA QUÍMICACURSO DE DISEÑO Y EVALUACIÓN DE PROCESOS

INFORME DE LABORATORIO 8PROGRAMAS EN VISUAL BASIC.

Luis Felipe Miranda Z.

1. En la tabla adjunta se presentan datos correspondientes a la conductividad del dióxido de carbono, en BTU/hr.ft.ºF, y a la viscosidad del etilen glicol, en lb/ft.hr, siendo la temperatura expresada en grados FahrenheitTemp Conductividad Temp Viscosidad32 0,085 0 242212 0,0133 50 82,1392 0,0181 100 30,5572 0,0228 150 12,6

200 5,57Para cada propiedad determine el polinomio más 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 señaladas para cada caso. Genere un archivo donde registre estos resultados y grafique en Excel los resultados.

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 método podrá servir para filtrar datos incorrectos en términos generales?. Justifique su respuesta.X SIN(X)0,2 0,198670,25 0,247400,30 0,295520,35 0,349200,40 0,384920,45 0,434970,50 0,479430,55 0,522690,60 0,564640,65 0,605290,70 0,644220,75 0,681640,80 0,72736

Page 2: Programación e Interpolación

EJEMPLO ILUSTRATIVOPROGRAMA QUE EMPLEA ALMACENAMIENTO DE RESULTADOS EN ARCHIVOEl archivo creado con Visual Basic puede ser abierto con Excel y los resultados graficados mediante los utilitarios de Excel. Este programa ilustra además el uso de funciones, la documentación al interior del programa, el uso de ciclos de cálculo y el empleo de variables indexadas.

Public x0 As Double, y0 As Double, z0 As Double, ZStep As SinglePublic x2 As Double, y2 As Double, z2 As DoublePublic Nrey As Double, Cdrag As Double, DragFactor As Double, DragForce As Double

Public Sub Command1_Click()'ELECTROSTATIC ATOMIZATION: SIMULATION MODULE‘Luis Felipe Miranda Zanardi. ‘University of Brunel. Department of Systems Engineering. July 21st, 2001.‘'Declaring variablesDim Ntrial As IntegerDim Zmax As Single, Xmax As Single, X1 As Double, Z1 As DoubleDim voltage As Double, current As Double, permittivity As Double, flow As SingleDim diameter As Single, adens As Single, avisc As Single, ldens As SingleDim vel0 As Double, Angle As SingleDim z As Single, Veff As Single, Path As Single, charge As SingleDim Mass As DoubleDim VelZ0 As Double, VelX0 As Double, VelX As Double, VelZ As Double, VelMod As DoubleDim potent(4) As Double

'*** INPUT INITIAL DATA'Properties of Fluids ldens = 789 'density of ethanol kg/m3 adens = 1.12 'density of air kg/m3 avisc = 0.0000211 'air viscosity kg/(m.s) permittivity = 0.000000000008854 'vacuum permittivity F/m'Operating Conditions flow = 0.0000000003 'flow rate m3/s curr = 0.00000013 'total current, A voltage = 20000# 'electric potential, V diameter = 0.000015 'diameter of droplets, m vel0 = 15# 'initial velocity of droplets m/s Zmax = 0.15 'distance from nozzle to target'Simulation Conditions Angle = 20 'Half Spray cone angle in degrees ZStep = 0.005 'Integration step in Z coordinate TimeStep = 0.1 'Time integration step Ntrial = 30 'Number of elements in potential comp.'Constants Declaration Const pi = 3.1416 Const g = 9.81 'Acceleration of gravity m/s2 Const void = 0.65 'void fraction in packed bed of spheres''***INITIAL COMPUTATIONS'Initial calculations Angle = Angle * pi / 180 'angle in radians

Page 3: Programación e Interpolación

VolDrop = pi / 6 * diameter ^ 3 'volume of droplet Mass = VolDrop * ldens 'mass of droplet Ndrop = flow / VolDrop 'number of droplets produced per second Veff = Ndrop * VolDrop / void 'total volume occupied by droplets VelX0 = vel0 * Abs(Sin(Angle)) VelZ0 = vel0 * Abs(Cos(Angle))'Computation of the Charge of the Parcel' A parcel is a group of droplets that have the same size.' As a first approach, before introducing size distribution of particles, it is' assumed that all particles have the same size and charge.' So the charge per particle is the total current divided by the number of particles N charge = curr / Ndrop 'units are Coulombs/s divided by drops/s UnitCharge = charge / Mass 'charge per mass of droplet''CREATE A FILE TO STORE RESULTS FileName = "A:\Modelling2.dat" & n& Open FileName For Output As #1 ' Open file to write Print #1, "RESULTS OF THE SIMULATION" Print #1, 'introduces blank line Print #1, "z0, x0, DragForce, ZSpaceChargeForce, ZExternalForce, XExternalForce, ZTotalForce, XTotalForce, VelX, VelZ" Print #1,''INITIAL DRAG FACTOR COMPUTATIONS Call Drag(diameter, adens, avisc, ldens, vel0, Mass) InitVel = vel0 'Saving Initial value of velocity InitDrag = DragFactor 'Saving the Drag Factor at initial conditions InitDragForce = DragForce'INITIAL EXTERNAL ELECTRIC FIELD COMPUTATIONS' Computing boundary conditions for the external electric field potent(0) = 0 'initial electric potential value x0 = 0 y0 = 0 z0 = Zmax Xmax = Zmax * Tan(Angle)' Calling function to compute initial electrical potential at boundary?? potent(0) = Potential(Ntrial, x0, y0, z0, ZStep, Zmax, Xmax, voltage)' Initial Values of the potential vector For i = 1 To 3 potent(i) = 0 Next i' Initializing value of z0 for loop computations z0 = 0#'STARTS LOOP TO COMPUTE MAIN VARIABLES ALONG THE Z COORDINATEDo Until z0 > Zmax 'Computation of the DRAG FORCE ' Call Drag(diameter, adens, avisc, ldens, VelZ0, Mass) ' Z1 = z0 + ZStep 'Computation of the SPACE CHARGE FORCE Path = FreePath(Angle, Veff, ZStep, Z1) 'call function to compute free path ZSpaceChargeForce = SumCharge(Path, charge, permittivity) * UnitCharge XSpaceChargeForce = SumCharge(Path, charge, permittivity) * UnitCharge ' 'Computation of the EXTERNAL ELECTRIC FIELD FORCE

Page 4: Programación e Interpolación

'Inner LOOP in the X Direction 'Initial condition x0 = 0 Xmax = Z1 * Tan(Angle) Do Until x0 > Xmax 'Starting loop in X direction X1 = x0 + ZStep 'Computation of electrical potential at point x(i),0,z(i) potent(1) = Potential(Ntrial, X1, 0, Z1, ZStep, Zmax, Xmax, voltage) 'Computation of electrical potential at point x(i-1),0,z(i) potent(2) = Potential(Ntrial, x0, 0, Z1, ZStep, Zmax, Xmax, voltage) 'Computation of electrical potential at point x(i),0,z(i-1) potent(3) = Potential(Ntrial, X1, 0, z0, ZStep, Zmax, Xmax, voltage) 'Computing Electric Field Force XExternalForce = (potent(2) - potent(1)) * UnitCharge / ZStep 'This is a finite divided difference ZExternalForce = (potent(3) - potent(1)) * UnitCharge / ZStep 'This is a finite divided difference 'Computation of Electric Field Force is finished 'Now it is performed the computation of the TOTAL FORCE XTotalForce = XExternalForce + XSpaceChargeForce ZTotalForce = ZExternalForce + ZSpaceChargeForce + DragForce + g If (z0 = 0#) And (x0 = 0#) Then InitXTotalForce = XTotalForce 'Saving values for initial conditions InitZTotalForce = ZTotalForce 'Saving Values for initial conditions End If 'Computation of DROPLET VELOCITY for Transient State 'This expression is the result of integrating the equation dVel/dt -DragFactor*Vel = TotalForce 'The Init values refer to initial conditions at t=0 and vel=vel0 'VelX = VelX0 - DragFactor * XTotalForce - InitVel / InitDrag * InitXTotalForce * Exp(-DragFactor * Time) 'VelZ = VelZ0 - DragFactor * ZTotalForce - InitVel / InitDrag * InitZTotalForce * Exp(-DragFactor * Time) 'Computation of Droplet Velocity for Steady State VelX = XTotalForce / (-DragFactor) 'Velocity Component X VelZ = ZTotalForce / (-DragFactor) 'Velocity Component Z VelMod = Sqr(VelX * VelX + VelZ * VelZ) 'Computation of the module of velocity 'PRINTING RESULTS IN FILE Print #1, Format(Z1, 0#), Format(X1, 0#), Format(DragForce, 0#), Format(ZSpaceChargeForce, 0#), Format(ZExternalForce, 0#), Format(XExternalForce, 0#), Format(ZTotalForce, 0#), Format(XTotal, 0#); Format(VelX, 0#), Format(VelZ, 0#) x0 = X1 'Actualizing value for X VelX0 = VelX 'Actualizing value for X velocity component VelZ0 = VelZ 'Actualizing value for Z velocity component ' Loop 'Closing X loop ' 'Call ElectricPotential(Ntrial, x0, y0, z0, Zstep, voltage) z0 = Z1 'Actualizing value for ZLoop 'Closing Z loop 'FILE OPERATIONS Close #1 'Close File'

Page 5: Programación e Interpolación

Open FileName For Input As #1 ' open file to read results Do While Not EOF(1) Line Input #1, Filedata 'Reads a line from a file Loop Close #1 'close file'End Sub

Page 6: Programación e Interpolación