....
B. Wayne Bequette
Process Dynamics Modeling, Analysis, and Simulation
Prentice Hall International Series in the Physical and Chemical Engineering Sciences
PRENTICE IIALL INTERNATIONAL SERIES IN THE PHYSICAL AND CHEMICAL ENGINEERING SCIENCES NEAL
R.
!\i\lUNDSON, SE!{IES liDITOR, Un/verst!.\' t?!1foIlS!Ofl
AnVISORY E1JJTORS AN[)J{l~AS ACRIVOS,
JOHN DMII,ER,
S{(l!!(oI'r! Unil-'ersify
University (d'IVlillllesO{{/
H. SC'(rlT FOGIJ]{, Unil'CI"sity (~rMichigan 'T'1l0MAS
J.
University (?( fllil/oi,\' (?FCa!i;(omia University 1?(Minl/csota
IIANKATTY,
JOHN M. P[~AUSN[TZ, Univcrsily
L.
E::. SCRIVEN,
Chemical !'.lIgilleaing ThennodYl/tllllics Process Oynamics: A1odcling, Analysis, and Simulatio/l BWUU.:R, CiROSS\-\i\NN, AND WESTERBERG Sy.l"tcmafh' iHethods rd' Chemica! Process J)esij{11 CROWL and 1,()(JVA1{ Chemica! Process Sq(ety DFNN Process' Fl/lid lvlec!wlI/c"S [;'OGLER {:lemcfI!s q(Cllcmical Rcaction Engineering, 2nd I~'dition HANNA AND SANDA[J COll/putatiolla! Methods ill ChclIIical Engineering I-IJ~IMI~LBLAU Basic Principles {{lid C(llcl/larions ill Chemical Engincering, 6th editioll HINES i\!>il) MADDOX Mass Tnl/lsjt'r KYLE Chemical and Proces..,. '1henllodyl1amics, 2nd edition NEWMAN Efectmchc/Ilical Systcms, 2nd edition PR;\tJSNll/., LICIITFNTI-lMJ',R, and DL A/.l'VEDO Molecular Thermodynamics (~rFlllid-PIUlse Eqlli/ihria, 2nd cdition PHrNTlC:E Elec!rochcmical Ellgincering Principles STEPHANOI'OULOS Chemical Process COlltrol TI~STER AND MOllF.!J. Thermodynamics (lnd Its /\pplicatio/ls, 3rd edition TURTON Analysis, SrI/thesis, and Design (~rChell/iCflI Processes Bi\LZlllSER, S;\:-'·IUEJ.S, Mm 1-::l.uASSEN
Br',QUFTrl::
PROCESS DYNAMICS Modeling, Analysis, and Simulation B. Wayne Bequette Rensselaer Polytechnic Institute
To join a Prentice Hall PTR Internet mailing list, point to: http://www.prenhall.com/maiUists/
Prentice Hall PTR Upper Saddle River, New Jersey 07458
Library of Congl'l'ss
Catalogil1g~il1-PllblicatitmData
Bequette, B, Wayne. Process dynamics: modeling, analysis, and simulation / B, Wayne Bequette. p.
ern.
Includes bibliographical references and index, ISBN O,-11-206889~3 1. Chemical procc%es. I. Tille. TPI55,7.B45 1998 (j6()',2X4'OI185---dc21
97 36053 elP
Acquisitions editor: Bernard M. Coodwin Cover design direcloc Jerry Votta Manufacturing manager: Alexis R. Heydt lvlilfketing Jnanllger: tvli1es Williams Compositor/Production services: Pinc Tree Composition, Inc. (D 1998 by Prentice Hall PTR Prentice-Hall, Inc. A Simon & Schuster Company Upper S,\dd\c River, Nnv Jersey 07458 .
Prentice Hall books arc widely"used by corporations anu govel'lllllent agencies for training, marketing, and resale. The publisherofkrs discoullts on this hook when ordered in bulk quantities. For more information contact: Corporate Sales Department Phone: 800-382-3419 Pax: 201-236-7141 E-mail:
[email protected] Or write:
Prentice I-fall PTR Corp. Sales Dept One Lake Sircet Upper Saddle Rivcr, New Jersey 07458 AI! rights reserved. Nl.J part of this book mily be rcpf(l(luced, ill any forlll or by any means, without permission in writing from the publisher. Printed in the United St,l!cs of Alllerica 10 9 8 7 6 5 4 J 2
ISBN: 0-13-206889-3 Prentice-Hall Intcrnational (UK) Limited, LOlldoll Prcnticc-Hall oj" Australia Ply. Limited, Sydlley Prenlice-Hall Canada Inc.. Toronto Prcntiee--Flall HispanOimlcricana, 5.A., Mexico Prentice-Hall of India Private Limited. N('\\, IJdhi Prenlice-Hall of Japan, Inc" lilkyo Simon & Schuster Asia Pte. Ltd., Singapore Editora Prcnticc--Hall do Brasil. LtdH., Rio de .falleiro
CONTENTS
Preface
XVII
SECTION I PROCESS MODELING 1
Introduction
1.1 1.2 1.3
1.4 1.5
1.6
1
3
Motivation 3 Models 4 1.2.1 How Models Are Used 5 Systems 10 1.3.1 Simulation 10 1.3.2 Linear Systems Analysis 11 1.3.3 A Broader View of Analysis 11 Background of the Reader 12 How To Use This Textbook 12 1.5.1 Sections 12 1.5.2 Numerical Solutions 13 1.5.3 Motivating Examples and Modules 13 Courses Where This Textbook Can Be Used 13 Summary 14 Further Reading 14 Student Exercises 15
vii
Contents
viii
2
Process Modeling
2.1 2.2
2.3 2.4
2.5
2.6 2.7 2.8 2.9
16
Background 17 Balance Equations 17 2.2.1 Integral Balances 18 2.2.2 Instantaneous Balances 20 Material Balances 20 2.3.1 Simplifying Assumptions 25 Constitutive Relationships 27 2.4.1 Gas Law 27 2.4.2 Chemical Reactions 27 2.4.3 Equilibrium Relationships 28 2.4.4 Flow-through Valves 29 Material and Energy Balances 30 2.5.1 Review of Thermodynamics 31 Distributes Parameter Systems 34 Dimensionless Models 35 Explicit Solutions to Dynamic Models 36 General Form of Dynamic Models 37 2.9.1 State Variables 37 2.9.2 Input Variables 2.9.3 Parameters 38 2.9.4 Vector Notation 38 Summary 40 Further Reading 40 Student Exercises 41
SECTION II
3
Algebraic Equations
3.1 3.2 3.3
3.4
3.5
NUMERICAL TECHNIQUES
49
51
Notations 51 General Form for a linear System of Equations 51 Nonlinear Functions of a Single Variable 54 3.3.1 Convergence Tolerance 55 3.3.2 Direct Substitution 55 3.3.3 Interval Halving (Bisection) 58 3.3.4 False Position (Reguli Falsi) 60 3.3.5 Newton's Method (or Newton-Raphson) 60 MATLAB Routines for Solving Functions of a Single Variable 3.4.1 fzero 63 3.4.2 roots 64 Multivariable Systems 64 3.5.1 Newton's Method for Multivariable Problems 66 3.5.2 Quasi-Newton Methods 69
63
ix
Contents
3.6
4
MATlAB Routines for Systems of Nonlinear Algebraic Equations Summary 71 Further Reading 72 Student Exercises 73 Appendix 78
Numerical Integration 4.1 4.2
4.3
4.4
80
Background 80 Euler Integration 81 4.2.1 Explicit Euler 81 4.2.2 Implicit Euler 82 4.2.3 Numerical Stability of Explicit and Implicit Methods Runge-Kutta Integration 88 4.3.1 Second Order Runge-Kutta 89 4.3.2 Fourth-Order Runge-Kutta 93 MATlAB Integration Routines 94 4.4.1 ode23 and ode45 95 Summary 97 Further Reading 97 Student Exercises 98
SECTION III
5
LINEAR SYSTEMS ANALYSIS
103
linearization of Nonlinear Models: The State-Space Formulation 5.1 5.2
5.3 5.4
5.5 5.6
State Space Models 106 5.5.1 General Form of State Space Models 108 Linearization of Nonlinear Models 109 5.2.1 Single Variable Example 109 5.5.2 One State Variable and One Input Variable 5.2.3 Linearization of Multistate Models 112 5.2.4 Generalization 114 Interpretation of Linearization 117 Solution of the Zero-Input Form 119 5.4.1 Effect of Initial Condition Direction (Use of Similarity Transform) 120 Solution of the General State-Space Form 127 MATlAB Routines step and initial 127 5.6.1 The MATLAB step Function 129 5.6.2 The MATLAB initial Function 129 Summary 130 Further Reading 131 Student Exercises 131
83
110
105
70
Contents
x
6
Solving Linear nth Order ODE Models
6.1 6.2
6.3 6.4 6.5
7
7.4 7.5 7.6
8
Background 143 Solving Homogeneous. Linear ODEs with Constant Coefficients 145 6.2.1 Distinct Eigenvalues 146 6.6.2 Repeated Eigenvalues 148 6.2.3 General Result for Complex Roots 152 Solving Nonhomogeneous. Linear ODEs with Constant Coefficients 152 Equations with Time-Varying Parameters 154 Routh Stability Criterion-Determining Stability Without Calculating Eigenvalues 157 6.5.1 Routh Array 157 Summary 160 Further Reading 161 Student Exercises 161
An Introduction to laplace Transforms
7.1 7.2 7.3
142
168
Motivation 168 Definition of the Laplace Transform 169 Examples of Laplace Transforms 170 7.3.1 Exponential Function 170 7.3.3 Time-Delay (Dead Time) 172 7.3.4 Derivations 173 7.3.5 Integrals 173 7.3.6 Ramp Function 174 7.3.7 Pulse 174 7.3.8 Unit Impulse 176 7.3.9 Review 177 Final and Initial Value Theorems 177 Application Examples 178 7.5.1 Partial Fraction Expansion 179 Table of Laplace Transforms 185 Summary 187 Further Reading 187 Student Exercises 187
Transfer Function Analysis of First-Order Systems
8.1 8.2
8.3 8.4
Perspective 191 Responses of First-Order Systems 191 8.2.1 Step Inputs 193 8.2.2 Impulse Inputs 198 Examples of Self-Regulating Processes 200 Integrating Processes 206
190
xi
Contents
8.5
9
Transfer Function Analysis of Higher-Order Systems 9.1
9.2 9.3 9.4 9.5 9.6
10
11.5 11.6 11.7 11.8
215
247
A Second-Order Example 248 The General Method 251 MATLAB Routine ss2tf 252 10.3.1 Discussion of the Results from Example 10.2 Summary 257 Student Exercises 257
Black Diagrams 11.1 11.2 11.3 11.4
209
Responses of Second-Order Systems 216 9.1.1 Step Responses 217 9.1.2 Underdamped Step Response Characteristics 221 9.1.3 Impulse Responses 222 9.1.4 Response to Sine Inputs 224 Second-Order Systems with Numerator Dynamics 226 The Effect of Pole-Zero Locations on System Step Responses 228 Pade Approximation for Deadtime 230 Converting the Transfer E;unction Model to State-Space Form MATLAB Routines for Step and Impulse Response 234 9.6.1 step 234 9.6.2 impulse 236 Summary 236 Student Exercises 237
Matrix Transfer Functions 10.1 10.2 10.3
11
Lead-Lag Models 208 8.5.1 Simulating Lead-Lag Transfer Functions Summary 211 Student Exercises 211
255
261
Introduction to Block Diagrams 262 Block Diagrams of Systems in Series 262 Pole-Zero Cancellation 263 Systems in Series 267 11.4.1 Simulating Systems in Series 267 Blocks in Parallel 269 11.5.1 Conditions for Inverse Response 271 Feedback and Recycle Systems 273 Routh Stability Criterion Applied to Transfer Functions 11.7.1 Routh Array 277 SIMULINK 278
276
232
xii
Contents
Summary 279 Student Exercises
12
280
Linear Systems Summary 12.1 12.2 12.3
12.4 12.5
282
Background 283 Linear Boundary Value Problems 283 Review of Methods for Linear Initial Value Problems 287 12.3.1 Linearization 187 12.3.2 Direction Solution Techniques 288 12.3.3 Rewrite the State-Space Model as a Single nth Order Ordinary Differential Equation 289 12.3.4 Use Laplace Transforms Directly on the State-Space Model 290 Introduction to Discrete-Time Models 290 12.4.1 Discrete Transfer Function Models 291 Parameter Estimation of Discrete Linear Systems 295 Summary 297 References 297 Student Exercises 298 SECTION IV NONLINEAR SYSTEMS ANALYSIS
13
Phase-Plane Analysis 13.1 13.2 13.3
13.4
14
301
303
Background 304 Linear System Examples 304 Generalization of Phase-Plane Behavior 311 13.3.1 Slope Marks for Vector Fields 313 13.3.2 Additional Discussion 315 Nonlinear Systems 316 13.4.1 Limit Cycle Behavior 323 Summary 324 Further Reading 324 Student Exercises 324
Introduction Nonlinear Dynamics: A Case Study of the Quadratic Map 14.1 14.2 14.3
14.4 14.5
Background 332 A Simple Population Growth Model 332 A More Realistic Population Model 334 14.3.1 Transient Response Results for the Quadratic (Logistic) Map 335 Cobweb Diagrams 339 Bifurcation and Orbit Diagrams 342 14.5.1 Observations from the Orbit Diagram (Figure 14.14)
342
331
Contents
14.6
14.7
14.8
15
360
Motivation 360 Illustration of Bifurcation Behavior 361 Types of Bifurcations 362 15.3.1 Dynamic Responses 365 Summary 376 References and Further Reading 376 Student Exercises 377 Appendix 379
Bifurcation Behovior of Two-State Systems 16.1 16.2 16.3 16.4
17
Stability of Fixed-Point Solutions 344 14.6.1 Application of the Stability Theorem to the Quadratic Map 344 14.6.2 Generalization of the Stability Results for the Quadratic Map 346 14.6.3 The Stability Theorem and Qualitative Behavior Cascade of Period-Doublings 348 14.7.1 Period-2 348 14.7.2 Period-4 351 14.7.3 Period-n 14.7.4 Feigenbaum's Number 353 Further Comments on Chaotic Behavior 354 Summary 354 References and Further Reading 355 Student Exercises 356 Appendix: Matlab M-Files Used in This Module 358
Bifurcation Behavior of Single ODE Systems 15.1 15.2 15.3
16
xiii
Background 381 Single-Dimensional Bifurcations in the Phase-Plane limit Cycle Behavior 384 The Hopf Bifurcation 388 16.4.1 Higher Order Systems (n > 2) 391 Summary 392 Further Reading 392 Student Exercises 392
Introduction to Chaos: The Lorenz Equations 17.1 17.2 17.3
381
395
Introduction 396 Background 396 The Lorenz Equations 397 17.3.1 Steady-State (Equilibrium) Solutions
398
382
346
xiv
17.4
17.5
17.6 17.7
Contents
Stability Analysis of the Lorenz Equations 399 17.4.1 Stability of the Trivial Solution 399 17.4.2 Stability of the Nontrivial Solutions 400 17.4.3 Summary of Stability Results 301 Numerical Study of the Lorenz Equations 402 17.5.1 Conditions for a Stable Trivial (No Flow) Solution 17.5.2 Stable Nontrivial Solutions 403 17.5.3 Chaotic Conditions 405 Chaos in Chemical Systems 407 Other Issues in Chaos 409 Summary 410 References and Further Reading 410 Student Exercises 411 Appendix 412
SECTION IV Module 1
Introduction to MATlAB M1.1 M1.2 M1.3 M1.4 M1.5 M1.6 M1.7 M1.8 M1.9 M1.10 M1.11 M1.12 M1.13 M1.14
Module
2
REVIEW AND LEARNING MODULES
Background 416 Using This Tutorial 416 Entering Matrices 417 The MATLAB Workspace 419 Complex Variables 421 Some MATLAB Operations 421 Plotting 422 More Matrix Stuff 426 FOR Loops and IF-THEN Statements 427 m-files 428 Diary 430 Toolboxes 430 Limitations to Student MATLAB 431 Contacting Mathworks 431 Student Exercises 432
Review of Matrix Algebra M2.1 M2.2 M2.3 M2.4
415
435
Motivation and Notation 436 Common Matrix Operations 436 Square Matrices 440 Other Matrix Operations 448 Summary 450 Student Exercises 450
413
402
xv
Contents
Module 3
Linear Regression M3.1 M3.2 M3.3 M3.4 M3.5
Module
4
6
M6.1 M6.2 M6.3 M6.4 M6.5 Module 7
471
Background 490 The Dynamic Model 491 Steady-State Analysis 495 Step Responses 496 Unforced Behavior 501
Introduction 506 First-Order Irreversible Reaction Van de Vusse Reaction 516
Biochemical Reactors M8.1 M8.2 M8.3 M8.4
478
490
Isothermal Continuous Stirred Tank Chemical Reactors M7.1 M7.2 M7.3
Module 8
466
Introduction 471 Developing the Dynamic Model 472 Steady-State Conditions 475 State-Space Model 475 Laplace Domain Model 477 Step Responses: Linear versus Nonlinear Models Unforced System Responses: Perturbations in Initial Conditions 483
Absorption
456
464
Introduction 464 Transfer Function-Based Simulation Printing SIMULINK Windows 469
Stirred Tank Heaters M5.1 M5.2 M5.3 M5.4 M5.5 M5.6 M5.7
Module
Motivation 452 Least Squares Solution for a Line 454 Solution for the Equation of a Line Using Matrix-Vector Notation 455 Generalization of the Linear Regression Technique MATLAB Routines polyfit and polyval 458
Introduction to SIMUlINK M4.1 M4.2 M4.3
Module 5
452
529
Background 529 Modeling Equations 530 Steady-State Solution 534 Dynamic Behavior 535
507
506
Contents
xvi
M8.5 M8.6 M8.7 M8.8 Module
9
Diabatic Continuous Stirred Tank Reactors M9.1 M9.2 M9.3 M9.4 M9.5 M9.6 M9.7 M9.8 M9.9
Module
10
617
540
559
Background 560 The Modeling Equations 561 Steady-State Solution 563 Dynamic Behavior 565 linearization of Dynamic Equations 567 Phase-Plane Analysis 571 Understanding Multiple Steady-State Behavior Further Complexities 580 Dimensionless Model 584
Ideal Binary Distillation M10.1 M10.2 M10.3 M10.4 M10.5 M10.6 M10.7
Index
linearization 536 Phase-Plane Analysis 539 Understanding Multiple Steady-States Bifurcation Behavior 549
572
597
Background 597 Conceptual Description of Distillation 599 Dynamic Material Balances 601 Solving the Steady-State Equations 603 Solving the Nonlinear Dynamic Equations 605 State-Space Linear Distillation Models 606 Multiplicity Behavior 608
PREFACE
An understanding of the dynamic behavior of chemical processes is ilnportant from bolh process design and process control perspectives. It is easy to design a chemical process, based on stcady~state considerations, which is practically uncontrollable when the process dynamics arc considered. The current status of computational hardware and software has made it easy to interactively simulate the dyo<:unic behavior of chemical processes.
It is comJllon for process dynamics to he included as the introductory portion of a process control textbook, however, there afC a number of limitations to this approach. Since the emphasis of most or the textbooks is on process control, there is too little space to give adequate depth to modeling, analysis, and sinwlatioll of dynamic systems. The focus tends to he on transfer function~based models that arc used for control systenl design. The prime motivation for my textbook is then to provide a more comprehensive treatment of process dynamics, including modeling, analysis, and simulation. This textbook evolved from notes dcvelopcd for a course on dynamic systems that I have becn teaching at Rcnsselaer since 199 I. Vie have been fortunate to have a two~semestcr se~ qucnee in dynamics and control, allowing more depth to the coverage of each topic. Topics covered here that arc not covered in a traditional text include nonlinear dynamics and the usc of MA TLAB for numerical analysis and simulation. Also, a signifi~ cant portion of the text consists of review and learning modules. I~ach learning module provides model development, stcady~statc solutions, nonlinear dynamic results, linear~ ization, state space and transfer function analysis and simulation. The motivation for this approach is to allow the student to "tic~togelher" all of the concepts, rather than {rcat~ ing the III independently (and not understanding the connections between the different methods).
xvii
Preface
xviii
An important feature of this text is the usc of MATLAB software. A set of In-files used in many of the examples and in the learning nlodules is available via the world wide wcb at the following locations: http:/wwwhpi.cdu/-hel}ueb/Process_Dynamics hHp:/www.mathworks.com/education/thirdparty.htm I Additional learning modules will also be available at the RPI location. A few acknowledgments arc in order. A special thanks to Professor Jim Turpin at the University of Arkansas, who taught me the introductory course in process dynamics and control. I-lis love of teaching should be an inspiration to us all. Many thanks to one of my graduate students, Lou Russo, who not only made a numher of suggestions to improve the text, but also sparked an interest in many of the undergraduates that h;:lVe taken the course. The {(Isk of developing a solutions manual has heen carried out by Venkatcsh Natarajan, Brian Aufderheide, l
B, Wayne RequeUe
SECTION
I PROCESS MODELING
INTRODUCTION
1
This chapter provides a motivation for process modeling and the study of dynamic chemical processes. It also provides an overview of the structure of the textbook. After studying this chapter, the student should he able to answer the following questions: What is a process model? • Why develop a process model?
• What is the difference between lumped parameter and distributed parameter systoms? • What numerical package forms the basis for the examples in this text? • What arc the major objectives of this textbook? The major sections arc: 1.1
Moti valion
1.2
Models
1.3
Systems
1.4 1.5
Background or the Reader How to Use This Texthook
1.6 Courses Where This Textbook Can Be Used
1.1
MOTIVATION
nze
Robert Reich in Work {~lNations has classified three broad categories of employment in the United States. In order of increasing educational requirement these categories are: 3
Introdu ction
4
Chap. 1
tic services. To diroutine production services, in-person services, and symboli c-analy rectly quote from Reich: l1ng symbols. They sim"Symbo lic analysts solve, identify, and broker problem s by manipula ented with, COlllexperim juggled, ed, rearrang be call that inmges abstract plify reality into reality. The mainto hack municat cd to other spc<:iaJists, and then, eventual ly, transfor med tools Illay be The ce. experien by d nipulatio ns arc done with analytic tools, sharpene s, psycho-· princiule .rcief/rifle s, gimmick financial lts, lIlathematical algorithms, legal argmllcl n, or any deductio or n inductio of systems amuse, to or persuade to how logical insights ahoUl s) emphasi for other sct of techniqu es for doing conceptu al puulcs. " (italics added
. Process enginee rs Engineers (and particularly process enginee rs) are s)'mholic analysts that charact erize usc fundamental scientif ic principles as a hasis for mathem atical models physical variables, such the behavio r of a chemic al process. Symbol s are used to represe nt d and numerical alas pressure, tempera ture or concentration. Input informa tion is specifie . Process: enginee rs gorithm s arc llsed to solve the rnodels (simula ting a physical system) endatio ns regarding analyze the results of these simulat ions to make decisions or recomm the design or operation of a process. es in one way Most chemic al enginee rs work with chemic al manufactUling pmcc:':is l troubles hooting in or another. Often they arc process ergince rs responsible for technica ~Ire respons ible 1'01' dethe day-tn-deiY operatio ns nf a particld ar chemic al process. Some as tempera ture or pre.ssigning feedback control systems so that process variables (such ihle for redesigning a .sure) can he maintai ned at desired values. Others may be respons ibilities require an unchemica l process to provide more profitahility. All of these respons processes. derstan ding of the time-de penden t(dynam ic) behavio r of chemic al
1.2
MODELS an underst anding of 'fhe primary objectiv e of this textboo k is to assist you in develop ing g the dynami c bethe dynami c behavio r of c1\
Didiona ry Definitions:
Mode!
as a noun, it means "a small Model is derived fro1l11he Latin modus, which means a measure . Used y). Dictiof/w World New r's represen tation of a pl
Sec. 1.2
Models
5
Notice that both definitions stress that a model is a representation of a system or ohject. In this textbook, when we usc the term model, we will be referring to a mathematical model. We prefer to usc the following definition f~)r model (more specifically, a process model).
Working Definition:
Pmccss Model
A process model is a set of equations (including the necessary input data to solve the equations) that allows us to predict the behavior of a chemical process system.
The emphasis in this text is on the development and lise offundamental or first-principles models. By fundamental, we mean models that are based on known physical-chemical rc~ lationships. This includes the conservation of mass and conservation of energy, I as well as reaction kinetics, transport phenomena, and thermodynamic (phllse equilibrium, etc.) relatiomdlips. Another common model is the empirical model. An empirical model might be used if the process is too complex for a fundamental model (either in the fonnulation of the model, or the numerical solution of the model), or if the empirical model has satisfactory predictive capability. An example of an empirical model is a simple least squares fit of an equation lo experimental data. Generally, we would prefer to use models based on fundamental knowledge of chemical-physical relationships. Fundamental models will generally he accurate over .a mueh larger range of conditions than empirical models. Empirical models may be useful for "interpolation" but are generally not useful lilr "extrapolation"; that is, an empirical model will only be useful over the range of conditions used for the "fit" of the data. It should be nOled that it is rare for a single process model to exist. A model is only an approximate representation of an actual process. The complexity of a process model will depend on the final usc of the model. If only an approximate answer is needed, then a simplified model can often be lIsed.
1.2.1
How Models Are Used
As we have noted, given a set of input data, a model is used to predict the output "response." A model can be used to solve the following types of problems: Marketing: If the price of a product is increased, how much will the demand decrease? • Allocation: If we have several sources for raw materials, and several manufacturing
101' course, the real conservalioll law is that of mass-energy, but we will neglect the interchange of mass and energy due to nuclear reactions.
Introduction
6
Chap. 1
plants, how do we distrihute the raw materials among the plants, and decide what products each plant produces?
Synthesis: What process (sequence of reactors, separation devices, etc.) can he used to manufacture a product? • Design: What type and size of equipment is necessary to produce a product? Operation: What operating conditions willmaxirnizc the yield of a product? Control: How can a process input be manipulated to maintain a measured process output at a desired value? Safety: If an equipment failure occurs, what will he the impact on the operating personnel and other process equipment? Environmental: IIow long will it take to "biodegrade" soil contaminated with hazardolls waste? Many or the rnodels cited above arc based on a steady-state analysis. This book will cxtend the steady-state material and energy balance concepts, generally prescnted in an introductory textbook on chemical engineering principles, to dynamic systems (systems where the variables change with time). As an example of the increasing importance of knowledge of dynamic behavior, consider process design. In the past, chemical process design was based solely on steady-statc analysis. A problem with performing only a steady-state design is that it is possible to design a process with desirable steady-state characteristics (minimal energy consumption, etc.) but which is dynamically inoperable. Hence, it is important to consider the dynamic operability characteristics of a process during the design phase. Also, batch processes that arc commonly used in the pharmaceutical or specialty chemicals industries arc inherently dynamic and cannot bc simulated with steady-state models. In the previous discussion we have characterized models as stcady-state or dynamic. Another characterization is in ter111s 01" lumped porarneter system.)· or distributed parameter systems. A lumped parameter systcm assumes that a variable or interest (temperature, for example) changes only with one independent variable (time, For cxamjJlc, but not space). A typical example of a lumped parameter system is a perfectly mixed (stirred) tank, where the temperature is uniform throughollt the tank. A distrihuted parameter system has more than one independent variable; for example, temperature may vary with both spatial position and time.
EXAMPLE 1.1
A Lumped Parameter System Consider a perfectly insulated, well-stirred tank where a hot liquid stream at 60 uC is mixed with a cold liquid stream at lone (Figure 1.1). The wc11~mixed assumption means that the fluid temperature in the tank is uniform and equal to the temperature at the exit from the t<mk. This is all example of a lumped parameter system, since the temperature docs not vary with spatial pOSition.
Sec. 1.2
7
Models Hot
Cold
iii
Outlet
FIGURE 1.1
Stirred lank.
Consider now the ~leady-stale behavior of this process. If the only stream was the hot fluid, thell the outlet temperature wOl/ld be eqllal to the hot fluid temperature if the tank were perfectly insulated. Similarly, if the only stream was the cold stream, then the outlet temperature would be equal to the cold lluid temperature. A combination of the two streams yields an outlet tClJlpcrutufc that is intermediate between the cold and hot temperatures, as shown in Figure ] .2.
60
o
f?
50
'0
@ .2 40 ~
'"
Q.
~ 30
l-
ID
8 20 10
_~~------.l.-
o
0.2
------l~~~~~~~~
0.4
0.6
0.8
Hot Flow, fraction
FIGURE 1.2
Relationship between hot flow and outlet temperature.
We sec that there is a linear steady-state relationship between the hot flow (fraction) and the outlet temperature. Now we consider the dynamic response to a change in the fraction of hot flow. Figure 1.3 compares outlet temperature responses for various step changes in hot flow fraction at t :::: 2.5
Introduction
8
Chap. 1
minutes. We sec that the changes afC symmetric, with the same speed of response. We will find later that these responses afC indicative of a lincar system.
+20%
45
o
40
'" 35 f-~"-~~~~----Q~-o~---~-~~ ~ . .- ---ci:
E
230
-20%
25
20
, ..
o
5
10
15
,.--'-----
20
25
30
time, min
FIGlJRE 1.3
EXAMPLE 1.2
Response of temperature to various changes in the hoI llow fraction.
A Histributed Parameter System
A simplified representation of a counterflow heat exchanger is shown in Figure lA. A cold water stream flows through one side of the excbanger and is heated by energy transfcrcd fro!ll a condensing steam ,,,trcam. This is a distributed parameter systcnl because the tClnperature of the water stream can change with lime and position.
Water in
~I-------F=: FIG-URE 1.4
Steam in
Counterflow heat exchanger.
The steady~slate tell1perature profile (water temperature as a function of position) is shown in Figure 1.5. Notice that rate of change of the water temperature \vith respect to distance decreases as the water tcmpenlturc approaches the steam teinpcrature (I OOOe). This is because the tcmper-
Sec, 1,2
9
Models
ature gradient rOf heat transfer decreases as the water temperature increases. The outlet water temperature as a function of inlet water temperature is shown in Figure 1.6.
100
80 0
'" ""ci.
60
E
JE
40
20
a
0.2
0.6
0.4 Z,
Flf;LJlU: 1.5
0.8
distance
W::tter temperature as
it
function of position.
100 98 96 0
'" "'" J-' E
94 92
~
0
90 88 86
a
20
40
60
80
100
inlet temperature, deg C
FIGURE 1.6
Outlet water temperature;Is a function of inlet water temperature.
Introduction
10
Chap. 1
Mathematical models consist of the following types of equations (including combinations) Algebraic equations Ordinary differential equations Partial differential equations The emphasis in this textbook is on developing models that consist of ordinary differential equations. These equations generally result from macroscopic balances around processes, with an assumption of a perfectly mixed system. To find the steady-state solution of a set of ordinary differential equations, we must solve a set of algebraic equations. Partial ditTerential equation models result from microscopic b
1.3
SYSTEMS We have been using the term system yery loosely. Consider the following definition.
Dctinition:
Svstem
A combination of several pieces of equipment integrated to perform a specific function; thus a fire (arlillery) control system may include a tracking radar, computer, and gun (McGraw-Hill Dictiolimy (?f5;ciellt!fic and Technical Tenns).
The example in the definition presellted is of interest to electrical, aeronautical, and rnilitary engineers. I'or our purposes, a system witl be composed of chemical unit operations, such as chemical reactors, heat exchangers, and separation devices, which arc used to producc a chemical product. Indeed, we will oftcn consider a single unit operation to be a system composed of inputs, states (to be defined later) and outputs. A series of modules in Section V of this textbook cover the behavior of a number of specific unit operations.
1.3.1
Simulation
One of the goals of this textbook is to develop numerical analysis techniques that allow liS to "simulate" the behavior of a chemical process, Typically, steady-state simulation of a lumped parameter system involves the solution of algebraic equations, while dynamic simulation involves the solution of ordinary differential equations. We must be careful when using computer simulation. First of all, we must he able to say, Do the results of this
Sec. 1.3
11
Systems
simulation make sense? Common sense and "back of the envelope" calculations will tell us if the numerical results arc in the ballpark.
1.3.2
linear Systems Analysis
The mathematical tools that arc lIsed to study linear dynamic systems problems me known as linear systems analysis techniques. Traditionally, systems analysis techniques have been based on linear systems theory_ Two basic approaches arc typically used: (i) Laplace transforms afC lIsed to analyze the behavior of a single, linear, nth order o("ciinary differential equation, and (ii) state space techniques (based on the linear algebra techniques of eigenValue and eigenvector analysis) arc used to analyze the behavior of multiple first-order linear ordinary differential equations. If a system of ordinary difreren~ tial equations is nonlinear, they can be linearized at a desired steady-state operating point.
1.3.3
A Broader View of Analysis
In this textbook we usc analysis in a broader context than linear systems analysis that may be applied to a model with a specific vallie for the pararnetcrs. Analysis means seeking a deeper understanding of a process than simply performing a simulation or solving a set of equations for a particular set of parameters and input values. Often we want to understand how the response of system variablc (tempera.ture, for example) changes whcn a parametcr (c.g., heat transfer coefficient) or input (fJowrate or inlet temperature) changes. Rather than trying to obtain the understanding of the possible types of behavior hy merely running many simulations (varying parameters, etc.), we must decide which parameters (or inputs or initial conditions) are likely to vary, and use analysis techniques to determine if a qualitative change ofhehavior (number of solutions or stability of a solution) can occur. This qualitative change is illustrated in l';'igure 1.7 below, which shows possihle steady-state behavior for ajackcled chemical reactor. In l<'igure 1.7a there is a monotonic
Jacket Temperature
a. Monotonic
Jacket Temperature
b. MUltiplicity
FIGlJRE l.7 Two qualitatively differclll types of input/output behavior. Steady-slale reactor temperature as a function of steady-state jackct lelnperalurc.
Introduction
12
Chap. 1
relationship between jacket temperature and reactor temperature, that is, as the s(cady~ state j;:lckct temperature increases, the steady-state reactor temperature increases. Figure 1.7b illustrates behavior known as output multiplicity, that is, there is a region of stcadystate jacket temperatures where a single j'H.:kct temIJcraturc can yield three possible reactor temperatures. In Chapter 15 (and module 9) we show how to vary a reactor design pa~ wllleter to change from one type of behavior to another. Engineering problem solving can be a comhination of art and science. 'rile complexity and accuracy of a solution will depend on the information available or what is dc~ sired in the final solution. If you arc simply performing a rough (back of the envelope) cost estirnatc for a process design, perhaps a simple stcady~state material and energy bal~ ance will suffice. On the other hand, if an optimum design integrating several unit operations is required, then a more complex solution will be involved.
1.4
BACKGROUND OF THE READER It is assumed that the reader of this textbook htls a sophomore- or jUllior~levcl chemical engineering background. In addition to the standard introductory chemistry, physics, and mathematics (including dilTerential equations) eourse,S, the 'student has taken an introduction to chemical engineering (material and energy haJ;:mces, reaction stoichiometry) cour,Se. This textbook can also be used by an engineer in industry who nceds to develop dy~ namic models to perform studies to improve a process or design controllers. Although a few years may have lapsed since the engineer took a differential equations course, the review provided in this text should be sufficient for the development and solution of models based on differential equations. Also, this textbook can serve as review material for firstyear graduate student who is interested in process modeling, systems analysis, or numerical methods.
1.5
HOW TO USE THIS TEXTBOOK The ultimate objective of this textbook is to be able to model, simulate, and (more importantly) understand the dynamic behavior of chemical processes.
1.5.1
Sections
In Section I (Chapters ] and 2) we show how to develop dynamic models for simple chemical processes. Numerical techniques for solving algebl'
Sec. 1.6
Courses Where This Textbook Can Be Used
uks 1 through lO) consists or a number of learning modules cussed in Sections I through IV.
1.5.2
13 10
reinforce the concepts dis-
Numerical Solutions
It is much casier to learn a new topic by "doing" rather than simply reading about it. To understand the dynamic behavior of chemical processes, one needs to he able 10 solve differential equations and plot response curves. We have used the MATLAB numerical analysis package to solve equations in this text. AMATL.AB learning module is in the set
of modules in Section V (Module I) for readers who arc not
l~ulliliar
with or need to be
reintroduced to MATLAB. MATLAB routines arc detailed within the chapter that they arc used. Many of the examples haveMA"rLAB m-files associated with them. It is recom~ mended that the reader modify these Ill-files to understand the effect of parameter changes
on the numerical solution.
1.5.3
Motivating Examples and Modules
This textbook contains III any process examples. Often, new techniques arc introduced in the examples. You are c.ncouraged to work through each example to understand how a palticular technique can be applied. There is a limit to the complexity of an example that can he used when introducing a new technique; the examples presented in the chapters tend to be short and illustrate one or two numcricaltcchniqucs. 'fhere is a set of modules of t11odeb, in Section Y, that treats process examples in much more dclail. The objective of these modules is to provide a more complete treatment of modeling and simulation of a specific process. In each process modehng module, a numher of the techniques introduced in various chapters of the text arc applied to the problem at hancL
1.6
COURSES WHERE THIS TEXTBOOK CAN BE USED This textbook is based on a required course that 1 have taught to chemical and environmcntal engineering juniors at Renssclaer since 1991. This dynamic systems course (originally titled lumped parameler syslems) is a prerequisite to a required course on chemical process control, normally taken in the second semester of the junior year. This textbook can be used for the first term of a two~tcrm sequence in dynamics and control. I have not treated process control in this text because 1 feci that there is a need for more in-depth coverage of process dynamics than is covered in most process control textbooks. This textbook can also be lIsed in courses such as process modeling or numerical methods for chemic111 engineers. Although directed towards undergraduates, this text can also be used in a first-year graduate course on process modeling or process dynamics; in this case, much of the focus would be on Section IV (nonlinear analysis) and in-depth studies of the modules.
Introduction
14
SUMMARY At this point, the reader should be able to define or characterize the following • Process model Lumped or distributed parameter system
Analysis Simulation
FURTHER READING The textbooks listed below are nice introductions to material and energy balances. The Russell and Denn book also provides an excellent introduction to models dynamic systems.
or
Felder, R.M., & R. ROllsseau. (1986). Processes, 2nd cd. New York: 'Wiley.
ElementalY Principles
ql Chemica!
Hinmlclblau, D.M. (1996). Basic Principles and Colclllation.'; ill Chemical E'/lJ;i/leering, 6th cd. Upper Saddle River, NJ: Prentice-Hall. Russell, T.R.F., &M.M. Denn. (1971). Introduction to Chemico! !'.'nginecrin/!.
Ihudysis, New York: Wiley. A comprehensivc tutorial and reference for MA'fLAB is provided by Hanselman and Littlefield. Thc books by l~ttcr provide many excellent examples Llsing MATLAB to solve engineering problems. lIanselman, D., & B. Littlefield. (1996). Maslerill,\!. MATLAB. Upper Saddle River, NJ: Prentice-Hall. [~lter,
n.M. (199]). Engineering ProlJlem Soh'ing Ivilh MATLAB. Upper Saddle River, NJ: Prenticc-Ilall.
E~tter,
D.M. (t096). Introduction to MA TLAU ,Ii)r engineers (/nd c)'CiCllfists. Uppcr Saddle Rivcl', NJ: Prentice-rlalt.
The following book by Dcnn is a graduate-level text that discusses the more philosophical issues involved in process modeling.
Denn, M.M. (1986). Process iV/odcling. New York: Longman. An undergraduate control textbook with significant modeling and sitnulation is by Luyben. Numerous FORTRAN examples are presented. Luyben, \V.L. (1990). Process Modeling, 5'imulatioll alld Control for Chemical EI1Rineers, 2nd cd. New York: McGraw-HilL
Student Exercises
15
A nmnber or control textbooks contain a limited amount of Illodeling.
[~xal11p1cs
include:
Seborg, D.E., TJ'·. Edgar, & D.A. Mellichamp. (1989). Process Dynamics and COIltrol. New York: Vhley. Stephanopmdos, G. (l9X4). Chemical Process Control: An Introduction to Theory and Pract{(·e. r':nglewood Clift's, NJ: Prentice-Hall. The following book by Rameriz is more of all advanced undergraduHtelfirst-ycar graduate student text on numerical methods to solve chemical engineering problems. The emphasis is on FORTRAN subroutines to be used with the IMSL nmlleriea! package. Rameriz, W.F·, (1989). Computational 111ethods for Process SiJllulalioJl. Boston: Butterworths. Issues in process modeling are discllssed by IIimlllelblau in Chapter :1 or the following book: Bisio, A., & R.I.. Kabel. (1985). S'c'oleujJ
(~l ('hemicol
Processes. Nc\v York: V.,Iilcy.
The following book by Reich provides an excellent perspective on the glohal ecollomy
and role played by U.S. workers Reich, R.B. (1991). The Work qFNatiolls. New YOJ'k: Vintage Books,
STUDENT EXERCISES 1. Review the matrix operation:-; module (Section V). 2. \Vork through the MATLAB module (Section V),
3. Consider example 2. If there is a sudden increase in stearn prc.l-;surc (and therefore, temperature) sketch the expected eoJd~sjde temperature profilel-; at 0, 25, 50, 75, and loor;;;) or the distance through the heat exchanger.
PROCESS MODELING
2
In this chapter, a methodology for developing dynamic models of chcmicL11 processes is presented. After studying this chapter, the student should be able to: \Vritc balance equations using the integral or instantaneous methods. Incorporate appropriate constitutive relationships into the equations. Determine the state, input and output variables, and parameters for a particular model (set of equations). Determine the necessary in!~)tmatjon to solve it system of dynanlic equations. Define dinlcnsionlcss variables and parameters to "scale" equations. 'file major sections arc: 2.1
16
Background
2.2
Balance Equations
2.3
Material Balances
2.4
Constitutive Relationships
2.5
Material and Energy Balances
2.6 2.7 2.8 2.9
DistribulcdParamclcr Systems DimcllsionlcssModels Explicit Solutions loDynamic Models General ItOI'm
or Dynamic Models
Sec. 2.2
2.1
17
Balance Equations
BACKGROUND Many reasons for developing process modeLs were given in Chapter 1. Improving or unm(~jor overall objective for developing a dynamic process model. These models arc often used for (i) operator training, (ii) process design, (iii) safely system analysis or design, or (iv) control system design.
derstanding chemical process operation is a
Operator Training. The people responsible for the operation of a chemical manufacturing process arc known as process operators. A dynanlic process model catl be lIsed to perform simulations to train process operators, in the same fashion that flight sjm~ ulators arc used to train airplane pilots. Process operators call learn the proper response to upset conditions, before having to experience theill on the actual process. Process Design. A dynamic process model call be llsed to properly design chcmical process equipment for a desired production rate. F'or example, a model of a batch chemical reactor can be used to determine the appropriate size of the reactor to pro~ duce a certain product at a desired rate. Safety. Dynamic process models can aLso be used to design safety systems. For example, they can be llsed to determine how long it will takc after a valve Ltils for a system to reach a certain pressure. Control System Design. Feedback control systenls arc used to maintain process variables at desirable valucs. For cxample, a control system may measure a product temperature (an output) and adjust the steam Ilowratc (an input) to maintain that desired temperature. r'or complex systems, particularly those with many inputs and outputs, it is necessary to base the control system design on a process model. Also, before a COI11plex control system is implemented on a process, it is normally tested by simulating the expected performance u~ing computer simulation.
2.2
BALANCE EQUATIONS The emphasis in an introductory matcrial and energy balances tcxtbook is on steady-state balance cquations that have the rollowing form:
mass
I F~qlU1tion
01·
--mass or e'l1crgy :
energy]
cntcnng a systcm
-
leaving (l
=
0
(2. I )
systcm
(2,1 )is deccptively simple becausc there may be many ins and outs, particulmly for component balances. The in and out terms would then include thc gcneration and con-
Process Modeling
18
Chap. 2
version of species by chemical reaction, respectively. In this text, we arc interested in dynamic balances that have the form:
1-,
rate of mass (~r CT~crgyl rate of mass or accumulation 111 = .energyentering [ [ a system a system
-
ale of mass or)
enelgy leavmg a system
(2.2)
The rate of mass accumulation in a system has the form dM/dl where M is the total mass in the system. Similarly, the rate of energy accumulation has the form dEJdt where E is the total energy in a system. H Hi is llsed to represent the moles of component i in a system, then dN/dt represents the molar rate of accumulation of component i in the systclll. \Vhcn solving a problem, it is important to specify what is meant by system. In some cases the systcl1lmay be microscopic in nature (a e1i/Terential clement, for example), while in othcr cases it may be macroscopic in naturc (the liquid content of a mixing tank, for example). Also, when developing a dynamic model, we can take one of two general viewpoints. One viewpoint is based on an ifltegral balance, while the other is based on an instml{(lIIcoll.\· balance. Integral balances arc particularly useCul when developing models for distributed parameter systems, which result in partial differential equations; the focus in this text is on ordinary differential equation-based models. Another viewpoint is the instantaneous balance where the time rate of change is written directly.
2.2.1
Integral Balances
An integral balance is developed by viewing a system at two different Sll
mass or energy inside the system
[
atl+tJ.1
I
[mass or energy -
I
inside the system all
. mass or energy entering the system from t to t --I- 6.t
r
-
1
mass or energy ] leavmg the system
It om I to I
+
(2.3)
tJ.1
The rnean-value theorems of integral and differential calculus are thcn used to reduce the equations to differential equations. F·'or example, consider the system shown ill F'igure 2.1 below, where one boundary represents thc mass in the systcm at time t, while the other boundary represents the mass in the system at t + i1t. An integral balance 011 thc total mass in the system is writtcn in the form:
Sec. 2.2
Balance Equations
19
mass in system at time
)If
,r
=:
t
mass in system at time:= t+!\ t
mOUf (f) FIGURE 2.1 Conceptual material balance prohlem.
n~ass contained III
the system
I rn~ass -
In
all+Llt
I
contained the system
mass culcI ing the system
=
r
from t to (
all
j-
D.,
Ir -
mass ICdving the system
I
hom I to t -I nl
Mathematically, this is written: I I ~I
fiLii
MI, '"' - MI, J ';'i" iiI - J 11/"", lif or 1-1-,1/
MI'i"' - MI,
=
J(,izi" - ,iz,,,,,l dl ,
(2.4)
where M represents the total mass in the system, while filill andli1()111 represent the mass rates elltering and leaving the system, respectively. We can write the righthand side of (2.4), using the mean value theorem of integral calculus, as:
f,
1+ !:J./
(';/ill - filma> dl
where 0 < (X < 1. Equation (2.4) can now be written:
dividing by dt,
MI"",__ MI, = ( . . II D..f 111'-1/ -
lJlo"t
l!nM
and using the mean value theorem of dUferentia! calculus (0 < ~ < I) for the Icfthand side,
MI"",~ />1
MI,
,1M,
;it
[+IUI
20
Process Modeling
Chap. 2
which yields dM ~i;- I I ~
. .
I
= (1l1 iJi - In""J II
lIj.f
Taking the limit as At goes to zero, we find dM dl
.
= mill -
.
(2.5)
111,,,,(
and representing the total mass as M = VP"h ifl as FillPill andlilo!ll as FOII/p, where p is the mass density (mass/volume) and F is a volumetric nowrate (volume/time) we obtain the equation: (2.6)
Note that we have assumed that the system is perfectly mixed, so that the density of material leaving the system is equal to the density or material in the system.
2.2.2
Instantaneous Balances
Here we write the dynamic balance equations directly, based on an instantaneous change:
I I
l
the laic 01 accumulatIOn of
mass
III
the system
·
I
rate of mass entering
=.::
I
the system
]
1.. -
rate of
.1
mass leaving
the system
ratc~of~
(2. 7)
which can be written directly as,
dM
df ---
J11 in .- l1I o l1!
(2.8)
or dVp ~ d/
(29)
which is the same result obtained using an intcgral balancc. Although the integral balancc takes longer to arrivc at the same resull as the instantaneous balancc method, the integral balance method is probably clearer whcn dcvcloping distributed parameter (partial differential equation-hased) models. An cxnmplc is shown in Section 2.6. Section 2.3 covers material balances and Section 2.5 covers material and energy balances. Section 2.4 discusses constitutive relationships.
2.3
MATERIAL BALANCES 'l'he simplcst modeling problems consist of material halances. [n this section we usc several process exarnples to illustrate the modeling techniques used,
Sec. 2.3
21
Material Balances
-~----~----
EXAIVIPLE 2.1
----
----~-------------
Liquid Suq.:e Tank
Surge tanks arc often Llsed to "smooth" f10wratc fluctuations in liquid streams f!mvillg between chemical processes. Consider a liquid surge tank with one inlet (flowing from process I) and one outlet stream (flowing to process Ii) (Figure 2.2). Assume that the dellsity is constant. Find how the volume of the tank varies as a function of time, if the inlet and outlet flowratcs vary. List the s((ltc variables, [Jarometers, as weI! as the il/fJut and oll/Im/voriables. Give the necessary information to complete the quantitative solution to this prohlem.
v •• F
_ _ _ _ _- L
FIGUnE 2.2
L,iquid surge tank.
The system is the liquid in the lank, the liquid surface is the top boundary of the system. 'rile following notation is used in the modeling equations: F,
~
inlet volumetric r10wrate (volume/time)
F
~
outlet volumctric f10wratc
V
volumc of liquid in thc tank
P
liquid dcnsity (mass/volullle)
Integral i\'lethod Consider a fillite time intcrval, !J.l. Performing a material balance over that time interval,
J11dSS 01 \Vdlel] [tlldSS 01 WdtCl ] lllslde the lank - lllSldc the td.nk
!J.t
elt I
mass of water] [lllass of walcr entering lank leaving tank
froJ11 ( to I -f- !:it
from I to t 1- ill which we can write InalhcmaticaHy as: (', .3.1
Jr:p dt
,
ESCOL/\ Dc Ei CIULlO
i
1\':'1
J
,
Fpdl
(2.10)
Procoss Modeling
22
Chap.2
Bringing the righthand side terms under the same integral
J(r,:p
1;"\/
vpl, ..\< .- vpl, -
I-i,) rlr
(2.11 )
We can lise the mean value theorem of integral calculus to write the righthand side of (2.11) (where 0 So: 0' :::; 1) as: I !j{
J(1';1' --- I'p)
dl
(2.12)
Vpll'''' vpll
(2.13)
,
Substituting (2.12) into (2.11)
Dividing by f),.t, we obtain
vpl, ,', __ JlPI, ~ (r- r 11 b.t
IP
PI","
(214)
and using the lucan value theorem of differential calculus. as !\.r' ;. 0
dVp dt
(2.15)
InstantaneOllS Method Here we write the balance equations based on an inslautancOU:i rate of-change:
-the rate of ch,~ngc of -I = I.mass n~l\vratc (}C..I Imass flowratc of-I 1mass of water tank _water lllln tank water out of tank_ III
The total mass of water tn fhe tank is Vp, the rate of change is dVp/dt, <:Inc! the density of the outlet stream is equal to the tank contents:
dyp dt
(2.16)
which is exactly what we derived using the intcf{ral method. Given the same set of assumptions the two methods should yield the sam<.~ rnodel. You should usc the approach (integral or instantaneous) that makes the most sense to YOL!o In this. text we generally usc the illstantaneous approach since it requires the fewest number of steps. Notice the implicit assumption that the density of water in the tank docs not depend upon position (the perfect mixing assumption). This ai>sumption allows an ordinary differential cqlJa~ tion (ODE) formulation. \Ve refer to any system that can be modeled by ODEs as lumped parameIer systems. Also notice that the outlet stream density must be equal to the density of water in the tank. This knowledge also allows us to say that the density terms in (2.16) arc equal. This equation is then reduced 101 lit might he tempting to the reader to begin to direuly write "volume balance" exprt'ssions that look similar to (2.17). We wish to make it clear that therc is llO such thing as a volume balance and (2017) is only correct hecause of the constant density assumption. It is a good idea to always write a mass balance expn:ssion, such ::1S (2.16), before making as~;umpti()ns about the fluid density, which Jllay lead to (2.17).
Sec. 2.3
Mntcrial Balances
23 dV
1-; -- F
dt
(2.17)
Equation (2.17) is it lineDr ordinary dilTcwntial equation (ODE), which is trivial to solve if we know the inlet and outlet flowmtes as a fllnction of time, and if we know all initial condition for the volume in the wnk. In equation (2.17) we refer to Vas a slale variable, and F; nnc! F as input variah!cs (even though Fis an outlet stream flowratc). If dellsity remained in the equatioll, \VC would refer to it as a /NlrWJlctcF. tn order to solve this problem \ve nlUst specify the inputs F/t) andF(t) and the initial con·
dition \1(0).
Exanlple 2.1 provides all introduction to the notion of states, inputs, and parameters. This cxarnple illustrates how an overall material balance is llsed to find how the volume of a liquid phase system changes with time. It may he desirable to have tank height, II, rather than tank volume as the slate variable. If we aSSUlllC a constant tank cross-sectional area, ll, we call express the tank volumc as V = Aft and the modeling eqU<:ltion as dli dl
F
A
(2.18)
it
If we also know that the flowrate out of the tank is proportional to the square ront of the height of liquid in the tank, wc can usc the relationship (sec student exercisc 21) F = [3VIi
(2.19)
where 13 is a J'lmv coefficient, to find dli
[3VIi
dt
A
,( -I
A
(2.20)
For tbis model \ve refcr to h as the stole variablc, inlet nowrate (F) as the input variable and f3 and A as parameters. Notice that a single system (ill this case, the liquid surge tank) can have slightly different modeling equations and variables, depending on assumptions and thc objectives used whcn dcve-Jopiug the model.
EXAi\iIPI.,E 2.2
An Isothernwl Chemi<:al Rcactor
Assume that two chemical species,;\ and 8, arc in a solvent feedstream entering a Iiquid~phase chemical reactor that is maintained at a constant tcmperature (l"igurc 2.3). The two spec'lc::, react irreversibly to form a third species, F. Find the reactor concentration of each species as a ftlllClion of time.
Process Modeling
24
Chap. 2
F. I
C
I
F C
FIGlJRE 2.3
Isothermal chemical reactor.
Overall Material Balance The overall mass balance is (since the tank is perfectly mixed)
(2.21) The liquid phase density, p, is not a function of concentration, The tank (and outlet) density is then cqllallo the inlet density, so:
ASSlIIllption:
Pi
P
(2.22)
and we can write (2.21) as:
dV tit
(2.23)
Component IVIaterial Balances It is convenient to work in molar units when writing component balances, particularly if chemical reactions arc involved. Let (,'1\' ('/I. and C" represent the molar concentrations of A, H, and P (moles/volume). Assume that the stoichiometric equation for this reaction is
The component material balance equations are (assuming no component P is in the feed to the reactor):
(Ive A dt dVC II dl dVC,. dl
(2.24)
(2.25)
(2.26)
Sec. 2.3
25
Material Balances
Where 1~4' rr;, and I'p represent the rate of generatioll of species;\, II, and P per unit volume, and (~li and C'/li represent the inlet coneentallons of species A and N. Assume that the rate of reaction of A per unit volume is second-order and 11 function of the concentration of both A and B. The reaction rate can be written (2.27)
where k is the reaction rate constant and the minus sign indicates that A is consumed ill the reaction. Each mole of A reacts with two moles of If (frotH the stoichiometric equation) and produces olle mote of I), so the rates of generation of Band P (per unit volume) arc: (2.2X)
(2.29) Expanding the [cftlland side of (2.24),
dVC A
f'
C dV
df
'/I
dt
(2.30)
combining (2.23), (2.24), (2.27), and (2.30) we find:
(2.31) Similarly, the concentrations of n aud P call be written
dell
(2.32)
df
(2.33) This model consists of four differential equations (2.23, 2.31, 2.32, 2.33) and, therefore, four state variables (V, c~\, C n. and C,,). To solve these equations, we must specify the initial conditions (V(O), CA(O), C/:I(t», and C,,(O)), the inputs (Fi . C Ai, and e/li) as a function of time, and the parameter (k).
2.3.1
Simplifying Assumptions
The reactor model presented in Exalnple 2.2 has four differential equations. Often other simplifying assumptions arc made to reduce the number of differential equations, to make theln easier to analyze and faster to solve. For example, assmning a constant volume (dVldt:::: 0) reduces the number of equations by one. Also, it is common to feed an excess of one reactant to obtain nearly completc conversion of another reactant. If species B is maintained in a large excess, then CHis nearly constant. The reactioll rate cqual'101l can then be expressed: I'.1
(2.34)
26
Process Modeling
Chap. 2
where kl
The resulting differential
equation~
=
(2.35)
kel/
are (since we assumed dVldt and dClldt::: 0)
de"
(2.36)
cit
(2.37) Notice that if we only desire to know the concentration of species A we only need to solve one differential equation, since the concentration A is not dependent on the concentration of P.
or
EXAMPLE 2.3
Gas Surge Drum
Smgc drums are oncn used as intermediate storage capacity for gas streams that arc lransfclTcd hctween chemical process units. COl1::-idcr a drum depicted in Figure 2.4, where (fi is the inlet Inola!" Ilowratc and q is the outlet molar tlowrate. Here we develop a model that describes how the pressure in the tank varies with time.
q. I
{
)--
p
FIGliRE 2.4
q
Gafi surge drum,
Let V = voJurne of the drum and V::: molar volume of the gas (volome/mole). 'rhe total amount of gas (moles) in the tank is then VI\/.
Assumption:
The pressure-volume relationship is characterized hy the ideal gas law, so PV= NT
(2.3H)
where P IS pressure, T is temperature (absolute scale), and R is the ideal gas constant. Equation (2.38) can be written
1
P
if
RT
(2.39)
and, therefore, the total amount of gas in the tank is
v V
PV
NT = total amount (moles) of gas in the tank
(240)
the rate of accumlation of gas is then d(PV/NT)/dt. Assume that T is constant; since Vand Rare also constant; then the molar rate of accumlatioll of gas in the tank is:
Sec. 2.4
27
Constitutive Relationships V tiP RT dt ~ 'Ii - 'I
(2.41)
where q,: is the molar rate of gas entering the drum and q is the molar rate of gas leaving the drum. Equation (2.41) can be written
dP dt
RT V (qi-q)
(2.42)
To solve this equation for the state variable P, we must know the illfJll1s lfi and q, the parameters R, 1; and V, and the initial condition P(O). Once again, although (j is the molar rate Ollt of the drulll, we consider it an input in terms of solving the model.
2.4
CONSTITUTIVE RELATIONSHIPS Examples 2.2 and 2.3 required Illore than simple material balances to define the modeling equation::;. These required relationships are known as constiflltive equations; several examples of constitutive equations are shown in this section.
2.4.1
Gas law
Process systems containing a gas will normally need a gas-law expression in the model. The ideal gas law is commonly used to relate molar volume, pressure, and temperature:
PV= RT
(2.43)
The van del' Waars FVT relationship contains two parameters (a and b) that are systcm~ specific:
(P + \12a) (V, - b) =
RT
(2.44)
For other gas laws, sec a thermodynamics text such as Smith, Van Ness, and Abholl (1996).
Chemical Reactions
2.4.2
The rate of reaction pCI' unit volumc (mollvolume*timc) is usually a function of the con~ centration of the reacting species.I;or example, consider the reaction A + 2B --> C + 3D. If the rate of the reaction of A is first-order in both A and B, we use the following expression: (2.'15)
where rA
k CA CjJ
is the rate of reaction of A (mol A/volume*time) is the reaction rate constant (constant for a given temperature) is the concentration of A (mol A/volume) is the concentration of B (mol B/volume)
Process Modeling
28
Chap.2
Reaction rates arc normally expressed in terms of generation of a species. The minus sign indicates that A is consumed in the reaction <:lbovc. Il is good practice to associate the units with all parameters in a model. For consistency in the units for 1"1\> we find that k has units of (vol/mol B* time). Notice that 2 mols of B react for each mol of A. Then we can write 1'8 ,--
2rA
=
r/!
- 2k C~,Cll k C't\C: n
rc
~
rf)
-- JrA c. 3
=
k C"C"
Usually, the reaction rate coefficient is a function of temperature. The most commonly used representation is the Arrhenius rate law k(T) = A expC -10/ /IT)
(2.46)
where k(T) :::: reaction rate constant, as a function of temperature A ;::; frequency nlctor or prccxponcntial factor (sanle units as k) 10 = activatioll ellergy (cai/glllol) R :;:;: ideal gas constant (1.987 caJlgmol K. or another set of consistent units) T :::; absolute temperature (dcg K or dcg R)
The frequency factor and activation energy can be estimated data of the reaction constant as a function of reaction temperature. Taking the natural log of the Arrhenius rate 1mv, we find:
in k
InA - F'
=
/I
(I)T
(2.47)
and we sec that A and E can be found from the slope and intercept of a plot of (In k) versus (117).
2.4.3
Equilibrium Relationships
The relationship between the liquid and vapor phase compositions of component i, when the phases arc in equilibrium, can be represented by:
v,
.
(2.48)
where Xi
::;:
liquid phase mole fraction of component i
Yi :;;: vapor phase mole fraction of component i
Ki
:;:;:
vapor/liquid equilibrium constant for component i
The equilibrium constant is a fUllction of composition and temperature, Often, wc \vill sec a ('otis/an! relative volatility aSSUlllption made to simplify vaporlliquid equilibrium models.
Sec. 2.4
Constitutive Relationships
29
In a binary system, the relationship between the vapor and liquid phases for the light component often used is: (xx l' =
.
I + (
(2.49)
x :::: liquid phase mole fraction of light component y ::;: vapor phase mole fraction of light component (X :::: relative volatility Co. >. I)
Heat Transfer
2.4.4
The rate or heal transfer through a vessel wall separating two fluids (a jacketed reador, for example) can be described by (2.50)
where
Q U ;\ fiT
:::: rate of heat trallsfcrcd from the hot tluid to the cold fluid ;:;;;; overall heat transfer coefficient ::::: area for heat transfer = difference between hot and cold fluid temperatures
The heat transfer coefficient is onon estimated from experimental data. At the design stage it can be estimated from correlations; it is a function of fluid properties and velocities.
Flow-through Valves
2.4.5
The flow-through valves are often described by the following relationship: F
( ',.t.(.\') \1JAP,. , s.g.
(2.51 )
where
F Cl' x
:::: volumetric f10wrate valve coefficient fraction of valve opening 0./\ :::: pressure drop across the valve s.g. :::: specific gravity of the fluid J(x) :::: the flow characteristic (varies from () to 1, as a function of .r) Three common valve characteristics arc (i) linear, (ii) equal-percentage, and (iii) quickopening.
Process Modeling
30
Chap. 2
0.8 ~ 0
~
quick-opening 0.6
15 c 0
t .:g
0.4
linear
02
equal·percentage
FIGURE 2.5 r~'low characteristics of control valves. (I::::::::' 50 for cqualpercentage valve.
0 0
0.2
0.4
0.6
0.8
fraction open
For a linear valve
f(x)
0"
x
For an equal-percentage valve
f(x)
,,'
1
For a quick-opening valve
f(x)
~
',Ix
The three characteristics arc compared in Figure 2.5. Notice that for the quick~opcning valve. the sensitivity of flow to valve position (fraction open) is high at low openings and low at high openings; the opposite is true for an cqual~pcrcclltagc valve. 'fhe sensitivity of a linear valve docs not change as a function or valve position. The equal-percentage valve is commonly used in chemical processes. because of desirable characteristics when installed in piping systems where ;:1 significant piping pressure drop occurs at high Ilowrates. Knmvledgc of these characteristics \vill be important when developing !cedback control systems.
2.5
MATERIAL AND ENERGY BALANCES Section 2.3 covered models that consist of material balances only. These arc useful if thermal effects arc not important, \vhere systcm properties, reaction rates, and so 011 do not depend on temperature, or if the system is truly isothennal (constant temperature). Many chemical processes have important thermal effecls, so it is necessary to develop material and energy balance Illodels. One key is that a basis must always be selected when evaluating an intensive property such as enthalpy.
Sec. 2.5
2.5.1
31
Material and Energy Balances
Review of Thermodynamics
Developing correct energy balall(:c equations is not trivial and the chemical engineering literature contains many incorrect derivations. Chapter 5 of the book by DCl1Il (1986) points out numerous examples where incorrect energy balances "vert used to develop pnlCcss models. The total energy erE) or a system consists of internal (U), kinetic (KE) and potential energy (Pf{):
TE
U -I KE
+ PI'
where the kinetic and potential energy terms arc:
1 , 2 111\'-
I'E
mgh
Often we will lise cncrgyltnolc or energy/mass and write the following A
U
no""~
TE
+ KE
A
-I 1'10'
U -I K I,' -I I' E
where II and represent per mole and per mass, respectively. The kinetic and potelltial ellergy terms, on a mass basis, arc 1
KE PE
,
2u ~
gil
[,'or most chemical processes where there arc thermal effects, we will neglect the kinetic and potential energy terms because their contribution is generally at least two orders of inagnitude less than thai of the internal energy tcnn. When dealing with flowing systems, we willuslIally work with enthalpy. Total enth;:Jlpy is defined as:
II
U -I pV
11
U I pV
while the enthalpy/mole is
and the enthalpy/mass is (since p::::: 1/( \I)
II
If -I pV
U I·
p
i'
we will make usc
or these relationships in the following example.
Process Modeling
32
EXAMPLE 2.4
Chap. 2
Stirred Tank Heater
Consider a perfectly mixed stirred-tank heater, with a single feed stream and a single product stream, as shown in Figure 2.6. Assuming that the f10wratc and temperature of the inlet stream can vary, that the tank is perfectly insulated, and that the rate of heat added per unit time (Q) can vary, develop a modcllo find the tank temperature as a function of time. Slate your assumptions.
F. I
~
T. I
V
T F T Q
FIGlJRE 2.6
Stirred tank
hl~ateL
Material Balance accumulation
=--=
in - out
dVp
(252)
dt
Energy Balance accumulation = in by flow - out by flow -+- in by heat transfer -+- work done on system dTE •• r;p,T Ei -FpTE + Q + W, df Here we neglect the kinetic and potential energy:
dU dt
~
FIIlI., I · I FI'U ,
f).' ~
WI
(2.53)
We write the total work done on the system as a combination or the shaFt work and the energy added to the system to get the-fluid into the tank and the energy that the system performs on the surroundings to force the fluid out.
(254) This allows us to write (2.53) as:
j.
Pi) _l'jJ(Uj p) + Q + W, Pi
P
(2.55)
Sec. 2.5 and since II
33
Material and Energy Balances "=
U + P\/, we can rewrite (2.55) as
tit
dpV tit
"'Pi Hi -- Fp 11 -I- Q -1-- W,
(2.56)
Since, rip Vld, = V dpldl + P dVldt, if the 1'011111/(-' is cOl/slall! and tile mean pressure change can be neglected (a good assumption for liquids), we can write
(2.57)
We must remember the assumptions that went into the development of (2.57): 'fhe kinetic and polential energy effects were neglected.
The change in p\l term was neglected. This is a good assumption for a liquid system, provided I\p is not too large and constant volume is assumed. The total enthalpy term is:
II
Vp 11
and assullling no phase change, we select an arbitrary reference temperature U:_,j) for enthalpy: r
ii(T)
~. Jc,,
'.
Often we aSSU!llc that the heat capacity is constant, or calcuated at an average temperature, so
ll;
1;,,)
c,,(7'
II =
(2.58)
c>( T; - 7~,,-,)
(2.59)
We now write the energy balance (2.57) In !he following fashion:
d(Vpc"CI' dt
T",))
(2.(>0)
lIsing the asslIIJlplio/ls of constant density and volume (so Fi
V'"
='
0::
F; from (2.52». we filld
F pc'I(T -- Trei.) - (T-- T rei )1 )· l
j
.
+
/il
(2.61 )
~
or
F V (/;- T) I 0::
Q Vpcf
-I !
w
(2.62)
Veep
dTidt. Also, neglecting WI' we can write
F
dt
V
/i (1-1')1" '
.
(2.63)
\fpc"
In ordcT to solve this problem, we must specify the parameters \I, p, (as a function of time), and the initial condition '1(0),
c[J'
the inputs F. Q, and Ti
Process Modeling
34
2.6
Chap. 2
DISTRIBUTED PARAMETER SYSTEMS In this section we show how the balance equations can be used to develop a model for a distributed parameter system, that is, a system where the state variables change with re~ spect to position and time. Consider a tubular reactor where a chemical reaction changes the concentration of the fluid as it moves down the tube. Here we usc a volullle clement 6. V and a time clement Lll. The total moles or species A contained in the clement 6. V is written (6. V)Ck The amount of species A entering the volume is FcAI v and the amount of species leaving the volume is FC) F-,-:.W' The rate of A leaving by reaction (assuming a first-order reaction) is ( k C~,)n
v.
The balance equation is then: I + ill
(n V) C:, I, ,'" - (n V)CAI,
f,
=
[FC"lv - Fc"lv"v - kC"n V] £It
Using the mean value theorem of integral calculus and dividing by D.f, wc find: (2.64)
Dividing by D.. V and letting ti.t and L.i. V go to zero, we find:
aFC --" av - kCA
iiCA
at
(265)
Normally, a tube with constant cross-sectional area is used, so elV;:::: Adz and F :::: Av z' where V z is the velocity in the z-dircction. Then the equation can be written: g(~A iJt
av_c, --'--'- - kC iJz
A
(2.66)
Similarly, the overall material halance can be found as: rJp
at
~Vi:P iJz
(2.67)
If the fluid is at a constant density (good assumption for a liquid), then we can write the species balance as
'1'0 solve this problem, we must know the initial condition (concentration as a function of distance at the initial time) and one boundary condition. For example, the following boundary and initial conditions C~,(z,
t = 0) = CAO(Z) CA(O, t) = CA;,,{t)
(2.69)
Sec. 2.7
Dimensionless Models
35
indicate that the concentration of A initially is known as a function of distance down the reactor, and that the inlet concentration as a function of time must be specified. In deriving the lubular reactor equations we assumed that species A left a volume element only by convection (bulk now). In addition, the molecules can leave hy virtue or a concentration gradient. For example, the amount elltering at V is (2.70)
where is the diffusion coefficient. The reader should be able to derive the following
reaction-diffusion equation (sec exercise 19). (JC~\
(27])
at
Since this is a second-order PDE, the initial condition (C~\ as a function of z) and two boundary conditions must be specified. Partial differential equation (PDEs) models are much more difficult to solve than ordinary differential equations. Generally, PDEs arc converted to ODEs by discretizing in the spatial dimension, then tcchniques for the solution of ODEs can be used. 'rile rocus of this text is on O[)Es; with a grasp or the solution of ODr~s, one can then begin to develop solutions to PDEs.
2.7
DIMENSIONLESS MODELS Models typically contain a large number of parameters and variables that may differ in value by several orders of magnitude. It is orten desirable, at least for analysis purposes, to develop models composed of dirnensionless parameters and variables. 'To illustrate the approach, consider a constant volume, isothcnnal CSTR moue led by a simple first-order reaction:
It seems natural to work with a scaled concentration. Defining x ~ C/C,,/0 where C AID is the nominal (steady-state) feed concentration of A, we rind
where Xj= CN/CAIO ' It is also natural to choose a scaled time, T = //1< where I'" is a scaling parameter to determined. We can usc the relationship df = f"'dT to write:
be
36
Process Modeling
Chap. 2
dx {:;:dr
A natural choice for 1*' appears to be VIF (known as the residence time), so
dx =x·(Vk) 1+ .···x I F
dT
The term VklF is dimensionless and known as a Damkholcr Ilmnber in the reaction engineering literature. Assuming that the feed concentration is constant, .'j::;: I, and letting Ci;::: Vk/F, we can write: dOl I ~X -+- (Xx (IT which indicates that a single parameter, (X, can be used to characterize the behavior of all first-order, isothermal chemical reactions. Similar results arc obtained if the dimensionless state is chosen to be conversion
2.8
EXPLICIT SOLUTIONS TO DYNAMIC MODELS Explicit solutions to nonlinear differential equations can rarely he obtained. The most common case where all analytical solution can be obtained is when a single differential equation has variables that are separable. This is a very limited class of problems. A main objective of this textbook is to present a number of techniques (analytical and numerical) to solve more general problems, particularly involving many simultaneous equations. In this section we provide an example of problems where the variahles are separable.
EXAlVIPLE 2.5
Noulincln Tank Height
Consider it Lank height problem where the outlet flow is a nonlinear function of lank height:
tilt d/
r~
Il
1\
i\
v1/
Here tbere is not au analytical solution because of the nonlinear height relationship and the forcing function. 1'0 illustrate a problem with an analytical solution, we will assume that there is no inler flow to the tank:
dh df \Ve can see Ihat the variables are separable, so
tilt
v'h
Il d/ i\
37
General Form of Dynamic Models
Sec. 2.9
II
dll
(
Vii
h,.
!
-j
IJ A ell
which has the solution ~
2 v'Ji ,- 2\/h"
A (1-
U
or letting
t,,;:::
0, and squaring both sides, \ve obtain tile solution
I fl' vii --~ "
iI(I)
"
0
2/\ .
This analytical solution call be used, for example, to determine the lime that it will take for the tank height to reach a certain level.
2.9
GENERAL FORM OF DYNAMIC MODELS The dynamic models derived ill this chapter consist of a set of first-order (tncaning only first derivatives with respect [0 time), nonlinear, explicit, initial value ordinary differential equations. A representation of" a sel first-order differential equations is
or
XI =
II(.tl" .. ,_rll,uj,... ,ltm,Pt,···,fJr)
);"} --: l:(x1"",x1I'ut,···,ll/ll' PI'''''!)/") (2.72)
where Xi is a state variable, IIi is an input variable and Pi i:-; a parameter. The notation.< is used to represent drldt. Notice that there arc II equations, II state variables, III inputs, and r parameters.
2.9.1
State Variables
A stale variable is a variable that arises naturally in the accumulation tefm of a dynamic material or energy balance. A state variahle is a Tncasurable (at least conceptu;dly) quantity that indicates the state of a systelll. For example, tern perature is the COll'lIllOn state variable that arises from a dynamic energy balance. Concentration is a state variahle that arises when dynamic component balances are written.
38
2.9.2
Process Modeling
Chap. 2
Input Variables
An input variable is
2.9.3
Parameters
A parameter is typically a physical or chemical property value that must be specified or known tomathcmatically solve a problem. Parameters arc often fixed by nature, that is, the reaction chemistry, molecular structure, existing vessel configuration, or operation. Examples include density. viscosity, thermal conductivity, heat transfer coefficient, and mass-transfer coefficient. When designing a process, a parameter might be "adjusted" to achieve some desired performance. For example, reactor volume lllay be an important design parameter.
2.9.4
Vector Notation
The set of differential equations shown as (2.72) above can be written more compactly ill vector form.
x =, f(x, II, II)
(2.73)
\vhere x::;;: vector of n state variables u = vector of In input variables p :::: vector of r parameters Notice that the dynamic models (2.73) can also be used to solve steady-state probJenls, since
x=
()
(2.74)
that is,
f(x,u,p)
=. ()
(2.75)
for steady~state processes. Numerical techniques (such as Newton's method) to solve algebraic equations (2.75) will be presented in Chapter 3. The steady~state state variables from the solution of (2.75) arc often used as the initial conditions for (2.73). F'requently, an input will be changed froni its steady-state value, and (2.73) will be solvcd to understand the transient behavior of the system. 'rhe numerical solution of ordinary differential equations will bc prescllted in Chapter 4. In thc example helow we show Example 2.2 (chcmicalrcactor) in state variable form.
Sec. 2.9 ------~
EXAMPLE 2.6
39
General Form of Dynamic Models
-~~------------- ---~-----
State Variable Form for Example 2.2
COlls'lder the modeling equations for Example 2.2 (chemical reuctor)
dV dl
~F-F
(2~23)
j
(2.31 )
(2.32)
(2~33)
There are four states (V, C~\, Cu' and C p ), four inputs (Fi , F, CAi, ('/Ii), and a single parameter (k). Notice that although F is the outlet fJowrate, it is considered all input to the model, because it must be specified in order to solve the equatiolls.
v CA F
Ii (CHi -- Cli) -
2 kC,C"
F
VC/, + kCAC/I
or
X2
x,
II,
Xl
i:
(lI J -
(11 4 --
11,
x 2)
-" P.X2 X;l
x.,) -- 2
i, x4 +
P,X 2X3
.
l)l X1X;;
I'I(X,II,P)]
___ ti x,U,IJ)
- [ f,(X,II,p) J 4(x,u,p)
Process Modeling
40
Chap. 2
SUMMARY
or
A number material and energy balance examples have been presented in this chapter. The classic assumption of a perfectly stirred tank was generally used so that all models (except Section 2.6) were IUlTlped-parameter systems, Future chapters develop the analytical and Ilmllcrical techniques to analyze and sinudatc these models. The student should now understand: that dynamic models or lumped parameter systems yield ordinary differential equations.
that steady-state models of lumped parameter systcrns yield algebraic equations. The notion of a state, inpul. output, parameter. A plethora of models arc presellted in modules in the final section of the textbook. More specifically,. the following modules arc of interest: Module 5. IJcatedMixing'rank Module 6. LillcarEquilibrium Stage Models (AbsorpLioll) Module 7. Isothermal Continuous Stirred 'Tank Reactors Module 8.
Biochemicall
Module 9. Diabatic Reactor Models Module 10. Nonlinear Equilihrium Stage Models (Distillation) Each of these modules covers Illodel development and presents examples for analytical and nUlllerical calculations.
FURTHER READING A nice introduction to dlClnical engincering calculations is provided by: Felder, R.M., & R. Rousse
L'lcmcnfmy Principles r!/ C'hemicrtl
Excellent discussions of the issues involved in modeling a mixing lank, incorporating density crfects, and energy balances is provided in the follO\:ving two hooks: Denn, M.M. (1986)./Jrocess Modeling. New York: Longman. RusselL T.R.F., & M.M.Denn. (1971). Introduction Allrdysis. New York: Wiley. An introduction to chemical reaction engineering js:
lo
Chemical Engineerillg
Student Exercises
41
Fogler, H.S. (1992). Elements (d' Chcmh'ol ReaUiol/ Engineering, -'.l1d eel. Englewood Cliffs, NJ: Prentice-Ilall. An exccllenttextbook for an introduction to chemica! engineering thermodynmnics is: Smith, 1.M., ftC. Vall Ness, & M.M. Abbott. (1996). Chcmhxd Engineering Ther· fIlorfvllomics, 5th cd. New York: McGraw-HilI. The following paper provides an advanced treatment of dimensionless variables and parameters: Ads, R. (1993). Ends and beginnings in the mathematical modelling or chemical engineering systems. Chemica! l-:.'ngineering 5'cience, 48( 14). 2507--2517. 'I'he relationships for mass and heat transport arc shown in textbooks on transport phenomena. The chernicaI engineer's bible is Bird, R.B., WJ~. Stewart, & E. Lightfoot. (1960). Transpurt Phcl/oIJ/('!la. New York: Wiley. The predator-prey model in student exercise 16 is also known as the Lotka- Volterra e(luations, after the researchers that developed them in the late 1920s. A presentation of the equations is in the following text: Bailey, J .E., & DJ<'. Ollis. (1986). Biochemical Engilleerinf!, Fundamentals, 2nd cd. New York: McGraw-HilI.
STUDENT EXERCISES r~xaJ1lple 2.1 it was assumed that the input and output f10wratcs could he independently varied. Consider a situation in which the outlet flow rate is a function of the height of liquid in the tank. Write the modeling equation for tank h~ight assuming two different constitutive relationships: (i) F:::: f3h, or Oi) F:::: f3 \/h, where [3 is known as a flow c;oefficicnL You will orten sec these relationships expressed as F = h/R or F =V/ZIR, where R is a flow resistance. List the state variables, parameters, as well as the input and output variables. Give the necessary information to complete the quantitative solution to this problem. If the f10wrate has units of liters/min and the tank height has units of meters, find the units of the flow coefficients and flow resistances for (i) and (Ii).
I. In
2. Consider a conical water lank shown below. Write the dynamic material balance equation if the flow rate out gr the tank is a function of' the square root of height of water in the tank (Fo :::: f3Yh). List state variables, input variables and parameters. (Hint: Usc height as a state variable.)
ESCOLA Dc Et'-JGEi'-IHARIA BIBLI01ECA
42
Process Modeling
,
•
R
Chap, 2
•
F
i
H
~
•
Fa
3. Extend the model developed ill Example 2.2 (isothermal reaction) to handle the following stoichiometric cqu;:llion: A + B --> 21'. Assume that the volume is constant, but the change in concentration of component B cannot be neglected. 4. 13xtcnd the model developed in Example 2.2 (isothermal with first-order kinetics) to handle multiple reactions (assume a constant volume reactor).
A
2A
+ B - -> 21'
(react;on I)
+ I' - -> Q
(reaction 2)
Assume that no P is fed to the reactor. Assume that the reaction rate (generation) of A per unit volume for reaction I is characterized by expression -k1 C'A
fA
en
where the minus sign indicates that A is consumed in reaction 1. Assume that the reaction rate (generation) of A per unit volume for reaction 2 is characterized by the expreSSIon I'll
=
- k2
c/\
C/,
[I' the concentrations are ex.pressed in gmolllitcr and the volume in liters, what arc the units of the reaction rate constants? If it is desirable to know the concentration or component Q, how many equations must be solved? If our COncern is only with P, how many equations must be solved? Explain.
5. Model a mixing tank with two reedstreams, as shown below. Assume that there arc two components, A and B. C represents the concentration of A. (C, is the mass concentration 01';\ in stream I and C2 is the mass concentration of A in stream 2). Model the following cases:
F C
43
Student Exercises
a. Constant volullle, constant density. h. Constant volume, density varies linearly with concentration. c. Variable volume, density varies linearly with concentration. 6. Consider two tanks in series where the flow out of the first tank enters the second tank. Our objective is to develop a model to describe how the height of liquid in tank 2 changes \vith time, given the input flow rate fi~I(t). Assume that the flow out of each tank is a linear function of the height of liquid in the tank (F J :;:;: I3lhl and F2 :;:;: l3i12) and each tank has a constant cross~sectional area.
•
h,
to. h2
7.
8.
9. 10.
11.
F,
:b=L
F 2
A material balance around the first tank yields (assuming constant density and P, ~ (3,11,) Two liquid smge tanks (with constant cross~seclional area) arc placed in series. Write the modeling equations for the height of liquid in the tanks assmning that the f!owrate from the first tank is a function of the difference in levels of the tanks and the f10wrate from the second tmik is a funclion of the level in the second tank. Consider two cases: (i) the function is linear and (ii) the function is a square root relationship. State all other assumptions. A gas surge drurn has two components (hydrogen and methane) ill the rcedstreHlll. Let Yi and y represent the mole fraction of lnethanein the feedstream and drum, respectively. Find dP/df and dy/dt if the inlet and outlet f]owrates can vary. Also as~ sume that the inlet concentration can vary. Assume the ideal gas law for the effect of pressure and composition on density. Consider a liquid surge drum that is a sphere. Develop the modeling equation using liquid height as a state variable, assuming variable inlet and outlet /lows. A car tire has a slow leak. The fJowratc or air out or the tire is proportional to the pressure of air in the tire (we ;Ire using gauge pressure). The initial pressure is 30 psig, and after five days tile pressure is down to 20 psig. flow long will it take to reach 10 psig? A car lire has a slow leak. The flowratc of air out of the tire is proportional to the square root of the pressure of air in the tire (we arc using gauge pressure). 'rhe initial pressure is 30 psig, and after 5 days the pressure is down to 20 psig. How long will it lake to reach 10 psig? Compare your results with problem 10.
Process Modeling
44
Chap. 2
12. A small room (IOn X Ion X lOft) is perfectly scaled and contains air at I atm pressure (absolute). There is a large gas cylinder (100 nJ ) inside tbe room tha( contains helium viith an initial pressure of 5 atm (absolute), Assume that the cylinder
valve is opened (at t = 0) and the molar f10wratc of gas leaving the cylinder is pro~ portional to the difference in pressure helween the cylinder and the room. Assume HUll room air docs not diffuse into the cylinder. Write the differential equations that (if solved) would allow you to find how the cylinder pressure, the room pressure and the roorn mole fraction of helium change with time. Slate all assumptions and show all of your work.
13. A balloon expands Or contracts in volume so that the pressure inside the balloon is approximately the atlllOspheric pressure. a. Develop the mathematical model (write the differential equation) for the V01UIllC of a balloon that has a slow leak. Lct V rcpresenllhe volume of the balloon and q represent the molar flowratc of air leaking from the balloon. State all assumptions. List state variables, inputs, and parameters. h. The following experimental data have been obtained for a leaking halloon. t (minutes)
o
r (em) I (J
5
7.5
Predict when thc radius of the balloon will reach 5 cm using two different assumptions for thc molar rate of air leaving the halloon: (i) ·rhe molar rate is constant. (ii) 'fhe molar rate is proporlionallo the surface area or the balloon. Reminder: The volumc of H sphere is 4IJ
'ITr 3
and the ,1rea of a sphere is 47Tr2.
14. Often liquid surge tanks (particularly those containing hydrocarbons) will have a gas "blanket" of nitrogen or carbon dioxide to prevent the acculllulation of cxplosive vapors above the liquid, as depicted below.
liqUid
• F
Develop the modeling equations with gas pressure and liquid volume as the state vari'lble;.;. Lel Cfr(lnd Cf repre;.;cnt the inlet and outlct gas molar flowrates, F"rand F the liquid volumetric f1owratcs, V the constant (total) volume, Vjthe liquid volume, and P the gas prcssure. Assume thc ideal gas law. Show that lhe modeling equations arc:
riP dl
P
V~V(Ff-F) I
and statc any other assumptions.
Student Exercises
45
15. Most chemical process plants have a natural gas header that circulates through the process plant. A siInplified version of such a header is shown below.
P
I
V,
From source
valve i Plant piping, represented as a perfectly mixed drum
Gas drum for a boilerhouse unit
To furnaces
Here, the natural gas enters the process plant from a source (the natural gas pipeline) through a control valve. It fltnvs through the plant piping, which we have represented as a perfectly mixed dnnH for simplicity. Another valve connects the plant piping to the gas drum for a boi!erhouse unit. Gas passes through another valve to the boilerhouse furnaces. Write modeling equations asslllning that the pressures in drums I and 2 arc the state variables. Let the input variables be h J (valve position 1),11 2 (valve position 2), and Pi (source pressure). 16. 'file Lotka- Volterra equations \Vere developed to mode! the behavior of prcdatorprey systems, making certain assumptions about the birth and death rates of each species. Consider a system composed of sheep (prey) and coyotes (predator). In the following Lotka- Volterr~1 equations Xl represents the number of sheep and X2 the number of coyotes in the system.
Discuss the meaning of the parameters model.
0', ~,
-y,
E
and the- assumptions made in the
17. Consider a perfectly mixed stirred-tank heater, with a single liquid feed stream and a single liquid product stream, as shown below.
F
i
T;
_
~
L j - - - - t - ' - - - - -.. F T
Process Modeling
46
Chap. 2
Develop the material and energy balance equations that describe this process. Fi is the volumetric nowrate into the tank, F is the volumetric rJOWfi:ltC oul of the lank, '1;is the temperature or the fluid entering the lank, r is the lcrnperalurc or the fluid in the tank, II is the height of liquid in the tank, and Q is the rate of energy added to the tank. State assumptions (such as constant density, etc.). _ Assume that the volume Call vary with time and that F is proportional to \1/1. How lllany differential equations docs it take to model this system? What arc the state variables'! What afC the parameters? What <:11"( the inputs? List the information necessary to solve this problem.
18. Consider a gas surge drum witb variable inlet and outlet molar flowratcs, {jr and q, res[Jectively. Asslilne that heat is being added to the tank at a rate, Q. \Vrite the modeling equations lhat describe how the temperature, and pressure, fl, vary with time. r)o not neglect the p V tenn in the energy balance. 19. Derive the reaction~dilJusionequation
1:
dC.\
at
= - v
neil ilz.
using the same method to derive lhe tubular reactor model in Section 2.6. As:mme that a chelnical species enters a v()lllIne clement via convection (bulk flow) and a concentration gradient (diffusion):
leaves by convection and a concentration gradiellt:
and also leaves by a first-order reaclion.
20. Consider the nonlinear tank heipht model
"II
F,
"I
A
13 VII
A
tmd define the dimensionless variables
II :::: F/F:I . and x:::: hlhs.. 'Where Fs and h. 1 are the stcady-stateflowrale and height. respeclively (VI' :::: ~\Ih). Definc the dimeIl+ sionless limc, T, that will yield the follO\ving dimensionless equation:
dx elT
=
--
\/x
+
U
21. I)erive the constitutive relationship F:::: fjVh by considering a steady-state energy balance around a tank with a constant flowrate. Use P :::: 1\, + pgh for the pressure al the bottom of the lank, where Po is the atmospheric pressure (pressure at the top surface), 11 is the height of liquid in the tank, p is the density of fluid. Assume lhat
47
Student Exercises
the cross-sectional area at the surface is much larger than the cross-sectional area of the exit pipe.
22. Consider the isothermal CSTR Inodel with first-order kinetics: dC,
dt
Use T =- kl as the dimensionless time. [)evclop the dimensionless cquation for t\",O cases: (i) _y ;;;:;: C,/(\l' and (ii) x =- I --- C,/(~\r Compare and contrast the resulling equations with the example in Section 2.7.
23. Semibatch reactors are operated as a cross between batch and continuous reactors. A semibatch reactor is initially charged with a volume of material, and a continous feed of reactant is started. There is, however, no outlet stream. !)eve(op the modeling equations for a single first-order reaction. The state variables should be volume and concentration of reactant A. 24. Pharmacokinetics is the study of how drugs infused to the body are distributed to other parts of the body. 'rhe concept of a cOlnpartmental model is orten used, where it is assumed that the drug is injected into compartment I. Some of the drug is eliminated (reacted) in compartmcnt I, and somc of it diffuses into cmnpartrnent 2 (the rest accumulates in compartment I). Similarly, some of the drug that diffuses into compartment 2 diffuses back into compartment I, while some is eliminated by reac~ tion and the rest accumulates in compartment 2. Assume that the rates of diffusion and reaction arc directly proportional to the concentration of drug in the compartmenl or interest Show thal the following balancc equations arise, and discuss the meaning of each parameter (k{i' units of min-I) dX I
dt
df
where Xl and x2 =- drug concentrations in compartments I and 2 (/-Lg/ml), and u =: ratc of drug input to compartment I (scaled by the volumc of compartment I, /-Lg/ml min).
SECTION
II NUMERICAL TECHNIQUES
ALGEBRAIC EQUATIONS
3
The purpose of this chapter is to introduce rllcthods to solve systems of algebraic equations. Arter studying this module, the student should be able to: Solve systems of linear algebraic cqua.lions. Solve nonlinear functions of one variable graphically and fllll11crically. Usc thcMAI'LAB function fzero to solve a single algebraic equation. Discuss the stability of iterative techniques. Usc thcMATLAB function f solve to solve sets of nonlinear algebraic equations.
The major sections in this chapter are:
3.1
3. J
Introduction
3.2
General r,'onn for a Lincar System of Equations
3.3
Nonlinear Functions of a Single Variable
3.4
MATLAB Routines for Solving Functions of a Single Variable
3.5
MuJtivariablc Systems
3.6
MATLAB Routines for Systeills of Nonlinear Algehraic Equations
INTRODUCTION In Chapter 2 we discussed how to develop a model that consists of a set of ordinary differential equations. To solve these problems we need to know the initial conditions and how the inputs and parameters change with time. Often the initial conditions will be the steady-state values of the process variables. To obtain a steady-state solution of a system of differential equations requires the solution of a set of algebraic equations. The purpose of this chapter is to review techniques to solve algebraic equations. 51
Algebraic Equations
52
Consider a set of 11 equations in
11
Chap. 3
unknowns. The representation is
fl(XI,xz,
x,,) ~ ()
flex I ,x2'
).:)
:=
0 (31 )
/;/(.\;\,X2' ... x,)::: 0
The objective is to solve f\1r the set of variables, Xi' that force all of the functions, .fi, to zero. A solution is called aJixed point or all. equilibrium poinf, Vector notation is used for a compact representation I'(x)
~
(}
(3.2)
where rex) is a vector valued function. Notice that these can be the same functional relationships that were developed as a set of differential equations, with x:= rex) := O. The SO~ lution x is then a steady-state solution to the system of differential equations. Before we cover techniques for systems of nonlinear equations, it is instructive to review systems of linear equations.
3.2
GENERAL FORM FOR A LINEAR SYSTEM OF EQUATIONS Consider a linear system with n equations and allxl
unknowns. The first equation is
11
+ "12x'2 + 0nrl + ... + all/XII = b l
where the a's and b's are known constant parameters, and the x's are the unknowns. The second equation is: anx I +
([22
x2 + ([2J~rJ +. . + ([2Ir\:1/ =
/;2
while the nth equation is:
The coefficient, aU' relates the jilt dependent variahle lo the itlt equation.
a 12
au
a21
an
aLl
alii
aliI
(lId
I"
"1 llZIl
XJ
b,
Xz
b2
x:'\
bJ
(3.3)
a/l/l
XII
Or, using compact matrix notation: Ax~b
(3.3a)
The goal is to solve for the unknowns, x. Notice that (3.3a) is the same form as (3.2), with f(x)
~
Ax - b
Sec. 3.2
General Form for a Linear System of Equat'lons
53
Prclllultiplying each side of (3a) by A--l we find: A-IAx=bu and since,
(3.4)
provided thallhe inverse of A exists. [I' the rank or A is less than 11, then A is singular and the matrix inverse docs not exist. If the condition number of A is vcry high, then the solution may he sensitive to model error. The concepts of rank and condition number are reviewed in Module 2 in Section V. Equation (3.4) is used for conceptual purposes to represent the solution of the sel of linear equations, In practice the solution is not obtained by finding the matrix inverse. Rather, equation (3.3a) is directly solved Llsing a numerical technique such as Gaussian elimination or LU decomposition. Since the codes to implement these techniques are readily availahle in any Ilumericallibrary, wc do not rcview thcm hcrc. The next example illustrates how MATLAli can he used to solve a system of lincar equations.
EXAI\ilPLE 3.t
Linear Ahsor(}tion Model, Solved Using l\:lATLAB
Consider as-stage ahsorption column (presented in Module 6 in Section V) that has a model of the following form (x is a vector of stage liquid-phase compositions and u is a vector of column feed compositions):
O=1\x+llu or Axc;::-~HII
the solution for x is x c;:: - A-I n 11 Thc valucs of A, n, and 11 are:
a -0.3250 0.2000 0 0
0
O.12'SO
o
a
-0.3250 0.2000 0 0
0.1250
o
-0.3250 0.2000
--0.3250
0.1250
o
0.2000
-0.3250
b
0 .2000 0 0 0 0 u
-
0 0 .1000
0 0
a 0 0.2500
0.1250
o o o
Algebraic Equations
54
Chap.3
The following MATLAB command can be used to solve for x
»x
~inv(a)*b*u
x
0.0076 0.0]98 0.0392 0.0704 0.1202
Usc of the MArLAB left-division operator (\) yields the same resull more efficiently (faster computation time), using the LU decomposition technique:
3.3
NONLINEAR FUNCTIONS OF A SINGLE VARIABLE Functions of a single variable Call be solved graphically by ploUing./(x) for many values of.t and finding the values of x whcrcj(x) :::;; O. This approach is shown in Figure 3. J. An interesting and challenging characteristic of nonlinear algebraic equations is the potential for mnltiple solutions, as shown in Figure 3.1 b. In fact, for a single nonlinear algebraic equation it is often not possible to even know (without a detailed analysis) the number of solutions that exist. The situation is easier for polynomials because we know that an nth order polynomial has 11 solutions. Fortunately, many chemical process problems have a single solution that makes physical sense. Numerical techniques for solving nonlinear algebraic equations arc covered in the next section. A graphical representation will be used to provide physical insight for the numerical techniques. Numerical methods to solve nonlinear algebraic equations are also known as iterative techniques. A sequence of guesses to the solution are made until we arc "close enough" to the actual solution. To understand the concept of "closeness" we must use the notion of convergence tolerance. f(Xi
f(Xi
x
°
x
The solution
a. Single Solution
FIGURE 3.t
b. Multiple Solutions
Graphical solution tof{x) "'" O.
Sec. 3.3
3.3.1
55
Nonlinear Functions of a Single Variable
Convergence Tolerance
A solution to a problcmj(x) :::; 0 is considered converged at iteration kif:
where 1::: is a tolerance that has been specified, !/(xk)! is lIsed to denote the absolute value of fUllctionJ(x) evaluated at iteration k, and x k is the variable value at iteration k. At times it is useful to base convergence on the variable rather than the function; for example, a solution can be considered converged at iteration k if the change in the variable is less than a certain absolute tolerance, E(I:
'I'he absolute tolerance is dependent on the scaling of the variable. so a relative tolerance specification, l,;r' is orten lIsed:
The relative tolerance specification is not useful iLr is converging to O. A combination the relative and absolute tolerance specifications is often used, and can be expressed as
or
The iterative methods that we present for solving single algebraic equations are: (i) direct substitution, (Ii) interval halving, (iii) false posilion, and (iv) Newton's Jnethod.
3.3.2
Direct Substitution
Perhaps the simplest algorithm for a single variable nonlinear algebraic equation is known as direct substitution. We h.ave been writing the relationship for a single equation in a single unknown as f(x) = 0
(3.5)
Using the direct substitution technique, we rewrite (3.5) in the Conn x = g(x)
(3.6)
this means that our "guess" ft.)!' x at iteration k+ 1 is based on the evaluation of M(X) atiteration k (subscripts arc used to denote the iteration) Xk+ l :::: M(Xk )
(3.7)
If formulated properly, (3.7) converges to a solution (within a desired tolerance) x* = g(x*)
If not formulated properly, (3.7) may diverge or converge to physically unrealistic tions, as shown by the following example.
(3.8) solll~
56
Algebraic Equations
EXAMPLE 3.2
A Reactor with
Chap. 3
Second~Ordcr Kinetics
The dynamic model for an isothermal, constant volume, chemical reactor with a single sccondorder reaction is: ~{~;, df
Find the
slcady~statc
concentration for the following inputs and parameters:
F/\I:;;;; I min-I, CAf '=. I gmolliiter, k:::: I litcr/(gmol min)
At steady-state, riCA/til
:=
n, and substituting the parameter and input vatues, we find I
~
Clis ~ C'As ~ 0
where the subscript s is used to denote the steady-state solution. For notational convenience, let .r:;;: CA" and write the algebraic equation as
We can directly solve this equation using the quadratic formula to find x:::: -·1.6IX and 0.61X to be the solutions. Obviously a concentration cannot be negative, so the only physically meaningful solution is x::;;: 0.618. Although wc know the answer llsing the quadratic formula, our objective is to illustrate the behavior of thc direct substitution method. To use the direct substitution method, we can rewrite the function in two different ways: 0) x 2 :;;;; ~J_- + I and Oi) x:;;;; --x 2 + J. We will analyze (I) and leave (Ii) as an exercise for the reader (see student exercise 4). (i) Here we rewrite JCi,.:) to fino the following direct substitution arrangement
x ~
v=:;:-+) ~ g(x)
Or, using subscript k to indicate the kth iteration
For a first guess of xo :;;;; 0.5, we find the following sequence
x,
~
x,
~
V - 0.5 +
1
0.7071 + I
~
0.7071
~
0.5412
+ 1 ~ 0.6774
XJ ~
0.5412
X4 ~
0.6774 + I
~
0.5680
'[his sequence slowly converges to 0.618, as shown in Figure 3.2.
57
Nonlinear Functions of a Single Variable
Sec. 3.3
0.75 0.7 0.65
'"
.".
0.6 0.55 0.5 0
20
15
10
5
k
FIGOH.E 3.2 The iteration XI; sequence converges to 0.61 XO.
I I with Xo
11
0:;;:
0.5. This
Notice that an initial guess of xo:::O () or ! oscillates between 0 and 1, never converging or diverging, as showil in Figure 3.3.
0.8 0.6
'".".
0.4
I I I 0.2 I I 0 0
\ \ \ \ \
2
4
6
10
FIGURE 3.3 The iteration xI; i [ = ~--::t~- 1 Wilh Xo::= 0 (dashed) or (solid). Thi::; sequence oscillates between 0 and 1.
As noted earlier, this problem has two solutions (x* :;:::; --1.618 and x~: :;;:: 0.(18), since il is a second-order polynomial. This tall be verified by plotting x versus J{x) as shown in
Algebraic Equations
58
Chap.3
Figure 3.4. From phy:;ical reasoning, we accept only the positive solution, since a concentration cannot be negative.
~
a/V 3:
/
-1 f··················· , .
.
,............
\ .
\[\
-2
-3 L...".
-2
FIGURE 3.4
.i.._ _
.._--"~._
_-"- .
-1
2
Plot ofj(x) versus x to find whcrcJ(x)::::; O.
Example 3.2 illustrates that certain initial guesses may oscillate and never yield a solution, while other guesses may converge to a solution. It turns out that the way that a direct substitution problem is formulated may eliminate valid solutions from being reached (sec student exercise 4). These problems exist, to a certain extent, with any numerical solution technique. The potential prohlems appear to be worse with direct substitution; direct substitution is not generally recommended unless experience with a particular problem indicates that results arc satisfactory, Direct substitution is often the easiest numerical technique toformulate for the ,,,>olution of a single nonlinear algebraic equation. If a numerical technique does not converge to a solution when the initial guess is close to the solution, we refer to the solution as unstable. The stability of iterative methods is discussed in the appendix.
3.3.3
Interval Halving (Bisection)
The interval halving technique only requires that the sign of the function value is knowll. The following steps arc used in the interval halving technique:
1. Bracket the solution by finding two values of x, one wherej{x) is less than zero and another whereJ{x) is greater than zero. 2. Evaluate the function,./C-r), at the midpoint of the bracket. 3. Replace the bracket limit that has the same sign as the function value at the midpoint, with the midpoint value. Check for convergence. If llot converged, go back to step 2.
Sec. 3.3
Nonlinear Functions of a Single Variable
59
f(x)
initial lower limit
x 2 initial upper limit
FIGURE 3.5
Illustration of the bisection technique.
An example of the interval halving approach is shown in Figure 3.5. Notice that the solution was bracketed by
1. Findingx\, whcrcj(xl) is negative andx2 wheref(x2) is positive. 2. The midpoint between xl and x2 was selected (x]). The function value at x3,}(x3)' was negative, so 3. xl was thrown out and x3 became the lower bracket point. 4. The midpoint between x 3 and .:rz was selected (x4)' The function value at --'"4' .!{.r4), was positive, so 5. '\:2 was thrown out and x 4 became the upper bracket point. 6. The midpoint between x 3 and x4 was selected (x s)' The function value al x 5, j(x s )' was negative, so 7. x3 was thrown out and x5 became the lower bracket point You can see that the midpoint between x5 and x4 will yield a positive value for}(x(), so that the x4 point will be thrown out. You can also see that this process could go on for a very long time, depending on how close to zero you desire the sol11tion. Engineering judgement must be used when making a convergence tolerance specification. The advantage to interval bisection is that it is easy to understand. A disadvantage is that it is not easily extended to multi variable systems. Also, it can take a long time to reach the solution since it only uses information about the sign of the function values. The next technique is similar to interval bisection but uses the function values to determine the variable value for the next iteration.
60
Algebraic Equations
3.3.4
Chap.3
False Position (Reguli Falsi)
The false position or rcguli falsi technique uses the function values at two previous iterations to determine the value for the next iteration. The technique of false position consists of the foJlowing steps:
1. Select variahle values xk and x k+ to bracket the solution. 2. Draw line hctwccnj{xk) andf(xk + 1) and find xk+2' 3. Evaluate f(xk+2)' Replace the bracket limit that has the S
the sign o(l{xk+2)' An example of the false position approach is shown in J1'igurc 3.6. The next step would be to draw aline from.f(x'j) to.!(x2) and find -'"4- Continue until a certain tolerance is met. The false position method generally converges much more rapidly since it uses known function values to determine the next "guess" for the variable. We have sho\vn graphically how each technique is used. You willlHlVe an opportunity in the student exer~ ciscs to write all algorithrn to implement the two techniques.
3.3.5
Newton's Method (or Newton-Raphsonl
The most commonrnethod for solving nonlinear algebraic equations is known as Newton's method (or Newton-I
I(x
+ Llx)
= f(x)
+ I'(x)Llx + rex) (Llx)2 + f"'G') (Llx)' + 2
6
=0
(3.9)
f(x)
initial lower limit
X2
initial upper
limit
FIG-URE 3.6
Illustration of the false position technique.
------------------~~~-
Sec. 3.3
Nonlinear Functions of a Single Variable
61
where
and so
011.
Neglecting the second-order and higher derivative terms and solving for 1{,I:+~t) = 0, we ohtain
-/(x)
L'.x
=
(3.10)
F(x)
Since this is an iterative procedure, calculate the guess YOI x at iteration k+l as a function of the value at iteration k:
defining from (3.1 0)
(3.11 )
=At,)
dX k + I
f'(x,)
from (3.11)
F(x,)
}\x,)
= x, -/"( _ x.k )
(3.12)
(3.13)
(3.14)
Equation (3.14) is known as Newton's method for a single-variahle problem. Notice that we can obtain the following graphical representation {{Jr Nc\vton's method (Figure 3.7). Statting from the initial guess of Xl' we find that -':2 is the intersection off'Cr 1) with the x-axis. [~valuatcJ(.1:2) and draw a line with slopcf'(x2) to the x-axis to find x 3 . This procedure is continued until convergence.
I(x) I(x,)
I(x,) I(x,)
I(x)
~
'SlOpe" f'(x,)
-1-------",'"""'7."---,----
x,
x,
ESCOLA Dc ENC:::NHARIA BIBLIOTLCA
Flf;{JRE 3.7 mclhod.
Illustration of NeWlon's
62
Algebraic Equations
Chap. 3
Advantages to Newlon's method include quadratic convergence (when close to the solution) and that the method is easily extended to l1lultivariablc problenls. Disadvantages include the fact that a derivative of the function is required, and that the method may not converge to a solution or may not converge to the nearest solution. Foran example of nonconvcrgencc, consider the fUllction shown in l"igure 3.8. Here the initial guess is at a point where the derivative of function is eqllal to zero (f'(xo ) -:;: 0), therefore there is no intersection with the x-axis to determine the next guess. \Vc also sec from (3.14) that there is no finite value for the next guess for x. Another probIcm is that the solution could continuously oscillate between two values. Consider/Cx) =::.x3 -- x. A plot of Newton's method for this function, with an initial guess o1'xo::= ~1/\/5,is shown inl<'igure 3.9. Notwithstanding the problems (possible diviSion by zero or continuous oscillation) that we have shown with Newton's method, it (or some variant of Newton's) is still the most commonly llsed solution technique for nonlinear algebraic equations. Notice that Newton's method essentially linearizes the nonlinear model at each iteration and therefore results in successive solutions of linear models. Notice that increasing amounts of information were needed to use the previous techniques. Interval halving required the sign of the function, reguli falsi required the value of the function, and Nevvton's method required the value and the derivative of the function. We also found that not all solutions to a nonlinear equation arc stable when direct substitution is used. Next, we show that all solutions are stable using NeWlon's method.
1
0.5 f(x)
a ______
_
.>-..-L~_"'
-0.5
horizon1al 1arlgel
never meet! x-axis -1
-1.5
-1
-0.5
o
0.5
1
x FIGURE 3.8
Problem with NeWlon's method whcllf'(r)::;;: O.
1.5
Sec. 3.4
63
MATLAB Routines for Solving Functions of a Single Variable
1
0.5 f(x)
l'
a
,
-....... ~_
l
'~_
,
,
J,I
-0.5 -1
-1.5
a
-0.5
-1
0.5
1
1.5
x FIGURE 3.9
3.4
OscillatIon of solution between two values.
MATLAB ROUTINES FOR SOLVING FUNCTIONS OF A SINGLE VARIABLE MA'fLAB has two routines that can solve for the zeros of a function
or a single v.:triable.
FZERO is lIsed for a general nonlinear equation, while ROOTS can be used if the nonlinear equation is a polynomial.
3.4.1
FZERO
The first routine that we usc for illustration purposes is [zero. [ZI<;1:'O uses a combination of interval halving and false position. In order to usc f ZE,;ro, you must first write a MATL,AB m-filc to generate the function that is being evaluated. Consider the function.!(x):::: x 2 - 2x ~ 3 :::: O. The following MATLAB m-filc evaluates this function (the Ill-file is named fcnl . m):
function y y
~
:=
x A 2 - 2*x
fcnl(x) 3;
After generating the m-filc tcnl. m, the user must provide a guess for lhc solulion to the fzero routine. The following command gives an initial guess of x:::: O.
y
fzero{'fcnl' ,0)
64
Algebraic Equations
Chap.3
MATL.AB returns the answer: -1
y
For an initial guess of x = 2, the user enters
z
~
fzero( 'fenl' ,2)
and MATLAB returns the answer
z
3
~
These results arc consistent with those of Example 3.2, where we found that there were two solutions to a similar problem (we could usc the quadratic rOl11mla to find theln). Again, the solution obtained depends on the initial guess. A third argument allows the user to select a relative tolerance (the default is the machine precision, eps). A fourth argument triggers a printing of the iterations.
3.4.2
ROOTS
Since the equation that we were solving was a polynomial equation, we could also lise the MATLAB routine roots to find the zeros of the polynomiaL Consider the polynomial function:
The user must create a vector of the coefficients of the polynomial, in descending order. e~[1-2-3]'
Then the user can type the following command roots(e) and MATLAB returns
ans :::: 3 ~l
Again, these are the two solutions that we expect.
3.5
MULTIVARIABLE SYSTEMS Tn the previous sections we discussed the solution of a single algebraic equation with a single unknown variable. We covered direct substitution, bisection, reguli falsi, and Newton's method. In this section, we will discuss the reduction of a multivariab1e problem to a single-variable problem, as well as the multivariab1c NeWlon's method. Consider a system of 1l nonlinear equations in Jl unknowns f(x) = 0
Sec. 3.5
65
Multivariable Systems
'There arc some special cases where 11 - 1 variables can he solved in terms of one vari~ ablc----lhen a single variable solution technique can be llsed. This approach is shown in the following example.
EXAMPLE 3.3
Reducing a
two~variahlc
problem to a
single~variablc
problem
Solve the following system of nonlinear cqllati(Hls. fl(x 1,X 2):::::
4x~-
XI
(3.15)
x Jx 2 :::O
(3.16) From (3.15) we can sol ve for x 2 in terms of x I to find: -'2:;:;;1-4x 1
(3.17)
I +3x,-ZBxf::::O
(3.18)
Substituting (3.17) into (3.16), we find:
which has the two solutions 1'1)]
XI
(from the quadratic formula)
The corresponding values of x 2 (1i'on} (3.17)) arc X 2 ;:::
OJ) and
x2:::;:
1.5714
Or, writing these solutions in vector form:
.
solutIOn 1 is
Question:
X.co"
[0.25]. . 0 . ' while solution 2IS x .
=
-0.1429] [ 1.5714
Arc we certain that there are only two solutions?
Observation: We can also see by inspection that the origin (sometimes cJlled the trivial solut'lOn), x =: tgl, is also a solution. Another solution that is slightly Jess obvious is x;::;; [~]. which we can see by inspection satisfies (3.15) and (3.16). Question:
How did we miss the other two solutions?
Observation: Perhaps we will find the olher solutions if we solve (3.16) for Xl in tCrIns of -\2' then substitute this result into (3.15) to solve for x 2 . When this is done, we obtain the result that
x-i -- 4 x
2
+
4 = 0
4 /116-16 dnd llSlllg the l(UMh,ttlC 100nJuid \} ~ 2 :1: \
--2
2
which gives us the solution x:;::: l~l. Notice that we are still missing the trivial solution, x ;::;;
rgl.
Algebraic Equations
66
Chap. 3
The mistake that we made was back at the fifst step, when we solved (3.15) for J.-2 in terms of xl to find (3.17). We must recognize that (3.15) is quadratic in Xl' therefore there arc two solutions for Xl in terms OLt2' This is more dear if we write (3.15) .'lS ~4
x7 + xI (1 - x2) + 0 ::: 0
and solve for xl to find xl -:;:;:. 0 or Xl ::: 1/4 (I - x2). The reader should show that substituting these values into (3. 16) will1cad to the four solutions:
x·~ 1.°' °11°.11°.25.]. 1- 01.5714' .1429.1 2 ' . ° ' dnd The previous example illustrates the care that must be taken when using reduction techniques to solve several nonlinear algebraic equations. If a problem cannot be reduced to a single variable, then a general multivariablc strategy (such as that discussed in the next section) must be used,
3.5.1
Newton's Method for Multivariable Problems
Recall that we arc solving the general set of equalions
rex) = 0
(3.19)
That is, a set of n equations in n unknowns
fl(x}l"t zl ' . , x,J
0
f,(x\,x" ... x,,)
0 (3.20)
t"(x,,x,, ... x,,)
0
The oQjectivc is to solve for the sct of variables, Xi' that forces all of the functions,};, to zero. We can use a Taylor series expansion for eachf;:
t;(x + Ax)
=
,f,(x) +
:s ar !H + higher order terms II
-c"
j
(3.21)
j ' l dX j
Neglecting the higher order terms and writing in matrix form
f(x + Ax)
=
f(x) + J Ax
(322)
where.J is known as the Jacobian
ilf,
iii,
iii,
ax!
dxz
dX"
.J =
(3.23)
aj;/ ax}
iJj;/
iI/;/
OX2
aXil
Sec. 3.5
67
Multivariable Systems
Now, since we wish 10 solve for Ax such that r(x + Ax):::: 0, then (from 3.22)
f(x) + J Ax
~
0
(3.24)
Solving for Ax at iteration k
(3.25) but Ax is simply the change in the x vector from the previolls iteration
=
AX k
xk
xkl- 1 -
(3.26)
Substituting (3.26) into (3.25) (3.27) Remember that xI, is a vector of values at iteration k. Notice that for a single equation (3.27) is:
.
x, , I
_.
xk
-
f(x k )
x, )
-"(
j
which is the result that we obtained in Section 3.3.4. Comment: In practice the inverse of the Jacobi;:l11 is not actually used in the sollilion of (3.25). Actually, (3.25) is solved as a set of linear algebraic equations, using Gaussian elimination or LU decomposition.
where
Jk and f(x k) are known at iteration k.
EXA1VIPLE 3.3
Revisited. Newton's method 1;(-'"x,)
f;(X"xJ
or
Xl -
=
4
2 x2-
xj
XjX? =
0
x~ -I 3 X1X2 = 0
f(x)·· [- x l -4xf
-X,X'j
1 - 8x 1 ~
J?·""'·······=-x L iJx .l
[OJ
-- 2 x 2 ~ xi + 3 x j x 2 _ =0
The Jacobian elements are
JJI
=
ill; .. ()J:
= r
so the Jacobian is written
X2
fJ/;
2
Algebraic Equations
68 Consider guess
all
initial guess of ,:rj :;:; ; --1 and
---J. Let x(O) represent the vector for this initial
x2 ;;;;;
The value of the Jacobian at this initial guess is
.I(x(O))
10
~_ [
3
T'hc inverse of the Jacollian is
~I]
1 .I I(X(O»
~13
[ .3 13
10 13 .
13
The value of the function vector for the initial guess is -
-- 1
4 I
f(x(O» ~ [ 2 (- I)
I[
+3
[-~]
and the guess for x( I), \-vherc x( I) represents the vector at iteration I, is
x(1) ~ x(O) ~.1 '(x(O)) f(x(O)
r~610 ~ r~ I [ ~ [.. 3 :-.d] 10 1 U
~I
x( I)
13
x(1 )
[
13
~053851 0.3846
Continuing with iterations 2 through 7 we find the foJlowing results
Iteration 0 1 2 3 4 5 6 7
Chap. 3
x,
XI ~I
~0.5385 ~0.3104
0.2016 ~0.156]
-0.1439 -0.1429 --0.1429
-
]
0.3846 1.0688 1.3952 1.5317 1.5683 1.5714 1.5714
Sec. 3.5
Multivariable Systems
69
The sequence of iterations for an initial guess of xl
::::
.I and x2::::::1 is
Iteration
x,
X2
0 1 2 3 4 5 6
1 0.6190 0.3893 0.2870 0.2542 0.2501 0.2500
1 0.0476 0.0081 0.0008 0.0000 0.0000 0.0000
Noticethataguc:'isofx:::o [-1 -1]' convergcdtox [-0.1429 1.5714.1' aftcrsix iterations, and a guess of x ::: [ l 1J' converged to x '" [ 0.2500 0.0000 I ' aftcr six iterations. Other initial guesses may lead to the other two known solutions that were determined analytically.
The previous example illustrates that, for systems that have ITIuhip1c solutions, the solution obtained depends on the initial guess.
3.5.2
Quasi-Newton Methods
Most computer codes actually implement some variant of Newton's method; these arc referred to as quasi-Newton methods. Remember that Newton's method is guaranteed to convcrge only if thc system is nonsingular and we arc "close" to the solution.
DAMPING FACTOR Often it is desirable to "dampen" the change in the guess for xk+l' to make Newton's method more stahlc. Applying a damping factor, a, to (3.27), we write xu, = x k - a J k ' f(xkl
(3.28)
where a is chosen so that II f(x k+1) II < II f(Xk) II and () < 'x S; I (we lise the II f(x k) I1l10tation to represent the norm of the vector f(x k Often IX is selected to minimize II f(x k + l ) II using a search technique l that is, IX is adjusted until II f(x k + 1) II is minimized. It should be noted that the single-variable equivalent to (3.28) is
».
(3.29)
HANDLING SINGULAR (OR ILL-CONDITIONED) JACOBIAN MATRICES Notice that the Newton method with ot without the damping factor requires the inverse of the Jacobian matrix (or the solution of a set of linear algebraic equations) to determine the
Algebraic Equations
70
Chap. 3
value for the next iteration. If the Jacobian is singular, it cannot he inverted. One method that avoids this problem is known as the L,evcnhcrg~Marquardl method:
xk + t
_
~
xk
~
T
(J k J k
+ [31) .... ] Jk T f(x k )
(3.30)
where T represents the matrix transpose and [3 is an adjustable parameter llsed to avoid a singularity. The single variable equivalent to (3.30) is (3.31 )
Notice that jf j3 = 0, the standard Newton algorithm results.
WHEN ANALYTICAL JACOBIAN MATRICES ARE NOT AVAILABLE If an analytical Jacobian is not available, a numerical approximation to the Jacobian mllst be used by the quasi-Newton techniquc.A backward differences approximation for the Jacobian is (3.32)
where oxJ-(k) is a small perturbation in variable x·.I at iteration k. A problcrn with this approaeh is that an n-variabfc problem requires 11 + 1 evaluations of the function vector at each iteration. There are other techniques that rely on infrequent function evaluations to update the Jacobian matrix.
3.6
MATLAB ROUTINES FOR SYSTEMS OF NONLINEAR ALGEBRAIC EQUATIONS 'fhe MATI,AB routine fsolve is used to solve sets of nonlinear algebraic equations, using a quasi-Newton method. The user must supply a routine to evaluate the function vector. It is optional to write a routine to evaluate the gradient of the function vector. As another option, the user can select tbe Levenburg-Marquardt method.
EXAMPLE 3.3
Reconsidered. Using MATLAB
The tn-file used to implement Example 3.3 using fsolve is:
function f = nle(x) [(1)= x(1)-4*xll)*xl1)-xll)*xI2); f{2)= 2*x(2)-x(2)*x(2)+3*x(1)*x(2); which is placed in an tn-file called nle. m The initial guess is entered xO
[1
1]';
Summary
71
and we obtain the solution by entering X
fsol ve ( 'nle' ,xO)
::0
which gives us the expected results x
=
[0.2500
0.0000] ,
Computationally faster results will he obtained if the analytical Jacobian is used.
2 'fhe following function file gcnerates the analytic,tI Jacobian for this problem.
[unction gf '=' gradnle(x) gf(1,1)=1~8'x(1)-x(2);
gf(l,2)=-x(1) ; gf(2,l)=3'x(2);
gf(2,21=2-2*x(2)+3*x(1); which we place in all Ill-file called gradnle. m. We can then solve this problem by entering xO =
[l
1]';
options (5) c-,-O; x fsolve( 'nle' ,xO,options, 'graclnle') 'fhe options vector can be used 10 seleel the Levcnberg-Marquanlt method by setting options(5)'='1;
SUMMARY In this cbapter we have presented a number of techniques to solve nonlinear algebraic equations. Each technique bad a number of advantages and disadvantages-the approach that you use may depend on tbe problem at hane!. If you have the option, it is a good idea to plot the function,f(x), to see if the results agree with your numerical solution. This option may not be available with l11ultivariablc problems. Notice that if a particular problem has multiple solutions, the actual solution obtained will depend on the initial guess. There are many actual chemical. processes that have "multiple solutions," that is, there are several possible "steady~states" that the process may operate at. In practice, the steady-state obtained wiU depend on dynamic considerations, such as the way that the process is started up. These issues will be ad~ dressed when we discuss differential equation~hased models. Much research is being done in applied mathematics to develop numerical tecbniques that yield everyone of the multiple solutions, without having to make many initial guesses. Among these is "homotopy continuation." These techniques arc not welldeveloped and are heyond the scope of this text. For now, the student must he willing to
Algebraic Equations
72
Chap. 3
try a numher of techniques, with a number of initial guesses, to find all of the solutions to a problem. It is recommended that you generally lise commcrically availahle routines for solving these problems. The numerical techniques covered were Direct substitution Interval bisection Rcguli falsi Newton's method Newton's method (and some variants) is the most commonly llsed multi variable technique. The reader should he able to understand the notions of • Jacobian Fixed or equilibrium points • COllvergence and stability
Tolerance Ilcration The MATLAB routines that were introduced in this chapter are f801 ve: Solves a system of nonlinear algebraic equations, using quasi-Newton and Levenberg-Marquardt based algorithms fzero:
Solves for a single equation
roots:
Solves for the roots of a polynomial equation
A I1lnnber of other numerical rOlltines are availiable through thcMATLAB NAtj Toolbox.
FURTHER READING More detailed treatments of numerical methods given in the textbooks by Davis, Finlayson, and Riggs: Davis, M.E. (1984). Numerical Methods ol1dModeling for Chell/ieal Engineers, Ncw York: Wiley. Finlayson, B.A. (1980), Nonlinear Analysis in Chonit'al Fngineering. New York: McGraw-Hili. Riggs, J.B. (1994). Numerh..al Techniques for Chemical Engineers, 2nd cd. Lubbock: Texas Tech University Press.
Student Exercises
73
Example numerical techniques arc also presented by Felder and Rousseau: Felder, R.M., & R.W. Rousseau. (1986). Elementary Principles Processes. 2nd cd. New Yark: Wiley.
(~r
Chemical
The following book is more of ail advanced undergraduate/first~year graduate student text on I1lllncrical methods to solve chcmical engineering problems. The emphasis is on FORTRAN subroutines to be used with tbe IMSL (FORTRAN-based) package. Rameriz, w.r-<. BUtlerworths.
«( 989).
Computational Methods for Process 5'imulalion. Boston:
STUDENT EXERCISES Single Variable Methods 1. Real gases do not normally behave as ideal gases except at low pressure or high tcmpcrature. A number of equations of state have been developed to account for the non-idealities (van del" Waal's, RedliclyKwong, Peng-Robinson, etc.). Consider the van cler Waal's (YO T relationship
where Pis pressure (absolute units), R is the ideal gas constant, T is temperature (absolute units), {, is the molar volume and a and b arc van der Waa!'s constanls. The van der Waal's constants are often calculated from the critical conditions for a particular gas. Assume that a, h, and R are given. We find that if P and T arc given, there is an iterative solution required for V. a. How many solutions for V arc there? Why? (Hint: Expand the PVT rclationshlp to form a polynomial.) b. Recall that direct substitution has the form Vk+J :::: gV k)' Write three different direct substitution formulations for this problem (call thcse 1, H, and Ill). c. What would be your first guess for V in this prohlem?Why? d. Write the MATLAB m-files to solve for V using direct substitution, for each or the three formulations developed in b. Consider the following system: air at 50 atm and -1 ()(PC. The van der Waal's constants arc (Felder and ROllsseau, p. 201) a :::: 1.33 altn Iitcr2/gmo!2, b = 0.0366 Iitc/Jglllol, and R = OJl8206 liter alm/glllol K. Solve the I{Jl1owing problems numerically. e. Plot V as a function of iteration number for each of the direct substitution methods in b. Usc 10 to 20 iterations. Also usc the first guess that you calculated in c. Discuss the stability of each solution (think about the stability theorem).
Algebraic Equations
74
Chap. 3
f. H.carrangc (I) to the form of/CO") :::: O-and plot./n/ ) as a function of V. How many sol uti OilS arc there? Docs this agree with your solution for a? Why or why
not? g. Usc the MA'rLAB function roots to solve for the roots of the polynomial de-
veloped in a. h. Write and lise an m-fi1c to solve for the equation in a using Newton's method. The nUlllerical Solulion is eonsidercd converged when ,,~
IVk~ Vk11
< ". Lel
k-- [
0.0001.
2. Consider the van der Waals relationship for a gas without the volume correction lerm (Ii ~ 0)
(P + V2a) V· A
A
a. IIow many solutions for
RT
if arc there? Show the solutions analytically.
b. Which solution is correct? 3. A process furnace is heating 150 Ibrllol/hr of
vapor~phase
mllmonia. The rate of
heat addition to the furnace is 1.0 x J 0 6 Btu/hI'. The ammonia fcedstrcam tempcra~ ture is 550 0 R. Use Newton's method to find the tcmperature of the aJl1monialeav~ ing the furnace. Assumc ideal gas and use the following equation for heat capacity at constant pressurc:
Btu
Ibmol "R Ii
ell
=
a + bT + cT- 2
~ 3.33
X
to
3
Btll lOS Btu "R Ibmol "R' c = - 1.20 X Ibmol
T
and remember that Q c.
,i r,,'·'" C" dT
where Ii is the molar rlowmtc of gas and Q is the ratc of heat addition to the gas pCI' unit timc. l-Iow did you detcrrnine a good first gucss to lise? 4. Consider Example 3.2 , .ltx) = _x2 ~ X + 1 = 0, with the direct substitution method jCll'lllulated as.x = -x 2 + 1 :;;:: g(x), so that the iteration sequence is Xk
I
c=
g(x k ) = - x~ + I
Try several different initial conditions and show whether these convcrge, diverge, or oscillate bctwcen values. Discuss the stability of the two sollitions .x*:;:: 0.618 and x*:;;:: -1.618, based on an analysis ofg'(.I;*). 5. Show why the graphical Newton's method is eqlJivalent to xk+l = x k ~-J(xJ.Yf(xk)'
6. Develop an algoritlnl1 (sequence of steps) to solve an algebraic equation using intcrval halving (bisection).
75
Student Exercises
7. Develop an algorithm (sequence of steps) to solve an algebraic equation using reglilt falsi (false position). Compare and contrast this algorithm with Newton's mcthod. S. A componcnt material balance around a chemical reactor yields the following steady-slale equation
0= F
where V
.=
F V
C- kc' ftC>
Ibmol
and k = 0 . 0 5 , . IbmoV ITIm a. How many steady-state solutions arc there? b. Write two different direct substitution methods and assesS the convergence of each. c. Perform two iterations of Newton's method using an initial guess of C:::: 1.0. 0.1 min " Cj"
1.0
9. Consider the following direct suhstitution problem, which results from all energy balance problem
T
-I'
k+ I -
15.04 0.716 _ 4.257 X 10
7~
'I'
Willlhis method converge to the solution or T = 443.571? Why or why not?
IO. Consider the following steady-stale model for an exothermic zero-order reaction in a continuous stirred-tank reactor. The variable x is the dimensionless reactor temperature.
lex)
0.42204 cxp
x
+
x
-1.3x=O
20
I'here arc two solutions to this equation, as illustrated in the figure below. The solu!ions mc x = 0.55946 and 2.00000. a. Formulatc a direct substitution solution to this problcm. Will your direct substitution tcchnique converge 10 0.55946'1 Will your direct substitution technique converge 10 x::: 2'1 Use a rigorous mathematical argument in each case. h. For an initial guess of x = 1.35, would you expect Newton's method to have any trouble with this problem? Explain. c. What is the next guess from the reguli falsi lechnique if your first guess was x;:;: I and your second guess was x:::::; 2.5 (show this mathematically)? d. Write a function routine to solve this problem using theMATLAB function f zero. Also show the commands that you would give in the MATLAB command window to run fzera.
76
Algebraic Equations zero-order rxn - dimensionless
0.5
~
Chap. 3
0
-0.5
a
2.5
2
1.5
0.5 x
Plot of x versus f(x) for problem IO.
11. A component material balance around a chemical reactor yields the following steady-state equation
o VF C';,,- FV C c
F where V
=
IU min'!, C;"
=
1.0
Ibmol 1 - and k fl'
=
k(·25
If'5
0.05 . ..... I ' lbmol "- min
Write two different direct substitution methods and assess the convergence of each to the steady-state concentration of 0.75354. b. Perform two iterations of Newton's method using an initial guess of C:::: 1.0. i:1.
12. Consider the dimensionless equations for an exothermic CSTR (continuous stirred tank reactor) shown in a module in the final section of the textbook.
= -'!>XIK(X,) + (I - XI) = 0 f,(x"x,) = j3X IK(X,) + (I + o)x, = 0 fl(xI,x,)
where K(X ) 2
= exp
2 .) (_X 1 + x,I'Y
Uscft (x['X2) to solve for xl in terms of x 2 and substitute intoh(xl,x2) to obtain the single equation
I)
I«X,) - (1 + o)x, ~ .
=
0
Consider the parameter values ~ :::: 8, (V : :;: 0.072, 'Y :::: 20, 0 = 0.3. Determine the number of solutions to this problem (graphically), Find the xI and .x2 values for each solution, using the single variable Newton's method.
Appendix
77
Multivariable Methods 13. Use the multivariabJe Newton's method to solve the following problem. Solve this as a two-variable problem. Do not reduce it to a single-variable problem via substitution.
f,(x)
=
2x,-x2 -5
=
0
J;(x) =-x, -x2 + 4 .•~ 0 How many iterations docs it take to converge to the solution? Explain this result conceptually.
14. A simple bioreactor model (assuming
where JJ..mi]X ::::: km = ::::: k, ::::: c :::::
stcady~statc operation)
is
0.53 0.12 0.4545 0.4 4.0
is the biomass concentration (mass of cells) and xl is the substrate concentration (food source for the cells). Find the steady-state values for xI and x2 if f)::::: 0.3 (There are three solutions).
MATLAB.
f,(x"x,)
CC
-
q>X,,,(xz) + (1 - x,)
= 0
j;(x"x,) = l3q,x,,,(x,) - (1 + I\)x z .c. 0 where ,,(x,) = exp (. . . ) I j- x,h and the following parameters arc used
13 =
8
'Y =
20
(I' = 0.072 1\ = 0.3
Algebraic Equations
78
Chap.3
APPENDIX Stability of Numerial Solutions-Single Equations If the iterates (xk) from a numerical algorithm converge to a solution, we refer to thal solution ns being stable. ..
-----._----------~----_
_--~-~--~---~-_._--------~
Definition 3.1 Let x''' represent the solution (fixed point) of x*
=:
S(x'''), or get''')
yO" =:
O. --------~-
Theorem 3.1 x~'
.IS a stahle soI uUon ' 01 x'::' . K(.r""), 0::
g ,- ~ g(,"'). if lu l (JX If
1~lgl
'1'li1gl - I
1
--~------
. .IS an 11llsta) II c SOIutHlll ' eva I llatcd at -r"'r';' () I'
<
llx
t evaluated at x*
!, then no conclusions can be drawn. For simplicity in notation, we generally usc
rJx
(jv
f
g to represent 1.':>1_ dx
\Vc continue with Example 3.2 to illustrate the numerical stability of direcl substitution.
- - - - - - - - - - - - - - - - . _ - -. ._ - - EXAMJ'LE 3.2 Contimlcd.
Stability of din~ct substitution
Consider the Case I formulation,
x
~
g(x)
x+1
which has the derivative
ag
ax II
I I
- I
. g' -
x
I 1
I, then x*' is a stable solutioH.
1. For xo;' := 0.618, we find that
lex ")
:::;0
O.61X +- I
O.X090
I.Sox''':=O.6ISisa
stable solution, that is, all initial "guess" for X o close to 0.618 will convergc
-I 2. [-'or x'"
0::::
-1.618, wc find I g'(x"') I 0::::
.618
f
J
10
xO;o 0::::
0.618.
0.30(]O,' 1. So _y*' :::; . . ~ 1.618 should
be a stable solution, that is, an initial "guess" frw Xu close to - 1.61 g should converge to 0:::: -1.618.
x'"
c
Appendix Question:
79 Why did we find previollsly that an Initial guess close to -1.61 Xdid not converge?
Observation: We must realize that the square root of a positive number has two values. For example, the square rooL of I call either be + I or -I (after all (-1)2 ::0:: In. --------You may be questioning the utility of a stability test for the direct substitution method, which requires that the solution be known to apply the test. Our purpose is mainly to show that the direct substitution method can he unstable. Newlon's rncthod guarantees stable solutions, if the "guess" is close to the solution.
Stability of Newton's Method for Single Equations Here we use 'rhcorcm 3.1 to show that Newton's method is stable. 'to/e see that NewLon's lllcthod can be written in the form of
where
fix,) f'(x,J Then we can find that tbe derivative, //Ctk) is
or g'(x,) At the solution,
~
lex,) n\,)
II' (\,J I'
x"" we sec that g' (x*)
/(x*) r(x"')
II'(x*)]'
And sincc.f(x*') ::::: 0, we find that the stability constraint is satisfied
g'(x*) = () as long as/ex"~') *- O. This shO\vs that Newlon's method will converge to the solution, provided an initial guess close to the solution.
NUMERICAL INTEGRATION
4
Most chemical process models arc nonlinear and rarely have analytical solutions. This chapter introduces numerical solution techniques for the integration of initial value ordi~ nary differential equations. After studying this material, the student should be able to: Understand the difference between explicit and implicit Euler integration. Write MATLAB code to implement fixed step size Euler and Runge-Kutta techniques. Usc thcMATLAB ode45 integration routine. The major sections
4.1
or this chapter arc:
4.1 4.2
Background Euler Integration
4.3
Runge-Kulla Integration
4.4
MATLAB Integration Routines
BACKGROUND Thus far we have developed modeling equations (Chapter 2) and solved for the steady states (Chapter 3). One purpose of developing dynamic models is to be able to perform "what if' types of studies. For example, you may wish to determine how long a gas storage tank will take to reach a certain pressure if the outlet valve is closed. This requires in80
Sec. 4.2
81
Euter Integration
tegrating the differential equations from given initial conditions. If the dynamic equations are linear, then we can generally obtain analytical solutions; these techniques will be presented in Chapters 6 and 8 through 10. Even when systems are linear, we may wish to use numerical methods rather than analytical solutions. At this point itis worth reviewing the difference between linear and nonlinear differential equations. An example of a linear ordinary differential equation is:
dx = -r dt • since the rate of change of the dependent variable is a linear function of the dependent variable. An example of a nonlinear differential equation is:
dx dt
=
~-x
2
since the rate of change of the dependent variable is a nonlinear function of the dependent variable. Although this particulary nonlinear equation has an analytical solution, this will not normally be the case, particularly for sets of nonlinear equations. Notice that the following equation is linear:
since the only nonlinearity is in the independent variable (t). The purpose of this chapter is to introduce you to numerical techniques for integrating initial value ordinary differential equations. The first numerical integration technique that we will present is the Euler integration. In the next section we discuss two algorithms, the explicit and the implicit Euler methods.
4.2
EULER INTEGRATION Consider a single variable ODE with the form
dx. dl = x
=f
( ) x
(4.1 )
We consider two different approximations to the derivative. In Section 4.2, I we consider a forward difference approximation, which leads to the explict Euler method, In Section 4.2.2 we consider a backwards differences approximation, which leads to the implicit Euler method.
4.2.1
Explicit Euler
If we use a forward difference approximation for the time derivative of (4, I), we find
dx dl
=
t(k
+ I _. + I) ~ t(k)
(4.2)
Numerical Integration
82
Chap. 4
where k represents the kth discrete time step of the integration. Now, assume that)(.\:) is evaluated at x(k). We will refer to this fuuclion ast(x(k)), and can write (4.1) and (4.2) as x(k+ 1)...- x(k) = j(x(k)) I(k + 1) - 'rk) Normally we will use a fixed increment of time, that is, t(k + 1) - t(k) ~
(4.3)
at,
where!:;;'/ is
the integration step size. Then we write (43) as x(k
+
2t- x(k)
Cc
J(x(k))
(43)
Solving t{)r x(k + I)
x(k
+ I)
= x(k)
+ D.tJ(x(k)) K,plicit Euler
(44)
We can view (4.4) as a prediction of x at k + 1 based on the value of x al k and the slope at k, as shown in Figure 4.1. Equation (4.4) is the expression for the explicit Euler method for a single variable. The general statement for a lllultivariable prohlcm is
x(k + 1)
=
x(k) + 6.lf(x(k))
(45)
Where x(k) is a vector of state variable values at time step k and f(x(k» is a vector of functions evaluated at step k. Equations (4.4) and (4.5) are explicit because the statc variable value at time step k + 1 is only a function of the variahle values at step k. 'I'his method is straightforward and easy to program on either a handheld calculator or a cornputer. A major disadvantage is that a small step size must he llscd for accuracy. llowevcr. if too small of a step size is used, then numerical truncation problems may result. Explict Euler is not often used in practice, but is covered here for illustrative purposes.
4.2.2
Implicit Euler
This method uses a backwards difference approximation for the derivative in (4.1). The function (or vector of functions) is evaluated at time step k + 1 rather than time step k:
+I)-x(k)
6.1'
=
j(x(k
+ 1))
(46)
x(k+ 1) based on x(k) and f(x(k))
x(k)
----~ k
k+1
slope, f(k), evaluated at step k
FIGURE 4.1 Pictorial representation of the explicit Euler method.
Sec. 4.2
Euter Integration
83
which can be written
x(k + J) = x(k) + Iltf(x(k + 1)) Implicit Euler
(4.7)
Equation (4.7) is implicit because the value x(k + I) must be known in order to solve for + 1). What this generally requires is a nonlinear algebraic solution technique, slIch as Newton's method. For a linear system, equation (4.7) can be explicitly solved to obtain the form
x(k
x(k + 1) = g(x(k)) The following section compares the explicit and implicit methods for a single linear ordinary differential equation. In particular, we compare how the integration step size (At) affects the stability of each method.
4.2.3
Numerical Stability of Explicit and Implict Euler Methods
Consider the tank height problem covered in Example 2.1. There was no inflow, and the outlet flowratc was assumed to be linearly related to height, which gave us the following equation: dx
1
dt
T
x
Ax
co
= f(x)
(4.8)
where 'T = A/13, A = - lIT and the state variable x is the tank height. Since the variables are separable, the reader should show that the analytical solution is:
= x(O)e,j· = x(O)e"
x(t)
(4.9)
Next, we compare this analytical solution with the explicit and irnplicit Euler solutions.
EXPLICIT EULER The function value at step k is:
f(x(k»)
J Oc
x(k)
-
T
and the state variable value at the next time step is:
x(k + J) = x(k) + - Ilt T x(k) =
(t1t) J - .~. x(k)
IMPLICIT EULER The implicit Euler method evaluates the function at k + 1 rather than k:
I(x(k
+ 1))
=
-
I T
and the state variable at slep k + lis:
x(k
+ 1)
(4.10)
Numerical Integration
84
x(k + I)
x(k) + -
~
ill
Chap. 4
x(k + I)
(4.1 J)
T
Notice that, since this is a linear problem, a nonlinear algebraic equation solver is not needed for (4.11). We can rewrite (4.11) as
x(k + I)
1
~
ill x(k)
+
(412)
T
In the next section we compare the numerical stability of the explicit and implicit Euler methods.
NUMERiCAL 5TABILITY The explicit Euler solution, written in terms of the initial condition, is (from (4.10»):
x(k + I) which will be stable if
~
(1 - flt)"
I
T
x(O)
11- AlIT 1< 1. This is the same re~Htlt if we usc the representation: x(k + i)
and the stability requirement that
=
g(x(k))
~
(I - ~1)X(k)
Ig' I< I. The explicit Euler method is then stable if: -1<1-
ill
T
and will oscillate for:
flt
-1< 1-- < 0 T
These criteria lead to the explicit Euler stability condition of:
0
T
o<
ill < T
The implicit Euler solution, written in terms of the initial condition, is (from (4.12)):
x(k +
'"
( )
I)~ I;~I
x(O)
th
Euter Integration
Sec. 4.2
85
which will be stable if II/l+~t,'T1 < 1. This is the same result if we usc the representation
x(k + I) = g(x(k)) = (
1
I
+ !it
) x(k)
7
and the stability requirement that 11/ ::to < 1. Notice that the implicit Euler method is stable for any value of D.f (as long as the sign of D.l is corrcct) and will not oscillate.
EXAMPLE 4.1
Numerical Compm'json of Explicit and Implicit Euler
Let x(O) ::::: 4, T :::: 5, and tlt ;:: I. Table 4.1 compares the exact solution (4.9) with the explicit Euler (4.10) and implicit Euler (4.12) methods.
TABLE 4.1
x,
Linear First Order Example (. = 5, dt;:: 1)
exact
()
4.()()()()
1 2 3
3.2749 2.6813 2.1952 1.7979 1.4715
4
5
x, Explicit Euler 4.0000 3.2000 2.5600 2.0480 1.6384 1.3107
error
-2.YkJ ·-4'yf{-)
-6.7(70
---8.99() -10.9%
x, Implicit Euler
errol"
4.0000 3.3333 2.7778 2.3148 1.9290 1.6075
J.(-H(' 5.49;
The results shown in Tahle 4.1 are illustrated graphically by the curves in Figure 4.2.
implicit explicit
FIGlJRE 4.2 D.t = I.
Comparison of the exact solution with the explicit and implicit Euler for
1.81;1,
7.Yfri
9.2(;{,
86
Chap,4
Numerical Integration
at : : :
Larger Integration Step Size. We have seen the well-behaved response for I (which is 7/5). Consider now a larger D..t. We cun sec from (4.10) that the explicit l-:u1cr method predicts.r::::: 0 for all time after time 0, if at;;:::; T. Indeed, the explicit Euler solution is oscillatory for fj,t > 7, for this process. For example, let at = 6 for this problem. The results arc shown in 'fable 4.2. These results arc illustrated more graphically by the curves plotted in Figure 4.3. The implicit Euler techniquc has monotonic behavior and more closely approximates the exact solution. We sec that the implicit Euler method call tolerate it larger integration step size than the explicit Euler technique. Linc)]r First Order Example (r;:: 5, ilt;:: 6)
TABLE 4.2
,~~---~
x, exact
x, Explicit Euler
4JJOOO U04S 03629 0-1093 (W329
4JJOOO -II-SOOO 0,1600 ,(HmO OJI064
°
6 12 IS 24
-Y,
Implicit Euler 4,0000 LSIS2 11-8264 IU757 IU70S
4
3
2
implicit
~
exact
0 explicit
-1 0
FIGURE 4.3
5
10
15
20
25
Comparison of exact solution with implicit and explicit Euler for D.l;;o.
30
o.
We have seen that thcre is a limit to how large a step size can bc tolerated by the explicit Euler method before it goes unstable, while the Implicit Euler Inethod rcmains stable for any step size. This is true for a simple linear ordinary differential equation. The following example illustrates an important issue when solving nonlinear equations. That is. the implicit Eulcr method requircs an iterativc solution at each time step.
Sec. 4.2
87
Euter Integration ---------------~-- -
EXAjVII.JIJ~ 4.2
....
_----------~----
Explicit and Implicit Eulcl"-Nonlinear System
Consider a surge tank with an outlet f!owratc that depends on the square rool of the height of liquid in the tank. Whclllhcrc is 110 inlet flow, the model has the following form fix
(4.13a)
dl
WA (:::: flow coefficicntJcross-scctional
where x is the tank height and (/:::;;
Analytical solution (exact).
'l'he analytical solution is
[\1,(1»
x(l)
lit
/21'
Next, we compare tbis solution with the explicit and implicit
Explicit Euler.
area).
(4.13bl r~Lllcr
solutions.
The explicit Euler method yields the following equation
,(k
+
I)
(4.14)
x(k) - tH lI\le(k»
l<'or the numerical example of ([;;;; 0.8, curves for 3 different D.ts are shown in Figure 4.4.
2
3
4
5
F1G{][{E 4.4 Explicit Euler solution. !:1t:::: O.()I, 0.1, and LO. The 0.01 and 0.1 step sizes yield virtually identical results. while there is a significant error ill a step size of 1.0.
Implicit Euler.
The implicit Euler method yields the following equation
,(k + I)
~
x(k) -- uta\lx(k + 1)
(4.15)
R.ecall that when we were dealing with a linear equation we were able to rewrite the implicit Euler equation to yield an explicit calculation of the state variable at the next time step. Here we sec that this is impossible for a nonlinear equation. Rewriting (4.15),
,(k + I) + ula\lx(k + I)-x(k)" 0
(4.16)
we sec that (4.16) requires an iterative solution. That is, at time step k + I we must usc a numerical method that \vill solve a nonlinear algebraic equation. We know from Chapter 3 that a num-
Numerical Integration
88
Chap.4
bel' of techniques, including Newton's method, can be used. To illustrate clearly one approach that we can take, let y represent tbe value of x at step k + I for which we desire to find the solulion. We can rewrite (4.16) as
y + b\/v - c = 0
(417)
where y -= x(k + I), b "" 1:11 (/, and c :;;: x(k). If Newton's method is used, we can write:
MCr(i»
c.
y(i) + 1,v)'O) - c
(4.18)
where (i) is an index to iudicatc the ith iteration of Newton's method.
yO +
I) ~ rei) _ M(YO» . g' (yO»
(4.191
where
g'(y(i»
~
1
iJ
+ --7'
(420)
2VY(I)
We call write (4.19) as (from (4.18), (4.19), and (4.20»
yO+
I),~y(i)-
Iln,'(i) iJ
(\1)'0)]
(4.21 )
\lv(i) + 2 Equation (4.21) is then iterated to convergence. Summarizing, at step k+l of an integration, we must iteratively solve for the value of x at k+ I. That is, (4.21) is iteratively solved to convergence, in order to find x(k + 1) in (4.16).
COMMENT ON IMPLICIT INTEGRATION TECHNIQUES We have seen that the implicit Euler method is more accurate and stable than the explicit Euler method. We also noted that, for nonlinear systems, a nonlinear equation must be iteratively solved at each time step. The implicit Euler method allows a much larger time step, hut some or the computational savings Inuch be sacrificed in the inlcralive solution of the nonlinear algebraic equation at each lime step_ There arc a Ilumber of more advanced implicit methods that arc used in a number of commercially availahle integration codes. In this text we emphasize e.rplicit techniques, which are used by the MATLAB routines ode23 and ode4 5. SIMULINK has choices of some implicit integration routines. An explicit technique that is more accurate than the explicit Euler technique is known as the Runge-Kutta method and is shown in the next section.
4.3
RUNGE-KUTTA INTEGRATION This technique is an extension of the Euler method. In the Euler method, the derivative at time step k was used to predict the solution at step k+ 1. Runge~Kutta methods use the Euler technique to predict the x value at intermediate steps, then use averages of the slopes at intcmediatc steps for the full prediction from the beginning of the time step.
Sec. 4.3
4.3.1
89
Runge-Kutta Integration
Second-Order Runge-Kutta
The first Rungc-Kutta approach that we discuss is the second-order Rungc-Kutta method, which is also known as the midpoint Euler method, for reasons that will become clear. The Euler technique is first used to predict the state value at I:3.t12. The derivative is evaluated at this midpoint, and used to predict the value of x at the end of the step, l:i.t, as shown in r'igufc 4.5. Let Tnj represent the slope at the initial point and lJl 2 represent the slope (dddt) at the midpoint:
n1,
~
n1,
= [
x(k + 1)
I(t (k), x())
~
(4.22)
At At) ( t(k) + 2' x(k) + 2 n1,
x(k) + n1,At
(4.23) (4.24)
For autonomOllS systems, the derivative functions arc not explicitly functions of time, so (4.22) and (4.23) can be written:
n1,
[(x(k))
(4.22a) (4.23a)
or
n1 2
•••
[(x(k) +
~ !(X(k))
(4.23b)
x(k+l) based on x(k) and slope at t k + D. t 2 x(k) ----------~ t k+ 1
FIGURE 4.5
Pictorial representation of sccolld~ordcr Runge-Kutta (midpoint Euler) technique.
Numerical Integration
90
Chap" 4
Equation (4.24) can now be written:
x(k + I)
~ x(k)
+ L1t r (r(X(k) +
~tr(X(k))))
(4"24a)
which is of the form:
x(k + I)
~
g(x(k))
It should be noted that the second-order RUllgc- Kutta is accurate to the order of :i1 2 ,
while the explicit Euler is accurate to the order of dt.
Second-order Rnngc~Kutta (Midpoint Euler) Tedmique
EXAMPLE 4.3
Consider again the first-order process: dx
dt
~ {(x) ~
1
-
x
(4"8)
T
Ill, ~
r(x(k))
~
( -"
I
T
x(k) )
~
-I T
x(k)
(4"25)
(4"26)
For t1t::;;;; 1,
T
From (4"25)
=
5, and x(O) = 4.0: 111[=
~
-4 --5
-1( I) x(O) - -15 (I - OJ)(4) I - """" 5 10
From (4"26)
[:rom (4.24)
-1 x(O) 5
x(l)
~
x(O) +
x(1)
~
4"0 - OJ2 ~ 32800
111 ,
~
H 5
bot
Compare this with the analytical result of 4.0 e -1/5:::: 3.2749 Notice that the error is O.16 1YtJ. Contrast this with an error of-2.3% from Table 4.! for the Euler method. For the same step size, Rungc-Kutta techniques arc more accurate than the standard Explicit Euler technique.
Thus far, we have used single variable examples. The next example is for a able system.
two~statc vari~
Sec. 4.3
EXAMPLE 4.4
91
Runge-Kutta Integration
Two~statc
Variable System, Second~ordcr Rungc~Kutta Method
Consider two interacting tanks in series, showll in Figure 4.6, with outlet tlowrates that are a fun~~,igl_~_ ~!f the square root of tank height. Notice that the He)w from tank 1 is a function of while the flowratc out of lank 2 is a function of Vl1
VII I - il 2,
2·
F
FIGURE 4.6
Interacting tanks.
The following modeling equations describe this system
(4.27)
For the following parameter values: ft2.5
13,
= 2.5
min
13 2
5
=·~C
fl2S
A, = 5 ft' A, = to ft'
\/6 min
and the input: F = 5 ft 3 /min the steady-state height values are:
Numerically, we can write (4.27) as:
dh c] i t ' . ) 1,(h"h 2 dh, 11;(h"h 2) 1 [ dt
~
[
, ! ·.---1-0.5vh,-h, 2< O. -,
=
_I '2
_1. ;,-
]
(4.28)
2\16 \ h,
Since this system is autOnomous (no explicit dependence on time), we can leave (oul of the arguments:
m,
=
111
~ 2
.
I
];(h,(k), h2(1e))] j(h(le)) = j;(h,(k), h,(k))
.ti(h,(Ie) + at2 [1;(h,(k) + at2
""I'
Ill",
at]
h,(k) +2 h2(k)
fI1 21 )
M
+ 2
fI1 21 )
Numerical Integration
92
+ IlJ + 1l ~ [h,h '((k l ~ [hh '((klJ l + k + 1 2 k
h(k
Chap. 4
1I1,C,t
Let the initial conditions be 11 1(0) = 12 ft and hiD):= 7 ft. Also. let!J.! 0::: 0.2 minutes. Por k = 0, we find
. 05
YI2-~7
I ..
-7-,IY7-
2v6
-0.118034.] 1. 0.018955
so
I
h,(O)] hiO)
j
h,(O) +
!!.t 2
. 12 +2 0.2 ( 0.118(34) • ~ 111.9881971
----m
~t 111" ~
h,(O) + !!.t 111" 2'
"'" •. t;(h,(O) ~
"'" .0
.=
0.2 7 + -;C (0.018955)
'
+
~
12 +
7
f·
7.001896
0~2 (_ 0.118(34) ~
0 .2 (0.018955) 7_
~t "'". h (O) + ~t "''') 2
~
11.988197f1
7.001896 fl
1;(11.988197.7.001896)
1-0.5vI1.988197-7.001896 ~ -0.116501
t;(h,(O)
+ ~. "'", h,(O) +
~t "''') ~ /,( 11.988197, 7.001 R96)
0.25 vi (.988197 -7.(J()lWJ6-
",(I)
~
",(0) +
",( I) - ",(0) +
m"c,t
~
v7.001896
~
0.OIH116
12 + - 0.116501 (0.2) - 11.976700 It
m"c,t - 7 + 0.01 R116 (0.2) .= 7.1l03623 It
and we call continue for the next time step, k = t. A plot of the response of this system is shown in Figure 4.7. The response of Ii] actually increases slightly hefore dccrcasing------this is missed became of the scaling. Notice that when hi is greater than h 2 , the flow is from tank I to tank 2; while when hi is less than 1l 2, the flow is from tank 2 to tankl (although this cannot occur at steady-state). Since we have assigned a positive value to F[ when the flow is from tank I to tank 2, then a negative value of F I indicates the opposite flow. Care must he taken when solving this problem numerically, so that the square root of a negative number is not taken. For this pU'lJOse, the sign function is used
Sec. 4.3
93
Runge-Kutta Integration
::~ 10 1
- - - -
gL
81
7r-------61o
20
--==========~! 40
60
80
100
time (minutes)
FIGlJUE 4.7
Transient response of the interacting lank example, using second-order
Runge- Kutta.
The idea behind the second-order Runge-Kutta can be extended to higher-orders. The most commonly used method is the .f(Jllrth-order Runge-KaNa method as outlined in the next section.
4.3.2
Fourth-Order Runge-Kutta
Using this method, the approximations arc more accurate than explicit Euler or sccondorder Runge-Kutta. The idea is to use the initial slope (m J ) to generate a first guess for the state variable at the midpoint of the integration interval. This first guess is then used to find the slope at the midpoint (m 2 ). A "corrected" midpoint slope (m 3 ) is then found by using mz. A final slope (m 4 ) is found at the end of a step using 111 3- A weighted average of these slopes is then used for the integration. The algorithm is fill ~
[(I(k), x(k))
fIl 2 =
[~(k)) + ~ D.I, x(k)
(4.29)
~ fIllD.I)
(4.30)
~ [(I(k) + J D.I, x(k) + 1 11I D.I) · 2 2 2
(4.3 J)
+
fll,
fIl 4 = [(I(k)
t
+ D.I, x(k) + 11I,D.t)
(4.32)
94
Numerical Integration
x(k
+ i)
~
x(k)
j
I
~!lL
-I-
IJ}z
11
3
+ tn, + m•4 3
11
!,
uf
Chap.4
(433)
To become rnore familiar with integration techniques, yOll should solve sOllle of your initial problems using the explicit Euler method. Make certain that your step size is small enough so that the errors do not build up 100 rapidly. As you find a need for more accuracy, you should then lise the fourtlHlrdcr Runge-Kulla method. In Section 4.4 we introduce the MAI'LAB routines that arc available for numerical integration.
SELECTiON OF INTEGRATION STEP SiZE Generally, integration step size must be "small" for Euler, call be larger for second-order RUllgc~KLltta (as far as accuracy is concerned), and can be still larger for fourth-order Rungc-Kutta. Particularly for Euler, step sizes that are (00 large can be unstable or inaccu~ rate. Step sizes that arc too small may waste computer time or have numerical truncation errors sillce the state variables Inay not change much from step to step. If the student L1ses a fixed step si/.e, then it is generally a good idea to try larger and smaller step sizcs to sec if the results change significantly. Generally, you will want to use as large a step size as possible, A particular challenge is from "stiff' systelns (time constants that span a wide range), where a commerical code specifically for stirI' systems should be Llsed. One welJknown implicit mcthod for stitT systems is (Jear's method, which is available in SIMULINK. Implicit methods will only work wel! for systems that arc continoLls. IT discontinuous systems are simulated (for example, step changes at certain times), then Runge-Kutta methods should be used. Most eommerical integration packages use a variable step size. The integration step size is automatically chosen and varied from step-to-skp to assurc accuracy while minimizing computation time. The integration routines in MA'rLAB use a variable integration stcp size.
4.4
MATLAB INTEGRATION ROUTINES Thc primary purposc of thc previous sections in this chapter was to review simple numcrical techniqucs for integrating initial valuc ordinary differential equations. We havc illustrated the techniques with some simple numcrical examples, implemcnted as m-files in MATLAB. In practicc, we do not recOlnmend that you write your own integration routincs. You will spend much tinle debugging these routines and they will generally not be as po\verful as existing academic or commcricalintegration routines. Your goal should bc to providc the correct formulation of the model, spccifying the corrcct initial conditions and parameters. You should generally usc a well-documented, commerical or public domain integration code to implement your simulation. MATLAB has several routincs for numerical integration; two arc ode23 and ode45. ode2:3 uses second-order and odC'4:) uses founh-order RLlngc~Kutta integration. Both routines usc a variable integratioll step size (Lit is not constant). The integration
Sec. 4.4
MATLAB Integration Routines
95
step size is adjusted by the routinc to provide the necessary accuracy, witholll taking too !llllch computation limc-,
4.4.1
ode23 and ode45
To usc od(-~23 or ode4~-), the reader must first generate an m-filc 10 evaluate the state
variable derivatives. Theil the student gives the cOlllmand:
It, xl
ode45 ( , xpr ime '
I
rto, t
t ] xO )
where xprimc
is a string variable containing the Halne of the Ill-file for the derivatives
to
is the initial time is the fjnal time is the initial condition veclor for the state variables (usually a column vector)
t t
xO
The arrays that arc returned arc
x
a (column) vcctor or lime an array of state variables as a function of time (column I is Slate I, etc.)
For example, jf the lillle vector has 50 elements, and there arc three state variables, then the stale variable vee lor has the 50 rows and three columns. After the integration is performed, if the student wishes to plot all three variables as a fUllction of time, she/he simply types
plot(t,x) If you only want to plot the second state variable. then the command plot (t, x ( : ,2) ) is given.
EXAMPLE 4.4
Revisited Solution Using MATLAH Routine ode45
rirst. the following file titled twotnk. m was generated:
function hdot
Lwotnk{t,h) ;
consL~(1/{2*sqrtI6)));
hdotll) = 1-0.5*sqrtlh{l) h(2)); hdot(2)
"" O.2')"c3qrtlhll)--h{2))-cow,t*:;qrt(h(2));
'fhcn, the following command is entered ill the !VIATLAB command window: [t, h 1"'ode4S { T twotnk' , [0100] , [12 7
J ' };
Numerical Integration
96
Chap. 4
Notice lhat we arc generating two arrays, ( and h, and using ode45. The function file is named twotnk. m. The initial time is to :; :;: 0 and the final time is ~r:;;:: 100. The initial condition IS 110:;;:;: fl2 Tj'. At the MATI,AB prompt (») the following commands were given: plot(t,hl"l)) plot (t, hi, ,2) )
The transient responses are shown in Figure 4.8.
12
11.5
£
11
10.5
10
o
20
40
60
80
100
80
100
time (minutes) a. Height of Tank 1
7.2 7 6.8 N
-c
6.6 6.4 6.2 6 0
20
40
60
time (minutes)
a. Height of Tank 2 FIGURE 4.8
Transient response curves for interacting tank example.
Notice the tremendous reduction in effort when compared with generating your own RungeKuua code.
Further Reading
97
Often it is desirable to know the state variable valucs at a particular timc or at fixed time steps. A variable stcp size algorithm yields variable valucs that are not at a fixed step sizes. One has two options. If the variable step size is smaller than that of the variable step, then we could reduce the step slze. The major disadvantage is that computation time will increase. The best option (and that recommended by MATLAB) is to use a spline fit to interpolate or extrapolate the values to desired points. The routine used is interpl.
SUMMARY It is important for the student to understand the Euler, as well as the second and fourth order Runge-Kutta integration techniques. When using your own fixed step size integration code, be careful with the selection of !1t. In practice, it is preferable to use a commercial integration code, which automaticalJy selects the integration step size. The MATLAB routines llsed were ODE23:
Variable step size, second-order Runge-Kutta
ODE45:
Variable step size, fourth-order Runge-Kutta
FURTHER READING A nice treatment of numerical integration is provided by: Parker, T.S., & L.O. Chua. (J 989). Practical Numerical Algorithms .ftJr Chaotic S'.vstems. New York: Springer- Verlag.
A treatment of integration techniques with chemical engineering applications is presented by Davis. Davis, M. E. (1984). Numerical Methods and Modeling for Chemical Engineers. New York: Wiley. The following book is more of an advanced undergraduate/first-year graduate student text on numerical methods to solve chemical engineering problems. The emphasis is on FORTRAN subroutines to he used with the IMSL (FORTRAN·hased) package. Rameriz, W.P. (1989). Computational Methods ./iJr Process Simulatioll. Boston: Butterworths.
Numerical Integration
98
Chap.4
STUDENT EXERCISES 1. Consider the scaled predator-prey equations.
dy,
··-=a(l-y)y dt .2 I
dy,
;il
The parameters are
<X
=
r3
=
-13(1 - y,)y,
= 1.0 and the initial conditions arc ."1(0) :;;;; 1.5 and
y,(O) = 0.75. The time unit is days.
a. Solve these equtions using explicit Euler integration. Compare various integration step sizes. What b.t do yOll recommend? In addition to transient responses (t versus y, and Y2), also plot "phase-plane" plots (y, versus yz). b. Solve these equations using the MATLAB integration routine ode45. Compare the transient response curves with the Euler results. c. How do the initial conditions effect the response of YI and Y2? Please elahorate.
2. Consider a CSTR with a second-order reaction. Assurne that the fate of reaction (per unit volume) is propottional to the square of the concentration of the reacting component. Assuming constant volumc and constant density, show that the modcl~ ing equation is:
dC dt Use the following parameters: V 5 . p=.mll1
k 2 = 0.32 flO Ibmol' min-'
and a steady-state inlet concentration of C i , = 1.25 Ib11101 fl ' Calculate the steady-state concentration of C, = 0,625 Ibmol ft-3 Assume that a step change in thc inlet conccntration occurs at t:::: o. That is, C i changes from 1.25 Ibmol fl-} to 1.75 Ihmol ft-} atl = 0 minutes. Use ode45 10 simulate how the outlct concentration changes as a function of time.
3. Analyze the stability of the fOliJ1h ordcr Runge-KuHa method for the classical order process.
dx
tit
first~
-x
What is the largest integration step size before the numerical solution becomes unstable?
t
Student Exercises
99
4. A gas surge drum has two componcnts (hydrogen and methane) in the feedstream. Let Yi and y represent the mole fraction of methane in the fcedstream "mel drum, respectively. Find dP/dt and {I,v/dt if the inlet and outlet now rates can vary. Also assume that the inlet concentration can vary. Assume the ideal gas law for the effect of pressure and composition on density. Assume that the gas drum volume is 100 liters. The temperature of the drum is 3 J.5 deg C (304.65 K). At steady-state the drum pressurc is 5 atm, the molar flow rate in and out is 2 gmollmin and the concentration is 25Cff! mcthane, 75% hydrogen. Usc Eulcr integration and ode45 to solve the following prohlems. Discuss the effect of integration step size when using Euler integration. In all cases, you arc initially at steady-state. a. Assume that the molar llowrates remain constant, but the inlet methane concentration is changed to 509h. F'ind how pressure and composition change with time. b. Assume that the molar f10wrate out of the drum is proportional to the difference in pressure between the drum and the outlet header, which is at 2 atm pressure. Perform a step change in inlet concentration to 5(Y./o methane, simultaneously with a step change in inlet tlowrate to 3 gmollmin. c. Assume that the MASS f10wrate out of the drum is proportional to the square root of the difference in pressure between the drum and the outlet header (which is at 2 atm pressure). Again, perform a step change in inlet concentration to 501ft" methane, simultaneously with a step ch;:mgc in inlet flowratc to 3 gmol/min, d. Assume that the MASS rlowrates in and out are proportional to the square root of the pressure drops. Assume that the steady-state inlet gas header is at 5 atm. Perform a step change in inlet concentration to 50W" methane, simultaneously with a step change in inlet pressure to 6 atm. 5. Pharmacokinetics is the study of how drugs infused to the hody arc distributed to other parts of the body. The concept of a compartmental model is often used, where it is assumed that the drug is injected into compartment I. Some of the drug is eliminated (reacted) in compartment 1, and some of it diffuses into compartlnent 2 (the rest accumulates in compartment 1). Similarly, some of the drug that diffuses into compartment 2 diffuses back into compartment 1, while some is eliminated by reaction and the rest accumulates in compartment 2. The rates of diffusion and reaction arc directly proportional to the concentration of drug in the compartment of interest. The following balance equations describe the rate of change of drug concentration in each compartment.
Numerical Integration
100
Chap. 4
drug concentrations in compartments J and 2 (fLg/kg patient where x J and x2 weight), and u = rate of drug input to compartment 1 (scaled by the patient weight. [Lg/kg min). Experimental studies (of the response of the compartment I concentration to various drug infusions) have led to the following parameter values: ;:;0
(k lO + k 12 ) = 0.26 mini
(k 20 + k21 ) = 0.094 min-I k l2 k 21 = O.(1I5 mio- I for the drug atracurium, which is a I1lll.<';clc relaxant. Notice that the parameters have not hccnindcpcndcntly determined. Show (through numerical simulation) that all of the following values lead to the same results for the behavior of xl' while the results for x2 afC different. Let the initial concentration he 0 for each compartment and as~ slime a constant drug infusion rate of 5.2 fLg/kg min.
a. kJ2~k2l b. k 12 =2k 21 C. k l2 = 0.5 k21 Discuss how the concentration of compartment 2 (if measurable) could be Llsed to dctcrmine the actual values of k l2 and k 21 . Usc the MATLAB [unction ode45 for your simulations. 6. A stream contains a waste chemical, W, with a concentration of I moilliter. To Illcet EPA and statc standards, at least 90% of the chemical must be removed by rcaction. The chemical decomposes by a second-order reaction with a rate constant of 1.5 liter/(mol hr). The stream f10wratc is 100 liter/hr and two availahle reactors (400 and 2000 liters) have been placed in series (the smaller reactor is placed hcforc the larger onc). a. Write the modeling equations for the concentration of the waste chemical. Assume constant volume and constant density. Let ell'l ~ concentration in reactor 1, mol/liter C w2 ~ concentration in reactor 2. mol/liter F' ::::: volumetric tlowrate, liter/hr
Vj V2
liquid volume in reactot 1, liters liquid volume in reactor 2, liters k : : : second-order rate constant. liter/(mol hI') :::::
b. Show that the steady-state concentrations are 0,33333 mol/liter (reactor I) and 0,0')005 mol/liter (reactor 2), so the specification is met. (I-lint: You need to solve quadratic equations to ohtain the concentrations,) c. The system is not initially at steady-state. Write a function file and use ode45 for the following:
Student Exercises
101
(i). If C",I(O) = 0.3833 and C",2(0) = 0'()9005, fine! how the concentrations change with time. (ii), [I' C",I(O) = 0.3333 and C",2(0) = 0.14005, find how the concentrations change with time.
7. Consider a batch reactor with a series reaction where component A reacts to form the desired component B reversibly. Component B can also react to form the undesired component C. The process objective is to maximize the yield of component B. A mathematical model is used to predict the time required to achieve the maximum yiele! of B. The reaction scheme can be characterized by
Here k]fand k tr represent the kinetic rate constants for the forward and reverse reactions for the conversion of A to B, while k2 represents the rate constant for the con~ version of B to C. Assuming that each of the reactions is first-order, the reactor operates at constant volume, and there arc no feed or product streams, the modeling equations arc:
where CA, Cu' and C c represent the concentrations (mol/volume) of components A, B, and C, respectively. a. For k,{= 2, k l ,. = I, ane! k 2 = 1.25 h,l, use ode45 to solve for the concentrations ~IS a function of time. Assume an initial concentration of A of CAO := t mollliter. Then plot the concentrations as a function of time. For what time is the concentration of B maximized? b. Usually there is some uncertainty in the rate constants. If the real value of k2 is 1.5 hr- l find how the concentrations vary with time and compare with part a.
SECTION
III LINEAR SYSTEMS ANALYSIS
LINEARIZATION OF NONLINEAR MODELS: THE STATE-SPACE FORMULATION
5
Many dynamic chemical processes arc modeled by a set of nonlinear, first-oruer differential equations that generally arise from material and energy balances around the system. Common analysis techniques arc based on linear systems theory and require a ,\·tate~space model. Also, most control system design techniques are based on linear models. The purpose of this chapter is to provide an introduction to state-space Inodcls and linearization of nonlinear systems. After studying this chapter the reader should be able to: Write a linear model in stale-space form. • Linearize a nonlinear model and place in state-space form. Use thcMATLAB eig function to analyze the stability of a state-space model. • Develop the analytical solution of state-space models. Understand stability and transient response charactcrstics as a function of the eigenvalues. • Understand the importance of initial condition "direction". Be able to use the MATLAB routines step and initial for simulation of statcspace models. The major sections in this chapter are: 5.1 5.2 5.3 5,4 5.5 5.6
State-Space Models L,inearization of Nonlinear Models Geometrical Intell1retation of Linearization Solution of the Zero-Tnput Form Solution of the General State-Space Form MATLAB Routines step and initial 105
106
5.1
Linearization of Nonlinear Models: The State-Space Formulation
Chap. 5
STATE·SPACE MODELS Thus far in this text we have discussed dynamic models of the general form:
x=
f(x,u)
('ill
where f(x,u) is, in general, a nonlinear function vector. A linear model is a subset of the more general modeling equation (5.1). 'I'he fonn of linear model that we discuss in this chapter is known as a statc-space model. First. \vc show how to write statc~spacc models for systems that arc inherently linear. Tlll'.IL \VC show how to approximate nonlinear systems with linear models. [~xamplc 5.1 illusln:ttcs the form of a state-space model.
EXAi\IPLE 5.1
NOllintcracting Tanks
Consider two tanks in series where the flow nut of the first tank enters the second lank (Figure 5.1). Our objective is to develop a model to describe how the height of liquid in tank 2 changes with lillIe, given the input fJowratc F,,(t). We aSsumc that the flow out of each lank is u linear function of the height of liquid in the tank. Fo
t h1
tbi. tt=L. F1
h2
FIGURE 5.1
F
2
Noninteracting tanks.
A material balance around the first tank yields (assuming constant density and F] :;;; [1 IlIl)
(5.21 where A J is the constant cross-sectional area (parameter), I) I is the flow coefficient (paranlt'((TL Po is the fJowrale into the tank (input), and hi is the tank hcight (state). Writing a materi
F. J- _ ../3)' II A, 2
A,
Sec. 5.1
107
State-Space Models
where A 2 is the constant cross-sectional area for tank 2 (parameter), ~2 is the now coefficient (parameter), F J is the flowratc into the tank, and /1 2 is the tank height (state). In this case, F I is not an independent input variable that can be manipulated, since F 1 =. {3Jh J " We can write the previous equation as
dI',. /3, df - A
~2 h
h
2
A
1 -
2
2
(5.3)
Notice that we can write (5.2) and (5.3) in the following matrix form:
(5.4)
which has the general form:
x=Ax+Bu
(5.5)
where:
/3, A,
/3, A2 The state and input vectors arc (notice that the input is a sC:;llar):
x
= r~:J
anel
II
= Fo
The additional equation that is nonnally associated with a state space model is (5.6)
y"c:Cx+[)u
where y is a vector of output variables. Generally, output variables arc variables that can he measured (at least conceptually) or arc of particular interest in a siumlation study. Here, we will consider the case where both tank heights arc outputs. Let output I be the first tank height and output 2 be the second tank height
The matrix-vector form is: y
[I 0] [h'l
~ o
I
h,
cc
where:
c
oj
I [o I
ex
108
Linearization of Nonlinear Models: The State-Space Formulation
Chap, 5
/fwe also consider the input, F o' to be the third output variable, we have the following relationship:
y
~
which is the form of (5.6), with
5.5.1
'l I [] 1
0
0
1 [;;'] +
0
0
1
o
'
2
()
[F;,]
General Form of State Space Models
Example 5.1 illustrated a specific case of a state-space model. In general, a state-space model has the f{)lIowing form: dX I
-I-
dt
(JIll X;,
-I- b ll
H)
-I-
-I- h Jill
-I-
lim
dim U IlI
which has n state variables (x), m input variables (ll) and r output variables (y). This relationship is normally written in the matrix form:
["] x"
['
(lui
(112
(1,,2
'or] [" """
x"
+
b",
[" I"[" '1'],I' ell
Yr
(r1
(;,<2
em
x"
tid
btl
bill
"r] b~!Il1 I:",
d l2
da
"]1 "] d~lIl ltl/l
Linearization of Nonlinear Models
Sec. 5.2
which has the general
109
(state~space) form:
x~Ax-l-Bu y~Cx
-I-Du
(5.7)
where the dot over a stale variable indicates the derivative with respect to time. A~ shown in Section 5.4, the eigenvalues of the Jacobian matrix (A) determine the slabihty of the system of equations and the "speed" of response. The aij coefficient relates state variable j to the rate of change of state variable i. Sillli~ larly, the bij coefficient relates inputj to the rate of change of state variable i. Also, cij relates state j to output i, while dij relates input) to output i. We can also say that the klh row of C relates all states to the ktll output, while the kth column of C relates state k to all outputs. In this section we have shown how to write modeling equations that arc naturally linear in the state-space form. In the next section we show how to linearize nonlinear models and write them in the state-space form. Linear models are easier to analyze for stability and expected dynamic behavior.
5.2
LINEARIZATION OF NONLINEAR MODELS Most chemical process models are nonlinear, but they arc orten linearized to perform a stability analysis. Linear models are easier to understand (than nonlinear models) and are necessary for most control system design methods. Before we generalize our results, we will illustrate linearization for a single variable problem.
5.2.1
Single Variable Example
A general single variable nonlinear model is: d-,,; dl ~f(x)
(5.8)
The function of a single variable, j(x), can be approximated by a truncated Taylor senes approximation around the steady-state operating point (.-r):
. ~ f(xJ -I- .. iif j(x)
I (x - xJ -I- I ..,a rI (x - x,)' -I- hIgher . order terms 2
dx x,
2 dx
(5.9)
x,
Neglecting the quadratic and higher order terms, we obtain:
. = j(xJ . j(x) -I- af . I (x - xJ dx
(5.10)
x,
Note that:
dx y dl
() ~jx, ~O
(5.11 )
110
Linearization of Nonlinear Models: The State-Space Formulation
Chap. 5
by definition of a steady-state, so:
I
dx = f(x) == 'iii . dt rh
(x- x,)
.1,
where the notation 0f1(}ti.t is used to indicate the parlial derivative ofJ(x) \vith respect to .t, s evaluated at the steady-state. Since the derivative of a constant (1;) is zero. we call write: dx
'J
d(x dl
dl
I) 13)
which leads to:
I (x - x,)
d(x - xJ ,.= ill .' dl dx
() 1-II
-I,
ThcTcaSOll for using the expression above is that we arc orten interested in deviations in '-1 stale from a steady-stale operating point. Sometimes the symbol is llsed to represellt dc viat;rm variu!JIes, x' ::::: X -'_:y We can sec that a deviation variable rcprcscllls the CIWll).!C or perturhation (dcviatirm) 1'1'0111 a stcady-state value. I
() 1)1
'Ihis can be written in
state~space
Corm: dr' (f
dt
(516)
x'
where {/ :::: iH!dxx s . We have shown how to linearize a single variable equation. Next, system with one state and one input.
5.2.2
\VC
consider a
One State Variable and One Input Variable
Similarly, consider a function with one state variable and one input variable dx
x
dl
~
f(X,II)
() 171
Using a Taylor Series Expansion Corf(x,u): x
. /(X"II,) + ;'ill I d.x
.t,.Il,
.iY'/1 .:
dxtJU
(x - xJ
+ {iu .'ill I. (II - IIJ .1,.1/,
(x - X,)(II - II,) + l ;i'il 2 1 (II ~.1 II,)' .1,.11,
2
rJlr
.\\.11\
+ higher order terms
b
Sec. 5.2
Linearization of Nonlinear Models
111
and truncating aftcr the linear terms, we have:
x.
~~
. It ) fix
,
s, s.
I
iI f +. (Jx
(x - x )
.\",.(1,
S
-
t-
ill ()ll
I
IJ',
(It -
ItJ
(5.18)
and realizing thatj(x,I"u) :::: 0 and dx/dt = d(x ~ .r)/dt:
d(x dl
xJ .~. ilf I ax
(x
~. x) +
',.11,
,
Using deviation variables,./ ::::.r - xI" and u' =
It -
ilf
all
I
(li
',,II,
.~
uJ
11,1':
which can be written:
dx' dt
= (/ x'
j--
b u'
(5.19)
where ({:::: cYIc-1rLr,\' and b::::; ~fl()u[x,\"u.\, If there IS a single output that is a function of the states and inputs, then:
g(x.lI)
Y
(5.20)
Again. performing a Taylor series expansion and truncating the quadratic and higher terms:
(5.21 ) Since g(x,I"u\) is simply the stcady-state value of the output Cv), we can write:
(5.22) or
y - y, ~ where c:::: aJ;J{)xi.\. \" /I s and d
co (x - xJ + d (li - lIJ
= dg/au:,_'-
.\',II.\'
Using deviation notation:
y' ,,::. l~xalnplc
system.
C
x'
+ d II'
5.2 illustrates the application of linearization to a
(5.23) one~input,
one-slate nonlinear
Linearization of Nonlinear Models: The State-Space Formulation
112
EXA \IPLE 5.2
Chap. 5
Consider H Nonlinear 'rank lleight Probll'l11
\vhcrc Ii i\ tlie
sjalC
dh
I·
13 \ II
.1
.'1
\ariilhlc. F is the input \'ariahlc. 13 Hild A arc parameters. The riglJlhand side is:
r
I(ld)
I ,
1(l1F) I
hi'
Ij \
,I
\
A
[3
I-
2/\ \ h,
III
(:,),251
rile ftl'\l terll] ell] the righthand side is lern. because the lincari/
I
I
dl!'
()
.1
J
W(, call jll)\'\ \\Tite:
hJ
d(h
II, 11.1
I'
1,,\ \ II
and lI\ing dC\ialiul1 \ariahk nutatioll (1/::0: Ii - h and j
dh'
I'
2/\\ 11,
I +
II'::::
A
r
II and dmpping the
II" ,I
I.'
!--'\)r \:UIl\CllicllCC (simplicl1;' in llotatj()!11 we often urlJJ! the (') notation and assume that x ~l!1d II
arc dc\j,Hi(1I1 \(lriahles Cr:::: Ii - h,.
/I::::
r
(,i
dIld
write:
til:
IJ
I
dl
2/\ \' h,
I
"
which i" in the :sta!('-sp;\l'l' form
dr
dr
5.2.3
ux-l-bu
(527)
Linearization of Multistate Models
The prC\ious cx,-ullples sho\\ed how to linearize single-stale vari~lhlc systems. In this seclion \VC geJlcralizc the technilJue for any' I1umber slates. lkfnre vvc generalize the techniquc. it is worthv,hile to consider an example system with Ivve) states, olle input and OIlC output.
ur
-
••
~ . ._ - - - - - - - - - - - - _
Sec. 5.2
EXAMl'LE 5.3
113
Linearization of Nonlinear Models
Two~statc
S.ystCJll dX j ~ 1;(.r, ,X"ll) lit
(5.28)
(5.29)
(5.30) Performing a Taylor series expansion of the nonlinear functions, and neglecting the quadratic and higher terms:
From the linearization about the steady-state:
j;(Xj"Xh,U) = J;(X il ,X2",Il,)
=
0
and:
g(X I."X2"U) ,=-, y, Since the derivative of a constant is zero:
"\x,
-=-or,,} and
dl
we can write the state-space model:
d(x] - x 2 )
lit
Linearization of Nonlinear Models: The State-Space Formulation
114
Chap. 5
,II,
,ll""1
(Ju
f-
_.
[ df e (JII
,
I
\\hid)
i~
,II~'
dg
d.t]
t .. " . "
ilx,
I·
(5.311 XI,
t"
lhe form or a st:l!t'-SP:lCl' IlHldel:
x'
A x' ex'
y'
+ H u' + D u'
\\here (') indicates dC\iation variahles.
5.2.4
J
Generalization
NO\\ consider the tll'ncral nonlinear Illodel \\'hcrc x is
x,
~
f,(.r,. ... \'",u, .. ·1/111)
xn
..
1;,(x 1
... .x/I·u I'
lJ
is
(j
, .. lI m )
-V ,
gJ (.r j ....-\"".11 J' .If",)
Yr
g,(.\l"
,X",II], .. .11 1)
In \-ector notation:
f( X,II)
15 ..\.11
g(x,u)
(';,\41
F killen!" of the linearization matrices arc defined III the follll\ving fashion: /\ 1.1
"1.1
(lX,' __ Ii
<11/,
I .. "
b
Sec. 5.2
Linearization of Nonlinear Models
115
I
(5.37)
c,'.I
= iJu '''i ~ dAj
i)u D = -"-" II
After linearization, we have the
.1,_1<,
I
aU
j
statc~spacc
"/'>
(538)
form:
x'
A x' + H u'
y'
Cx'+Du'
Generally, the () notation is dropped and it is understood that the model is in deviation variable form:
x=Ax+BlI y=Cx+[)lI Usually, the measured (output) variable is not a direct function of the input variable, so it is Illore common to sec the following state~spacc model: x~Ax+BlI
This procedure is applied in
EXAMPLE 5.4
[~xample
5.4.
Interacting Tanks
Consider the interacting tank height problem shown in Figure 5.2:
FIGURE 5.2
Interacting tanks.
AsslIlne that the flowratc out of tanks is a nonlinear function of tank height. The f]owratc out of tank one is a function of the difference in levels between tank I and lank 2.
116
Linearization of Nonlinear Models: The State-Space Formulation
Chap. 5
Also, assume that only the second tank height is measured. The output, in deviation variable form is
Notice that there arc two state variables, one input variable, and one outptH variable. Let
= F- F,
u
The clements of the A (Jacobian) and R matrices «5.35) and (5.36» arc:
"fl
I
ilf ah'}
I
lJil 1 Au
=
2
IJ I 2A I Vhl,\~--h~;
hJ;
~I
2A1VhL\-=7i~\
h F ".<
~2
~J
2A2v'hl;~-li;_;
li
= II
ill I ilF hJ',
2A,vh"
1
i
Al
=0 Since only the height of the second tank is measured, y
ell
and the state-space model is:
=
0:::
(jj;; k.", ~~ 0
g(h 1,h 2,F)::o::: h 2 --
ilL,
(from (5.37)):
Sec. 5.3
117
Interpretation of Linearization
Il,
(!li'] [
--- 2/tl\,/h l:;- :~)17s cc
Il,
{fJ:}
2A2V/hl,--~-h2'
dt
t
y
Ul}UI
[O!]
1~:1
where:
In this section we have shown how to linearize a nonlinear process model and put it in slate-space form. The states in this model arc in deviation (perturbation) variahle form; that is, the states arc perturbations from a nominal stcady~stat:c. A stale-space moclel provides a good approximation to the physical system when the operating point is "close" to the linearization point (nominal steady-state).
5.3
INTERPRETATION OF LINEARIZATION In Section 5.2 we illustrated the method of linearization of models into slalc~space form. The objective of this section is to illustrate what is meant hy linearization of a function. Consider the single tank height problem, which has the following model: dh dl
~
F
J(h,l')·c
A
-
f3 II
...
vh
(5.39)
I/V5
for a system with A -= 1 n2 , !Is :::: 5 ft, and fj ;;:; ft L5 /min the steady-state f10wrale is 3 F s ;;;;: I ft /min. To focus our analysis 011 the meaning of the linearization with rcspect to the statc variable, consider the ease where the input is constant. Then, from (5.39) and the given parameter valucs:
f(hYJ
c.c
I ~
1
vh
performing the lincarization:
J(h.FJ = f(h,,!',)
+:"If I . (h ~ h,) dh
h,)"s
(5.40)
118
Linearization of Nonlinear Models: The State-Space Formulation
Chap, 5
0,5 ~
"'"
linear
o
-a,s
o
4
2
6
10
8
x
FIGlJRE 5.3 Basic idea of linearization. 'rhe linear approximation is exact for the steady-state value of x;::o: 5.
for our parameter values (h,FJ '" 0
+
2\15
(h -
hJ
or I
('(hF)=O--(h-h) 's . 10'
(54 I)
.
10
8
'" 'q; '" .c
6
1"
.' ..
4
'
2
a
o
10
20
30
40
lime, min
FIGURE 5.4
Comparison of linear and nonlinear responses for two different
initial conditions.
50
Sec. 5.4
Solution of the
Zero~lnput Form
119
We can see how good tbe linear approximation is by ploning both the nonlinear function (5.40) and the linear function (5.4l), as shown inlijgurc 5.3 011 p. liS. Here we have used x to represent tank height and .f(x) to represent the nonlinear and linear functions. Notice that the linear approxiruation works well between roughly 3.5 to 7 feet. or course, the two functions arc exactly equal at the steady-state value of 5 [eet, which was the point at which the Taylor series expansion was performed. H.calizc that .f(x) is dx/dt, which is the rate of change of tank height. It makes sense that the rate of change is positive at a tank height less limn 5 feet, because the system "seeks" to achieve a steady-state level of 5 feel. Similarly, for a tank height greater that 5 feet, the rate of change of tank height is negative, because the level "desires" to decrease to 5 feet. We can also see that the linear system wiJl be slower than the nonlinear syslem, if the tank height is less that 5 feet, but will be faster if the height is greater than 5 feet, as shown in Figure 5.4.
5.4
SOLUTION OF THE ZERO·INPUT FORM We have previously written the general state space Inodel in the following form: x~Ax+llll
where x and u are deviation variable vectors for the stales and inpulS, respectively. In this section we assume Ihat the inputs are held constant at their steady-state values, but thaI the states may be initially perturbed from steady~state. The "zero-input" form of the state space model is then:
.j [ [ \1
all
t'/I
{lnl
{/lll
(/1I2
llll/l
·] 1r XI
.fn
or
x
Ax
(542)
This form is used to analyze the stability of a system and to understand thc dynamic behavior of a system that has had its statcs perturbed from the steady-state values. Recall that the single variable equation:
X
ax
has the solution:
X(I)
,,'" x(O)
which is stable if a < O. In a similar fashion, the solution to (5.42) is
X(I) ~ e"'x(O)
(5.43)
and the solution to (5.43) is stable if all of the eigenvalues of A are less than zero. The response of (5.43) is oscillatory if the eigenvalues arc complex.
Linearization of Nonlinear Models: The State-Space Formulation
120
Chap. 5
There arc many differenl ways to calculate the exponential of a matrix; in this chapter we discuss only the similarity tr{[n.~1"orm method.
Recall that the eigenvector/eigenvalue problem is written (sec Module 2 for a review):
AV=V;\
(5.44)
l
V = where
S,
=[~~:]=
S2 =
[~~~]
[s,
S2J
I
v" =. v"
"12) "22
(5.45)
first eigenvector (associated with AI)
= second eigenvector (associated with 1.. 2)
and the following eigenvalue matrix: ;\ =
I I I.., 0 1..0
(5.46)
2
Multiplying (5.44) nn the right side hy V·] wc find:
A=V;\V '
(5.47)
multiplying by the scalar t and taking the matrix exponential, we find: eM
= V
ei\1
V-I
(5.48)
(5.49)
where and we sec imlllediately why Ai
< () is required for a stable solution. The solution for x(t) is x(t) = V e'" V-I x(O)
(5.50)
An interesting result is that an initial condition vector in the same direction as ~i has a response in the direction of ~i with a "speed or response" of Ai" This is shown by the foll{)w~ ing analysis.
5.4.1
Effect of Initial Condition Direction (Use of Similarity Transform)
Recall that we arc solving the following model
x=
Ax
(5.42)
Define a new vector z, such that
x = Vz
(5.51 )
Sec. 5.4
121
Solution of the Zero-Input Form
or
z = V--- J X
(5.52)
and notice that (from (5.51 )):
x=
V Z
(5.53)
Substituting (5.53) and (5.51) into (5.42):
Vz=AVz
(5.54)
z = Vi A Vz
(5.55)
V'AV=!\
(5.56)
or, left multiplying by V-I
But, from (5.44) A V = V A so we can write:
which yields (from (5.55) and (5.56)):
z=
(5.57)
!\ z
But A is a diagonal matrix (sec (5.46», so we have:
[il] 'A0I "-20]1"'_ ] Z2
=
_
Z2
(5.58)
Notice that (5.58) represents two independent equations:
z]
= "-IZ\
12 =
"-2 Z2
(5.59) (5.60)
which have the solutions:
z,(t)
=
Z,(O) e'"
(5.61)
z,(I)
= Z2(0) e'i
(5.62)
"e'0 " e',1O][Z](O)] .Z2(O)
(5.63)
z(O)
(5.64)
and we can write:
[ ZI(t)1 z,(t)
=
or
z(t)
=
eAl
Notice that, if the z(O) vector has the form: (5.65)
ESCOLA Dc EHGENHARIA BIBLIOTECA
122
Linearization of Nonlinear Models: The State-Space Formulation
Chap. 5
then:
z(t)
(5.66)
and, if tile z(()) vector has the form: (').67)
then,
(568)
that is. initial condition,,; of z{O) :::
AI' v\ihile initial conditions ofz(O):::
will yield a ';spced of response" associated with
"
will yield a "speed of response" associated with
Al • 'I'llis means that state variable initial conditions in the "direction" of the first eigenvector will have a speed or response associated with the first eigenvalue:
(569)
and state variable initial conditions in the "direction" of the second eigenvector will have a speed or response associated with the second eigenvalue
x(t)
v z(t) (5.71l)
Knowing the effect of the initial condition "direction" is impOitant. If a randOlll case study approach was taken, then we might arbitrarily select initial conditions that \verc '"fast.'" \vhilc other (missed) initial conditions could cause a much slo\\'cr response. We \vill show two examples of tbe c-free! of initial condition: Example 5.5, where the syS!elll is stable, and r':xample 5.6, \\'here the system is unstable.
t
Sec,5A
I<;XAMI'LE 5.5
123
Solution of the Zero-Input Form
A Stable System
Consider the following system of equations
+ x2
XI = - 0.5 XI
(5,71 ) (5,72)
Using standard state-space notation
x = Ax
(5A2)
The Jacobian matrix is A
= [. -1l.5
1 '.1
°
(5,73)
-2
the eigenvalues are the solution to det(H - A) :;;:; 0, which yields A
det ([.
+ 05
°
J)
- 1
+ 05)(A + 2)
= (A
A+ 2
~
°
so
A,
- 0,5
= -
A,
2
and the eigenvectors are
<, = [-11.5547 '1 0,8321 Note that Sl is the "slow" subspace, since it corresponds to Al = -0.5 and space, since it concsponds to'\2 :::;::-2, The numerical values of (5.50) for this problem are
X(I)
= V
~2
is the "fast" sub-
e'" V 'x(O) O
-0,5547J[.e 0,8321
°
"
011' 0,6667] x(O) 1.2019
e"
°
(5,74)
If the initial condition is in the direction of ~l' that is
x(O)
~ [~J
(5,75)
we find the following slate solution (from (5.74) and (5.75»:
X(l)
=
[I e-~5'1
(5,76)
If the initial condition is in the direction of S2' that is,
X(O)
= I. - 0.5547.1 0,8321
(5,77)
124
Linearization of Nonlinear Models: The State-Space Formulation
Chap. 5
we find the following state solution (from (5.74) ami (5.77»:
- 0.5547
X(f)
(5.781
0.8321
Note that x(O) :::; ~l"'" f.lll is the slow initial condition and x(O) :;; ~2 :::;; I---~;_:~-_:~
I is
the fast
initial condition, as shown in Figures 5.4 and 5.5. The initial conditions in the fast subspace IWH' reached the steady-state in roughly 2.5 minutes (Figure 5.6), while the initial conditions in the slow subspace afC roughly 7SCYo complete in 2.5 minutes (J-'igurc 5.6').
11'IGlJRE S5
Transient response for initial condition in the slow
subspace.
The expm (matrix exponential) function from MATLAB can be llsed to verify these simulations. Using t :;; 0.5 and the fast initial condition, we find
»d
;:::
[~O. ~j
I
1;
0, '-2] ;
»x -;;; expm(a*O.5)*[--O.5547 x
0.8321]
;:::
-0.2040
0.3061
t
Solution of the Zero-Input Form
Sec. 5.4
which agrees with the plot
~hown
125
in I,\gurc 5.6.
fa.:H suospace
x(O) = [- 0.5547 ] 0.8321 -1
o'-------------------=' 2 345
FIGURE 5.6
Transient response for initial condition in the fast
subspace.
The previous example was a stable system. The next example is an unstable system.
EXAMPLE 5.6
An Unstable S}'stem (Saddle)
Consider the following system of equations; .\:) =
~\'2
The Jacobian matrix is
A
1.22
=
2x 1
+ Xl
= 2x, -. Xl
II
- I
the eigenvalues are A,
= -1.5616
A2
I
<2 -
=.
2.5616
and the eigenvectors are
<1 =
...
0.270:1 .1 -O.962g .
o.R719]
l0.4896
s[
since Al < 0, is a stable subspace; since A2 >. 0, S2 IS an unstable suhspace. The solution for this system is: Xl
__._ ["
() -
o.R71911e
0.2703 -0.9628 0.4896
15(,lr"
0
°11 0.5038
e 1.56 \(il.O.9907
If the initial condition is in the direction of ~l' that is:
8972 -0. 1 x(O) 0.2782
126
Linearization of Nonlinear Models: The State-Space Formulation
Chap. 5
O,'7(H!
x(O)
--
O.~h2-f-; I
we find the fulJrming :--1,l1C SolUli(l1l O.270J ('
xl t) ~I\
which is a stablt' solution.
shown in
~
o
r"i)!UH:
.".7
stable sUbspace
~~-~--===-------I
~~
x -0 5
- O,9h28 ('
f /,.
1/ "
x(O)
~[
-
0.2703] 0 9628
-I'L----:----------::---;;-----o 2 3
FlCa"IU: 5.7
Inlli,t1l'(11Hli\i(l1l in till' \[:lhk SUh"p:ICl'.
If lhe initi;d condilinll is in the dirl'ctioll pI x(lI)
that is,
X7191
0 [ (l'-iS96
we find the following state \o]lIliun: X(I)
rUnl9 (-"';('11,' [O.-iX(l() eo' ,",h'
which is all lHl.s[,lhJe SO!llliulL as ShU\\'ll lJl FlgUIT 5.S.
o
o
FIGUI-U: 5.8
02
O~
06
08
Initial umditioll in tilt' unstahle \uhspau_'_
Il should be noted lhal if the initial conditioll is Ill)! ('.Y(lU/\' in the stahle slIh"pacc. the solUliull \\'illl.w~jll to di\l'I'!,!c and hCCOllll' unslahk. Thut is. if thl' initlal cunditi()11 i" olT by. "a;, 10 !p. thl' rl'Sp()Il"l~ \\,ill l'\,cntually lxconw Llllbuumkd.
t
Sec. 5.6
5.5
127
MATLAB Routines step and initial
SOLUTION OF THE GENERAL STATE-SPACE FORM
b 12
;.]
",-
b n2
b nm .
_U~iI
Now, consider the general form:
[] ["
__u:
"T] l"
at?
11
(lll/!~
ali?
b"l
\ /I
or x~Ax
Illu
(5.79)
Recall that the single variable equation:
x=a.\l-bu
(5.80)
has the solution:
X(I)
~c
b en, x(O) I (e'" - I) 1/(0) a
(5.8 I)
when u(f) = constant = {f(O).
In a similar fashion, the solution to (5.79), for a constant input (u(t) = t::::: {)
nCO»~
from
to tis
X(I)
~
P xeD)
+
Q u(O)
(5.82)
where
(583)
Q
and F:quation (5.82) can be used to time step by using:
ttl
~
(I' - I) A 'II
(5.84)
solve f{}I' a system where the inputs change from time step
X(I + AI)
+ Q U(I)
(585)
Px(k) + Qu(k)
(5.86)
P X(I)
More often this is written as
x(k + I)
~
where k represents the kth time step. Often a general purpose nuttlcrical integration tcch~ niquc (such as one presented in Chapter 4) will be used to solve (5.79).
5.6
MATLAB ROUTINES step AND initial We show the usc of step and 1. nit i a 1 by way of the following example.
128
EXA!\'1PLE 5.7
Linearization of Nonlinear Models: The State-Space Formulation
Chap. 5
A Linearized BiOl"Cactol" l\lodel
Consider the follO\ving: lincarilcd form of a biorcactor model with suhstrate inhibition kinetics (see tvloduJe 8 for details):
x=Ax-fBu
)'=Cx+Du where:
o
A=
- 0.7500
009056-] 2.5640
B _[- 1.5302 [ _ 1.8255
[oI 0]I J) -
[~;I
Enter the state space model: »
a =
[0,
0.9056;--0.7500, -).')640]
<::1
o
0.9056
-0.7500 -2, 'j640 »
b
b
c
co::
[--1.5302;3.8255)
-1.5302 3.8255 [l,O;l,OJ
>-,.c
1
0
o
1
[0;0)
»c1
d
o o
t
Sec. 5.6
MATLAB Routines
~;tep
and initiiJl
129
Check the stability »
eig(a)
ans : :; : ~().3000
-2.2640
The system is stable. Assume the process is initially at steady-state. Since this model is in deviation variable form, the initial condition is the zero vector.
5.6.1
The MATLAB step Function
The MATLAB step [unction assumes a deviation variable form (the initial conditions are zero). The cOlllmands arc.: »
[y,x, t]
stcp{a,b,c,d,l);
" plol(t.,y) which yields the plot shown in Figure 5.9. Notice that the ::3 te-p function automatically determined the length of the Ii me vector. You may also provide an equal~spaccd time vector and usc the following command [y,x] = step(a,b,c,d,l,t)
5.6.2
The MATLAB initial Function
The MATLAB ini t ial function assumes a deviation variable form, with the initial conditions perturbed from zero. The commands arc:
FIGURE 5.9
Plot of outputs, for a step input change.
130
Linearization of Nonlinear Models: The State-Space Formulation » »
[Y,x,tJ
=
Chap. 5
initial(a,b,c,d/l);
ploL(t,y)
Notice that the band d matrices are not really used by' the initial function. since it is assUllled that there is no input change.
SUMMARY In this chapter we have developed a statc~spacc model of a chemical process thm is in.. hcrcntly linear (e.g., the tank height example). \\ic have also \ho\vn I1mv to linearize models that are nonlinear. The models obtained in this fashion arc based on r/eriulioll l'ariables, that is. the states and inputs arc perturhotiolls from the steady-state operating point where the linearization is pcrfonncd. The stahility of a nonlinear syqcrn is determined from the eigellvalues of the Jacobian matrix in the linearized model (statc-sracc form ). Several important concepts were presented in this chapter.
For unforced systems (zero input). the initial conditiclll vector \vil! determine the "speed" (If response. For stable systems (all A 0), the eigenvector associated \vith the largest rnagnitude A is the fast direction, while the eigenvector associated with the smallest A is the s\()\v direction. Although it is possible for a system with both Ilegatin; (stable) and positi\e (unstable) eigenvalues to have stable behavior if the initial condition is In the stable subspace, this is impossible in practice. Any perturhation from the stable trajectory \-vill cause lhe solution to become unbounded (unstable). The I,,:1ATLAB routines that \-vere used include: exprn:
step:
Matrix exponential Step response of a state-space (or transfer function) model
State-space rnodels can be transformed to Laplace transfer function fOnl1, which is particularly useful for control sy'stcm design. Applications of Laplace transforms \vill be presented in Chapters 7 through 10. Eigcnvector/cigenvalue analysis \vill be useful in pe-rfonning phase~p!anc analysis. which is covered in Chapter 13. The reader should understand the fol\O\ving terms: state-space Jacobian deviation or perturbation variable eigenvalue
Student Exercises
131
eigenvector linearization stability Taylor series
FURTHER READING L,inearization is discussed briefly in most books on process control, including: Luyben, W.L. (1990). Process Modeling, Simulation and Control for Chelnical Engineers, 2nd Ed., New York: McGraw-Hill. Marlin, T.E. (1995). Process Control. Designing Processes and Control Systems for Dynamic Performance, New York: McGraw-HilI. Ogullnaike, B.A. and W. H. Ray (1994). Process Dynamics, Modeling and Control, New York: Oxford University Press. Seborg, D.E., T.F. Edgar, and D.A. Mcllichamp (1989). Process Dynamics and Control, New York: Wiley. Stephanopoulos, G. (1984). Chemical Process (:ol1trol: An Introduction to Theory and Practice, Englewood Cliffs, NJ: Prentice-Hall.
STUDENT EXERCISES 1. As a process development engineer you arc working on a process with three continuous-stirred-tank reactors (CSTRs) in series. A constant volumetric H(l\vrate (flowratc docs not vary with time) is maintained throughout the system, howcver the volume in each reactor is different (but constant). Since thc temperature varies from reactor to reactor (but is constant in an individual reactor) the reaction rate parameter is different for each reactor. The molar concentration of the inlet stream varies.
2
Assume that the density of the streams remains constant (independent of concentration). The reaction is a first-order (irreversible) decomposition (11 --> B). Molar rate of decomposition of A (per unit volume) = k CA
Linearization of Nonlinear Models: The State-Space Formulation
132
Chap. 5
tI. \\irite the::; dynamic model equations. h. \Vritc the statc-space model oCt") ::: A x + B It c. The values or the parameters and variables arc
F::::: 1 nJ/min C(I::: I IhmoJlft.'l
V, = I() ft1 V, = ft' V, = 5 fl ' :;:; O.O:n3 mini k::.::::: 0.2 min- 1
kl
k:;:::
0.55 mirr· 1
i. Find the steady-state concentrations in each reactor it Evaluate the A matrix (Jacobian) and find the eigenvalues
2. Consider a chemical reactor with bypass. as shO\vn below. Assume that the rcnction rate (per unit volullle) is first-order (r::: kC j ) and ('I is the concentration in the reactor (the reactor is perfectly' mixed). Assume that the volume in the reactor (V) and the feed flowrate (F) remain constant. crhc fraction of feed bypassing the reactor is (l -a)F and that entering the reactor is aF. Assume that the fraction bypassing the re~ actor does not change. The inlet concentration (C i) is the input vmiable and the mixed outlet strcarn composition (e 2 ) is the output variable. \\lrite this model in state-space form (this model is inherently linear, so deviation variahles are not neededj.
A :( + n If \"=C'x+-Dl/
o(.{-)
3. C\msidcr the follc)\\.;ing set of series and parallel reactiolls A
k. I
.~)
A + A
k.-, [i ~,
k,
C
.)
D
Material balances on cOlnponents A and B yield the following t\-\/O equations F , V ((",1/ - CAl - k. (", - k, (":,
d('., dl dC"
F
V ( .. ("/1)1 (k,
dl
where
k,
5 6
min
(Ii
I
Ie 10 mol
liter
5 ]
(A -
k: elll
.
I liters 6 mol min
nlln- I k, =----:-
,
(" ii'
~
mol
.,-~
.
I iter
a. Find the steady-state dilution raIl' UIVj and concentration of B (show all units). h. Linearizc and put in state-space hlrm (find the numerical values of the A. B, and (' matrices), assuming that the manipulated vari,l!,!e is dilution rate (F/I/) , and the output variable is CI). c. r;'ind the eigenvalues (shmv units). d. Find perturbations in initial conditions that arc in the fastest and slo\-vcsl directions.
h
133
Student Exercises
4. A chemical reactor that has a singlc second-ordcr reaction and an outlct r10wrate that is a linear function of hcight has the following model: dVC -= Fe dt In
- FC - WC
2
III
dV = F -F dt III
(5.87)
(5.88)
where the outlct f10wratc is linearly related to the volume of liquid in the reactor (F == 13V). The parameters, variables and thcir steady-state values are shown below.
== inlet llowrate (I liter/min) C in = inlet concentration (l gmolliiter) C == tank concentration (0.5 gmollliter) V = tank volume (I liter) k == reaction rale constant (2 liter/(gmol min)) f3 == I min-- l Fill
Equations (5.87) and (5.88) can be written in physical state variahle form as dC = Fi" (C _ C) _ kC 2 dt V -
(5.89)
(1l
dV
dt = F - "V t..J
(5.90)
11/
l---ist the states, outputs, inputs and parameters for the nonlinear equations (5.89) and (5.90). b. Linearizc (5.89) and (5.90) and write the state space modcl (find the numeric_al values for the A, B, and C matrices), assuming that thc inlet tlowratc is the input variable and that both states arc output variables. Define thc deviation variahles for states, inputs, and outputs. 5. Find the "fast" and "slow" initial conditions for the foJlowing model H.
6. Find the stable and unstable subspaccs for the following system of equations
Plot the transient responses for initial conditions in both the stable and unstable subspaces. Show that a small perturbation from the stable initial condition will lead to an unstable solution.
134
Linearization of Nonlinear Models: The State-Space Formulation
Chap, 5
7. The l1ol1intcracting tank model I:) (sec Example 5. () 1
13
"-
0
AI,
_
A,
A,
13 1
I
1
13,,
I" I ] ["1\ + AI, ",'. 0
.
I';,
.
Consider a system where the stcady~statc f10wratcs arc 5 ftJ/min, and the following cross-sectional areas and steady-state heights: Al ~ ~
hi We find (1"')Ill F I ~
2n'
A, ~
2.5 It
h,
~
lon' 5 It
I3 lh l and F, ~ 13 2h 2), then, that: 2 1'1 nz 13, ~ 2 , I', ~ 1 rnm
nlln
and the state-space model (in physical variables) becmHes:
1,
0 '1Ihh, ,I+[05I F l
--1
0,2 - OJ
:J [o ()
0
"
(:1[" 1,1 + [~;- [F I I
",
()
0
"
1
a. Work in deviation variable form and find the fast and slow subspaces. Use ini-· tial to simulate the unforced deviation variable systcrn (input deviation remains constant at 0), from initial conditions in both the fast and slow suhspaces. h. Usc the results from part <1, and convert to the actual physical variables. c. Work in physical variable form. Usc ini tial to simulate the unhJrced deviation variable system (input remains constant), from initial conditions in both the fast and slow subspaccs. Show that the results obtained afe the same as those in part b. 8. As a chemical engineer in the pharmaceutical industry you are responsible for a process that uses a bacteria to produce an antibiotic. The reactor has been contaminated with a protozoan that consumes the bacteria. The predator-prey equations arc Llsed to model the system (b ::::: bacteria (prey), jJ ::::: protozoa (predator)). The time unit is days.
dh dl dl' dl
u
b
'Y bp
" 'Y hp-
13 I'
Student Exercises
135
a. Show thatthc steady-state values are
b. Usc the scaled variables, tv and z, to find thc following scaled modeling equations Ii rill'
d/
dz d/
,,(I =~
p
z=
ll'
~z)w
fl (1
~
w)
Z
c. [<'ind the eigenvalues of the Jacobian matrix for the scaled equations, evaluated at W s and zr Realize that ll'.I ' and z,\. are 1.0 by definition, Find the eigenvalues in terms of ct and f3. d. "rhe parameters arc (~ :::0 f3 ;:; : 1.0 and the initial conditions arc w(O) ;:;;: 1.5 and z(O) = 0.75. i. Linearize and write the state-spacel~ml1 (let the state variables be Xl :::0 HI ,- It\- and );:, ;;;;; Z - z).Find the initial condition vector xo ;;;;; [,,".,«0)) [, to use . ~ . 'x,D with in.it_ial. ii. Solve the state space model from (I) lIsing lsim and plot the transient response of Xl and x2 as a function of time (plot these curves on the same graph), simulating to at least t ;:;;: 20. iii. Show a phase-plane plot, placing Xt on the x-axis and x2 on the y-axis. iv. WhItt is the "peak-to-peak" time for the bacteria? By how much time docs the protozoan "lag" the bacteria? 9. Consider the state-space model
Ii'l I. ~ 1.0 "2
4.0
~
0.011 X'i .\,
5.0
a. Find the "fast" and "slow" initial condition directions. 10. Consider the foJiowing system of two reactors.
~
Linearization of Nonlinear Models: The State-Space Formulation
136
Chap. 5
Assullle a firsHmJcr decornpositi()tl of ;\-->8. Assume that all flo\\TatC\ arc C(lll· stant (volumes arc consUlllt). a. \\;'ritc the moueling equations for concentration or A, using either the instantaneous or integral method. h. \Vritc these in state-space form: X~AX4
Bu
c. Given the following constants. calculate the steady-slale concentrations:
I·;,
cu
=
_ kgnlOl .j
IJ.3.1.13.1 hr
L
I
111
V~ = l)m
VI'" 15nr'
d. Find the eigenvalues of the A matrix. Discuss the swbility of this Sy'stClll. e. The inlet concentration.
('Ii'
is changed from 1.5 to 1.75 at {:::: O. Usc ,:;l:cp tel
simulatc the behaVior of this system. 11. ;\ stirrc,d lank heater is used to supply a chemical proct:~ss \vith a fluid at a constant temperature. The heater receives fluid from an upstrcam pnll'l'SS unit \vhich may cause the f10wrate or tcmperature to change. Consider the diagram of the stirred tailk heater sho\vn belt)\:!". \vhere the tank inlet stream is received from another process unit. /\ heat transfer fluid is circulated through ajacket to heat the fluid in the tank, Assume that no change of phase nccurs in either the tank liyuid or the jacket liquid. Tank inlet
F,
T,
~
~
V
Tank Jacket outlet
Jacket
r-
T
---
Jacket inlet
F
T Tank outlet
Part 1 a. Write the dynamic modeling equatiolls to find the tank ami jacket tcmperaturcs. Do not usc any numerical values----Jeavc these equations in terms of the process parameters and variahles. State any additional assumptions needed [0 sol ve the problem.
Student Exercises Assume:
137
Constant level. Perfect mixing in both the tank and jacket.
The tank inlet flowratc, jacket flowrate, tank inlet temperature, and jacket inlet temperature may change. The rate of heat transfer from the jacket to the tank is governed by the equation Q ;:;; UAClj ~ T), where U is the overall heat transfer coefficient and A is the area for heat exchange. b. State the nl(~jor objective of this process. c. What do you consider the most important measured variable? d. What is a likely input variable variahle that you would use to maintain a desired tank temperature?
Part 2 Assume that both the tank fluid and the jacket fluid are water. The steady-state ues of this system variables and some parameters arc:
I'l' min
1; = Tjill
=
p(~, = 61.3
Btu
OF
p/'~)j = 61.3
50"F
Toe 125°F
v c=
20(Y'F
7; = 150"F
VJ = 1 ft'
10
val~
Btu OF
n'
e. Find Fj and UA (show units) at steady-state. f. Linearize the set of two nonlinear ODEs obtained in problem a, to obtain the state space form:
x=Ax+Uu
where
x=
=
u=
state variables
input variables
1'- l' ]
Y = 1T- 7: J J.I
= output variables
Determine the A, H, and C matrices (symbolically and numerically) g. Find the eigenvalues of A.
Linearization of Nonlinear Models: The State-Space Formulation
138
Chap. 5
Part 3 h. Simulate the system of state-space equations for a step change in the jacket flowratc from F:i =: 1.5 ft 3/min to l'j =1.75 ft 3/rnin F at time::: 5 minutes (work in deviation variables, but remember to convert back to physical variahles before plotting). What is the final value of the states, in the physical variables (T and 7/? Plot the response. i. Perform some simulations with step changes on some of the other input variables. Comment on any different behavior that yOll Illay observe. 12. Consider the following model of 2-stagc ahsorption column:
dzdl ~, (L) w _ (L + Vii) "+ V ". MM· M'I where IV and z arc the liquid concentrations on stage I and stage 2, respectively. L and V arc the liquid and vapor molar flow rates. 'Zr is the conccntration of the vapor strcam cntering the column. Thc steady-state input values arc L := 80 gmol incrt liquid/min and V:::: 100 gmol inert vapor/min. 'fhe paramcter values arc M:::: 20 glnol inert liquid, a = 0.5, and 7f= 0.1 gmo] solutc/gmol inert vapor. H. Find the steady-state values of wand z. h. Lincahzc and find the stale space model, assuming that L and V arc the inputs. c. Find the cigenvalucs and eigenvectors of A (Jacobian). d. l,'ind thc expected "slowest" and "fastcst" initial conditions (perturbations from steady-statc).
13. Most chemical proccss plants have a natural gas header that circulates through the process plant. A simplified version of such a header is shown below.
Pi From source
valve i Plant piping, represented as a perfectly mixed drum
Gas drum for a boilerhotlse unit
To furnaces
Here, the natural gas enters the process plant from a source (the natural gas pipeline) through a control valve. It flows through the plant piping, which we have represcnted as a perfectly mixed drum for simplicity. Another valve connects thc
Student Exercises
139
plant piping to the gas drum for a hoilerhouse unit. Gas passes through another valve to the hoilerhouse furnaces. The objective of this problem is to develop a linear model that relates changes in valve position to changes in drum pressures. a. Write modeling equations assuming that the pressures in drums I and 2 arc the state variables. Let thcinput variables- be (I) valve position I, (2) valve position 2, and (3) sourcc prcssure. b. Solve for the steady-state conditions and write the modeling equations in lincar, deviation variable form.
x=Ax+Uu y = ex
x=
,
rP2p , -- 1"'1 Ph
=
:;::
\I
state variables
[
change in valve position 1 change ~n v<.llve position 2
J = input
variables
change III sourCe pressure
output variables
y
c. Study the effect of step changes in each input on each tank pressure.
HINTS: For simplicity, assume that the following equations can be used for the flow through the valves: fJj
== (Xi hi (pi - PI)
=::
flow through valve i
C/I :::: ('(, hi (PI - P2) == flow through valve I
q2 ::;: 0'2 11 2 (P2 ~ p}) == flow through valve 2
where the f10wrate is in Ibmol/min, h is the fraction that a valve is open (varies between 0 and I), and Ct is a valve coefficient.
STEADY STATE DATA: gas flowratc Pis:;::;;
=:
lOOO std ff~/min
250 psig, PIS::::: 50 psig, P 2s ::;: 30 psig, P 3s == 5 psig
assume that each valve is 1/2 open under these conditions (his:::: h lA,:::: h 2s == 0.5)
140
Linearization of Nonlinear Models: The
State~Space Formulation
Chap. 5
CONSTANTS: V, ~ I 135 n3, V, ~ 329 ft3, Temperature ~ 32 "F
R (gas constant)
~
10.73
psia ft J IbmoloR
MAGNITUDE OF STEP CHANGES: Make separate step changes of 0.1 (10(*)) in the valve openings, and! 0 psia in the inlet pressure. Simulate for t:::; 0 to I = 15 minutes. 14. A strealll contains a waste chemical, W, with a concentration of 1 mol/liter. To Illeet EPA and slale standards, at least 9()fJ{) of the chemical must be removed by reaction. The chemical decomposes by a second-order reaction with a rale constant of 1.5 liter/(mol hr). The stream nowratc is 100 Iiter/hr and two available reactors (400 and 2000 liters) have been placed in series (the smaller reactor is placed before the larger onc). a. Write the modeling equations for the concentration of the waste chemical. A')sumc constant volume and constant density. Let ('wi
C w2 F
V, V2 k
~
~
~
~
~
~
concentration in reactor 1, mol/liter concentration in reactor 2, mol/liter volumetric flowrate, liter/hr liquid volume in reactor I, liters liquid volume in reactor 2, liters second-order rate constant, liter/Cmol hI')
b. Show that the steady-stale concentrations are 0.33333 mol/liter (reactor I) and 0.09005 mol/liter (reactor 2), so the specification is met. (Hint: You need to solve quadratic equations to obtain the concentrations.) c. L,inearize at steady-state and develop the state space model (analytical), of the form:
x
Ax-t-Bu
where: u~
d. Show that the A and B matrices are: - - 1.25 A = [ 0.05
o
- 0.320 IS
I
Il
.=
[0.0016667 O.25J 0.0001216 o
(also, show the units associated with each coefficient) c. i. Find the eigenvalues and eigenvectors using the MATLAB eig function. ii. Find the eigenvalues by hand, by solving det(Al- A) ~ o.
141
Student Exercises
f. The system is not initially at steady-state. Solvc the following for the linearized model, using the MATLAI3 function initial (first, convert the physical variables to deviation variablcs) i. If Cw,(O) = 0.3833 and C w2 (0) = O.(J9005, find how the concentrations change with timc. ii. If Cw,(O) = 0.3333 and CwiO) = 0.14005, find how the concentrations change with time. Relate these responses to the eigenvalues/eigenvector analysis of c. Discuss the differences in speeds of response (you should find that a perturbation in the first reactor concentration responds more rapidly and a perturbation in the second reactor concentration). The MATL.AB ini tial function needs you to create the following matrices before using it:
c
=
[1o 011
0=[0 01 °°
g. Solve f for the nonlinear equations, using ode4 5. Compare the linear and nonlinear variables on the same plots (make certain you convert from deviation to physical variables for the linear results).
h. Now, consider a step change in the flowrate from 100 liters/hour to 110 liters/hour. Assume the initial concentrations arc the steady-state values (0.3333 and ().(l9005). Compare the IincHr and nonlinear responses of the reactor concentrations. Is the removal specification still obtained? i. Would better steady-state removal of W be obtained if the order of the reaction vessels was reversed? Why or why not? (Show your calculations.)
ESCOLA Dc ENGENHARIA BIBLIOTLCA
6
SOLVING LINEAR nTH ORDER ODE MODELS
The purpose of this chapter is to review methods to solve solve linear 11th order ()[)F~s, After studying this material, the student will be able 10: Transform a linear state-space model with differential equation.
1/
states to a single nth order ordinary
Solve an 11th order constant coefficient coefficient homogeneous ODE. Solve an 11th order constant coefficient coefficient heterogeneous ()DE. Solve a first-order ()DE with a time-varying coefficient. Usc the H.outh stability criterion for stability analysis.
The nwjor sections in this chapter arc:
142
6.1 6.2
Background Solving Homogeneous, Linear ODEs with Constant Coefficients
6.3
Solving Nonhomogeneous, Linear OIJEs with Constant CocfTicicnts
6.4 6.5
Equations with Time- Varying Parameters Routh Stability Criterion ,.. Determining Stability without Calculating l:':igenvalues
Sec. 6.1
6.1
Background
143
BACKGROUND A model composed of a single, nth order linear ordinary differential equation has the lowing form:
dx + ",,(I) x til du + b,(I) til + b,,(I)
fol~
... + {/,(t)
(6.1 ) It
where the state variable is x and the input variable is u. 'rhis general model is linear because the state (x) and input (ll) and all of their derivatives with respect to time appear linearly. Notice thallhc coefficients do not have to be linear functions of time, however.
Models of the form of (6.1) do not arise naturally when chemical processes arc modeled. As shown in previous chapters, dynamic chemical process models arc generally sets of first-order (either linear or nonlinear ordinary differential equations. The advantage of the form of (6.1) is that there exist a number or·tcchniques to obtain analytical solutions. In this chaptcr we show how t(? transform scts of lincar, first-order differclltial equations to a single nth order differential equation. We then review several techniques for solving this type of equation. For motivation, we use Hbatch reactor example to illustrate each of the tcdllliques. It should be noted that there arc many good mathematics tcxts that covcr each of these techniques in more depth (see Boyce andlJiPrima, 1992, for cxampic). Our goal here is to provide a concisc overview of some morc lIscful tcchniques to solve dynamic chemical process problems.
EXAMPLE 6.1
Hatch Chemical
R(~ador
Cunsidcr a hatch chemical reactor, where there is no flow in or out of the vessel. The reactor is initially charged \vith a liquid of volume \I and an initial concentration (mol/liter) of reactant A of" C~,IO'
We consider a series reaction where component A reacts to lImn the desired component B. Component B call rurther relet to form the undesired component C. Each of the reactions is irreversihle, so A can react 10 rorm R, hUI B does not react to form A. A
k
--,>1
k 11 -}- C
Here k l represents kinetic rate constant (lime l ) for the conversion of /\ to Ii, while k] represents the rale constant II)r the conversion of U to C. Since component 8 is the desired product, we would like to know how long to run the feaction in order to maximi/.c the amount of 8 produced. If the reaction time is too long, all or B will eventually be converted to C,
Develop the Modeling Equations. Assume that each of the reactions is first-order. Since the volume is constant (dVldt ;:;:; 0), and there is no flow in or out, the modeling equations arc (the reader should be able to derive these, based on material balances on each component);
Solving Linear nth Order ODE Models
144
dC""j dt
Chap. 6
(6.2)
k 1 Cit
~{_Cll dt
(6.3)
dec _ . '
-'--- Ie,
f
(6.4)
(II
{/
where C.',\' C'fj, Hnd C( represent the concentrations (mol/volume) of components A. fl, and C, respectively. The units for the rate constants (k 1 and "-2) arc LIllie' I. Notice that the time faLl' of change of component A is only a fUllction of the COllccntnllion of /\. 'fhcH equation (6.2) call be solved, since C~4 and t arc separable, (0 find (6.5)
where C;\O is the initial condition for the concentration of 1\. If we define the conversion of A as \: :;;:; (CAO - C;\)/('"o and the dimensionless time T :::: kJt. (6.5) can be represented by the single
curve shown in r;igurc 6.1 (x:::: [
~ ('7).
0.8
c
0.6
.Q
"'>
ill c
g0.4
0.2
o o
2
3
4
5
dimensionless time
FIGlJRE 6.1
Conversion of;\ as a function of the dimensionless timc,
Now wc wish to find a single diJlerelltial equation to solve for Cflo
Reduce to a Single Equation for CB. Here we have (wo different ways to solve for Method I, Substitute (6.5) into (6.3) to obtain the expression
ell' (6.6)
Sec. 6.2
Solving Homogeneous, Linear Odes with Constant Coefficients
145
Equation (6.6) is a linear, constant coefficient, heterogeneous differential cquatiOiL ]t is hetenJgcneolls because of the "forcing function" on the righthand side. Heterogeneous equations are solved in Section 6.3. Method 2. Here we can rewrite (6.3) to solve for ell in terms of en: (6.7)
Taking the first derivative of (6.7) with respect to time, we find: (6.8)
Substituting (6.7) and (6.8) into (6.2), we find the second-order equation:
(!2~~'-'i ' {It
+ (k, + k,)
deft
til
+ k,k,
('/I
C
(6.9)
0
Notice that (6.9) has the form (6.10)
Equation (6. J 0) is known as a linear, constant coefficient, homogeneolls differential equation. The term homogeneous means that there is no "forcing function" on the rigbthand side. In Section 6.2 we cover the solution of these equations.
6.2
SOLVING HOMOGENEOUS, LINEAR ODES WITH CONSTANT COEFFICIENTS Homogeneous nth order linear differential equations have the form
d/lx lin
tit'f
+ an _ I
{pr--1x dt'l-l
dx
I + aox + ... + ", {/
=
0
(6.11)
To solve equation (6.11) we replace all (JiX/df i terms by AJ (6.12)
Equation (6.12) is called the characteristic equation. The n roots of the characteristic equation are called eigenvalues (in control textbooks the rools are often called poles). The eigenvalues arc used to solve (6.1 I). Two related methods are used, depending on whether the eigenvalues are distinct (all are different) or repeated (some are the same),
Solving Linear nth Order ODE Models
146
6.2.1
Chap. 6
Distinct Eigenvalues
We sce that (6.12) is ,jJl nth order polynomial that will have arc distinct (not repeated), the solution to (6.11) is
JI
roots, Ai' If all of the roots (6.11)
or
where each the constants ('I through en is found from the initial conditions, \iO). !lx ll " I (0 l!dIIl··1 . In (lrder [0 find the coefficients, c i' \VC rl)ust know the illitia/ cOlldifiollS for r and its derivatives.
6.1 Continued. ~c('
Solution for C:nmponent A
l'nllll equation (6.2) that the concentration of /\ does not depend on the vahle:; or U
e (h,14)
til lIle
l'haracteri'ilic
cqlW(IOII is
A+ k]
II
and [he eigenvalue is A:o: -- k l The solution is then C\(I)
e ,(I)
=c
J
C
e",e
(6.16)
k!
(h.17)
I.,
\\hich is the ",[llle result nhlaillcd in (h.)) usil1g Sl'lMratioll of variablcs and integnilioJ1. Now. let's cuntilluc and use lhe gel]cnd procedure 10 so!vc a sccond-order differential eqllalion
EXX\IPLE 6.1 ContimH'(I,
Solution for Component B
r\.t'ctl! lhatthc cyuatin!l fur the concentration of B i.s: (I
(h.! 01
t
Sec. 6.2
Solving Homogeneous, Linear Odes with Constant Coefficients
147
which can be written: (6.19)
So the eigenvalues arc:
and the solution call be written:
CJI)
~
c, exp(- ki) + (', cxp( . ki)
(6.20)
We need two initial conditions, ell(O) and dCjj(O)Jdt, to evaluate the constants, (:1 and ("2' We assumed that there is no component B in the reactor initially, so ell(O) :::: O. From (6.20) we then find:
From (3) we sec that: (6.22)
Taking the derivative of (6.20) and using (6.21) and (6.22), we find: (623)
C,,(t)
This expression can be used, for eX
Dimensionless Equation, It should also be noted that (6.23) call he made dimensionless by defining the following variables: x
Cfic'!W = conversion of A to B =
dimensionless time
= rate constant ratio to find:
I n
~-
1
[expCT) _. exp(-uT)1
which is shown in Figure 6.2, for a "'" 0.5 and 2. Notice that when the first rcw:tion is faster than thc sccond (ex "'" 0.5), there is a highcr concentration of B than when the first reaction is slower
Solving Linear nth Order ODE Models
148
Chap. 6
than the second (0: = 2). When the second reaction is faster than the first, component B reacts further to form C before a substantial amount of H is formed. 0.5 ............
_-~
-alpha - - alpha
co 0.4
~ 0
0.5 2.0
'0 C
"'"c0 ""' "'
'"
0.3 :'~~~~,
.:
C
.Q
"'c
0.2
,
,
'"
:'
E '6
: 0.1
0
"'
.. '. ", ",
"
0
.... 345
2
6
7
dimensionless time
FIGLJRE 6.2 Concentration of B as a function of time. When the rate for the second reaction is faster than the first «(~ = 2), the peak concentration of B is lower.
We notice in the previous example that (6.23) cannot be used if k 2 :::: k l . This is a case where the eigenvalues are repeated. The procedure for repeated eigenvalues is shown next.
6,2,2
Repeated Eigenvalues
If a particular root in the solution of (6.12), Ai' occurs r times, then the corresponding terms in the solution to (6.11) are: (6.24)
EXAMPLE 6.1 Continued.
Repeated Roots
The equation for the concentration of B is when k2
~t':~_:.11_ rIl
2
:::::
kl
;;;;;:
k is: (6.25)
Sec, 6,2
Solving Homogeneous, Linear Odes with Constant Coefficients
149
and the characteristic equation is: A'
+
2 k A + k2 ~ 0
(A
+ k) (A + k)c., 0
(6,26)
which can he factored as:
so the eigenvalues (roots) are: A,
A2
~
~
-k
The solution can be written:
C,,(t)
~
(e, + e, I) cxp( - k,)
(6.27)
Notice that we can find cl from the initial condition for C n- From (6.27) at t = 0,
But Cn(O);;;;; 0, since there is no II initially, so:
C,,(I)
~
e, t cxp( -
kl)
(6,2H)
The derivative of (6.28) with respect to time is:
at t = 0,
We also know from (6.3) that
"e,,(O) , dt - k CAO so:
C,,(I)
k C AO ' exp( '" I,,)
If we define lhe conversion or A to H as x = (6.29) can be written:
x(i)
c,/eAO ' ilmllhe dirncnsionlcss TexpC T)
(6.29)
tiulC as T;::: kt. then
«(dO)
Solving Linear nth Order ODE Models
150 which is shown version of A to
0.4
ill
Chap. 6
Figure 6.3. The reader should be able to find the 1l.1<1xiunJJn value for the
COI\~
n and the reaction time required for this conversion. ----,.-
0.35 0.3 0.25 0.2 0.15 0.1 005
o o
________-'
-'--
L.
2 3 dimensionless time
4
5
FIGURE 6.3 Conversion of A to B as a fUllction of dimensionless time (T "" kt), for the case of equal rate constants.
The previolls example illustrated the solution for systems with real roots. The next pie illustrates a system with complex roots.
- - - - - _.. EXA MIJl..E 6.2
cxam~
_ ~ -...
Complex Roots
Consider the second-order equation:
dx dt
+x
()
(6.31 )
The characteristic equation is:
A'
o
+ A+ I
Solving for the roots lIsing the quadratic formula, we find that the rools mc complex:
±
-4
2
A~_l±V.3. 2
2
J
(6.32)
Solving Homogeneous, Linear Odes with Constant Coefficients
Sec. 6.2
151
I. The solution is
where j
,(t)
c .1
e(-
2I
+ V3) 2 j t + c 1 e (J ,- 2 -
Vi) --2' -- j t
(6.33)
We can use the following Euler identities:
ejll elo and the property that
eXtI' "" eXe Y
10 ce'-cos ' 1
x(t)
1
x(t) = e
_
l
•
=
=0
cos f:l
jSln f:l
(6.34)
cosO -jsinH
«(dS)
j-
to write (6.33) as:
V3 (--I 2
J'sill .
Vii [Vi Vi I t -1- ' c ('. '/'"cos 2 . 2 1-- J" .sin 2 I
., [c 1 COS V3 2 t
(6.36)
(6.37)
/-
which can be written:
x(t)
e ,/2
[e c ,
x(t)
e
vi
Ie,) ]cos . 2 t e (e, -- ( 2 ) j sin
[V cos 2i t + c
2 lie;>
4
sin Vi 2 t
~3 tj
«(d8)
I
(6.39)
Again, initial conditions for x(O) and ~\:(O) can be used to determine {'3 and ('4- The student should verify that jf x(O}:::: 1 and ~~(O) = I, then c J :::: \.0 and (.'4 ::::1.5. A plot is shown in Figure 6.4.
1.5
::.:;
0.5
a 0.5
o
2
FIGURE 6.4
4
6
8
Plot of (6.39) with x(O) : :;:; I and ~r((»:::: I.
10
Solving Linear nth Order ODE Models
152
Chap. 6
Chemical process system models with complex roots include some exothermic chemical reactors. Also, models including feedback control will often have complex roots (leading to oscillatory behavior).
6.2.3
General Result for Complex Roots
We can now generalize the results of Example 6.2 for any equation that has pairs of complex roots. For each pair of complex roots, A ;: : ; At ±j Ai' where Ar and Ai arc the real and imaginary portions, the solution is:
x(/)
co
(N
lei cos A.,f + c, sin Ai II
(6.40)
In the previous example the real part of the complex roots was negative (stable). Notice that the state variables decayed to zerO with time. Notice from (6.40) that there will be no decay (simply a continuous oscillation) if the real portion is O. We can also sec from (6.40) that a positive real portion of the complex root will lead to an ever growing (unstable) solution. This behavior is shown by studellt exercise 19. Most chemical processes are stable; however, some exothermic chemical reactors have unstable operating points. Also, improperly tuned feedback control systems call be unstable. Thus far in this chapter we have solved the homogeneous problems. Homogeneolls problems result from models that are "unforced," that is, there is no input. This usually occurs when the process model is in deviation variable form, and there is no change in the input variable. They are based on a perturbation from steady~state in the state variable values. In Section 6.3 we will solve nonhomogeneo