This pdf illustrates how to use the programming language Python to solve the problems posed in the book Introduction to Chemical Engineering Computing, Bruce A. Finlayson, Wiley (2006-2014). The material mirrors the use of MATLAB in the book, and solves the examples in Chapters 2, 3, 4, and 8. In addition, a new Appendix F gives summaries of many Python commands and examples. Together with the book, chemical engineering applications are illustrated using Microsoft Excel®, MATLAB®, Aspen Plus®, Comsol Multiphysics®, and Python. This pdf is intended to be used in conjunction with the book, and the treatment using Python mirrors that using MATLAB. Appendix F includes information for setting up Python on your computer. To get the pdf, go to

Posted in Chemical engineering computing | Leave a comment

Error Bounds using the Green’s Function

Green's Function

Green’s Function

November 18, 2014

One of the fundamental concepts when solving partial differential equations is the Green’s function. This function allows you to represent the exact solution as an integral. It may be hard to find, and if found, may be hard to evaluate (needing many terms to converge). But, there are problems for which one is known. Problem 10 from my website ( shows how to use the Green’s function to provide error bounds for a numerical solution. In this case the problem is simple: flow in a square or rectangular duct. An example of the Green’s function is shown in the figure as a function of x and y, for a particular value of zeta and eta, (0.7, 0.3). The figure becomes sharper as more and more terms are kept in the infinite series, but the world does march on! The problem statement gives some mathematical background for deriving the error bounds, and the solutions (obtained through SIAM) gives the answers.

Posted in Chemical engineering computing | Leave a comment

September 2, 2014 – Numerical Results with Rigorous Error Bounds

converter4x6 catalytic_converter001

Have you ever solved a problem numerically and wondered: How accurate is my answer? Oftentimes the only clue you have is how the solution changes (hopefully not much) as you refine the mesh and solve it with more degrees of freedom. I have posted some new problems and a few solutions that help with this problem.

The method is to use mathematical theorems that bound the error. Sometimes the error can only be bounded in an average sense – called the mean square error, which is the error squared, integrated over the domain, and then take the square root. The best situation, though, is when you can bound the difference between the exact solution and the approximate solution you’ve found at every point in the domain. That is called the point-wise error.

The book Method of Weighted Residuals and Variational Principles discusses these points in Chapter 11. While the book was first published in 1972, it has been republished by the Society for Industrial and Applied Mathematics, Of course the mathematical proofs are still valid. But, back in 1972, you couldn’t solve many problems very accurately. However, now you can. Thus, the problems I’ve posted on the website use the theorems given or mentioned in the book and solve the problems using modern technology, and then compute the mean-square error bound and sometimes the point-wise error bound for the approximate solution. The solutions are sometimes found using MATLAB and sometimes found with Comsol Multiphysics.

Problems 7, 8, and 9 have just been posted. These refer to a problem called ‘effectiveness factor’ in chemical engineering. They compute the average reaction rate in a porous catalyst that is undergoing both diffusion and reaction. This is a classic problem in chemical reaction engineering. Problem 7 sets the stage – gives the theorems and equations that aren’t already in the book and solves the problem for a plane geometry using Hermite cubic polynomials in Comsol Multiphysics. Other parts use Lagrange quadratic polynomials and solve for both plane geometry and a spherical catalyst pellet. Problem 9 is for a non-linear problem. (You thought no error bounds would be available didn’t you!)

Posted in Chemical engineering computing | 1 Comment

Source Code for Examples is now Available

July 18, 2014

The source code for all the examples in the book has recently been made available by Wiley. They total 26 MB and can be downloaded by going to and searching on author: Finlayson (or, title or ISBN number). These would allow you to work all the examples in the book just by loading the source code into the requisite Excel, Matlab, Aspen, or Comsol. The problems at the end of the chapter you still must do yourself!

When I first wrote the book I thought that it was important for students to start from nothing and learn each program. However, I’ve realized that even if you do that, you learn only the things relevant to that example, and still have to learn some more. Now, by starting with an example, whose solution is in front of you, you can learn that problem faster, and, hopefully, continue that learning process when you tackle new problems.


The book web site, has links to the same file stored by Wiley. It has other downloads, as well, that might be useful. Don’t ignore the material on The Method of Weighted Residuals and Variational Principles, which is there, too. It deals with error bounds, and you may be willing to just accept your answer, but the bounds do give you confirmation and useful insight into the method of solution.


Posted in Chemical engineering computing | Leave a comment

April 4, 2014

         I’ve added a problem to the website for electrochemical polymerization in a series of stirred tanks. Solutions are given as derived in Excel and MATLAB. It is a simple problem with important insight and comes from the book Electrochemical Reaction Engineering, by K. Scott, Academic Press, New York (1991). The plot of conversion versus number of stirred tanks is shown here from the Excel solution.



         I have also collected the figures from my book, Introduction to Chemical Engineering Computing. They are available to instructors who use the book as a text in class. Shortly I will have the programs that were used for illustration in the book so that instructors can run them without much hassle. You get these by contacting Wiley. The following web sites can be used to obtain material from Wiley. It includes the keys to the problems (useful to your Teaching Assistant), and the figures in the book (useful to you when you go to class). Go here to learn what is in the book:

and here to fill out the form

         The updated version of the 2nd edition should be available in the next few days. The parts on Aspen Plus have been updated to be consistent with Aspen Plus 8, which comes in Aspen Suite 8.4. The windows are the same, but how you get to them is different. The figures available from Wiley have the updated windows. This is the only textbook available now that has been updated for Aspen Plus 8.

Aside | Posted on by | Leave a comment

More problems/solutions with error bounds and help integrating in time in Comsol Multiphysics


March 3, 2014

I’ve added some more problems to the website that goes along with the book pictured above.  Now there are six problems, for eigenvalue problems, boundary value problems in 1D, elliptic boundary value problems, and initial value partial differential equations. All of these first six problems have solutions with them, that can be downloaded from the website. They illustrate how variational principles are used to calculate error bounds, or sometimes just trends (always going up or always going down as the approximation improves).  See additional description in the Jan. 15th blog below.

I’ve corrected the page proofs for the revision of Introduction to Chemical Engineering Computing. It now is based on Aspen Plus User Interface 8.0, which comes with the Aspen Suite 8.4, the latest one. See the Jan. 15th blog below for further information. The new printing should be in April. If you order it, be sure to specify that the ISBN number is

ISBN 978-1-118-88831-5

After Aspen Tech made the changes in the Aspen Plus User Interface, there are a lot of books being revised!


Hints when the time integration is having difficulty getting started in Comsol Multiphysics. (I supplied these on LinkedIn in response to a query.)

1. If it is natural convection in an enclosed space, be sure you set the pressure at one point on the boundary. Otherwise the pressure will not be defined and the simulation won’t start.

2. Next, if some of your equations are not time dependent, it is possible for Comsol not to take those variables into account when it makes the error estimates in the time step. That is appropriate because those variables would adjust instantly to the others, and might change a lot in one time step. Otherwise you will have to take very small time steps. These problems are called quasi-static. To do this, unclick them in the “Equations to be solved for”.

3. You can set the initial time step to a smaller value. Then, in desperation, you can set the Absolute and/or Relative Tolerance to higher values.

4. Also, it might help, depending on your problem, if you could supply an initial guess of the solution – it doesn’t have to be right, or even close, but something non-zero sometimes helps. Be sure to check the box for Values of Dependent Values Solved for. Good luck – this is a common problem and not easy to solve (in my experience).

5. You can also set the error criterion for the error in a time step (or the changes from one time to another) to a larger value. This is called Scaling; the default is 0.01. For kicks, try something very much larger (like 1 or 10).

6. There are a variety of other options that have not always worked well for me, but they are in the Time-Dependent Solver: increase MUMPS (this has worked for me, under Direct – when you start, it may be changed by the program and listed on the Log or Progress, and if you see it increasing it is easier to just use the larger number when you start),. Also, you can change the way the Jacobian is solved (has never worked for me). Scaling of the variables differently permits you to essentially apply different error criteria to different variables, based on your expectation of which variables are the most important to have correct. This program has lots of options, and it is confusing even to one who has programmed many of them back in the days of FORTRAN. Another one that sometimes works is to clear the solution, clear the Study and recreate the Study. I don’t have to do that often (1/10,000) but it has worked for me (and was suggested by Comsol).

7. Finally, of course, is to send it to Comsol for help. I probably should have recommended that first!

Posted in Chemical engineering computing | Tagged | Leave a comment

A book in revision and an old book resurfaces!

January 15, 2014

I have revised the material in Introduction to Chemical Engineering Computing to be consistent with AspenPlus 8. The interface looks different when you start, but the ultimate windows where you define the problem are the same. It took me a bit to get used to, but I like the new version. One of the main things is that there are three tabs, and the ribbons (across the top) are different for each tab. Thus, if you want to define the chemicals or the thermodynamic model, you have to have selected the Properties tab or you won’t find the appropriate windows. Then when you define the process you must have chosen the Simulation tab in order to prepare the flowsheet. The thermodynamics are not there in the Simulation tab, so you may have to go back and forth. The third tab is Energy Analysis. The advantage of this format is that the things seen in the ribbon are all pertinent to the tab you have chosen, which makes for fewer options, but the right ones. This format is called a ribbon format and was introduced by Microsoft for Excel some time ago. Then Aspen changed to it, and Comsol just changed to it. Matlab also changed to it, but in my book most of the time I’m describing actual programs, not the icons. The revised book will be available in April, 2014, with a stamp on the front identifying that it uses Aspen Plus 8.

The next thing I have to report is the republication of my 1972 book, Method of Weighted Residuals and Variational Principles by the Society of Applied Mathematics (SIAM) as a SIAM Classic 73. (I’m 73th in the list of classic applied mathematics books chosen by them in their history. In 1972, computers were just beginning to make an impact on the solution of differential equations. The first part of it treats differential equations governing transport problems, of flow, heat, and mass, using approximate methods and a series of functions, but using only a few terms. The Galerkin, collocation, least squares, and integral methods were all subsumed under the phrase Method of Weighted Residuals. The second part describes variational principles (or not) for those problems and shows how to find them and use them to construct error bounds and create stationary principles. Finally, the variational principles are used to derive error bounds that can be calculated for some problems. This was important because the series used in the approximate methods for nonlinear problems could not be extended to a large number of terms without the use of a computer. Since then computers have advanced considerably and much more sophisticated numerical techniques are available, but the mathematical principles described in the book are still valid, and still useful.

Chapter 11 in particular gives error bounds for many problems. Examples are given in the book, but there is a need to expand the coverage to include higher approximations and numerical methods that are now possible. Thus, problems are being formulated and posted at that use the error bounds, but also use methods like the finite difference method and finite element method. Some of the problems are given with solutions, some with partial solutions, and some have no solutions on the website, but they are available to instructors via SIAM. Right now there are only two problems – a boundary value problem and an eigenvalue problem, but each problem has about four sub-problems. The areas covered are boundary value problems (1D), eigenvalue problems, elliptic partial differential equations, parabolic partial differential equations in 1D and 2D. In each type there will be one problem with complete solutions using a variety of methods so that everyone can get a good head start.  Additional problems will be added as time permits, but they do give good examples of the value of error bounds and make use of modern computational tools like MATLAB® and Comsol Multiphysics®, the finite difference and finite element methods (when applicable – sometimes the error bounds are derived with pretty stringent mathematical conditions). So check it out, and keep checking it out as I add problems.

Bruce Finlayson

Posted in Chemical engineering computing | Leave a comment