You are on page 1of 13

3420

Enhancing Computer-Based Problem Solving Skills


with a Combination of Software Packages

Mordechai Shacham
Dept. of Chemical Engineering, Ben Gurion University of the Negev
Beer-Sheva 84105, Israel
e-mail: shacham@bgumail.bgu.ac.il

Michael B. Cutlip
Dept. of Chemical Engineering, University of Connecticut
Storrs, CT 06269, USA
e-mail: michael.cutlip@uconn.edu

Introduction

It is generally recognized that computer-based (or computer-enhanced) problem solving (CBPS)


can be a very important or possibly the most important application of the computer in
engineering education and practice. However, the penetration of CBPS in the various
engineering disciplines has been disappointingly slow and of limited extent. (Kantor and Edgar2,
Jones3) The mistaken premise that one software package is appropriate for all problem solving is
possibly one of the major impediments to CBPS. There are selected engineering courses where
the computer is used as a sophisticated calculator that can solve differential and implicit
algebraic equations and also perform regressions on experimental data. In other cases, the
graphical and the database management capabilities of the software are important. Still other
courses require considerable programming abilities.

We have long advocated that the most educational benefit can be gained by the integration of
several software packages throughout the curriculum (Shacham and Cutlip4). There is a need for
a numerical problem solver that accepts the model equations close to their mathematical forms
and provides their numerical solution with very minimal user intervention. Spreadsheets are used
widely for organization and presentation of information in tabular and graphical forms and for
database management with related operations. Software packages that support programming
(such as MATLAB, for example) are needed to implement algorithms are required in advanced
programming and numerical analysis courses.

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
In our experience, most students find it rather difficult to convert mathematical models of even
medium complexity to the format required by spreadsheets and by programming languages. This
initial difficulty may prevent them from using spreadsheets and programming languages in an
advanced level. This barrier to the extensive use of CBPS can be minimized if the software can
be utilized for converting the equations from their mathematical form into the format required by
spreadsheets and programming languages.

In this paper we will describe a numerical software package called POLYMATHA that we have
developed over the last 20 years that accepts the equations close to their mathematical forms and
provides their numerical solutions. The latest version of this software also automatically outputs
the equations in the format acceptable to a spreadsheet program, ExcelB, and a software package
that supports programming, MATLABC. This automated generation of completely operational
Excel and MATLAB programs greatly enhances the teaching of computing and numerical while
simultaneously introducing the students to widely used software packages. The potential
application of POLYMATH with these recently developed capabilities will be demonstrated by
several examples in engineering education.

Numerical Methods Courses

Courses involving the fundamentals of "Numerical Methods" are taught in most engineering
disciplines. These courses can consider the fundamental algorithms involved in numerical
problem solving and can also provide engineering students with many good examples that
illustrate the use of several software packages for effective CBPS. The examples provided in
most textbooks of numerical methods are often unrelated to the problems that have to be solved
in the student’s particular field. The use of realistic problems in a student’s engineering
discipline can increase their motivation in numerical problem solving and develop his/her ability
to select the appropriate numerical method to be used with the particular problem under
consideration.

In this paper we will demonstrate, using two examples, the potential benefits of the use of the
POLYMATH package to code and debug the mathematical model of the problem in hand. The
POLYMATH model can then be easily converted to an Excel worksheet or to a MATLAB
function. These packages can then be used to carry out the repetitive and/or iterative calculations
required by the particular numerical method.

Example 1 - Calculation of the Flow Rate in a Pipeline Using Successive Substitution

This example is based on Problem 5.10 presented by Cutlip and Shacham1. The detailed problem
statement is shown in Appendix A. The problem involves calculation of flow velocity and flow
rate in a pipeline configuration for a large number of combinations of pipe lengths and diameters.
The results should be presented in tabular and graphical forms. The solution for one set of pipe
diameter and length values involves solution of a nonlinear equation, the general mechanical
energy balance on an incompressible fluid, where the friction factor is function of the Reynold's

A
POLYMATH is copyrighted by M. Shacham, M. B. Cutlip and M. Elly (http://www.polymath-software.com/ )
B
Excel is a trademark of Microsoft Corporation (http://www.microsoft.com)
C
MATLAB is a trademark of The MathWorks, Inc. (http://www.mathworks.com/)
Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
number (thus the flow velocity). The successive substitution method has long been used for
solving this type of problems (even when graphical solution techniques were used), and it is
known that this technique converges very fast for flow velocity calculations. The successive
substitution method can be conveniently programmed with Excel, but the direct input of the
model equations into Excel can be a tedious and error-prone process. A better approach for
students is to first enter the equations into POLYMATH that requires minimal changes in the
naming of the variables, solve the equations for one sets of parameter values, and then compare
the results with the solution provided in the problem statement. After this is completed, an option
within POLYMATH can be used to convert the set of equations into a spreadsheet within Excel
that can immediately be used to also obtain a problem solution.

The equations, as entered into the POLYMATH program, are shown in Figure 1. Students find
the "user friendly" features of POLYMATH very helpful while entering the equations: The
notation used in the equation entry is almost the same as in the problem definition (except that no
Greek characters can be used). POLYMATH issues warnings for undefined variables so that
errors such as using the letter o in the variable name (like in eoD) in one equation and the
number 0 in another equation can be easily detected. The needed equations can be entered in the
same order as they appear in the problem definition even if the calculation order must be
different since POLYMATH reorders the equations when the calculations are made. For
example, the necessary calculation for the friction factor, fF, first involves ε/D and then Reynolds
number, Re. However POLYMATH allows direct entry of the equations in the same order as
they are defined in the problem statement.

Common mistakes in entering the model equations typically involve inconsistency in the units
used (i.e. inches instead of feet), wrong sign of the pressure or elevation difference, and
inappropriate use of parenthesis in Equations (A-1) and (A-4). POLYMATH enables much
easier detection of errors in the model equations because the model debugging stage is clearly
separated from the numerical solution stage.

Figure 1 - POLYMATH Equation Entry for Example 1

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
After the correct solution as given in the problem statement is obtained, the model equation set
can be converted to an Excel worksheet using a single command within POLYMATH. Part of
the Excel worksheet generated is shown in Figure 2 where the variable cell calculations are
indicated.

Figure 2 - POLYMATH Equations Converted to Excel Formulas for Example 1

The variable names are translated to cell addresses, intrinsic function names are changed as
necessary, and the syntax of the if statement is changed. The equations are rearranged in a form
that appropriate for solving the equation using the goal seek or solver tools available within
Excel. The complete worksheet with the solution obtained using goal seek is shown in Figure 3.

Figure 3 - Excel Worksheet with Numerical Results and Documentation for Example 1
The numerical results are identical to those obtained by POLYMATH, and thus the correctness
of the Excel solution has been verified. The variable names in column C, the POLYMATH
equations in column E, and the variable descriptions in column F provide complete
documentation for the Excel formulas in column C.

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
The successive substitution method can be implemented by revising the equations that are
functions of the unknown flow velocity v and adding Equation (A-6) for estimating the error in
the current value of vi as shown below.

Arranging the variables in consecutive columns, copying and pasting them in consecutive rows
and substituting vi+1 in the cell that contains vi starting iteration No. 1 yields the desired solution
as obtained by the successive substitution method (see Table 1).

Table 1 - Successive Substitution Iterations for Example 1

Iteration. No. i vi Re fF vi+1 εi = |vi+1-vi| q

1 10 545193.3 0.003892 11.58185 1.581854 1559.383

2 11.58185 631434.9 0.003849 11.64971 0.067853 1806.055

3 11.64971 635134.2 0.003847 11.65229 0.002578 1816.636

4 11.65229 635274.8 0.003847 11.65238 9.75E-05 1817.038

5 11.65238 635280.1 0.003847 11.65239 3.69E-06 1817.053

After the correct solution has been obtained for one set of pipe length and diameter values the
"Two Input Table" option of Excel can be conveniently used for carrying out all the calculations
that required in part (b) of the problem statement in Appendix A. The plot of flow velocity for all
combinations of pipe length and diameter is shown in Figure 4.

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
18.000
16.000
14.000
12.000
Velocity (ft/s)

D=4"
10.000 D=5"
8.000 D=6"
6.000 D=8"

4.000
2.000
0.000
0 2000 4000 6000 8000 10000
Pipe lenght (ft)

Figure 4 - Flow Velocity versus Pipe Length and Diameter for Example 1

Example 2 - Flow Distribution in a Pipeline Network Solved by Broyden’s Method

This example is based on Problem 5.11 presented by Cutlip and Shacham1. The detailed problem
statement is shown in Appendix B. The problem involves calculation of flow rates and pressure
drops in a pipeline network that includes seven interconnected pipe segments. The problem can
be brought into a form of seven algebraic equations (where three of them are nonlinear) with
seven unknown pipe-segment flow rates. The use of Broyden's Quasi-Newton method for this
type of problems is attractive because it has super-linear convergence and it does not require
calculations of the matrix of partial derivatives. The various matrix-matrix and matrix-vector
multiplications required by this method can be easily carried out when MATLAB is used for
implementation. Students may find this method difficult to program if another programming
package is used that does not support algebraic expressions that contain matrices and matrix
operations.

In this example it is very important to verify that the mathematical model is correct and has a
solution before attaching to it the numerical solution technique, because the Broyden’s' method
may not converge to the solution even if the problem does have a solution. Some potential causes
for no convergence will be demonstrated in this example.

The model equations, as entered into the POLYMATH nonlinear algebraic equation solver
program are shown in p. 188 of Cutlip and Shacham1. The problem can be solved with
POLYMATH when using the initial estimates shown in the problem statement without any
difficulties. The POLYMATH equations can be easily converted to a MATLAB function. We
have used an automatic conversion routine to do that but the conversion can be done easily by
hand also. The MATLAB function that was obtained by the conversion routine and edited in
order to bring it to a more compact form is shown in Figure 5.

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
Figure 5 - MATLAB Function Representing the Pipeline Network of Example 2

The main program for solving the pipeline network problems using Broyden's method is shown
in Figure 6. Note that only the computational commands are shown, the input output commands
were removed for brevity.

Figure 6 - MATLAB Main Program for Solving Example 2 Using Broyden's Method

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
Note that Broyden's method, as implemented in Figure 6 diverges from the initial estimates
specified in Appendix B. One reason for that is the order of magnitude differences between the
functions associated with Equation (B-3) and those associated with Equation (B-4). The
Equations (B-3) are comprised of terms of the order of 0.1 while the Equations (B-4) are
comprise of terms of the order of 106.

The equations can be rescaled by dividing the Equations (B-3) by the largest kij associated with
the particular equation. This rescaling was already carried out in the function shown in Figure 5.
However, Broyden’s method diverges even after rescaling the equations. To validate the solution
technique an initial estimate, closer to the solution is selected, based on the solution obtained by
POLYMATH. From this initial estimate Broyden's method converges to the correct solution
shown in Table 2. But even when starting from an initial estimate close to the solution the
convergence of Broyden's method is non-monotonic as can be seen in Figure 7. This Figure
shows the logarithm of the error norm (defined in Appendix B) as function of the iteration
number. The error norm gets reduced for several iterations and increases once again until,
finally, gets close enough to the solution to achieve monotonic convergence. Sophisticated
nonlinear equation solver packages use a one-dimensional search in order to prevent the increase
of the error norm and this is a good example to demonstrate the need for such modification of the
solution algorithm.

Table 2 - Initial Estimates and Solutions for Pipeline Network Flow-rates

Initial
Estimate Solution

q01 (m3/s) 0.1 0.098134

q12 (m3/s) 0.07 0.06482

q13 (m3/s) 0.04 0.033314

q24 (m3/s) 0.05 0.049372

q23 (m3/s) 0.02 0.015449

q34 (m3/s) 0.05 0.048763

q45(m3/s) 0.1 0.098135

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
0
0 5 10 15 20 25
-1

-2
εk
logarithm of

-3

-4

-5

-6

-7
Iteration Number (k)

Figure 7 - Convergence Pattern of the Broyden's Method for Example 2

Conclusions

We have demonstrated, using two practical examples from the fluid mechanics field several
benefits of the use of a number of software packages in engineering problem solving. When
teaching numerical methods the preparation, coding and debugging of the mathematical model
can be separated from the coding and debugging of the solution algorithm by using a software
package that takes care of the technical details of the numerical solution. This enables solving
complex, realistic problems increasing the students' motivation to learn CPBS techniques.

Once a correct, verified solution has been obtained for a particular model a different software
package, more appropriate for coding the numerical solution algorithm can be used. The
existence of a solution for the problem can alleviate considerably the solution algorithm and can
help to identify weak points of the basic algorithm such as the need to rescale the functions and
variables, start the iterations from points close to the solution or carry out one dimensional search
for minimum.

Example 1, in slightly modified form was presented as a final exam question to the students of a
"Process Modeling and Numerical Methods" course in the Chemical Engineering Department of
the Ben-Gurion University. Using two software packages (POLYMATH and MATLAB) for
solution most of the students managed to solve correctly the problem in two hours. This clearly
demonstrates the benefits of the use of several software packages simultaneously to enable
solving realistic problems by computer in reasonable timeframes.

Bibliography

(1) Cutlip, M. B. and Shacham, M., Problem Solving In Chemical Engineering with Numerical
Methods, Prentice-Hall, Upper Saddle River, New-Jersey, 1999.
Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
(2) Jones J. B., "The Non-Use of Computers in Undergraduate Engineering Science Courses",
Journal of Engineering Education, Vol. 88, 1998, pp. 11-14.

(3) Kantor, J. C. and T. Edgar, "Computing Skills in the Chemical Engineering Curriculum", pp.
9-20 in Carnahan, B. (Ed), Computers in Chemical Engineering Education, CACHE, Austin,
Texas, 1996.

(4) Shacham, M. and M.B. Cutlip, “A Comparison of Six Numerical Software Packages for
Educational Use in the Chemical Engineering Curriculum”, Computers in Education Journal,
Vol. IX, No. 3, 1999, pp. 9-15

Appendix A

Problem Statement for Example 1

Calculation of the Flow Rate in a Pipeline

The Figure below shows a pipeline which delivers water at constant temperature T = 60 °F from
point 1 where the pressure is p1 = 150 psig and the elevation is z1 = 0 ft to point 2 where the
pressure is atmospheric and the elevation is z2 = 300 ft.

(a) Calculate the flow rate q (in gal/min) for a pipeline with effective length of L = 1000 ft
and made of nominal 8-inch diameter schedule 40 commercial steel pipe. (Solution: v =
11.65 ft/s, q = 1817 gpm)
(b) Calculate the flow velocity and flow rate for pipelines with effective length of L = 500,
1000, … 10000 ft and made of nominal 4,5,6 and 8-inch schedule 40 commercial steel
pipe. Use the successive substitution method for solving the equations for the various
cases and present the results in tabular form. Prepare plots of flow velocity versus D and
L and flow rate versus D and L.
Equations and numerical data

The general mechanical energy balance on an incompressible liquid that applicable to this case is
the following

1 2 g c ∆P f F Lv 2
− v + g∆z + +2 =0 (A-1)
2 ρ D

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
where v is the flow velocity in ft/s, g is the acceleration of gravity given by g = 32.174 ft/s2, ∆z =
z2-z1 is the difference in elevation (ft), gc is a conversion factor (in English units gc =32.174
ft·lbm/lbf·s2), ∆P = P2-P1 is the difference in pressure lbm/ft2), ρ is the fluid density (for water at
T = 60 °F, ρ = 62.3 lbm/ft3 ), fF is the Fanning friction factor, L is the length of the pipe (ft) and D
is the inside diameter of the pipe (ft). To use the Successive Substitution method equation (A-1)
should be rewritten:

g c ∆P
g∆z +
ρ
v= (A-2)
f L
0 .5 − 2 F
D

The equation used for calculating the Fanning friction factor depends on the flow regime. The
flow regime is characterized by the Reynold's number Re. The Reynold's number is a
dimensionless number Re= vρD/µ where µ is the viscosity (for water at T = 60 °F, µ = 0.76×10-3
lbm/ft·s). For laminar flow (Re < 2100) the Fanning friction factor can be calculated from the
equation
16
fF = (A-3)
Re

For turbulent flow (Re > 2100) the ShachamD equation can be used.
1
fF = 2
(A-4)
  ε / D 5.02  ε / D 14.5  
16log  − log +  
  3 .7 Re  3 .7 Re  

where ε/D is the surface roughness of the pipe (ε = 0.00015 ft for commercial steel pipes).
The flow velocity in the pipeline can be converted to flow rate by multiplying it by the cross
section of the pipe, thus q = vπD2/4 (ft3/s). The inside diameter (D) of commercial steel pipes can
be found, for example, in Table D-5 of the book by Cutlip and Shacham (1999). The iteration
function of the successive substitution method for calculation of the flow velocity is
vi +1 = F (vi ) i = 0, 1,K (A-5)
where i is the iteration number, F is the function in the right side of Equation (A-2) and v0 is an
initial estimate for the flow velocity (use v0 = 10 ft/s ). Equation (A-6) provides an error estimate
at iteration i:
εˆi =| vi − vi +1 | (A-6)

The iterations can be stopped when εˆi < 10 −5 .

D
Shacham, M. Ind. Eng. Chem. Fund., 19, 228-229(1980)

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
Appendix B

Problem Statement for Example 2

Flow Distribution in a Pipeline Network

Water at 25 °C is flowing in the pipeline network given in Figure B-1. The pressure at the exit of
the pump is 15 bar (15 ×105 Pa) above atmospheric, and the water is discharged at atmospheric
pressure at the end of the pipeline. All the pipes are 6-inch schedule 40 steel with an inside
diameter of 0.154 m. The equivalent lengths of the pipes connecting different nodes are the
following: L01 = 100 m, L12 = L23 = L45 = 300 m, and L13 = L24 = L34 = 1200 m.

a) Use POLYMATH to calculate all the flow rates and pressures at nodes 1, 2, 3, and 4
for the pipeline network shown in the Figure. The Fanning friction factor can be
assumed to be constant at fF = 0.005 for all pipelines. The initial estimates for all the
volumetric flow rates can be set at 0.1 m3/s.
b) Use Broyden's Quasi-Newton method (programmed with MATLAB) to solve the
system of equations obtained in part (a).
Equations and data

For the solution of this problem it is convenient to express the pressure drop from node i to node
j as
∆Pij = k ij (qij ) 2 (B-1)

where ∆Pij is the pressure drop and qij is the volumetric flow rate between nodes i and j. The kij
terms in Equation (B-1) are related to the Fanning friction factors and average fluid velocities.
32 f F ρLij
k ij = (B-2)
π 2 D5

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education
There are two relationships that govern the steady-state flow rate in pipeline networks. First, the
algebraic sum of the flow rates at each node must be zero. Second, the algebraic sum of all
pressure drops in a closed loop must be zero.
The flow rate summation equations for nodes 1, 2, 3 and 4 are the following:
q 01 − q12 − q13 = 0
q12 − q 24 − q 23 = 0
(B-3)
q 23 + q13 − q34 = 0
q 24 + q34 − q 45 = 0

The pressure drop summation equations on Loops I, II and III (see Figure B-1) are respectively
∆P01 + ∆P12 + ∆P24 + ∆P45 + ∆PPUMP = 0
∆P13 − ∆P23 − ∆P12 = 0 (B-4)
∆P23 + ∆P34 − ∆P24 = 0

The pressure drops can be expressed as functions of qij using Equation (B-1). This substitution
leads to seven equations with seven unknown flow rates.
The iteration function of Broyden's quasi-Newton methodE for solving systems of nonlinear
algebraic equations is
x k +1 = x k − H k f (x k ) k = 0, 1,K (B-5)

where x is an n vector of variables, f is an n vectors of functions and Hk is the kth estimate for the
inversed Jacobian matrix (matrix of partial derivatives). The identity matrix I is often used as
initial estimate for the inversed Jacobian matrix H0. This matrix is updated in iteration k using
the equation
(H k y k − p k )p Tk .H k
.H k +1 = H k − (B-6)
p Tk H k y k

where p k = x k +1 − x k and y k = f (x k +1 ) − f (x k ) .

The Euclidean norm of pk can be used as error estimate. Thus ε~k =|| p k || . The iterations can be
stopped when εˆk < 10 −5 .

E
Broyden, C. G. Mathematics of Computation, 19, 577-593(1965)

Proceedings of the 2004 American Society for Engineering Education Annual Conference &Exposition
Copyright ©2004, American Society for Engineering Education

You might also like