excel for scientists and engineers phần 7 pdf

48 340 0
excel for scientists and engineers phần 7 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

266 EXCEL: NUMERICAL METHODS Thus, for example, Laplace's equation (12-2) is rewritten as F(x + h, Y)- 2F(x, Y) + F(x - h, Y) + F(x9 Y + k)-2F(xy v)+ F(x, Y -k) = h2 k2 (12-1 3) Our approach for solving these problems will be to subdivide the region of interest into a lattice of mesh size h x k and write the difference equations that correspond to the lattice points, to obtain values of the function at each lattice point. For the general lattice point x,, yI the derivative expression is =O (1 2- 14) m,+1 Y Y, ) - 2m, Y YI 1 + F(x,-, 9 Y, 1 + F(x, 7 YI+1) - 2F(x, Y Y, ) + F(x, 3 YI-1) h2 k2 If h = k, equation 12- 14 simplifies to F(X,+,Y Y,) + F(x, ,Y,+1) - Wx, ,Y,) + FkY Yl-1) + F(X,-,Y Y,) = 0 (1 2- 15) from which we obtain equation 12-16 F(x,+,,~l)+F(xlY~l+,)+F(xlY~l-,)+F(xl-,,~,) (12-16) 4 F(x,,y,) = For the case where h # k, an expression for F(x,y) can readily be obtained from equation 12- 14. Note that four lattice points are involved in the calculation of F(x,y) by equation 12- 16, as represented in Figure 12- 1. This representation is sometimes referred to as the stend of the method. -1 0 1 Xi Figure 12-1. Stencil of the finite difference method for the solution of an elliptic PDE. The points shown as solid squares represent previously calculated values of the function; the open square represents the value to be calculated. CHAPTER 12 PARTIAL DIFFERENTIAL EOUATIONS 267 Methods for the solution of equation 12-16 can best be illustrated by reference to a concrete example. An Example: Temperature Distribution in a Heated Metal Plate A typical example of an elliptic partial differential equation involves the solution of a steady-state heat-flow problem. For example, if a thin steel plate, 10 x 10 cm, has one of the edges held at 100°C and the other three edges at O"C, what are the steady-state temperatures within the plate? For simplicity, we assume that heat is not lost through the faces of the plate. We subdivide the plate by means of a grid with h = k = 0.5 cm, thus creating a lattice of size 20 x 20. At equilibrium, heat flows in the x-axis direction into a lattice element at a rate proportional to the temperature of the adjoining element in the x-axis, and flows out of the element at a rate proportional to the temperature of the element. The same is true in the y-axis direction. This model gives rise to an elliptic partial differential equation of the form of equation 12-2. The time and the thermal conductivity k of the material do not enter into the equation. We will use equation 12-16 to calculate the temperature at each lattice point; the temperature at a lattice point is the average of the temperatures of the four surrounding lattice points. Thus we have generated a system of 400 simultaneous linear equations in 400 unknowns. Although most of the terms in a given equation are zero, the problem is still unmanageable. However, we can solve the system by an iterative method, as described below. Figure 12-2 shows part of the spreadsheet used to solve the system; each cell of the 20 x 20 array corresponds to a lattice point. The formula in cell B6 is =(B5+A6+C6+B7)/4 You can Fill Down the formula into 20 rows and then Fill Right into 20 columns to create the 20 x 20 array. Since cell B6 refers to cell 87 and B7 similarly refers to B6, we have created a circular reference, a formula that refers to itself, either directly or indirectly. In fact, the spreadsheet contains a large number of circular references. A circular reference is usually an error; Excel displays the "Cannot resolve circular references" error message and puts a zero in the cell. In this case, however, the circular reference is intentional. We can make Excel recalculate the value in each cell, using the result of the previous iteration. 268 EXCEL: NUMERICAL METHODS Figure 12-2. Solving an elliptic PDE using intentional circular references. The worksheet shows part of the 20 x 20 array of lattice points representing the temperature distribution in a metal plate; the gray cells represent the temperature at the edges of the plate. (folder 'Chapter 12 (PDE) Examples, workbook 'Elliptic PDE', sheet 'Temp in a Plate') To "turn on" iteration, choose Tools+Options-+Calculation and check the iteration box. Unless you change the default settings for iteration, Microsoft Excel stops calculating after 100 iterations or after all values in the circular reference change by less than 0.00 1 between iterations, whichever comes first. When you press OK the iterative circular reference calculations will begin. CHAPTER 12 PARTIAL DIFFERENTIAL EQUATIONS 269 Figure 12-3. Temperature distribution in a metal plate. (folder 'Chapter 12 (PDE) Examples, workbook 'Elliptic PDE', sheet 'Temp in a Plate') Parabolic Partial Differential Equations The previous example showed the steady-state distribution of temperature within a metal plate. We will now examine how temperature changes with time. This so-called heat equation is an example of a parabolic partial differential equation. Consider the flow of heat within a metal rod of length L, one end of which is held at a known high temperature, the other end at a lower temperature. Heat will flow from the hot end to the cooler end. We want to calculate the temperature along the length of the rod as a function of time. We'll assume that the rod is perfectly insulated, so that heat loss through the sides can be neglected. Consider a small element dx along the length of the rod. Heat is flowing from the hot end (x = 0) to the cooler end (x = L). The rate of heat flow into the element at the point x is given by dT -KA- dx (1 2- 17) where K is the coefficient of thermal conductivity (cal s-l cm-' deg-'), A is the cross-sectional area of the rod (cm2) and dTldx is the temperature gradient. The 270 EXCEL: NUMERICAL METHODS minus sign is required because temperature gradients are negative (heat flows from a higher temperature to a lower). The material of which the rod is made has heat capacity c (cal g-' deg-') and density p (g ~m-~). The heat flow (cal s-') out of the volume element, at point x + dk, is given by - d( $ + s( g)dx) (1 2- 18) The rate of increase of heat stored in the element Adx is given by (12-19) dT cp( Adx) - dt From equations 12- 17 and 12- 18, the rate of increase of heat stored in the element Adx is Hi, - Hout, and this is equal to the expression in 12-19 which can be simplified to dT (a,::) dt K- =Cp- or =O d2T cp dT ax= K dt (12-21) (12-21a) an example of a parabolic partial differential equation. There are several methods for the solution of parabolic partial differential equations. Two common methods are the explicit method and the Crank- Nicholson method. In either method, we will replace partial derivatives by finite differences, as we did in the example of the parabolic partial differential equation. Solving Parabolic Partial Differential Equations: The Explicit Method Using equation 12-2 1 as an example and writing it in the form a2F dF -+k-=O ax2 dy ( 12-22) we can replace derivatives by finite differences, using the central difference formula for 8~/a~ CHAPTER 12 PARTIAL DIFFERENTIAL EOUATIONS 27 1 and the forward difference formula for dFldy (1 2-23) (1 2-24) When these are substituted into equation 12-22, we obtain equation 12-25, where r = Ay/(~l(hx)~). (Using forward and central differences simplifies the expression.) F,,/+I = f.(F,+l,/ + F,-l,/ ) + 0 - rk,/ (1 2-25) Or, when i represents distance x andj represents time t, Fx,t+l = r(Fx+,,, + Fx-l,, 1 + 0 - r)Fx,t (12-25a) Equation 12-25a permits us to calculate the value of the function at time t+l based on values at time t. This is illustrated graphically by the stencil of the method. -1 0 1 X Figure 12-4. Stencil of the explicit method for the solution of a parabolic PDE. The points shown as solid squares represent previously calculated values of the function; the open square represents the value to be calculated. An alternative to the use of equation 12-25 is to choose hx and Ay such that r = 0.5 (e.g., for a given value of Ax, Ay = k(A~)~/2), so that equation 12-25 is simplified to ( 12-26) 212 EXCEL: NUMERICAL METHODS An Example: Heat Conduction in a Brass Rod Consider an insulated 10-cm brass rod, initially at a temperature of 0°C. One end of the rod is heated to 100°C. Equation 12-20 describes the heat flow in the rod as a hnction of time. (For simplicity, we assume that there is no heat loss through the sides of the rod.) For brass, the coefficient of thermal conductivity k is 0.26 cal s-' cm-' deg-', the heat capacity c is 0.094 cal g-' deg-' and the density p is 8.4 g ~m-~. From these values, the coefficient k in equation 12-22 is 3.04 s cm-*. Figure 12-5 shows part of the spreadsheet used to calculate the temperature along the rod, in 1-second and 1-cm intervals. The table extends to t = 100 seconds (row 1 13). Figure 12-5. Calculation of heat flow in a brass rod. The text in cells M4:MlO are the names assigned to the cells L4:LlO. (folder 'Chapter 12 (PDE) Examples, workbook 'Parabolic PDE', sheet 'Temp distribution') CHAPTER 12 PARTIAL DIFFERENTIAL EOUATIONS 273 Cells K3:K9 contain constants used in the calculations; these cells were assigned the names shown in parentheses in column M. The formulas in cells K6, K7, K8 and K9 are, respectively =k/( hcap*rho) (coefficient k in general PDE, equation 12-22) =D12-C12 (AX) =B14-B13 (At) =e*Dt/( DxA2) (f) [In the spreadsheet, the range name f was used for the parameter Y in equation 12-26, since r can't be used as a name in Excel.] The values in cells on the edges of the table of temperatures (column C and column M) are the constant temperature values at the ends of the rod; the values in row 13 are the initial temperature of the interior of the rod. The formula in the remaining cells in the body of the temperature table (D14:L113) is based on equation 12-22. For example, the formula in cell D14 is =f*( C 1 3+E 1 3)+( 1 -2*f)*D 1 3 Experience has shown that the factorfmust be less than 1/2 in order to avoid instability in the calculations. For a given problem, this requires adjustment of both Ax and At. 50 $ 30 e .c a, ; 20 : 10 0 0 20 40 60 80 100 Time, seconds Figure 12-6. Temperature vs. time in a brass rod. (folder 'Chapter 12 (PDE) Examples, workbook 'Parabolic PDE, sheet 'Temp distribution') Solving Parabolic Partial Differential Equations: The Crank-Nicholson or Implicit Method In the explicit method, we used a central difference formula for the second derivative and a forward difference formula for the first derivative (equations 12- 24 and 12-25). A variant of equation 12-26 that makes the approximations to both derivatives central differences is known as the Crank-Nicholson formula - rKl,,+l + (2 + w4,,+1 - YFf+I,,+I =r%, + (2 - 2r)F,,, + rF,+1,, - rK-l,l+l + (2 + 2m,f+l - r4+1,1+1 = ~~x-I.1 + (2 - 2dF,,I + rK+l,* (12-27) or, if i represents distance x and j represents time t, (1 2-27a) where r = A~/(~(Ax)~). Choosing specific values for r and Ax determines the increment Ay. For r = 1, equation 12-27a simplifies to equation 12-28. - L,f+l + 4K,l+l - Fx+l,l+l = + Fx+~,l ( 12-28) Equation 12-27a or 12-28 shows that Fx,I+l is a function of yet-to-be- calculated values at t+l (Fx-l,l+l and Fx+l,l+l) in addition to known values at time t (the quantities on the right-hand side of the equation). This is illustrated by the stencil of the method shown in Figure 12-7. Equation 12-27a results in a set of simultaneous equations at each time step. Again, the solution procedure is best illustrated by means of an example. -1 0 1 X Figure 12-7. Stencil of the implicit method for the solution of a parabolic PDE. The points shown as solid squares represent previously calculated values of the function; the open circles represent unknown values in adjacent positions; the open square represents the value to be calculated. CHAPTER 12 PARTIAL DIFFERENTIAL EOUATIONS 275 An Example: Vapor Diffusion in a Tube An air-filled tube 20 cm long allows water vapor to diffuse from a source (liquid water) to a drying chamber, where the vapors are dissipated. Initially the tube is capped so that the vapor cannot escape. The temperature of the tube is held at 30°C. The equilibrium vapor pressure of water at this temperature is 3 1.8 mm Hg; thus the vapor pressure inside the tube is 3 1 .8 mm Hg. When the cap is removed, the vapor will diffuse toward the drying chamber, where the water vapor pressure is zero. We wish to model the vapor pressure along the length of the tube as a function of time. The diffusion equation is *=DEE dt ax2 ( 12-29) where p is the vapor pressure and D is the difhsion coefficient in units of cm2 s-I. For water vapor, D = 0.1 15 cm2 s-l at 30°C. We subdivide the length of the tube into uniform subintervals and calculate the value of the function (here the vapor pressure p) at each interior point. Choosing Ax = 4 yields four x values where the function value needs to be evaluated (at x = 4, 8, 12 and 16 cm) and two boundary values where it is known (at x = 0 and 20). Also, using Ax = 4 and Y = 1 sets At = 139 seconds. Using equation 12-28 yields four simultaneous equations in four unknowns, thus: for x = 4, t = 139: for x = 8, t = 139: for x = 12, t = 139: for x = 16, t = 139: For Y = 1, the values of the coefficients for the four simultaneous equations are shown in the spreadsheet in Figure 12-8. They are designated cl, c2, c3 and c4 in the table. These coefficients will have different values if a different value of Y is chosen. The constants (the values of the right-hand side of the four equations) are also shown in Figure 12-8. The formulas in cells l15:L15 are [...]... coefficients, their standard deviations, and the R2 value CHAPTER 13 293 LINEAR REGRESSION AND CURVE FITTING Type the LINEST formula with its arguments, in =LINEST(F3:F14,E3:E14,TRUE,TRUE) You can use "shorthand" for the logical arguments const and stats: represented by 0 and TRUE by any nonzero value, as this example the following FALSE can be in the formula =LINEST(F3:F14,E3:E14,1,1) Enter the formula by using... (13-5) = For a straight line y = mx + by the least-squares slope and intercept are given by equations (13-6) and (13 -7) m = SX,& ( 1 3-6) b = (Cy, - m Cx,)lN ( 1 3 -7) The Correlation coefficient, R, is a measure of the correlation between x and y If x and y are perfectly correlated (i.e., a perfect straight line), then R = 1 An R value of zero means that there is no correlation between x and y, and an... power series, for example, y = a + bx + cx2 + dx3 (13-1) and some functions containing exponentials, such as Mathematically, a function that is linear in the coefficients is one for which the partial derivatives of the function with respect to the coefficients do not contain coeficients For example, for the power series equation y = a + bx + cx2,8yIaa = 1, +lab = x and ayldc = + X2 2 87 288 EXCEL: NUMERICAL... used in the TableValuel, TableValue2 and TableValue3 formulas to return the appropriate value from the table of values (The number 7 in the formula might have to be changed if columns in the spreadsheet were rearranged.) The MaxCol and MinCol formulas are used in the IF function in the formula in the constants table so as to add the boundary value terms to the first and last constant terms Vapor Diffusion... SLOPE(known_y's, known-x's); the arguments of INTERCEPT and RSQ are the same as for the SLOPE function The values are shown in Figure 13-4 slope= intercept= - 970 5 38.61 0.9959 Figure 13-4 Slope, intercept and R2 of the plot of In P vs 1/T for methane hydrate (folder 'Chapter 13 Examples', workbook 'Methane Hydrate', sheet 'Phase diagram data') The formulas in cells F16, F 17 and F18 are =SLOPE(F3:F14,E3:E14) =INTERCEPT(F3:F14,E3:E14)... constitute a complete cycle of vibration This vibration time, 0.00 175 8 seconds, corresponds to a frequency of 569 sd, and agrees exactly with the value calculated by the formula f =zd5J 1 ( 12- 37) The above procedure can be expanded to model vibrations in two space dimensions ( 1 2-38) EXCEL: NUMERICAL METHODS 286 Problems Data for, and answers to, the following problems are found in the folder "Ch... formula uses the following named formulas CoeffFableCol =COLUMN()-MIN(COLUMN(coefficients)) CoeffFableRow =ROW()-MIN(ROW(coefficients)) 280 EXCEL: NUMERICAL METHODS Thus a Crank-Nicholson calculation can be set up on a spreadsheet using a single formula to create the coefficients table, a (different) single formula to create the constants table, and a single formula for the values table The results... coefficients: $D$9:$G$12; constants: $J$I 5:$M$26; values: $C$15:$H$ 27 The formulas in cells G5:G7 are, respectively, =D14-C14 =B16-B15 =(D*Dt)/DxY 278 EXCEL: NUMERICAL METHODS Figure 12-10 A convenient spreadsheet layout for solving a parabolic PDE by the Crank-Nicholson method The coefficients matrix is aligned directly above the table of values and the table of constants is directly to the right (folder... "array-enter" a formula, Excel puts braces around the formula, as shown below: {=LINEST(F3:F14,E3:E14,1,1)} Figure 13-6 Regression results and statistics returned by LINEST for the methane hydrate phase diagram data (folder 'Chapter 13 Examples', workbook 'Methane Hydrate', sheet 'Phase diagram data') You do not type the braces; if you did, the result would not be recognized by Excel as a formula When... any wtY0 ethylene glycol Assigning the names aa, bb, cc, dd for the regression coefficients in cells A18: D18 and W for the wt% ethylene glycol values in column A, respectively, is a good idea The formula =aa*WA3+ bb*WA2+cc*W+dd was used to calculate the values in column E of Figure 13-9 CHAPTER 13 LINEAR REGRESSION AND CURVE FITTING 2 97 Handling Noncontiguous Ranges of known-x's in LINEST One of the . explicit method, we used a central difference formula for the second derivative and a forward difference formula for the first derivative (equations 12- 24 and 12-25). A variant of equation 12-26. EOUATIONS 27 1 and the forward difference formula for dFldy (1 2-23) (1 2-24) When these are substituted into equation 12-22, we obtain equation 12-25, where r = Ay/(~l(hx)~). (Using forward. distance x and j represents time t, (1 2-27a) where r = A~/(~(Ax)~). Choosing specific values for r and Ax determines the increment Ay. For r = 1, equation 12-27a simplifies

Ngày đăng: 14/08/2014, 12:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan