Chemical and Biomedical Engineering Calculations Using Python - Jeffrey J. Heys - E-Book

Chemical and Biomedical Engineering Calculations Using Python E-Book

Jeffrey J. Heys

0,0
69,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Presents standard numerical approaches for solving common mathematical problems in engineering using Python.

  • Covers the most common numerical calculations used by engineering students
  • Covers Numerical Differentiation and Integration, Initial Value Problems, Boundary Value Problems, and Partial Differential Equations
  • Focuses on open ended, real world problems that require students to write a short report/memo as part of the solution process
  • Includes an electronic download of the Python codes presented in the book

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 397

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Cover

Title Page

Copyright

Preface

About the Companion Website

Chapter 1: Problem Solving in Engineering

1.1 Equation Identification and Categorization

Problems

Additional Resources

References

Chapter 2: Programming with Python®

2.1 Why Python?

2.2 Getting Python

2.3 Python Variables and Operators

2.4 External Libraries

Problems

Additional Resources

References

Chapter 3: Programming Basics

3.1 Comparators and Conditionals

3.2 Iterators and Loops

3.3 Functions

3.4 Debugging or Fixing Errors

3.5 Top 10+ Python Error Messages

Problems

Additional Resources

References

Chapter 4: External Libraries for Engineering

4.1 Numpy Library

4.2 Matplotlib Library

4.3 Application: Gillespie Algorithm

Problems

Additional Resources

References

Chapter 5: Symbolic Mathematics

5.1 Introduction

5.2 Symbolic Mathematics Packages

5.3 An Introduction to SymPy

5.4 Factoring and Expanding Functions

5.5 Derivatives and Integrals

5.6 Cryptography

Problems

References

Chapter 6: Linear Systems

6.1 Example Problem

6.2 A Direct Solution Method

6.3 Iterative Solution Methods

Problems

References

Chapter 7: Regression

7.1 Motivation

7.2 Fitting Vapor Pressure Data

7.3 Linear Regression

7.4 Nonlinear Regression

7.5 Multivariable Regression

Problems

References

Chapter 8: Nonlinear Equations

8.1 Introduction

8.2 Bisection Method

8.3 Newton's Method

8.4 Broyden's Method

8.5 Multiple Nonlinear Equations

Problems

Chapter 9: Statistics

9.1 Introduction

9.2 Reading Data from a File

9.3 Statistical Analysis

9.4 Advanced Linear Regression

9.5 U.S. Electrical Rates Example

Problems

References

Chapter 10: Numerical Differentiation and Integration

10.1 Introduction

10.2 Numerical Differentiation

10.3 Numerical Integration

Problems

Reference

Chapter 11: Initial Value Problems

11.1 Introduction

11.2 Biochemical Reactors

11.3 Forward Euler

11.4 Modified Euler Method

11.5 Systems of Equations

11.6 Stiff Differential Equations

Problems

References

Chapter 12: Boundary Value Problems

12.1 Introduction

12.2 Shooting Method

12.3 Finite Difference Method

Problems

Reference

Chapter 13: Partial Differential Equations

13.1 Finite Difference Method for Steady-State PDEs

13.2 Convection

13.3 Finite Difference Method for Transient PDEs

Problems

Reference

Chapter 14: Finite Element Method

14.1 A Warning

14.2 Why FEM?

14.3 Laplace's Equation

14.4 Pattern Formation

Additional Resources

References

Index

End User License Agreement

Pages

xi

xii

xiii

xv

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

Guide

Cover

Table of Contents

Preface

Begin Reading

List of Illustrations

Chapter 1: Problem Solving in Engineering

Figure 1.1 Engineering problem-solving process.

Figure 1.2 An example of interpolation for a set of data. The data is usually represented using points (circles) and the interpolant function is usually represented using a line.

Figure 1.3 An example of linear (a) regression and nonlinear (b) regression for a set of data.

Chapter 2: Programming with Python®

Figure 2.1 The process of going from source code (i.e., a set of instructions) into a running computer program is different for compiled programming languages (a) versus interpreted programming languages (b).

Figure 2.2 A screenshot of the Spyder IDE for Python programming including source code window on the left size, documentation window on the upper right side and Python console for rapid testing and executing the source code in the lower right side.

Figure 2.3 A screenshot of the Jupyter notebook on SageMathCloud. Two different cells are populated with Python code, and the cells are executed using “Shift-Enter”. The results of code execution are shown below each cell.

Figure 2.4 A screenshot of the Spyder IDE showing the two different methods for entering the example Python code: at the console in the lower right corner or into a script (i.e., text file) in the left half. The script on the left is run using the green, triangular “play” button along the upper part of the window.

Chapter 3: Programming Basics

Figure 3.1 A visual representation of the construction of the triangle function that acts as a machine that takes in two inputs, base and height, and returns the area of a triangle after performing the appropriate mathematical operations on the inputs.

Figure 3.2 A decision tree for assessing prepayment risk on a mortgage [3].

Chapter 4: External Libraries for Engineering

Figure 4.1 A Figure of the polynomial . Polynomial evaluation used the numpy polynomial package, and the plot was generated using matplotlib.

Figure 4.2 A Figure of a -wave generated using pylab with (a) a solid line (and (b) circles.

Figure 4.3 A plot showing a linear, quadratic, and cubic polynomial all on the same plot with a legend identifying each curve.

Figure 4.4 A contour plot of a function, for and .

Figure 4.5 Number of molecules of

A

and

B

for a first-order equilibrium reaction simulation using the Gillespie algorithm. Forward rate is and the reverse rate is (both per time).

Chapter 5: Symbolic Mathematics

Figure 5.1 -diagram of the two equations that were simultaneously solved in the multiple equations example.

Chapter 6: Linear Systems

Figure 6.1 Diagram of a distillation column for the coarse separation of methane (

M

), ethane (

E

), and propane (

P

). The composition of the product streams is given, but the mass flow rate of each stream is unknown.

Figure 6.2 Diagram of a simple network of three blood vessels: the flow is into vessel 1 (left) at pressure , and at the end of vessel 1, there is a bifurcation or branch and the flow is divided between vessels 2 (upper right) and 3 (lower right). The pressures, , at the ends of each vessel as well as the flow rate, , in each vessel are potential unknowns that need to be determined.

Figure 6.3 The CPU time required to solve a dense system of linear equations using

numpy.linalg.solve()

. If is the number of equations, the CPU time scales with .

Figure 6.4 A system of weights and linear springs that model a new chair lift design for ski resorts.

Figure 6.5 A three-stage, counter current cascade where all the lower streams have a flow rate of and all upper streams have a flow rate of . The feed stream with the compound of interest is fed into the first (left) stage at a concentration of .

Chapter 7: Regression

Figure 7.1 Example of two different data sets that might require regression to fit the data with either a line (a) or some other nonlinear function (b).

Figure 7.2 When the natural log of vapor pressure, , is plotted against the inverse temperature, , then the points fall on a straight line and linear regression can be used to fit the data.

Figure 7.3 (a) Sample data used in regression analysis and (b) the same data with the calculated regression line.

Figure 7.4 (a) Sample data used in nonlinear regression analysis and (b) the same data with the nonlinear regression line from

curve_fit()

. .

Figure 7.5 Fragmentation versus day after the event data is shown as descrete points, and the optimal exponential curve fitting the data is shown as a solid line.

Figure 7.6 Fragmentation versus day after the event data is shown as descrete points, and the optimal exponential curve fitting the data is extrapolated out to 700 days and shown as a solid line.

Figure 7.7 A bar chart showing pairs of bars for each experimental condition (temperature and pressure). The darker bar on the left is the yield from the original data, and the lighter bar on the right is the least-squares regression fit at the same conditions.

Chapter 8: Nonlinear Equations

Figure 8.1 The bisection method is used to find the roots or zeros of a nonlinear function. The first step is to identify points and such that (i.e., and have different signs). The distance between and is halved and then or is discarded depending on the sign of . This process is repeated until the location of the root within some tolerance is found.

Figure 8.2 Newton's method approximates a nonlinear function with a straight line at the point . The linear approximation is then used to obtain a new estimate for the root (i.e., the intersection of the nonlinear function with the -axis) of the nonlinear function.

Figure 8.3 The nonlinear function with roots at and .

Figure 8.4 The nonlinear SRK function with a single root at .

Figure 8.5 A plot of the zero contour lines (i.e., the lines where and equal zero) for the example functions. The thicker contour line is . The two points where both functions are zero are solutions to this nonlinear system, and two different solution vectors are seen to exist in this plot.

Figure 8.6 Sketch of a square containing a point that is 3, 4, and 6 ft from successive corners.

Figure 8.7 Trajectory of the football in the plane.

Chapter 9: Statistics

Figure 9.1 A screen capture showing the first few lines of the file “DOdata.csv”. The file contains a header row followed by the data.

Figure 9.2 A histogram of 33 temperature measurements. The data does not appear to be normally distributed.

Figure 9.3 Dissolved oxygen (mg/L) measurements as a function of time for an isolated sample. The order of the depletion rate is not clear.

Figure 9.4 Dissolved oxygen (mg/L) measurements as a function of time and the best fit curve based on a first-order depletion model.

Figure 9.5 Dissolved oxygen (mg/L) measurements as a function of time and the best fit curve based on a second-order depletion model.

Figure 9.6 Scatter plot showing the residential electric rate ($/kWh) for every U.S. zip code.

Figure 9.7 Scatter plot showing the commercial electric rate ($/kWh) versus the residential electric rate ($/kWh) for every Texas zip code.

Figure 9.8 Histogram showing the frequency of zip codes with various residential electric rates ($/kWh).

Figure 9.9 Rough sketch of desired BAC figure.

Chapter 10: Numerical Differentiation and Integration

Figure 10.1 Three different finite difference approximations for the derivative at : (a) backward difference, (b) forward difference, and (c) centered difference.

Figure 10.2 The fundamental idea behind the numerical approximation of a definite integral (from to ) is to estimate the area under the curve using simple subdomains with areas that are easy to calculate. The composite midpoint rule is illustrated here.

Figure 10.3 The area under a function (i.e., the definite integral of a function) can be estimated by subdividing the area into a sequence of trapezoids.

Figure 10.4 Illustration of Simpson's rule for integration of from to .

Chapter 11: Initial Value Problems

Figure 11.1 Substrate consumption (solid curve) and product formation (dashed curve) for a process governed by Michaelis–Menten kinetics.

Figure 11.2 An approximate solution to an initial value problem can be obtained by calculating a slope from the ODE equation based on the current values for and , and then taking a small step in time to a new set of values. This problem is repeated until the desired final time is reached.

Figure 11.3 Substrate concentration governed by a Michaelis–Menten reaction is modeled using the forward Euler method with two different time step sizes: 100 time steps (solid) and 4 times steps (dashed).

Figure 11.4 Two different solutions to the Lorenz system of equations using slightly different initial conditions. The three axes represent the three solutions variables, , , and , and time is not shown other than the variables oscillate in a cycle long term.

Figure 11.5 Two different solutions to the Lorenz system of equations using slightly different initial conditions. The final solutions are very different even though the initial conditions are similar.

Figure 11.6 The approximate solution resulting from using the forward Euler method on the initial value problem with and . The approximation error is large and growing exponentially.

Figure 11.7 The exact solution and the solution resulting from using

scipy.integrate.odeint()

on the initial value problem with and . The two curves overlap one another.

Chapter 12: Boundary Value Problems

Figure 12.1 Approximate solution to the BPV, using a guess of .

Figure 12.2 Approximate solution to the BPV, using a guess of .

Figure 12.3 Approximate solution to the BPV, using a guess of .

Figure 12.4 Using the finite difference method requires dividing the domain, into a set of discrete points or nodes with their locations given by . The goal of the approach is to determine the approximate solution, , at every node.

Figure 12.5 Approximate solution to the BPV, using the finite difference method with 10 nodes. The exact solution is also plotted (dashed line) and is almost indistinguishable from the approximate solution.

Figure 12.6 Concentration inside a spherical catalyst where a first-order reaction is occurring. The center of the particle is , and the surface is at . The concentration at the surface is . (a) and (b) , which represents a much faster reaction rate.

Figure 12.7 A thick cylindrical tube for transporting blood from an individual into a collection bag. The inner wall (1.0 cm from the center) of the tube is at 38 °C and the outer wall (1.3–1.8 cm from the center) is at 23 °C.

Chapter 13: Partial Differential Equations

Figure 13.1 If the finite difference method is used for a two-dimensional boundary value problem, each node is connected to its four nearest neighbors.

Figure 13.2 Contours of the solution for the model problem.

Figure 13.3 Contours of the solution for the model problem with a convective flow of , that is, toward the northeast corner.

Figure 13.4 Diagram illustrating the finite difference approximation for a transient PDE with one spatial dimension. Time is shown on the

y

-axis and space is on the

x

-axis. When solving for the concentration at a node for the next time step, the concentration will depend on three adjacent nodes from the previous time step.

Figure 13.5 Plot of the concentration for the model problem shown every 20th time step. The initial concentration is the highest, and as time increases, the concentration decreases.

Figure 13.6 Plot of the concentration for the model problem using only 40 time steps. The error grows exponentially, and the final solution is completely without value.

Chapter 14: Finite Element Method

Figure 14.1 Triangular mesh from the

UnitSquareMesh()

function.

Figure 14.2 FEM solution to the model problem (Laplaces equation) using a second-order Lagrange function space. The solution was visualized using Visit.

Figure 14.3 Pattern formation based on the reaction-diffusion system of Turing begins with a random concentration of activator (shown in upper left) and inhibitor (opposite of activator). Regions of greater initial activator concentration start to grow due to a positive feedback loop (upper right). The faster moving inhibitor suppresses the activator between the initial peaks (lower right) and ultimately leads to a stable pattern of peaks and valleys.

Figure 14.4 Activator concentration resulting from a Turing pattern simulation.

List of Tables

Chapter 6: Linear Systems

Table 6.1 Properties of the femoral artery and upper and lower branches

Chapter 7: Regression

Table 7.1 Estimates of the number of fragments of the former moon as a function of the number of days since the initial events

Chapter 10: Numerical Differentiation and Integration

Table 10.1 Accuracy of different numerical approximations of the first derivative of

Table 10.2 Accuracy of the midpoint and trapezoid rule for integrating with different numbers, of subintervals

Chemical and Biomedical Engineering Calculations Using Python®

 

Jeffrey J. Heys

Montana State UniversityBozeman, Montana, USA

 

 

 

 

This edition first published 2017

© 2017 John Wiley & Sons, Inc

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by law. Advice on how to obtain permission to reuse material from this title is available at http://www.wiley.com/go/permissions.

The right of Jeffrey J. Heys to be identified as the author of this work has been asserted in accordance with law.

Registered Office

John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, USA

Editorial Office

111 River Street, Hoboken, NJ 07030, USA

For details of our global editorial offices, customer services, and more information about Wiley products visit us at www.wiley.com.

Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Some content that appears in standard print versions of this book may not be available in other formats.

Limit of Liability/Disclaimer of Warranty

The publisher and the authors make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation any implied warranties of fitness for a particular purpose. This work is sold with the understanding that the publisher is not engaged in rendering professional services. The advice and strategies contained herein may not be suitable for every situation. In view of ongoing research, equipment modifications, changes in governmental regulations, and the constant flow of information relating to the use of experimental reagents, equipment, and devices, the reader is urged to review and evaluate the information provided in the package insert or instructions for each chemical, piece of equipment, reagent, or device for, among other things, any changes in the instructions or indication of usage and for added warnings and precautions. The fact that an organization or website is referred to in this work as a citation and/or potential source of further information does not mean that the author or the publisher endorses the information the organization or website may provide or recommendations it may make. Further, readers should be aware that websites listed in this work may have changed or disappeared between when this works was written and when it is read. No warranty may be created or extended by any promotional statements for this work. Neither the publisher nor the author shall be liable for any damages arising herefrom.

Library of Congress Cataloging-in-Publication Data

Names: Heys, Jeffrey J., 1974- author.

Title: Chemical and Biomedical Engineering Calculations Using Python® / Jeffrey J. Heys.

Description: Hoboken, NJ : John Wiley & Sons, 2017. | Includes bibliographical references and index.

Identifiers: LCCN 2016039763| ISBN 9781119267065 (cloth) | ISBN 9781119267072 (epub)

Subjects: LCSH: Engineering mathematics. | Python (Computer program language)

Classification: LCC TA330 .H49 2017 | DDC 620.00285/5133–dc23 LC record available at https://lccn.loc.gov/2016039763

Cover design by Wiley

Cover image: © lvcandy/Getty Images, Inc.

Preface

Computers have become a powerful tool in the field of engineering. Before the widespread availability of computers, mathematical models of engineering problems needed to be simplified to the point that the calculations could be reliably performed by a single individual using a calculator or slide rule, and, fortunately, for many engineering problems, simplified models were adequate. However, as process complexity and engineering design complexity increased, engineers increasingly turned to computers for help in managing and automating the large number of calculations required.

The computational tools used by engineers have evolved considerably over the past few decades. In the 1960s and 1970s, computers were not widely available, and they were a specialized tool that was operated by highly trained individuals. In the 1980s and 1990s, computers became widely available, but the engineering software and computational tools were relatively simple compared to what is available in the twenty-first century. The individual that was using the computer general understood the calculations that were being performed, and the computer was primarily a tool for automating those calculations. Many engineering students during this time learned to program in either FORTRAN or C, and the programs written by engineers were frequently limited to a few hundred lines of code. More specialized and easier to use programming environments like MATLAB and IDL were also developed during the 1980s, and they usually helped to decrease the time required to write a computer algorithm, but they increased the time required to execute or run the algorithm.

The trend toward greater specialization and ease of use in computational tools continued in the twenty-first century. The various fields of engineering saw an exponential increase in powerful and easy-to-use tools like AutoCAD, SolidWorks, ANSYS, and Aspen. (Clearly, it is a good idea to choose a name for your software that begins with “A” so it appears first alphabetically.) The individual that uses these software packages may have some understanding of the calculations that are being performed, but they almost never fully understand the calculations and in some cases have no understanding of the mathematics that is being performed by the computer. Today, engineering students are typically taught to use multiple computational software packages during the typical undergraduate education. The irony of this situation is that students often do not understand the calculation being performed by the software – they do not know the limitations of the mathematical models, they do not know the expected accuracy of the approximate solution, and they do not always have the intuition necessary to recognize a highly incorrect result. Another loss associated with the rise of specialized software tools for engineers is that it is often very difficult to find a computational tool for a new problem. The software often works well for the limited range of problems for which it was designed, but, if an engineer wishes to analyze something new or include some change that takes the problem just beyond the range of problems for which the software was design, that engineer is often “out of luck” because no computational tool is available to help.

I do not advocate abandoning modern engineering software. I do not advocate returning to the use of custom FORTRAN computer codes for every problem. I do advocate that engineering students get some experience writing short computer programs. This experience teaches one to think precisely as computers are notoriously unforgiving when we make mistakes in our logic. It teaches one to decompose a complex process down into small, individual steps. This experience teaches one to develop a unique solution for a new problem that is not handled well by existing software. Finally, the experience of creating a computer algorithm helps to develop a recognition of when computations are likely to be reliable and when they are not – when the computational solution is sufficiently accurate and when it is not.

The goal of this book is to provide the reader with an understanding of standard computational methods for approximating the solution to common problems in Chemical and Biomedical Engineering. The book does not have a comprehensive coverage of computational methods, but it is instead intended to provide the introductory coverage necessary to understand the most commonly used algorithms. The computer language used to explore the different computational methods is Python. The advantages of using Python include its wide and growing popularity, large library of existing algorithms, and its licensing as free, open source software. The final and possibly greatest advantage in using Python is that it is easy to learn to write general computational algorithms and more specialized numerical algorithms are also easy to write, thanks to the NumPy and SciPy libraries. By the end of this book, the reader should have a solid understanding of how to write and use computational algorithms in Python to solve common mathematical problems in Chemical and Biomedical Engineering.

The course that motivated the creation of this textbook is one semester of approximately 15 weeks. It is my belief that most of this material can be covered in that length of time. Each chapter in the textbook covers a different topic and the book was constructed so that the material in that chapter could be covered in approximately 1 week. There are, of course, some exceptions. The large number of topics and short amount of time associated with a single semester may encourage instructors using this book to consider a slightly different format than the traditional lecture format. For example, if two class times per week are available, an instructor may want to consider requiring students to read the book or watch an online lecture that presents the material to be covered before coming to the first class meeting time each week. The two class periods could then be used to cover example problems (the first class each week) and a “working class” could be used for the second class meeting of the week. When students are trying to complete the homework, they often need support to overcome a difficult error message or unexpected and unphysical numerical answer from the computer, and allowing students to work on problems for one class time per week is often very beneficial.

Suggested homework problems are included at the end of each chapter. Many of the homework problems are written so that the person answering the problem must respond to a request from a real or hypothetical organization such as a company or government agency. The author of this book typically assigns one or two problems per week and requires students to submit their solutions in the form of a memo to the organization that posed the problem. The memo typically is about 1 page of text plus 1–3 figures for a total of 2 or 3 pages for the main body of the memo, and the Python code is included by the student in an appendix with the memo. Requiring students to practice technical writing is a benefit of using this approach, and many students are motivated when the problems have more of a “real world” flavor and are less abstract.

In closing, I would like to offer my sincerest thanks and gratitude to the many unnamed individuals that have contributed to building Python and making scientific computing using Python such a wonderful reality. To me, it is really humbling and encouraging to see the great work that these individuals have freely given to the world. I would like to single out two individuals by name because of the transformative impact of their work – without their work, I would never have started using Python as extensively as I do, and this book would never have been written. The first individual is Travis Oliphant, the primary creator of NumPy and the founder of Continuum Analytics, which produces the Anaconda Python Distribution. The second individual is Fernando Perez, a physicist, creator of iPython, and, most importantly to me, the person that came into my office at the University of Colorado at Boulder and told me that I should try learning Python because it made programming fun!

Bozeman, MontanaJeffrey J. Heys July 15, 2016

About the Companion Website

This book is accompanied by a companion website:

www.wiley.com/go/heys/engineeringcalculations_python

The website includes:

Python Computer Codes.

Chapter 1Problem Solving in Engineering

In chemical and biological engineering, students find that the sequence of steps outlined in Figure 1.1 is an effective problem-solving approach for the vast majority of the problems they encounter.

Figure 1.1 Engineering problem-solving process.

In most courses, students practice all the steps outlined in Figure 1.1, but the focus is usually on the construction of the system diagram and developing the mathematical equations for every unique type of process that is described in a particular course. Only limited attention is usually given to solving the mathematical equations that arise in a particular course because the assumption is that the student should have learned how to do that in their mathematics courses or some other course. Many engineering curricula have a course that is focused on the use of computers to solve the many different types of equations that arise in a student's engineering courses. The focus of this textbook is just “using computers to solve the equation(s) that students typically encounter throughout the engineering curriculum.”

The timing of a course on computational or numerical methods for solving engineering problems varies considerably from one curriculum to the next. One approach is to schedule the course near the end of the curriculum. As an upper level course, students are able to review most of the engineering principles and mathematics that they learned previously and develop a new set of tools (specifically, computational tools) for solving those same problems. Two disadvantages are associated with this approach. First, students do not have the computational tools when they first learn a new engineering principle, which limits the scope of problems they can solve to problems that can be largely solved without a computer (i.e., problems that can be solved with paper and pencil). The second disadvantage is that the third and fourth years of many engineering curricula are already filled with other required courses and it is difficult to find time for yet another course.

A second approach is to schedule the computational methods course early in the curriculum, before students have taken most of the engineering courses in which they learn to derive, construct, and identify the mathematical equations they need to solve and that sometime require a computational approach. There are also two problems with this approach. First, the students have typically not taken all the required mathematics courses, and, as a result, it is difficult to teach a computational approach to solving a differential equation when a student is not yet familiar with differential equations or techniques for solving them. The second disadvantage is that the student has not taken courses on separations, kinetics, transport, and so on in which they learn to derive or identify the appropriate mathematical equation(s) for their particular problem. It is, of course, difficult to teach a computational approach to solving an equation when the importance or relevance of that equation is not known.

A third approach for addressing this dilemma is to simply not teach a stand-alone computational methods course and instead cover the relevant computational approaches as they are needed in each individual course. We will continue our listing of the “top two challenges” and identify two potential difficulties with this approach. First, instead of learning and becoming comfortable with two or three computational tools (i.e., mathematical software packages), students under this format often need to learn 4 or 5 computational tools because every one of their instructors prefers a different tool, and the students never really become proficient with any single tool. The second difficulty is that there are a few important concepts that play a role in many of the various computational methods, for example, rounding error, logical operators, and accuracy, that may never be taught if there is not a single course focused on computational methods.

This textbook, and the course that it was originally written to support, is focused on the second approach – a course that appears in the first year or early in the second year of an engineering curriculum. The main reason for adopting this approach is simply the belief that it is critical for students to understand both the potential power and flexibility of computational methods and also the important limitations of these methods before using them to solve problems in engineering. For a student to use a computational tool in a course and blindly trust that tool because they do not understand the algorithms behind the tool is probably more destructive than never learning the tool at all. Further, to limit a student to only problems that can be solved with paper and pencil for most of their undergraduate education is similarly unacceptable. Addressing the limitations associated with teaching computational methods before most of the fundamental engineering and some mathematics courses is difficult. The basic strategy employed by this book is to teach students to recognize the type of mathematical equation they need to solve, and, once they know the type of equation, they can take advantage of the appropriate computational approach that is presented here (or, more likely, refer back to this book for the appropriate algorithm for their particular equation).

There is a second, and possibly more important, reason for learning this material early in the engineering education process. It is related to the fact that one of the most difficult skills for many science, engineering, and mathematics students to master is the ability to combine a number of small, simple pieces together into a more complex framework. In most science, engineering, and mathematics courses in high school and early in college, students learn to find the right equation to solve the question they are asked to answer. Most problems can be completed in one or two steps. Problems in later courses, on the other hand, can often require 5–10 or more steps and can require multiple pages of equations and mathematics to solve. This transition from small problems that only require a few lines to large problems that require a few pages can be very challenging for many science, engineering, and mathematics students. I believe that programming in general, and numerical computations, in particular, can be a great way to develop the skills associated with solving larger problems. Programming requires one to combine a number of simple logical commands and variables together into a more complex framework. Programming develops the parts of our brains that allow us to synthesize a number of smaller pieces into a much larger whole. A good analogy is building something complex (e.g., the Death Star) with LEGO bricks. This process requires one to properly and carefully combine a number of simple pieces into a much larger structure. The entire process requires one to simultaneously think on both the large scale (“What is my design objective?”) and the small scale (“Will these two pieces stay connected? Are they compatible?”). This skill is necessary for both programming and engineering. It is a skill that almost everyone is capable of developing, but it takes practice – so, we might as well start early!

This textbook advocates that students develop the following skills: (1) recognize the type of mathematical equation that needs to be solved – algebraic or differential? linear or nonlinear? interpolation or regression? ordinary or partial differential equation (PDE)?, and (2) select and implement the appropriate algorithm. If students are able to develop these two skills, they will be equipped with a set of tools that will serve them well in their later engineering courses. These tools can be used by a student to check their work, even when they are primarily using paper and pencil to solve a problem. It is not optimal that students learn how to approximately solve mathematical equations before they know why the equation is relevant, but every effort is made in this book to at least try and explain the relevance of equations when possible.

1.1 Equation Identification and Categorization

We identified two categories of skills that we wish to develop throughout this book: (1) recognizing the type of mathematical equation(s) and (2) selecting and implementing an appropriate computational method. The first skill will be covered in this chapter and then the remainder of the book is for developing the second set of skills.

1.1.1 Algebraic versus Differential Equations

The distinction between algebraic and differential equations is trivial – a differential equation is a relationship between the derivatives of a variable and some function. Differential equations described the rate of change of a variable; typically the rate of change with respect to space or time. Equations can have both independent and dependent variables. It is usually simplest to identify the dependent variables because their value depends on the value of another variable. For example, in both and , is the dependent variable because its value depends on the value of and is the independent variable. There can be multiple independent variables, for example, multiple spatial dimensions and time, and the value of dependent variable may depended on the value of all independent variables. The density of air, for example, varies with location: latitude, longitude, and elevation above sea level, as well as time. Therefore, if we have an equation that describes the density of air as a function of location and time, then, in that equation, density is the dependent variable and location and time are the independent variables. Similarly, the ideal gas law can be used to calculate the density of air: . For this equation, is a function of temperature and pressure, so is the dependent variable and and are the independent variables. Alternatively, this equation could be seen such that pressure, , is the dependent variable that depends on density, , and temperature, , that is, .

For differential equations, there are three different notation styles that are commonly used for derivatives.

Leibniz notation

The derivative of the function,

, with respect to

is written as

and the second derivative is written:

The partial derivative of with respect to is

Lagrange notation

The derivative of the function,

, with respect to

is written:

and the second derivative is written:

The notation is not easily extended to partial derivatives and there is no universal standard, but one style that is used is to switch from the prime mark, , to a subscript so that the partial derivative of with respect to is

Euler notation

The derivative of the function,

, with respect to

is written:

and the second derivative is written:

The partial derivative of with respect to is

In summary, differential equations have at least one derivative and algebraic equations do not. The presence of a derivative has a significant impact on the computational method used for solving the problem of interest.

1.1.2 Linear versus Nonlinear Equations

A linear function, , is one that satisfies both of the following properties:

additivity:

.

homogeneity:

.

In practice, this means that the dependent variables cannot appear in polynomials of degree two or higher (i.e., is nonlinear because ), in nonlinear arguments within the function (i.e., is nonlinear because ), or as products of each other (i.e., is nonlinear).

For algebraic equations, it is typically straightforward to solve linear systems of equations, even very large systems consisting of millions of equations and millions of unknowns. Two different methods for solving linear systems of equations will be covered in Chapter 6. Nonlinear algebraic equations can sometimes be solved exactly using techniques learned in algebra or using symbolic mathematics algorithms, especially when there is only a single equation. However, if we have more than one nonlinear equation or even a single, particularly complex nonlinear algebraic equation (or if we are simply feeling a little lazy), we may need to take advantage of a computational technique to try and find an approximate solution. Algorithms for solving nonlinear algebraic equations are described in Chapter 8.

It is important to note that the distinction between linear and nonlinear equations can also be extended to differential equations and all of the same principles apply. For example, and are linear while is nonlinear. In some cases, the nonlinearity will not significantly increase the computational challenge, but, in other cases like the Navier–Stokes equations, the nonlinearity can significantly increase the difficulty in obtaining even an approximate solution.

Linear versus Nonlinear Examples

Linear:

single linear equation:

linear system of equations:

Nonlinear:

single nonlinear equation:

single nonlinear equation:

nonlinear system of equations:

nonlinear system of equations:

1.1.3 Ordinary versus Partial Differential Equations

An ordinary differential equation (ODE) has a single independent variable. For example, if a differential equation only has derivatives with respect to time, , or a single spatial dimension, , it is an ODE. A differential equation with two or more independent variables is a PDE. The following are examples of ODEs.

If you have not taken a differential equations course, this equation may look a little intimidating or confusing. To solve this equation, we need to find a function where the first derivative of the function, multiplied by , plus the second derivative of the function is equal to . If that sounds difficult, do not worry, by the end of this textbook, you will know how to get an approximate solution, that is, a numerical approximation of the function . It is also important to emphasize that multiplying the dependent variable by the independent variable did not make the equation nonlinear. A nonlinearity only arises if, for example, is multiplied by itself.

Again, if you have not had a differential equations course, solving this equation requires finding a function that has a derivative equal to plus . Do not worry if that makes your head spin, we will also cover the solution of this class of problems.

Some examples of PDEs are included below.

This is an equation that describes unsteady, conductive heat transport in one spatial dimension. You could use this equation to describe, for example, the warming of the ground when the sun comes up in the morning, among many other examples. Solving this equation requires finding a function of both time and space where the first derivative with respect to time is equal to times the second derivative with respect to space.

By now it is probably obvious that the standard mathematical convention is to use for derivatives in a PDE while ODEs use . The order of the equation is determined by the order of the highest derivative.

Solving a Differential Equation

Even though you may not have taken a differential equations course, you might be able to solve a simplified version of the first ODE example. Try to solve

Notice that we have eliminated the difficult term with multiplied by the first derivative. Let us start by integrating both sides of the equation with respect to :