Table Of ContentMATLAB Numerical Methods with Chemical
®
Engineering Applications
About the Author
Dr. Kamal I. M. Al-Malah, a portable, platform-independent professor of chemical engineering, is
currently mounted at the University of Ha’il in Saudi Arabia. He holds B.S., M.S., and Ph.D. degrees
in chemical/biochemical engineering. Dr. Al-Malah graduated from Oregon State University in 1993.
His area of specialty during M.S. and Ph.D. programs there was protein interactions and behavior at
interfaces in biological systems. He currently researches the modeling, simulation, and optimization
aspects of physical/biophysical systems and the characterization of molecular properties within the
dome of chemical, biochemical, pharmaceutical, and food engineering. In addition to his traditional
and classical field of study, Dr. Al-Malah is a software developer, using Microsoft Visual Studio
technology, and has created a bundle of Windows-based and MATLAB-based software for engineering
applications (https://sites.google.com/site/almalahweb/software).
MATLAB Numerical Methods with Chemical
®
Engineering Applications
Kamal I. M. Al-Malah, Ph.D.
New York Chicago San Francisco
Athens London Madrid
Mexico City Milan New Delhi
Singapore Sydney Toronto
Copyright © 2014 by McGraw-Hill Education. All rights reserved. Except as permitted under the United States Copyright Act of
1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval
system, without the prior written permission of the publisher.
ISBN: 978-0-07-183129-1
MHID: 0-07-183129-0
e-Book conversion by Cenveo® Publisher Services
Version 1.0
The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-183128-4, MHID: 0-07-183128-2.
McGraw-Hill Education eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in
corporate training programs. To contact a representative, please visit the Contact Us page at www.mhprofessional.com.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a
trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of
infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps.
Information has been obtained by McGraw-Hill Education from sources believed to be reliable. However, because of the possibility
of human or mechanical error by our sources, McGraw-Hill Education, or others, McGraw-Hill Education does not guarantee the
accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained
from the use of such information.
TERMS OF USE
This is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights in and to the work. Use of this work is
subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work,
you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute,
disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill Education’s prior consent. You may use the
work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may
be terminated if you fail to comply with these terms.
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL EDUCATION AND ITS LICENSORS MAKE NO GUARANTEES OR
WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM
USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK
OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill Education
and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation
will be uninterrupted or error free. Neither McGraw-Hill Education nor its licensors shall be liable to you or anyone else for any
inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill Education has
no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill Education
and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of
or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall
apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise.
Devotion
To my creator, who taught humans things they did not know before;
To the last prophet Mohammad and to the preceding prophets, peace be upon all of them;
To my first lovely teachers in this life, Mom and Dad;
To my wife Fadia, daughters Anwar and Lama, and sons Abdallah and Mohammad;
To my biological brothers and sisters;
To my first class teacher Raslan Al-Malah, mercy be upon him;
To my succeeding teachers and professors from my first class to my Ph.D.;
To my last professor (my Ph.D. supervisor, Dr. J. McGuire);
To the McGraw-Hill Education staff;
To Cenveo Publisher Services; and
Finally, to my brothers and sisters worldwide.
To the first, I say: I owe you everything and you are the first and last.
To the rest, I say: my sincere and warm greetings to all of you.
PRAISE IS TO ALLAH (GOD)
Kamal
Contents
Preface
1 MATLAB Basics
1.1 Starting MATLAB
1.2 Online Help
1.3 Simple Arithmetic Operations
1.4 MATLAB Built-in Library Functions
1.5 Output Display in MATLAB
1.6 Algebra
1.7 Vectors
1.7.1 The Row Vectors
1.7.2 The Column Vectors
1.7.3 The Colon Notation
1.7.4 Transpose
1.8 Plots and Graphs
1.8.1 Non-ASCII Character Display
1.8.2 Font-Related Attributes
1.8.3 Plotted Curve (Line) Attributes
1.8.4 Super-Positioning of Plots
1.8.5 Subplotting
1.8.6 Axes Control
1.8.7 Graphics of Functions of Two Variables
1.9 Interrupting Calculations
1.10 Syntax Errors
1.11 Suppressing Output
1.12 Problems
2 Living with Matrices
2.1 Defining Matrices
2.1.1 Referencing an Element in a Matrix
2.2 Size of Matrices
2.3 The Identity Matrix
2.4 Diagonal Matrix
2.5 Specialized Matrices
2.6 The Colon Operator
2.7 Manipulating Matrices
2.8 Array (Element-by-Element) Operations on Matrices
2.9 Matrix Multiplication
2.9.1 Matrix Exponentiation
2.10 String Arrays
2.10.1 Assignment
2.10.2 Input
2.10.3 Concatenation of Strings
2.10.4 Interconversion between Double and Char
2.10.5 Strings Comparison
2.11 Printing Output
2.12 Problems
3 MATLAB Scripting Language: M-File
3.1 What Is an M-File?
3.2 MATLAB Search Path, Path Management, and Startup
3.3 Script M-File
3.3.1 Effective Naming and Referencing of M-Files
3.4 Function M-File
3.5 Errors and Debugging
3.5.1 Scientific Notation, Significant Figures, and Precision
3.5.2 Errors Related to Floating-Point Arithmetic
3.5.3 Numerical Stability
3.5.4 Syntax Errors
3.5.5 Run-Time Logic Errors
3.5.6 Remedies to Minimize Errors
3.6 Problems
4 Image and Image Analysis
4.1 Reading a Graphics Image
4.2 Graphics Image Display
4.3 MATLAB Image-Modifying Functions
4.4 Image Saving
4.5 Image Resizing
4.6 Mathematical Manipulation of Image Arrays
4.7 Image Acquisition/Quality Control
4.8 Image Acquisition/Bacterial Colony Counting
4.9 MATLAB Image Acquisition Tool (imaqtool)
4.10 Problems
5 Curve-Fitting
5.1 (Two-Parameter) Linear Regression
5.2 Importing Data
5.3 Data Visualization
5.4 Statistical Definitions
5.4.1 Residuals
5.4.2 Sum of Residuals
5.4.3 Residual Sum of Squares
5.4.4 Error Variance
5.4.5 R2, or the Coefficient of Multiple Determination
5.4.6 AdjR2 (R2a), Adjusted Coefficient of Multiple Determination
5.5 The Model Goodness
5.5.1 By-the-Naked-Eye Test (No Statistics)
5.5.2 The Model Goodness (with Statistics)
5.6 MATLAB’s Curve Fitting Toolbox (cftool)
5.6.1 Results of MATLAB’s cftool
5.7 MATLAB’s Surface Fitting ToolBox (sftool)
5.8 Problems
6 Numerical Integration
6.1 Trapezoid Rule
6.1.1 Description (MATLAB’s Trapz Help)
6.2 Simpson’s Rule
6.3 Symbolic Integration
6.4 Problems
7 Solving Differential Equations
7.1 Euler’s Explicit Method
7.2 Euler’s Implicit Method
7.3 Runge–Kutta (R–K) Method
7.4 Solution of a Set of Ordinary Differential Equations
7.5 Solution of a Higher-Order Ordinary Differential Equation
7.6 ODE and System Solver Using MATLAB dsolve
7.7 The Shooting Method for a Higher-Order Ordinary Differential Equation
7.8 Problems
8 A System of Algebraic Equations
8.1 The Determinant of a Matrix and Its Inverse
8.1.1 (2 × 2) Square Matrix
8.1.2 (3 × 3) Square Matrix
8.2 A System of (n × n) Linear Algebraic Equations
8.2.1 A System of (n × n) Linearly Independent Equations (⇒ | A| ≠ O)
8.2.2 Gauss Elimination Method with Partial Pivoting
8.2.3 Ill-Conditioning
8.3 Problems
9 Statistics
9.1 Probability
9.2 Typical Distribution Functions
9.2.1 Uniform Distribution
9.2.2 Normal Distribution
9.2.3 Binomial Distribution
9.2.4 Poisson Distribution
9.2.5 Exponential Distribution Function
9.2.6 Gamma Distribution Function
9.2.7 Chi-Square Distribution
9.2.8 Weibull Distribution
9.2.9 Beta Distribution
9.3 Maximum Likelihood Estimates (MLE)
9.4 A Full-Fledged Example Showing Statistical Data Acquisition, Analysis, and Visualization
by MATLAB
9.4.1 Load In the Data Using the Dataset Array
9.4.2 Data Management and Manipulation
9.4.3 Show Plot by a Category
9.4.4 Customize the Plot
9.4.5 Hypothesis Testing
9.4.6 Screening Data Using Hypothesis Testing
9.4.7 Flagging or Labeling Data: Alive vs. Dead Sensor
9.4.8 Analysis of Variance (ANOVA)
9.4.9 Clustering (Showing Groups and Outliers)
9.4.10 Curve-Fitting
9.5 Problems
10 Chemical Engineering Applications
10.1 A Simple Electric Circuit
10.2 Van der Waals’ Equation of State
10.3 A Simple Cooling Tank
10.4 Isothermal Batch Reactor
10.5 A Non-Isothermal CSTR with Water Cooling Jacket
10.6 A Pressurized, Isothermal Gas-Phase CSTR
10.7 One-Dimensional Heat Flow
10.7.4 Solving 1D Heat Equation Using the MATLAB PDE Solver
10.8 One-Dimensional Mass Flow
10.8.1 Solving 1D Mass Equation Using the MATLAB PDE Solver
10.9 Unconstrained 1D Function Minimization
10.10 Unconstrained 2D Function Minimization
10.11 Constrained 2D Function Minimization
10.11.1 Inequality Constraint
10.11.2 Equality Constraint
10.12 Bubble-Point Calculation for Benzene-Toluene Mixture
10.13 Dew-Point Calculation for Benzene-Toluene Mixture
10.14 Problems
11 MATLAB Graphical User Interface Design Environment (GUIDE)
11.1 What Is the MATLAB Graphical User Interface Design Environment?
11.2 Invoking the MATLAB GUIDE
11.3 Simple Tasks with the MATLAB GUIDE
11.4 Graphical User Interface for an Ideal Gas Volume Calculation
11.5 Graphical User Interface for Evaluating Volume-Related Properties of a Pure Substance
11.6 Saving Results to a File
11.7 Deployment of MATLAB-Based Applications
11.8 Problems
Index