- Email: [email protected]

- Author / Uploaded
- Jo Ui Gyu

- Categories
- Documents

SECOND EDITION Simulation of Dynamic Systems ® with MATLAB and Simulink Harold Klee Randal Allen Boca Raton London Ne

* Views 8,960*
* Downloads 2,257*
* File size 21MB*

SECOND EDITION

Simulation of Dynamic Systems ®

with MATLAB and Simulink Harold Klee Randal Allen

Boca Raton London New York

CRC Press is an imprint of the Taylor & Francis Group, an informa business

®

MATLAB® is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks does not warrant the accuracy of the text or exercises in this book. This book’s use or discussion of MATLAB® software or related products does not constitute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the MATLAB® software.

CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2011 by Taylor and Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Printed in the United States of America on acid-free paper 10 9 8 7 6 5 4 3 2 1 International Standard Book Number-13: 978-1-4398-3674-3 (Ebook-PDF) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com (http:// www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com

To Andrew, Cassie and in loving memory of their mother and devoted wife, Laura. Harold Klee To Dave Lundquist and Steve Roemerman who believed in me. Randal Allen

This page intentionally left blank

Contents Foreword ........................................................................................................................................ xiii Preface............................................................................................................................................. xv Authors........................................................................................................................................... xix

Chapter 1

Mathematical Modeling............................................................................................... 1 1.1 Introduction....................................................................................................... 1 1.1.1 Importance of Models ......................................................................... 1 1.2 Derivation of a Mathematical Model ............................................................... 4 Exercises...................................................................................................................... 8 1.3 Difference Equations ...................................................................................... 10 1.3.1 Recursive Solutions ........................................................................... 11 Exercises.................................................................................................................... 12 1.4 First Look at Discrete-Time Systems ............................................................. 13 1.4.1 Inherently Discrete-Time Systems .................................................... 17 Exercises.................................................................................................................... 20 1.5 Case Study: Population Dynamics (Single Species) ...................................... 21 Exercises.................................................................................................................... 28

Chapter 2

Continuous-Time Systems......................................................................................... 31 2.1 Introduction..................................................................................................... 31 2.2 First-Order Systems ........................................................................................ 31 2.2.1 Step Response of First-Order Systems.............................................. 32 Exercises.................................................................................................................... 36 2.3 Second-Order Systems.................................................................................... 38 2.3.1 Conversion of Two First-Order Equations to a Second-Order Model................................................................................................. 43 Exercises.................................................................................................................... 46 2.4 Simulation Diagrams ...................................................................................... 47 2.4.1 Systems of Equations ........................................................................ 53 Exercises.................................................................................................................... 55 2.5 Higher-Order Systems .................................................................................... 56 Exercises.................................................................................................................... 58 2.6 State Variables ................................................................................................ 59 2.6.1 Conversion from Linear State Variable Form to Single Input–Single Output Form ................................................................ 64 2.6.2 General Solution of the State Equations ........................................... 65 Exercises.................................................................................................................... 65 2.7 Nonlinear Systems .......................................................................................... 68 2.7.1 Friction .............................................................................................. 70 2.7.2 Dead Zone and Saturation ................................................................. 72 2.7.3 Backlash ............................................................................................ 73 2.7.4 Hysteresis........................................................................................... 73 2.7.5 Quantization....................................................................................... 77 2.7.6 Sustained Oscillations and Limit Cycles........................................... 78 v

vi

Contents

Exercises.................................................................................................................... 82 2.8 Case Study: Submarine Depth Control System ............................................. 85 Exercises.................................................................................................................... 89 Chapter 3

Elementary Numerical Integration ............................................................................ 91 3.1 Introduction..................................................................................................... 91 3.2 Discrete-Time System Approximation of a Continuous-Time Integrator...... 92 Exercises.................................................................................................................... 94 3.3 Euler Integration ............................................................................................. 96 3.3.1 Backward (Implicit) Euler Integration .............................................. 99 Exercises.................................................................................................................. 101 3.4 Trapezoidal Integration................................................................................. 102 Exercises.................................................................................................................. 106 3.5 Numerical Integration of First-Order and Higher Continuous-Time Systems ......................................................................................................... 107 3.5.1 Discrete-Time System Models from Simulation Diagrams ............ 107 3.5.2 Nonlinear First-Order Systems........................................................ 111 3.5.3 Discrete-Time State Equations ........................................................ 114 3.5.4 Discrete-Time State System Matrices ............................................. 118 Exercises.................................................................................................................. 119 3.6 Improvements to Euler Integration............................................................... 122 3.6.1 Improved Euler Method .................................................................. 122 3.6.2 Modiﬁed Euler Integration .............................................................. 125 Exercises.................................................................................................................. 135 3.7 Case Study: Vertical Ascent of a Diver ....................................................... 138 3.7.1 Maximum Cable Force for Safe Ascent.......................................... 144 3.7.1.1 Trial and Error ................................................................. 144 3.7.1.2 Analytical Solution .......................................................... 145 3.7.2 Diver Ascent with Decompression Stops........................................ 145 Exercises.................................................................................................................. 147

Chapter 4

Linear Systems Analysis ......................................................................................... 151 4.1 Introduction................................................................................................... 151 4.2 Laplace Transform........................................................................................ 151 4.2.1 Properties of the Laplace Transform ............................................... 153 4.2.2 Inverse Laplace Transform.............................................................. 159 4.2.3 Laplace Transform of the System Response................................... 160 4.2.4 Partial Fraction Expansion .............................................................. 161 Exercises.................................................................................................................. 167 4.3 Transfer Function.......................................................................................... 168 4.3.1 Impulse Function ............................................................................. 168 4.3.2 Relationship between Unit Step Function and Unit Impulse Function........................................................................................... 169 4.3.3 Impulse Response............................................................................ 171 4.3.4 Relationship between Impulse Response and Transfer Function ... 175 4.3.5 Systems with Multiple Inputs and Outputs ..................................... 178 4.3.6 Transformation from State Variable Model to Transfer Function........................................................................................... 184 Exercises.................................................................................................................. 187

vii

Contents

4.4

Stability of Linear Time Invariant Continuous-Time Systems .................... 189 4.4.1 Characteristic Polynomial................................................................ 190 4.4.2 Feedback Control System................................................................ 194 Exercises.................................................................................................................. 198 4.5 Frequency Response of LTI Continuous-Time Systems.............................. 200 4.5.1 Stability of Linear Feedback Control Systems Based on Frequency Response................................................................... 210 Exercises.................................................................................................................. 213 4.6 z-Transform................................................................................................... 215 4.6.1 Discrete-Time Impulse Function ..................................................... 221 4.6.2 Inverse z-Transform......................................................................... 225 4.6.3 Partial Fraction Expansion .............................................................. 226 Exercises.................................................................................................................. 233 4.7 z-Domain Transfer Function......................................................................... 234 4.7.1 Nonzero Initial Conditions .............................................................. 236 4.7.2 Approximating Continuous-Time System Transfer Functions ....... 238 4.7.3 Simulation Diagrams and State Variables....................................... 244 4.7.4 Solution of Linear Discrete-Time State Equations ......................... 248 4.7.5 Weighting Sequence (Impulse Response Function)........................ 253 Exercises.................................................................................................................. 257 4.8 Stability of LTI Discrete-Time Systems....................................................... 259 4.8.1 Complex Poles of H(z) .................................................................... 263 Exercises.................................................................................................................. 269 4.9 Frequency Response of Discrete-Time Systems .......................................... 272 4.9.1 Steady-State Sinusoidal Response................................................... 272 4.9.2 Properties of the Discrete-Time Frequency Response Function..... 274 4.9.3 Sampling Theorem .......................................................................... 278 4.9.4 Digital Filters................................................................................... 284 Exercises.................................................................................................................. 289 4.10 Control System Toolbox .............................................................................. 292 4.10.1 Transfer Function Models ............................................................... 293 4.10.2 State-Space Models ......................................................................... 293 4.10.3 State-Space=Transfer Function Conversion..................................... 295 4.10.4 System Interconnections.................................................................. 298 4.10.5 System Response............................................................................. 299 4.10.6 Continuous-=Discrete-Time System Conversion............................. 302 4.10.7 Frequency Response........................................................................ 303 4.10.8 Root Locus ...................................................................................... 305 Exercises.................................................................................................................. 309 4.11 Case Study: Longitudinal Control of an Aircraft......................................... 312 4.11.1 Digital Simulation of Aircraft Longitudinal Dynamics .................. 325 4.11.2 Simulation of State Variable Model................................................ 327 Exercises.................................................................................................................. 329 4.12 Case Study: Notch Filter for Electrocardiograph Waveform ....................... 330 4.12.1 Multinotch Filters ............................................................................ 331 Exercises.................................................................................................................. 338 Chapter 5

Simulink® ................................................................................................................ 341 5.1 Introduction................................................................................................... 341 5.2 Building a Simulink® Model........................................................................ 341

viii

Contents

5.2.1 Simulink® Library ........................................................................... 342 5.2.2 Running a Simulink® Model........................................................... 345 Exercises.................................................................................................................. 347 5.3 Simulation of Linear Systems ...................................................................... 349 5.3.1 Transfer Fcn Block.......................................................................... 350 5.3.2 State-Space Block............................................................................ 353 Exercises.................................................................................................................. 362 5.4 Algebraic Loops ........................................................................................... 363 5.4.1 Eliminating Algebraic Loops .......................................................... 364 5.4.2 Algebraic Equations ........................................................................ 367 Exercises.................................................................................................................. 369 5.5 More Simulink® Blocks ............................................................................... 371 5.5.1 Discontinuities ................................................................................. 377 5.5.2 Friction ............................................................................................ 377 5.5.3 Dead Zone and Saturation ............................................................... 377 5.5.4 Backlash .......................................................................................... 379 5.5.5 Hysteresis......................................................................................... 380 5.5.6 Quantization..................................................................................... 381 Exercises.................................................................................................................. 382 5.6 Subsystems ................................................................................................... 385 5.6.1 PHYSBE.......................................................................................... 386 5.6.2 Car-Following Subsystem ............................................................... 386 5.6.3 Subsystem Using Fcn Blocks.......................................................... 389 Exercises.................................................................................................................. 392 5.7 Discrete-Time Systems ................................................................................. 393 5.7.1 Simulation of an Inherently Discrete-Time System ........................ 394 5.7.2 Discrete-Time Integrator.................................................................. 397 5.7.3 Centralized Integration .................................................................... 398 5.7.4 Digital Filters................................................................................... 402 5.7.5 Discrete-Time Transfer Function .................................................... 404 Exercises.................................................................................................................. 408 5.8 MATLAB® and Simulink® Interface ........................................................... 411 Exercises.................................................................................................................. 417 5.9 Hybrid Systems: Continuous- and Discrete-Time Components .................. 420 Exercises.................................................................................................................. 423 5.10 Monte Carlo Simulation ............................................................................... 424 5.10.1 Monte Carlo Simulation Requiring Solution of a Mathematical Model ................................................................ 428 Exercises.................................................................................................................. 434 5.11 Case Study: Pilot Ejection............................................................................ 437 Exercises.................................................................................................................. 441 5.12 Case Study: Kalman Filtering ...................................................................... 442 5.12.1 Continuous-Time Kalman Filter...................................................... 442 5.12.2 Steady-State Kalman Filter.............................................................. 443 5.12.3 Discrete-Time Kalman Filter........................................................... 443 5.12.4 Simulink® Simulations .................................................................... 444 5.12.5 Summary.......................................................................................... 455 Exercise ................................................................................................................... 456

Contents

ix

Chapter 6

Intermediate Numerical Integration......................................................................... 457 6.1 Introduction................................................................................................... 457 6.2 Runge–Kutta (RK) (One-Step Methods)...................................................... 457 6.2.1 Taylor Series Method ...................................................................... 458 6.2.2 Second-Order Runge–Kutta Method............................................... 459 6.2.3 Truncation Errors............................................................................. 461 6.2.4 High-Order Runge–Kutta Methods ................................................. 466 6.2.5 Linear Systems: Approximate Solutions Using RK Integration ..... 467 6.2.6 Continuous-Time Models with Polynomial Solutions .................... 469 6.2.7 Higher-Order Systems ..................................................................... 471 Exercises.................................................................................................................. 478 6.3 Adaptive Techniques .................................................................................... 481 6.3.1 Repeated RK with Interval Halving................................................ 481 6.3.2 Constant Step Size (T ¼ 1 min)....................................................... 485 6.3.3 Adaptive Step Size (Initial T ¼ 1 min) ............................................ 485 6.3.4 RK–Fehlberg ................................................................................... 486 Exercises.................................................................................................................. 490 6.4 Multistep Methods ........................................................................................ 492 6.4.1 Explicit Methods ............................................................................. 493 6.4.2 Implicit Methods ............................................................................. 495 6.4.3 Predictor–Corrector Methods .......................................................... 498 Exercises.................................................................................................................. 502 6.5 Stiff Systems................................................................................................. 503 6.5.1 Stiffness Property in First-Order System ........................................ 504 6.5.2 Stiff Second-Order System.............................................................. 506 6.5.3 Approximating Stiff Systems with Lower-Order Nonstiff System Models ................................................................................ 509 Exercises.................................................................................................................. 522 6.6 Lumped Parameter Approximation of Distributed Parameter Systems ....... 526 6.6.1 Nonlinear Distributed Parameter System ........................................ 531 Exercises.................................................................................................................. 534 6.7 Systems with Discontinuities........................................................................ 535 6.7.1 Physical Properties and Constant Forces Acting on the Pendulum BOB .................................................................... 543 Exercises.................................................................................................................. 549 6.8 Case Study: Spread of an Epidemic ............................................................. 552 Exercises.................................................................................................................. 559

Chapter 7

Simulation Tools ..................................................................................................... 561 7.1 Introduction................................................................................................... 561 7.2 Steady-State Solver....................................................................................... 562 7.2.1 Trim Function.................................................................................. 564 7.2.2 Equilibrium Point for a Nonautonomous System ........................... 565 Exercises.................................................................................................................. 574 7.3 Optimization of Simulink® Models.............................................................. 576 7.3.1 Gradient Vector ............................................................................... 585 7.3.2 Optimizing Multiparameter Objective Functions Requiring Simulink® Models ........................................................................... 587

x

Contents

7.3.3 Parameter Identiﬁcation................................................................... 590 7.3.4 Example of a Simple Gradient Search ............................................ 591 7.3.5 Optimization of Simulink® Discrete-Time System Models............ 599 Exercises.................................................................................................................. 605 7.4 Linearization ................................................................................................. 610 7.4.1 Deviation Variables ......................................................................... 611 7.4.2 Linearization of Nonlinear Systems in State Variable Form .......... 619 7.4.3 Linmod Function ............................................................................. 623 7.4.4 Multiple Linearized Models for a Single System ........................... 627 Exercises.................................................................................................................. 633 7.5 Adding Blocks to the Simulink® Library Browser ...................................... 637 7.5.1 Introduction ..................................................................................... 637 7.5.2 Summary.......................................................................................... 645 Exercise ................................................................................................................... 645 7.6 Simulation Acceleration ............................................................................... 645 7.6.1 Introduction ..................................................................................... 645 7.6.2 Proﬁler ............................................................................................. 647 7.6.3 Summary.......................................................................................... 647 Exercise ................................................................................................................... 648 Chapter 8

Advanced Numerical Integration ............................................................................ 649 8.1 Introduction................................................................................................... 649 8.2 Dynamic Errors (Characteristic Roots, Transfer Function).......................... 649 8.2.1 Discrete-Time Systems and the Equivalent Continuous-Time Systems............................................................... 650 8.2.2 Characteristic Root Errors ............................................................... 653 8.2.3 Transfer Function Errors ................................................................. 664 8.2.4 Asymptotic Formulas for Multistep Integration Methods............... 669 8.2.5 Simulation of Linear System with Transfer Function H(s) ............ 672 Exercises.................................................................................................................. 677 8.3 Stability of Numerical Integrators ................................................................ 680 8.3.1 Adams–Bashforth Numerical Integrators ........................................ 680 8.3.2 Implicit Integrators .......................................................................... 687 8.3.3 Runga–Kutta (RK) Integration ........................................................ 692 Exercises.................................................................................................................. 700 8.4 Multirate Integration ..................................................................................... 702 8.4.1 Procedure for Updating Slow and Fast States: Master=Slave ¼ RK-4=RK-4 ............................................................ 706 8.4.2 Selection of Step Size Based on Stability ....................................... 707 8.4.3 Selection of Step Size Based on Dynamic Accuracy ..................... 708 8.4.4 Analytical Solution for State Variables........................................... 712 8.4.5 Multirate Integration of Aircraft Pitch Control System .................. 714 8.4.6 Nonlinear Dual Speed Second-Order System ................................. 717 8.4.7 Multirate Simulation of Two-Tank System .................................... 723 8.4.8 Simulation Trade-Offs with Multirate Integration .......................... 725 Exercises.................................................................................................................. 728 8.5 Real-Time Simulation................................................................................... 730 8.5.1 Numerical Integration Methods Compatible with Real-Time Operation............................................................... 733 8.5.2 RK-1 (Explicit Euler) ...................................................................... 734

Contents

xi

8.5.3 RK-2 (Improved Euler) ................................................................... 734 8.5.4 RK-2 (Modiﬁed Euler) .................................................................... 735 8.5.5 RK-3 (Real-Time Incompatible) ..................................................... 735 8.5.6 RK-3 (Real-Time Compatible)........................................................ 736 8.5.7 RK-4 (Real-Time Incompatible) ..................................................... 736 8.5.8 Multistep Integration Methods ........................................................ 736 8.5.9 Stability of Real-Time Predictor–Corrector Method....................... 738 8.5.10 Extrapolation of Real-Time Inputs.................................................. 740 8.5.11 Alternate Approach to Real-Time Compatibility: Input Delay....... 746 Exercises.................................................................................................................. 753 8.6 Additional Methods of Approximating Continuous-Time System Models ............................................................................................. 754 8.6.1 Sampling and Signal Reconstruction .............................................. 754 8.6.2 First-Order Hold Signal Reconstruction.......................................... 759 8.6.3 Matched Pole-Zero Method............................................................. 760 8.6.4 Bilinear Transform with Prewarping............................................... 763 Exercises.................................................................................................................. 765 8.7 Case Study: Lego Mindstormse NXT ........................................................ 767 8.7.1 Introduction ..................................................................................... 767 8.7.2 Requirements and Installation ......................................................... 769 8.7.3 Noisy Model .................................................................................... 769 8.7.4 Filtered Model ................................................................................. 773 8.7.5 Summary.......................................................................................... 779 Exercise ................................................................................................................... 779 References .................................................................................................................................... 781 Index............................................................................................................................................. 785

This page intentionally left blank

Foreword As the authors point out in the preface, there is not yet extant a universally accepted deﬁnition of the term simulation. Another approach to deﬁning the ﬁeld would be ‘‘the art of reproducing the behavior of a system for analysis without actually operating that system.’’ The authors have written a seminal text covering the simulation design and analysis of a broad variety of systems using two of the most modern software packages available today. The material is presented in a particularly adept fashion enabling students new to the ﬁeld to gain a thorough understanding of the basics of continuous simulation in a single semester and providing, at the same time, a more advanced treatment of the subject for researchers and simulation professionals. The authors’ extensive treatment of continuous and discrete linear system fundamentals opens the door to simulation for individuals without formal education in a traditional engineering curriculum. However deﬁned, simulation is becoming an increasingly important component of curricula in engineering, business administration, the sciences, applied mathematics, and the like. This text will be a valuable resource for study in courses using simulation as a tool for understanding processes that are not amenable to study in other ways. Chris Bauer, PhD, PE, CMSP Orlando, Florida Simulation has come a long way since the days analog computers ﬁlled entire rooms. Yet, it is more important than ever that simulations be constructed with care, knowledge, and a little wisdom, lest the results be gibberish or, worse, reasonable but misleading. Used properly, simulations can give us extraordinary insights into the processes and states of a physical system. Constructed with care, simulations can save time and money in today’s competitive marketplace. One major application of simulation is the simulator, which provides interaction between a model and a person through some interface. The earliest simulator, Ed Link’s Pilot Maker aircraft trainer, did not use any of the simulation techniques described in this book. Modern simulators, however, such as the National Advanced Driving Simulator (NADS), cannot be fully understood without them. The mission of the NADS is a lofty one: to save lives on U.S. highways through safety research using realistic human-in-the-loop simulation. This is an example of the importance simulation has attained in our generation. The pervasiveness of simulation tools in our society will only increase over time; it will be more important than ever that future scientists and engineers be familiar with their theory and application. The content for Simulation of Dynamic Systems with MATLAB® and Simulink® is arranged to give the student a gradual and natural progression through the important topics in simulation. Advanced concepts are added only after complete examples have been constructed using fundamental methods. The use of MATLAB and Simulink provides experience with tools that are widely adopted in industry and allow easy construction of simulation models. May your experience with simulation be enjoyable and fruitful and extend throughout your careers. Chris Schwarz, PhD Iowa City, Iowa

xiii

This page intentionally left blank

Preface In the ﬁrst article of SIMULATION magazine in the Fall of 1963, the editor John McLeod proclaimed simulation to mean ‘‘the act of representing some aspects of the real world by numbers or symbols which may be easily manipulated to facilitate their study.’’ Two years later, it was modiﬁed to ‘‘the development and use of models for the study of the dynamics of existing or hypothesized systems.’’ More than 40 years later, the simulation community has yet to converge upon a universally accepted deﬁnition. Either of the two cited deﬁnitions or others that followed convey a basic notion, namely, that simulation is intended to reinforce or supplement one’s understanding of a system. The deﬁnitions vary in their description of tools and methods to accomplish this. The ﬁeld of simulation is experiencing explosive growth in importance because of its ability to improve the way systems and people perform, in a safe and controllable environment, at a reduced cost. Understanding the behavior of complex systems with the latest technological innovations in ﬁelds such as transportation, communication, medicine, aerospace, meteorology, etc., is a daunting task. It requires an assimilation of the underlying natural laws and scientiﬁc principles that govern the individual subsystems and components. A multifaceted approach is required, one in which simulation can play a prominent role, both in validation of a system’s design and in training of personnel to become proﬁcient in its operation. Simulation is a subject that cuts across traditional academic disciplines. Airplane crews spend hours ﬂying simulated missions in aircraft simulators to become proﬁcient in the use of onboard subsystems during normal ﬂight and possible emergency conditions. Astronauts spend years training in shuttle and orbiter simulators to prepare for future missions in space. Power plant and petrochemical process operators are exposed to simulation to obtain peak system performance. Economists resort to simulation models to predict economic conditions of municipalities and countries for policymakers. Simulations of natural disasters aid in preparation and planning to mitigate the possibility of catastrophic events. While the mathematical models created by aircraft designers, nuclear engineers, and economists are application speciﬁc, many of the equations are analogous in form despite the markedly different phenomena described by each model. Simulation offers practitioners from each of these ﬁelds the tools to explore solutions of the models as an alternative to experimenting with the real system. This book is meant to serve as an introduction to the fundamental concepts of continuous system simulation, a branch of simulation applied to dynamic systems whose signals change over a continuum of points in time or space. Our concern is with mathematical models of continuoustime systems (electric circuits, thermal processes, population dynamics, vehicle suspension, human physiology, etc.) and the discrete-time system models created to simulate them. The continuous system mathematical models consist of a combination of algebraic and ordinary differential equations. The discrete-time system models are a mix of algebraic and difference equations. Systems that transition between states at randomly occurring times are called discrete-event systems. Discrete-event simulation is a complementary branch of simulation, separate from continuous system simulation, with a mathematical foundation rooted in probability theory. Examples of discrete-event systems are facilities such as a bank, a tollbooth, a supermarket, or a hospital emergency room, where customers arrive and are then serviced in some way. A manufacturing plant involving multiple production stages of uncertain duration to generate a ﬁnished product is another candidate for discrete-event simulation. Discrete-event simulation is an important tool for optimizing the performance of systems that change internally at unpredictable times due to the inﬂuence of random events. Industrial engineering programs typically include a basic course at the undergraduate level in discrete-event simulation. xv

xvi

Preface

Not surprisingly, a number of excellent textbooks in the area have emerged for use by the academic community and professionals. In academia, continuous simulation has evolved differently than discrete-event simulation. Topics in continuous simulation such as dynamic system response, mathematical modeling, differential equations, difference equations, and numerical integration are dispersed over several courses from engineering, mathematics, and the natural sciences. In the past, the majority of courses in modeling and simulation of continuous systems were restricted to a speciﬁc ﬁeld like mechanical, electrical, and chemical engineering or scientiﬁc areas like biology, ecology, and physics. A transformation in simulation education is underway. More universities are beginning to offer undergraduate and beginning graduate courses in the area of continuous system simulation designed for an interdisciplinary audience. Several institutions now offer master’s and PhD programs in simulation that include a number of courses in both continuous and discrete-event simulation. A critical mass of students are now enrolled in continuous simulation–related courses and there is a need for an introductory unifying text. The essential ingredient needed to make simulation both interesting and challenging is the inclusion of real-world examples. Without models of real-world systems, a ﬁrst class in simulation is little more than a sterile exposition of numerical integration applied to differential equations. Modeling and simulation are inextricably related. While the thrust of this text is continuous simulation, mathematical models are the starting point in the evolution of simulation models. Analytical solutions of differential equation models are presented, when appropriate, as an alternative to simulation and a simple way of demonstrating the accuracy of a simulated solution. For the most part, derivations of the mathematical models are omitted and references to appropriate texts are included for those interested in learning more about the origin of the model’s equations. Simulation is best learned by doing. Accordingly, the material is presented in a way that permits the reader to begin exploring simulation, starting with a mathematical model in Chapter 1. A detailed derivation of the mathematical model of a tank with liquid ﬂowing in and out leads to a simulation model in the form of a simple difference equation. The simulation model serves as the vehicle for predicting the tank’s response to various inputs and initial conditions. Additionally, the derivation illustrates the process of obtaining a mathematical model based on the natural laws of science. Chapters 2 and 4 present a condensed treatment of linear, continuous-time, and discrete-time dynamic systems, normally covered in an introductory linear systems course. Coverage is limited to basic topics that should be familiar to a simulation practitioner. Section 2.7 is extended to include a discussion of additional common nonlinear elements, namely, dead zone, quantization, relay, and saturation. The instructor can skip some or all of the material in these chapters if the students’ background includes a course in signals and systems or linear control theory. Numerical integration is at the very core of continuous system simulation. Instead of treating the subject in one exhaustive chapter, coverage is distributed over three chapters. Elementary numerical integration in Chapter 3 is an informal introduction to the subject, which includes discussion of several elementary methods for approximating the solutions of ﬁrst-order differential equations. The material in Chapters 2 through 4 is a prerequisite for understanding general purpose, continuous simulation programs that are popular in the engineering and scientiﬁc community. Simulink®, from The MathWorks, is the featured simulation program because of its tight integration with MATLAB®, the de facto standard for scientiﬁc and engineering analysis, and data visualization software. Chapter 5 takes the reader through the basic steps of creating and running Simulink models. Section 5.5 includes new material related to simulation implementation of nonlinear systems using speciﬁc blocks from the Simulink library. Due to the popularity of the Kalman ﬁlter, a case study has been added in Section 5.12 on this topic. The continuous-time Kalman ﬁlter equations are developed and modeled in Simulink, including simulated output. Subsequently, the steady-state continuous-time Kalman ﬁlter equations are developed and modeled in Simulink. The steady-state results are compared with the continuous-time results. Finally, the

Preface

xvii

discrete-time Kalman ﬁlter equations are developed and modeled in Simulink. The discrete-time results are compared with the continuous-time results. Chapter 6 delves into intermediate-level topics of numerical integration, including a formal presentation of One-Step (Runge–Kutta) and multistep methods, adaptive techniques, truncation errors, and a brief mention of stability. Chapter 7 highlights some advanced features of Simulink useful in more in-depth simulation studies. A new section (Section 7.5) on S-blocks is introduced and an example is presented showing how to make the discrete-time Kalman ﬁlter available for drag-and-drop from the Simulink library. Other simulation programs offer similar features and the transition from Simulink to other simulation software is straightforward. Chapter 8 is for those interested in more advanced topics on continuous simulation. Coverage includes a discussion of dynamic errors, stability, real-time compatible numerical integration, and multi-rate integration algorithms for simulation of systems with fast and slow components. Due to the popularity of Lego’s Mindstormse NXT, a case study has been added in Section 8.7 on this topic. All but two chapters conclude with a case study illustrating one or more of the topics discussed in that chapter. The featured text examples and case studies are analyzed using MATLAB script ﬁles and Simulink model ﬁles, all of which are available from CRC Press. The text has been ﬁeld-tested in the classroom for several years in a two-semester sequence of continuous simulation courses. Despite numerous revisions based on the scrutiny and suggestions of students and colleagues, it is naïve to think the ﬁnal product is free of errors. Further suggestions for improvement and revelations of inaccuracies can be brought to the attention of the authors at [email protected]ﬂ.rr.com and [email protected] Numerous individuals deserve our thanks and appreciation for helping to make this book possible. In particular, a sincere ‘‘thank you’’ to Nora Konopka at Taylor & Francis=CRC Press for committing to the second edition and seeing it through to fruition. For MATLAB® and Simulink® product information, please contact: The MathWorks, Inc. 3 Apple Hill Drive Natick, MA, 01760-2098 USA Tel: 508-647-7000 Fax: 508-647-7001 E-mail: [email protected] Web: www.mathworks.com

This page intentionally left blank

Authors Dr. Harold Klee received his PhD in systems science from Polytechnic Institute of Brooklyn in 1972, his MS in systems engineering from Case Institute of Technology in 1968, and his BSME from The Cooper Union in 1965. Dr. Klee has been a faculty member in the College of Engineering at the University of Central Florida (UCF) since 1972. During his tenure at UCF, he has been a ﬁve-time recipient of the college’s Outstanding Teacher Award. He has been instrumental in the development of simulation courses in both the undergraduate and graduate curricula. He is a charter member of the Core Faculty, which is responsible for developing the interdisciplinary MS and PhD programs in simulation at UCF. Dr. Klee served as graduate coordinator in the Department of Computer Engineering from 2003 to 2006. Two of his PhD students received the prestigious Link Foundation Fellowship in Advanced Simulation and Training. Both are currently enjoying successful careers in academia. Dr. Klee has served as the director of the UCF Driving Simulation Lab for more than 15 years. Under the auspices of the UCF Center for Advanced Transportation Systems Simulation, the lab operates a high-ﬁdelity motion-based driving simulator for conducting trafﬁc engineering–related research. He also served as editor-in-chief for the Modeling and Simulation magazine for three years, a publication for members of the Society for Modeling and Simulation International. Dr. Randal Allen is an aerospace and defense consultant working under contract to provide 6DOF aerodynamic simulation modeling, analysis, and design of navigation, guidance, and control systems. His previous experience includes launch systems integration and ﬂight operations for West Coast Titan-IV missions, propulsion modeling for the Iridium satellite constellation, and ﬁeld applications engineering for MATRIXx. He also chairs the Central Florida Section of the American Institute of Aeronautics and Astronautics (AIAA). Dr. Allen is certiﬁed as a modeling and simulation professional (CMSP) by the Modeling and Simulation Professional Certiﬁcation Commission (M&SPCC) under the auspices of the National Training and Simulation Association (NTSA). He is also certiﬁed to deliver FranklinCovey’s Focus and Execution track, which provides training on achieving your highest priorities. Dr. Allen’s academic background includes a PhD in mechanical engineering from the University of Central Florida, an engineer’s degree in aeronautical and astronautical engineering from Stanford University, an MS in applied mathematics, and a BS in engineering physics from the University of Illinois (Urbana-Champaign). He also serves as an adjunct professor at the University of Central Florida in Orlando, Florida.

xix

This page intentionally left blank

1

Mathematical Modeling

1.1 INTRODUCTION 1.1.1 IMPORTANCE OF MODELS Models are an essential component of simulation. Before a new prototype design for an automobile braking system or a multimillion dollar aircraft is tested in the ﬁeld, it is commonplace to ‘‘test drive’’ the separate components and the overall system in a simulated environment based on some form of model. A meteorologist predicts the expected path of a tropical storm using weather models that incorporate the relevant climatic variables and their effect on the storm’s trajectory. An economist issues a quantitative forecast of the U.S. economy predicated based on key economic variables and their interrelationships with the help of computer models. Before a nuclear power plant operator is ‘‘turned loose’’ at the controls, extensive training is conducted in a model-based simulator where the individual becomes familiar with the plant’s dynamics under routine and emergency conditions. Health care professionals have access to a human patient simulator to receive training in the recognition and diagnosis of disease. Public safety organizations can plan for emergency evacuations of civilians from low-lying areas using trafﬁc models to simulate vehicle movements along major access roads. The word ‘‘model’’ is a generic term referring to a conceptual or physical entity that resembles, mimics, describes, predicts, or conveys information about the behavior of some process or system. The beneﬁt of having a model is to be able to explore the intrinsic behavior of a system in an economical and safe manner. The physical system being modeled may be inaccessible or even nonexistent as in the case of a new design for an aircraft or automotive component. Physical models are often scaled-down versions of a larger system of interconnected components as in the case of a model airplane. Aerodynamic properties of airframe and car body designs for high-performance airplanes and automobiles are evaluated using physical models in wind tunnels. In the past, model boards with roads, terrain, miniaturized models of buildings, and landscape, along with tiny cameras secured to the frame of ground vehicles or aircraft, were prevalent for simulator visualization. Current technology relies almost exclusively on computer-generated imagery. In principle, the behavior of dynamic systems can be explained by mathematical equations and formulae, which embody either scientiﬁc principles or empirical observations, or both, related to the system. When the system parameters and variables change continuously over time or space, the models consist of coupled algebraic and differential equations. In some cases, lookup tables containing empirical data are employed to compute the parameters. Equations may be supplemented by mathematical inequalities, which constrain the variation of one or more dependent variables. The aggregation of equations and numerical data employed to describe the dynamic behavior of a system in quantitative terms is collectively referred to as a mathematical model of the system. Partial differential equation models appear when a dependent variable is a function of two or more independent variables. For example, electrical parameters such as resistance and capacitance are distributed along the length of conductors carrying electrical signals (currents and voltages). These signals are attenuated over long distances of cabling. The voltage at some location x measured from an arbitrary reference is written v(x, t) instead of simply v(t), and the circuit is modeled accordingly.

1

Simulation of Dynamic Systems with MATLAB® and Simulink®

2

A mathematical model for the temperature in a room would necessitate equations to predict T(x, y, z, t) if a temperature probe placed at various points inside the room reveals signiﬁcant variations in temperature with respect to x, y, z in addition to temporal variations. Partial differential equations describing the cable voltage v(x, t) and room temperature T(x, y, z, t) are referred to as ‘‘distributed parameter’’ models. The mathematical models of dynamic systems where the single independent variable is ‘‘time’’ comprise ordinary differential equations. The same applies to systems with a single spatial independent variable; however, these are not commonly referred to as dynamic systems since variations of the dependent variables are spatial as opposed to temporal in nature. Ordinary differential equation models of dynamic systems are called ‘‘lumped parameter’’ models because the spatial variation of the system parameters is negligible or else it is being approximated by lumped sections with constant parameter values. In the room temperature example, if the entire contents of the room can be represented by a single or lumped thermal capacitance, then a single temperature T(t) is sufﬁcient to describe the room. We focus exclusively on dynamic systems with lumped parameter models, hereafter referred to simply as mathematical models. A system with a lumped parameter model is illustrated in Figure 1.1. The key elements are the system inputs u1(t), u2(t), . . . , ur(t), which make up the system input vector u(t), the system outputs y1(t), y2(t), . . . , yp(t), which form the output vector y(t), and the parameters p1, p2, . . . , pm constituting the parameter vector p. The parameters are shown as constants; however, they may also vary with time. Our interest is in mathematical models of systems consisting of coupled algebraic and differential equations relating the outputs and inputs with coefﬁcients expressed in terms of the system parameters. For steady-state analyses, transient responses are irrelevant, and the mathematical models consist of purely algebraic equations relating the system variables. An example of a mathematical model for a system with two inputs, three outputs, and several parameters is d2 d d y1 (t) þ p2 p3 y1 (t) þ p4 y1 (t) þ p5 y2 (t) þ p6 y2 (t) ¼ p7 u1 (t) dt 2 dt dt

(1:1)

d p9 d y2 (t) þ y2 (t) þ p11 y1 (t)y2 (t) ¼ p12 u1 (t) þ p13 u1 (t) þ p14 u2 (t) p10 dt dt

(1:2)

p1

p8

p15 y3 (t) ¼

p16 y1p17 (t) y2 (t)

(1:3)

The order of a model is equal to the sum of the highest derivatives of each of the dependent variables, in this case y1(t), y2(t), y3(t), and the order is therefore 2 þ 1 þ 0 ¼ 3. Equation 1.1 is a linear differential equation. Equation 1.2 is a nonlinear differential equation because of the term involving the product of y1(t) and y2(t). The mathematical model is nonlinear due to the presence p1 p2

u1(t) u2(t)

pm

y1(t)

System

ur(t)

FIGURE 1.1 A system with a lumped parameter model.

Output

y(t) =

. . .

y2(t) Input

. . .

u(t) =

...

yp(t)

Mathematical Modeling

3

of the nonlinear differential equation and the nonlinear algebraic equation (Equation 1.3). It is to be borne in mind that it is the nature of the equations that determines whether a math model is linear or nonlinear. An adjective such as linear or nonlinear applies to the mathematical model as opposed to the actual system. It is important to distinguish between the system being modeled and the model itself. The former is unique, even though it may exist only at the design stage, while the mathematical model may assume different forms. For example, a team of modelers may be convinced that the lead term in Equation 1.1 is likely to be insigniﬁcant under normal operating conditions. Consequently, two distinct models of the system exist, one third order and the other second order. The third-order model includes the second derivative term to accurately reﬂect system behavior under unusual or nontypical conditions (e.g., an aircraft exceeding its ﬂight envelope or a ground vehicle performing an extreme maneuver). The simpler second-order model ignores what are commonly referred to as higher-order effects. Indeed, there may be a multitude of mathematical models to represent the same system under different sets of restricted operating conditions. Regardless of the detail inherent in a mathematical model, it nevertheless represents an incomplete and inexact depiction of the system. A model’s intended use will normally dictate its level of complexity. For example, models for predicting vehicle handling and responsiveness are different from those intended to predict ride comfort. In the ﬁrst case, accurate equations describing lateral and longitudinal tire forces are paramount in importance, whereas passenger comfort relies more on vertical tire forces and suspension system characteristics. Mathematical modeling is an inexact science, relying on a combination of intuition, experience, empiricism, and the application of scientiﬁc laws of nature. Trade-offs between model complexity and usefulness are routine. Highly accurate microclimatic weather models that use current atmospheric conditions to predict the following day’s weather are of limited value if they require 48 h on a massively parallel or supercomputer system to produce results. At the extreme opposite, overly simpliﬁed models can be grossly inaccurate if signiﬁcant effects are overlooked. The difference between a mathematical model and a simulation model is open to interpretation. Some in the simulation community view the two as one and the same. Their belief is that a mathematical model embodies the attributes of the actual system and simulation refers to solutions of the model equations, albeit generally approximate in nature. Exact analytical solutions of mathematical model equations are nonexistent in all but the simplest cases. Others maintain a distinction between the two and express the view that simulation model(s) originate from the mathematical model. According to this line of thinking, simulating the dynamics of a system requires a simulation model that is different in nature from a mathematical model. A reliable simulation model must be capable of producing numerical solutions in reasonably close agreement with the actual (unknown) solutions to the math model. Simulation models are commonly obtained from discrete-time approximations of continuous-time mathematical models. Much of this book is devoted to the process of obtaining simulation models in this way. More than one simulation model can be developed from a single mathematical model of a system. Stochastic models are important when dealing with systems whose inputs and parameters are best modeled using statistical methods. Discrete event models are used to describe processes that transit from one state to another at randomly spaced points in time. Probability theory plays a signiﬁcant role in the formulation of discrete event models for describing the movement of products and service times at different stages in manufacturing processes, queuing systems, and the like. In fact, the two pillars of simulation are continuous system simulation, the subject of this book, and discrete event simulation. There is a great deal more to be said about modeling. Entire books are devoted to properly identifying model structure and parameter values for deterministic and stochastic systems. Others concentrate more on derivation of mathematical models from diverse ﬁelds and methods of obtaining solutions under different circumstances. The reader is encouraged to check the references section at the end of this book for additional sources of material related to modeling.

Simulation of Dynamic Systems with MATLAB® and Simulink®

4

Modeling is essential to the ﬁeld of simulation. Indeed, it is the starting point of any simulation study. The emphasis, however, in this book is on the presentation of simulation fundamentals. Accordingly, derivation of mathematical models is not a prominent component. For the most part, the math models are taken from documented sources listed in the references section, some of which include step-by-step derivations of the model equations. The derivation is secondary to a complete understanding of the model, that is, its variables, parameters, and knowledge of conditions that may impose restrictions on its suitability for a speciﬁc application. Simulation of complex systems requires a team effort. The modeler is a subject expert responsible for providing the math model and interpreting the simulation results. The simulationist produces the simulation model and performs the simulation study. For example, an aerodynamicist applies principles of boundary layer theory to obtain a mathematical model for the performance of a new airfoil design. Starting with the math model, simulation skills are required to produce a simulation model capable of verifying the efﬁcacy of the design based on numerical results. Individuals with expert knowledge in a particular ﬁeld are oftentimes well versed in the practice of simulation and may be responsible for formulation of alternative mathematical models of the system in addition to developing and running simulations. A simple physical system is introduced in the next section, and the steps involved in deriving an idealized math model are presented. In addition to beneﬁting from seeing the process from start to ﬁnish, the ingredients for creating a simulation model are introduced. Hence, by the end of this chapter, the reader will be able to perform rudimentary simulation.

1.2 DERIVATION OF A MATHEMATICAL MODEL We begin our discussion of mathematical modeling with a simple derivation of the mathematical model representing the dynamic behavior of an open tank containing a liquid that ﬂows in the top and is discharged from the bottom. Referring to Figure 1.2, the primary input is the liquid ﬂow rate F1(t), an independent variable measured in appropriate units such as cubic feet per minute (volumetric ﬂow rate) or pounds per hour (mass ﬂow rate). Responding to changes in the input are dependent variables H(t) and F0(t) the ﬂuid level, and ﬂow rate from the tank. Once the derivation is completed, we can use the model to predict the outﬂow and ﬂuid level response to a speciﬁc input ﬂow rate F1(t), t 0. Note that we have restricted the set of possible inputs to F1(t) and in the process relegated the remaining independent variables, that is, other variables which affect F0(t) and H(t), to second-order importance. Our assumption is that the eventual model will be suitable for its intended application. It must be borne in mind that if extremely accurate predictions of the level H(t) are required, it may be necessary to include second-order effects such as evaporation and hence introduce additional inputs related to ambient conditions, namely, temperature, humidity, air pressure, wind speed, and so forth. The derivation is based on conditions of the tank at two discrete points in time, as if snapshots of the tank were available at times ‘‘t’’ and ‘‘t þ Dt,’’ as shown in Figure 1.3. The following notation is used with representative units given for clarity: F1(t): Input ﬂow at time t, ft3=min H(t): Liquid level at time t, ft F0(t): Output ﬂow at time t, ft3=min A: Cross-sectional area of tank, ft2

F1(t)

Tank

FIGURE 1.2 Tank as a dynamic system with input and outputs.

F0(t) H (t)

5

Mathematical Modeling F1(t)

F1(t + Δt)

ΔH H(t)

H(t + Δt)

A

A F0(t)

F0(t + Δt)

Time: t

Time: t + Δt

FIGURE 1.3 A liquid tank at two points in time.

At time t þ Dt, from the physical law of conservation of volume, V(t þ Dt) ¼ V(t) þ DV

(1:4)

where V(t) is the volume of liquid in the tank at time t DV is the change in volume from time t to t þ Dt The volume of liquid in the tank at times t and t þ Dt is given by V(t) ¼ AH(t)

(1:5)

V(t þ Dt) ¼ AH(t þ Dt)

(1:6)

Equations 1.5 and 1.6 assume constant cross-sectional area of the tank, that is, A is independent of H. The change in volume from t to t þ Dt is equal to the volume of liquid ﬂowing in during the interval t to t þ Dt minus the volume of liquid ﬂowing out during the same period of time. The liquid volumes are the areas under the input and output volume ﬂow rates from t to t þ Dt as shown in Figure 1.4. Expressing these areas in terms of integrals, tþDt ð

tþDt ð

F1 (t)dt

DV ¼ t

F0 (t)dt

(1:7)

t

F1(t)

H (t)

F0(t)

ΔH

t

t + Δt

t

t + Δt

t

FIGURE 1.4 Volumes of liquid ﬂowing in and out of tank from t to t þ Dt.

t + Δt

Simulation of Dynamic Systems with MATLAB® and Simulink®

6

The integrals in Equation 1.7 can be approximated by assuming F1(t) and F0(t) are constant over the interval t to t þ Dt (see Figure 1.4). Hence, tþDt ð

F1 (t)dt F1 (t)Dt

(1:8)

F0 (t)dt F0 (t)Dt

(1:9)

t tþDt ð

t

Equations 1.8 and 1.9 are reasonable approximations provided Dt is small. Substituting Equations 1.8 and 1.9 into Equation 1.7 yields DV F1 (t)Dt F0 (t)Dt

(1:10)

Substituting Equations 1.5, 1.6, and 1.10 into Equation 1.4 gives AH(t þ Dt) AH(t) þ [F1 (t) F0 (t)]Dt

(1:11)

) A[H(t þ Dt) H(t)] [F1 (t) F0 (t)]Dt

(1:12)

DH )A F1 (t) F0 (t) Dt

(1:13)

where DH is the change in liquid level over the interval (t, t þ Dt). Note that DH=Dt is the average rate of change in the level H over the interval (t, t þ Dt). It is the slope of the secant line from pt A to pt B in Figure 1.5. Consider what happens as pt B gets closer to pt A; that is, Dt gets smaller. End pt DH=Dt B

H(t þ Dt) H(t) : Slope of line AB Dt

B0

H(t þ Dt 0 ) H(t) : Slope of line AB0 Dt 0

H

B B΄ Tangent A

ΔH

Pt

Coordinates

A

[t, H(t)]

B

[t + Δt, H(t + Δt)]

B΄

[t + Δt΄, H(t + Δt΄)]

Δt

t

t + Δt΄

FIGURE 1.5 Average rate of change DH=Dt as Dt gets smaller.

t + Δt

7

Mathematical Modeling

In the limit as Dt approaches zero, pt B approaches pt A, and the average rate of change in H over the interval (t, t þ Dt) becomes the instantaneous rate of change in H at time t, that is, lim

Dt!0

DH dH ¼ Dt dt

(1:14)

where dH=dt is the ﬁrst derivative of H(t). From the graph, it can be seen that dH=dt is equal to the slope of the tangent line of the function H(t) at t (pt A). Taking the limit as Dt approaches zero in Equation 1.13 and using the deﬁnition of the derivative in Equation 1.14 give DH (1:15) ¼ lim [F1 (t) F0 (t)] lim A Dt!0 Dt!0 Dt )A

dH ¼ F1 (t) F0 (t) dt

(1:16)

Since there are two dependent variables, a second equation or constraint relating F0 and H is required in order to solve for either one given the input function F1(t). It is convenient at this point to assume that F0 is proportional to H, that is, F0 ¼ constant H (see Figure 1.6). The constant of proportionality is expressed as 1=R where R is called the ﬂuid resistance of the tank. At a later point, we will revisit this assumption. F0 ¼

1 H R

(1:17)

Equations 1.16 and 1.17 constitute the mathematical model of the liquid tank, namely, A

dH þ F0 ¼ F1 dt

and

F0 ¼

1 H R

where F1, F0, H, and dH=dt are short for F1(t), F0(t), H(t), and (d=dt)H(t). In this example, the model is a coupled set of equations. One is a linear differential equation and the other is an algebraic equation, also linear. The differential equation is ﬁrst order since only the ﬁrst derivative appears in the equation and the tank dynamics are said to be ﬁrst order. The outﬂow F0 can be eliminated from the model equations by substituting Equation 1.17 into Equation 1.16 resulting in A

dH 1 þ H ¼ F1 dt R

(1:18)

Before a particular solution to Equation 1.18 for some F1(t), t 0 can be obtained, the initial tank level H(0) must be known. There are several reasons why an analytical approach to solving F0 Equation 1.18 may not be the preferred method. Even when the analytical solution is readily obtainable, for example, when the 1 F0 = — H 1 R system model is linear, as in the present example, the solution may be required for a number of different inputs or forcing functions. R Recall from studying differential equations what happens when the H right-hand side of the equation changes. A new particular solution FIGURE 1.6 A tank with out- is required that can be time-consuming, especially if the process is ﬂow proportional to ﬂuid level. repeated for a number of nontrivial forcing functions.

Simulation of Dynamic Systems with MATLAB® and Simulink®

8

Second, the input F1(t) may not even be available in analytical form. Suppose the input function F1(t) is unknown except as a sequence of measured values at regularly spaced points in time. An exact solution to the differential equation model is out of the question since the input is not expressible as an analytic function of time.

EXERCISES 1.1 A system consists of two tanks in series in which the outﬂow from the ﬁrst tank is the inﬂow to the second tank as shown in Figure E1.1: F1(t) F0(t)

A1

H1(t)

A2

H2(t) F2(t)

FIGURE E1.1

(a) Find the algebraic and differential equations that form the mathematical model of the twotank system. Assume both tanks are linear, that is, the outﬂows are proportional to the liquid levels, and R1 and R2 are the ﬂuid resistances of the tanks. (b) Eliminate the ﬂows F0(t) and F2(t) from the model to obtain a model in the form of two differential equations involving the system input F1(t) and the tank levels H1(t) and H2(t). (c) Obtain the model differential equations when F0(t) and F2(t) are present instead of H1(t) and H2(t). (d) The initial ﬂuid levels in the tanks are H1(0) and H2(0). Suppose that the ﬂow into the ﬁrst tank is constant, F1(t) ¼ F 1, t 0. Obtain expressions for H1(1) and H2(1), the eventual ﬂuid levels in Tanks 1 and 2, respectively. Do H1(1) and H2(1) depend on the initial ﬂuid levels? Explain. (e) Find the ratio of tank resistances R1=R2 if H1(1) ¼ 2H2(1). (f) Suppose the ﬂow between the two tanks is reduced to zero by closing the valve in the line. Show that this is equivalent to R1 ¼ 1 and determine the values of H1(1) and H2(1) assuming the inﬂow to the ﬁrst tank is still constant. 1.2 The two tanks in Exercise 1.1 are said to be noninteracting because the ﬂow rate from the ﬁrst tank only depends on the ﬂuid level in the ﬁrst tank and is independent of the ﬂuid level in the second tank. Suppose the discharged ﬂuid from the ﬁrst tank enters the second tank at the bottom instead of the top as shown in Figure E1.2. F1(t)

H1(t) A2

A1 F0(t)

FIGURE E1.2

H2(t) F2(t)

9

Mathematical Modeling

The ﬂow between the tanks is now a function of the ﬂuid levels in both tanks. The driving force for the intertank ﬂow is the difference in ﬂuid levels, and, for the time being, we can assume that the two quantities are proportional. That is, F0 (t) / [H1 (t) H2 (t)] ) F0 (t) ¼

H1 (t) H2 (t) R12

where R12 represents a ﬂuid resistance involving both tanks. The ﬂuid resistance of the second tank is still R2. (a) The general form of the differential equation model for the system of interacting tanks is dH1 þ a11 H1 þ a12 H2 ¼ b1 F1 dt dH2 þ a21 H1 þ a22 H2 ¼ b2 F1 dt Note: H1, H2, and F1 are short for H1(t), H2(t), and F1(t). Find expressions for a11, a12, a21, a22, b1, and b2 in terms of the system parameters A1, A2, R12, and R2. (b) The tanks are initially empty, H1(0) ¼ 0 and H2(0) ¼ 0. The ﬂow into the ﬁrst tank is constant, F1(t) ¼ F 1, t 0. Show that the ﬁnal ﬂuid levels in both tanks after a sufﬁcient period of time has elapsed, H1(1) and H2(1), can be obtained from the solution of the following system of equations: a11 H1 (1) þ a12 H2 (1) ¼ b1 F 1 a21 H1 (1) þ a22 H2 (1) ¼ b2 F 1 (c) Solve for H1(1) and H2(1) in terms of the system parameters A1, A2, R12, and R2 and the constant inﬂow F 1. Are the results different if the tanks are not initially empty? Explain. (d) Using the following baseline values unless otherwise stated: A1 ¼ A2 ¼ 25 ft2 ,

R12 ¼ 3 ft per ft3=min

R2 ¼ 1 ft per ft3=min,

F 1 ¼ 5 ft3=min

ﬁnd the eventual ﬂuid levels H1(1) and H2(1) and ﬂows F0(1) and F2(1). (e) Repeat part (d) with A2 ¼ 75 ft2. (f) The valve between the tanks is opened, some resulting in R12 ¼ 2 ft per ft3=min. The remaining baseline values remain the same. Find H1(1), H2(1), and ﬂows F0(1) and F2(1). (g) Suppose Tank 1 initially holds 10 ft of liquid and Tank 2 has 4 ft. Find the initial rates of change in level for both tanks. (h) Is it possible for the ﬂuid level in Tank 2 to exceed the level in Tank 1? Explain. (i) How does the model change if there is a separate ﬂow, say F3(t), directly into the top of Tank 2?

Simulation of Dynamic Systems with MATLAB® and Simulink®

10

1.3 Consider a cone-shaped tank with circular cross-sectional area like the one shown in Figure E1.3. F1(t)

Radius = r

H0

H(t)

R F0(t)

FIGURE E1.3

(a) How does this affect the derivation of the mathematical model? (b) Find the math model for this case.

1.3 DIFFERENCE EQUATIONS Looking back at Figures 1.3 and 1.4, recall that the level of ﬂuid in the tank at time t þ Dt is equal to the level at time t plus the change in liquid level over the interval (t, t þ Dt). Thus, H(t þ Dt) ¼ H(t) þ DH

(1:19)

From Figure 1.5, it is apparent that the change in level DH is simply the product of the average rate of change DH=Dt and the time interval Dt, that is, H(t þ Dt) ¼ H(t) þ

DH Dt Dt

(1:20)

Solving for DH=Dt in Equation 1.13 and substituting the result into Equation 1.20 give H(t þ Dt) ¼ H(t) þ

1 [F1 (t) F0 (t)]Dt A

(1:21)

Keep in mind that Equation 1.21 is approximate because of the approximations to the integrals in Equations 1.8 and 1.9. Assuming the output ﬂow F0 is proportional to the level H, as we did to obtain Equation 1.17, gives H(t þ Dt) ¼ H(t) þ

1 1 F1 (t) H(t) Dt A R

Dt Dt ) H(t þ Dt) ¼ 1 H(t) þ F1 (t) AR A

(1:22)

(1:23)

11

Mathematical Modeling

Since Equation 1.23 is only approximate, H(t) is replaced by HA(t) to distinguish it from the actual solution H(t). From Equation 1.23 with H(t) replaced by HA(t), HA (t þ Dt) ¼

Dt Dt HA (t) þ F1 (t) 1 AR A

(1:24)

Equation 1.24 is a difference equation that can be solved for the approximate solution HA(t) when F1(t), t 0 and HA(0) are known. As we shall see, the approximate solution HA(t) can only be determined at discrete times, namely, t ¼ 0, Dt, 2Dt, 3Dt, . . . .

1.3.1 RECURSIVE SOLUTIONS Difference equations are easily solved because of their inherent structure. The solution values HA(nDt), n ¼ 1, 2, 3, . . . are obtained in a sequential fashion by repeated application of the difference equation. The process begins with initial conditions HA(0) and F1(0) and proceeds as follows. Starting with t ¼ 0, from Equation 1.24 Dt Dt HA (0) þ F1 (0) 1 AR A

HA (Dt) ¼

(1:25)

Choosing HA(0) in Equation 1.25 equal to the known initial level H(0) produces the ﬁrst computed value for the approximate level, namely, HA (Dt) ¼

Dt Dt 1 H(0) þ F1 (0) AR A

(1:26)

The process can be repeated to obtain HA(2Dt) by letting t ¼ Dt in Equation 1.24, resulting in the following equation: HA (2Dt) ¼

Dt Dt 1 HA (Dt) þ F1 (Dt) AR A

(1:27)

Substituting HA(Dt) from Equation 1.26 into the right-hand side of Equation 1.27 yields HA (2Dt) ¼

1

Dt Dt Dt Dt 1 H(0) þ F1 (0) þ F1 (Dt) AR AR A A

(1:28)

Expanding Equation 1.28 gives HA (2Dt) ¼

1

Dt 2 Dt Dt Dt H(0) þ 1 F1 (0) þ F1 (Dt) AR AR A A

(1:29)

Another iteration of Equation 1.24 with t ¼ 2Dt and HA(2Dt) from Equation 1.29 leads to HA(3Dt). The result is Dt 3 Dt 2 Dt Dt Dt Dt H(0) þ 1 F1 (0) þ 1 F1 (Dt) þ F1 (2Dt) (1:30) HA (3Dt) ¼ 1 AR AR A AR A A Figure 1.7 illustrates the process up to this point.

Simulation of Dynamic Systems with MATLAB® and Simulink®

12

F1(t)

F1(2Δt) F1(Δt)

F1(0) 0

Δt

2Δt

t

3Δt HA(3Δt)

H(t)

HA(2Δt) HA(Δt)

HA(0) t 0

Δt

2Δt

3Δt

FIGURE 1.7 Illustration of the method for solving a difference equation.

Following the nth iteration, HA(nDt) is known. The next iteration uses it and F1(nDt) to generate a numerical value for HA([n þ 1]Dt) from Dt Dt HA (nDt) þ F1 (nDt) HA ([n þ 1]Dt) ¼ 1 (1:31) AR A Equation 1.31 is a more common form of the difference equation than Equation 1.24. The solution to the difference equation is HA(nDt), n ¼ 0, 1, 2, 3, . . . . It represents an approximation to the actual level H(t) only at discrete times t ¼ 0, Dt, 2Dt, 3Dt, . . . . The accuracy of the approximate solution depends on the size of Dt because the difference equation is based on the use of DH=Dt as a suitable approximation for the ﬁrst derivative dH=dt. As the step size Dt is reduced, the approximation is improved at the expense of more computations required to approximate H(t) for a ﬁxed period of time. In order to ﬁnd a solution H(t), t 0 to the mathematical model of the tank, F1(t) is required for t 0. However, the solution HA(nDt), n ¼ 0, 1, 2, 3, . . . to Equation 1.31 requires knowledge of the input F1(t) only at the discrete times t ¼ 0, Dt, 2Dt, 3Dt, . . . . Similarly, calculating a single value of the approximate solution, for example, HA(25Dt), requires only a ﬁnite number of discrete inputs, namely, F1(nDt), n ¼ 0, 1, 2, . . . , 24.

EXERCISES 1.4 Find the difference equation, similar to Equation 1.31, relating F0, A([n þ 1]Dt) to F0, A(nDt) and F1(nDt). 1.5 A tank with cross-sectional area A ¼ 5 ft2 is initially ﬁlled to a level of 10 ft. The ﬂow out is given by F0 ¼ H=R, R ¼ 1 ft per ft3=min. There is no ﬂow into the tank. (a) Find HA(nDt), n ¼ 0, 1, 2, . . . , 10 when Dt ¼ 2.5 min. (b) Find HA(nDt), n ¼ 0, 1, 2, . . . , 25 when Dt ¼ 1 min. (c) Find HA(nDt), n ¼ 0, 1, 2, . . . , 100 when Dt ¼ 0.25 min. (d) Plot the results and comment on the differences. 1.6 Repeat Exercise 1.5 for the case where the outﬂow is described by F0 ¼ cH1=2, c ¼ 3 ft3=min per ft1=2.

13

Mathematical Modeling

1.4 FIRST LOOK AT DISCRETE-TIME SYSTEMS The variables F1(t), F0(t), and H(t) in the liquid tank shown in Figure 1.3 are referred to as continuous-time (or simply continuous) signals. The reason is because there is a continuum of values between any two points along the t-axis where the variables are deﬁned. Equation 1.18 is a continuous-time model and the system is a continuous-time system because it involves only continuous-time variables. In contrast to the continuous-time signals F1(t), F0(t), and H(t), the sequence of sampled input ﬂow values, F1(nDt), n ¼ 0, 1, 2, . . . and the sequence of approximate tank levels HA(nDt), n ¼ 0, 1, 2, . . . are classiﬁed as discrete-time (discrete for short) signals because the independent variable ‘‘n’’ is discrete in nature. The difference equation (Equation 1.31) is classiﬁed as a discrete-time model, and the underlying system with purely discrete-time input and output signals is likewise a discrete-time system. Figure 1.8 portrays the liquid tank continuous-time system with dependent variable H(t) considered as the output. A complete description of the system includes the following: System: Continuous time Independent variable: t 0 Input: F1(t), t 0 Dependent variables: H(t), F0(t), t 0 Output: H(t), t 0 dH Model: A þ F0 (H) ¼ F1 (t) dt The differential equation model is shown with a term F0(H) representing an algebraic function relating the outﬂow F0(t) to the ﬂuid level H(t). We have assumed this function to be linear; however, a more accurate description will be introduced later. Figure 1.9 is a comparable diagram of the liquid tank discrete-time system with discrete-time input F1(n) and output HA(n). F1(n) is short for F1(nDt), n ¼ 0, 1, 2, . . . the sampled values of the input ﬂow. HA(n) is short for HA(nDt), n ¼ 0, 1, 2, . . . , the values computed from the difference equation in Equation 1.31. Note that HA(n), n ¼ 0, 1, 2, . . . differs from H(nDt), n ¼ 0, 1, 2, . . . , the sampled values of the continuous-time level H(t). A complete description of the system includes the following: System: Discrete time Independent variable: n ¼ 0, 1, 2, . . . Input: F1(n), n ¼ 0, 1, 2, . . . Dependent variables: HA(n), F0, A(n), n ¼ 0, 1, 2, . . . Output: HA(n), n ¼ 0,1, 2, . . . Dt Dt Model: HA (n þ 1) ¼ 1 HA (n) þ F1 (n) AR A Tank model

F1(t)

H(t)

FIGURE 1.8 Liquid tank continuous-time system. Δt F1(t)

F1(n)

FIGURE 1.9 Liquid tank discrete-time system.

Tank model

HA(n)

Simulation of Dynamic Systems with MATLAB® and Simulink®

14

Difference equations can always be solved recursively. Expressions for the ﬁrst three values HA(n), n ¼ 1, 2, 3 are given in Equations 1.26, 1.29, and 1.30. It is sometimes possible to recognize a general pattern for HA(n) from results of the ﬁrst several iterations. In this example, HA(n) is Dt n Dt Dt n1 Dt Dt n2 HA (0) þ F1 (0) þ F1 (1) HA (n) ¼ 1 1 1 AR A AR A AR Dt Dt n3 Dt Dt Dt 1 1 F1 (n 2) þ F1 (n 1), n ¼ 1, 2, 3, . . . F1 (2) þ þ þ A AR A AR A (1:32) Using summation notation, the general solution with HA(0) replaced by H(0) is HA (n) ¼

1

Dt AR

n H(0) þ

n1 Dt X Dt nk1 1 F1 (k), A k¼0 AR

n ¼ 1, 2, 3, . . .

(1:33)

Equation 1.33 is the general solution to the difference equation model in Equation 1.31. When speciﬁc values of HA(n) are required, say HA(100), it eliminates the need for recursive solution of the previous 99 values HA(n), n ¼ 1, 2, 3, . . . , 99. The summation in Equation 1.33 requires some effort; however, the z-transform introduced in Chapter 4 provides a way to avoid the sum altogether. Examination of Equation 1.33 reveals several important features of the approximate solution. First of all, notice the inﬂuence of the initial tank level H(0) on the estimated level HA(n) at the current time n. The ﬁrst term on the right-hand side of Equation 1.33 is the only term in the expression involving H(0). Furthermore, the effect of H(0) on HA(n) is reduced as the discrete-time variable n increases, provided the term in parenthesis, 1 Dt=AR, is less than 1 in magnitude. This appears reasonable if we ask ourselves, ‘‘How important is the initial tank level with respect to the current level after a signiﬁcant amount of time has elapsed?’’ Clearly, the answer is ‘‘not very signiﬁcant at all,’’ and so we should not be surprised to see the only term containing H(0) in the expression for HA(n) monotonically decreasing as n increases. The second point of interest relates to the ‘‘memory’’ inherent in the system. By this, we mean how far back in discrete-time inputs must we go when calculating the current discrete-time output HA(n). Based on Equation 1.32, the answer is ‘‘all the way back’’ to the initial input F1(0). As a result, the discrete-time system is said to have inﬁnite memory because the current discrete-time output HA(n) depends on all past values of the discrete-time input F1(k), k ¼ 0, 1, 2, . . . , n 1. The nature of this dependency is a weighted sum with the most recent inputs receiving the higher weights, as expected. The following example illustrates the use of Equation 1.33 to obtain an approximate solution to the level in the tank when the input ﬂow is constant. Example 1.1 A tank with cross-sectional area of 10 ft2 receives a constant input ﬂow of 5 ft3=min. The ﬂuid resistance of the tank is 2 ft=(ft3=min), and the tank is initially ﬁlled to a level of 4 ft. (a) Find the difference equation for obtaining an approximate solution for the level H(t) using a time step Dt ¼ 0.25 min. (b) Solve the difference equation recursively to obtain the approximate ﬂuid level HA(n), n ¼ 1, 2, 3. (c) Use the general solution to ﬁnd HA(3) directly and compare your answer with the result from part (b).

15

Mathematical Modeling

(a)

Dt 0:25 ¼ ¼ 0:025, A 10

1

HA (0) ¼ H(0) ¼ 4,

Dt 0:25 ¼1 ¼ 0:9875 AR 10(2)

F1 (n) ¼ 5,

n ¼ 0, 1, 2, 3, . . .

The difference equation (Equation 1.31) (with Dt omitted) becomes HA (n þ 1) ¼ 0:9875HA (n) þ (0:025)5,

n ¼ 0, 1, 2, 3, . . .

(b) HA(n), n ¼ 1, 2, 3 are easily computed. n ¼ 0 ) HA (1) ¼ 0:9875HA (0) þ 0:025(5) ¼ 0:9875(4) þ 0:125 ¼ 4:0750 n ¼ 1 ) HA (2) ¼ 0:9875HA (1) þ 0:025(5) ¼ 0:9875(4:075) þ 0:125 ¼ 4:1491 n ¼ 2 ) HA (3) ¼ 0:9875HA (2) þ 0:025(5) ¼ 0:9875(4:1491) þ 0:125 ¼ 4:2222 (c) From Equation 1.33 with n ¼ 3, HA (3) ¼ (0:9875)3 (4) þ 0:025

2 X

(0:9875)3k1 (5)

k¼0

¼ 3:8519 þ 0:025[(0:9872)2 (5) þ (0:9875)(5) þ (5)] ¼ 4:2222

Due to the simple nature of the input, that is, F1(t) ¼ F, t 0, the analytical solution of the differential equation model

A

dH 1 þ H¼F dt R

(1:34)

is easily obtained. The solution is H(t) ¼ RF þ [H(0) RF]et=AR

(1:35)

It is instructive to compare the approximate solution based on the difference equation approach with the exact solution shown in Equation 1.35. The results are shown in Table 1.1, which includes both solutions at equally spaced intervals for the ﬁrst 2 min of the response. Graphs of the continuous-time output H(t) and discrete-time output HA(n), n ¼ 0, 8, 16, . . . are shown in Figure 1.10. By observation of Figure 1.10, it appears that the exact and approximate solutions for the tank level are in close agreement. The step size Dt is the determining factor in terms of how close the two solutions are at the discrete points in time where the approximate solution

Simulation of Dynamic Systems with MATLAB® and Simulink®

16

TABLE 1.1 Comparison of Approximate and Exact Solutions N

tn ¼ nDt

HA(n)

H(tn)

0 1 2 3 4 5 6 7 8

0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0

4.0 4.0750 4.1491 4.2222 4.2944 4.3657 4.4362 4.5057 4.5744

4.0 4.0745 4.1481 4.2208 4.2926 4.3635 4.4335 4.5027 4.5710

11 HA(n), n = 0, 8, 16, …

10

H(t)

9 8

H (ft)

7 6 5 4 3

Δt = 0.25 min

2 1 0

FIGURE 1.10

0

10

20

30

40

50 t (min)

60

70

80

90

100

Exact and approximate solutions for tank level vs. time.

is deﬁned. Choosing the step size Dt is generally a trade-off between the accuracy of the approximate solution and the computational effort required to obtain the approximate solution values. Generally speaking, an assessment of whether the numerical value selected for Dt is reasonable cannot be made on the basis of comparing the approximate solution with the exact solution to the continuous-time model. Analytical solutions are rare due to the complexity of most real-world system models. A logical approach to ﬁnding an acceptable step size is to obtain approximate solutions with different step sizes (an order of magnitude apart) and comparing the results. If the approximate solutions are substantially identical, the smaller step size is eliminated from

Mathematical Modeling

17

consideration. Conversely, if the approximate solutions are not close, the larger value of Dt is discarded. Eventually, a value of Dt will be found, which balances accuracy and computational requirements. This point will be revisited in greater detail after the subject of numerical integration is discussed.

1.4.1 INHERENTLY DISCRETE-TIME SYSTEMS The dynamics of the liquid tank considered in Section 1.2 were classiﬁed as continuous because the variables associated with the tank’s dynamic behavior were continuous time in nature. The continuous-time model of Equation 1.18 governs the relationship between physical quantities, that is, the ﬂow in F1(t) and the liquid level H(t). Later on we learned that a discrete-time model (see Figure 1.9) could be obtained relating the approximate tank level and the sampled input ﬂow. Both signals F1(n) and HA(n) were deﬁned only at the discrete times tn ¼ nDt, n ¼ 1, 2, 3, . . . . Inherently discrete-time systems involve discrete-time signals, which are not the result of sampling a continuous-time signal. For example, consider the discrete-time system model given by 1 u(n) y(n þ 1) þ , n ¼ 0, 1, 2, 3, . . . y(n) ¼ 2 y(n 1)

(1:36)

Equation 1.36 is simply a rule for transforming a discrete-time input signal u(n) into an appropriate output signal y(n). Is this discrete-time system useful? Let us investigate its behavior for the case where the input u(n) is constant, for example, u(n) ¼ 25, n ¼ 0, 1, 2, 3,. . . . First of all, we notice that the initial condition y(1) must be given before we can proceed to calculate subsequent output values y(0), y(1), y(2), etc. Choosing y(1) ¼ 1 and solving for the ﬁrst several outputs, 1 u(0) 1 25 y(1) þ ¼ 1þ ¼ 13 2 y(n 1) 2 1 1 u(1) 1 25 y(0) þ ¼ 13 þ ¼ 7:4615 y(1) ¼ 2 y(0) 2 13 1 u(2) 1 25 y(2) ¼ y(1) þ ¼ 7:4615 þ ¼ 5:4060 2 y(1) 2 7:4615 1 u(3) 1 25 ¼ 5:4060 þ ¼ 5:0152 y(3) ¼ y(2) þ 2 y(2) 2 5:4060 1 u(4) 1 25 ¼ 5:0152 þ ¼ 5:0000 y(4) ¼ y(3) þ 2 y(3) 2 5:0152 y(0) ¼

Using different positive constants for u(n) and other starting pﬃﬃﬃ values for y(1) will reveal an interesting property of the system, namely, limn!1 y(n) ¼ u. The discrete-time signals u(n) and y(n) are plotted in Figure 1.11. Hence, the primary purpose of the discrete-time system governed by Equation 1.36 is to compute the square root of its positive-valued constant input u(n). Another inherently discrete-time system is one we are all familiar with, namely, an interestbearing account such as a bank account. The discrete-time signals of interest are y(k), the account balance at the end of the kth interest period, and u(k), the net deposit for the kth interest period (Figure 1.12). For this simple example, the net deposit during the kth interest period is assumed to have occurred at the end of the period.

Simulation of Dynamic Systems with MATLAB® and Simulink®

18 26

u(n)

25.5 25 24.5

(a)

24 −1

0

1

2

0

1

2

3

4

5

6

3

4

5

6

15

y(n)

10

5

0 −1

n

(b)

FIGURE 1.11 Discrete-time (a) input and (b) output of inherently discrete-time system for ﬁnding the square root of a positive number.

u(k)

FIGURE 1.12

Savings account

y(k)

Example of an inherently discrete-time system.

Consider an account with an interest rate i (per interest period). The balance at the end of the kth interest period, y(k), is the sum of . . .

The balance at the end of the (k 1)st period: y(k 1) The interest earned for the kth interest period: i y(k 1) The net deposit for the period: u(k)

Therefore, the model for this inherently discrete-time system is y(k) ¼ y(k 1) þ iy(k 1) þ u(k),

k ¼ 1, 2, 3, . . .

(1:37)

Example 1.2 A college trust fund is set up with $5000 on January 1, 2000. Starting on January 1, 2001, and every year thereafter, $1000 is added to the fund, which earns 7.5% interest annually. (a) Track the end of year fund balance for the ﬁrst several years. (b) Find the account balance at the end of 18th year. (a) The discrete-time model is y(k) ¼ y(k 1) þ 0:075y(k 1) þ u(k),

k ¼ 1, 2, 3, . . .

with input u(k) ¼ 1000, k ¼ 1, 2, 3, . . . and initial condition y(0) ¼ 5000.

19

Mathematical Modeling The account balance at the end of years 1, 2, and 3 are worked out as follows: k ¼ 1:

k ¼ 2:

k ¼ 3:

y(1) ¼ y(0) þ 0:075y(0) þ u(1) ¼ 5000 þ 0:075(5000) þ 1000 ¼ 6375 y(2) ¼ y(1) þ 0:075y(1) þ u(2) ¼ 6375 þ 0:075(6375) þ 1000 ¼ 7853:13 y(3) ¼ y(2) þ 0:075y(2) þ u(3) ¼ 7853:13 þ 0:075(7853:13) þ 1000 ¼ 9442:11

(b) The recursive solution could be continued for k ¼ 4, 5, 6, . . . , 18, resulting in the fund’s balance at the end of the 18th year. However, a general solution of the discrete-time model is preferable since it can be evaluated for any value of the discrete-time variable k. For the discrete-time model, y(k) ¼ y(k 1) þ iy(k 1) þ u(k),

k ¼ 1, 2, 3, . . .

(1:38)

¼ (1 þ i)y(k 1) þ A

(1:39)

¼ ay(k 1) þ A

(1:40)

where a ¼ 1 þ i and A is the constant net deposit each interest period. The ﬁrst several outputs are y(1) ¼ ay(0) þ A y(2) ¼ ay(1) þ A ¼ a[ay(0) þ A] þ A ¼ a2 y(0) þ aA þ A y(3) ¼ ay(2) þ A ¼ a[a2 y(0) þ aA þ A] þ A ¼ a[a3 y(0) þ a2 A þ aA] þ A suggesting the general expression for y(k) is y(k) ¼

y(0), k ¼ 0 ak y(0) þ (1 þ a þ a2 þ a3 þ þ ak1 )A,

k ¼ 1, 2, 3, . . .

(1:41)

Further simpliﬁcation is possible using the closed form of the ﬁnite geometric series in the previous equation. The general solution for y(k) is y(k) ¼ ak y(0) þ

1 ak A, 1a

k ¼ 1, 2, 3, . . .

(1:42)

The account balance after 18 years is easily computed from the general solution above with a ¼ 1.075, y(0) ¼ 5,000, and A ¼ 1,000. y(18) ¼ (1:075)18 (5,000) þ

1 (1:075)18 1,000 ¼ 54,056:41 1 1:075

The results from part (a) can be veriﬁed using the general solution.

Simulation of Dynamic Systems with MATLAB® and Simulink®

20

EXERCISES 1.7 Rework Example 1.1 using the trial-and-error method for determining a suitable value of Dt. Start with Dt ¼ 10 min and calculate HA(n), n ¼ 0, 1, 2, . . . , nf where nf Dt ¼ 100 min. Repeat the steps with Dt ¼ 5, 2.5, 1.25 min, and so forth until the approximations of H(10), H(20), H(30), . . . , H(100) are in agreement to at least one place after the decimal point. Use the following table for comparisons. Extend the table to smaller values of Dt if necessary.

HA(n) n 0 1 2 3 4 5 6 7 8 9 10

Dt ¼ 10

HA(n) n

HA(n)

Dt ¼ 5

0 2 4 6 8 10 12 14 16 18 20

Dt ¼ 2.5

N 0 4 8 12 16 20 24 28 32 36 40

HA(n) N

Dt ¼ 1.25

0 8 16 24 32 40 48 56 64 72 80

1.8 Prove that the output of the discrete-time system in Equation 1.36 will approach the square root of the input, any positive constant ‘‘A.’’ In other words, show that lim y(n) ¼

n!1

pﬃﬃﬃ A

where u(n) ¼ A, n ¼ 0, 1, 2, 3, . . . . 1.9 An alternate model of the tank relates the outﬂow and liquid level according to F0 (t) ¼ a[H(t)]1=2 (a) Develop a new discrete-time model of the tank using the above relationship in conjunction with the differential equation A(dH=dt) þ F0 ¼ F1. The tank cross-sectional area is 10 ft2 and the input ﬂow is constant at 5 ft3=min. The tank is initially ﬁlled to a level of 4 ft. Assume a ¼ 2 ft3=min per ft1=2. (b) Calculate the approximate tank level for the ﬁrst minute using a step size Dt ¼ 0.25 min. (c) Consider the same tank with zero in ﬂow and an initial ﬂuid level of 25 ft. Write a program to calculate the approximate level of the tank as it empties. Choose Dt ¼ 0.1 min. (d) The analytical solution for the level H(t) when F1(t) ¼ 0, t 0 is given by at 2 1=2 H(t) ¼ H0 2A where H0 is the initial tank level. Compare the results from part (c) to the exact solution. Present the comparison of results in tabular and graphical form.

21

Mathematical Modeling

1.10 A holding tank serves as an effective way of smoothing variations in the ﬂow of a liquid. For example, suppose the liquid ﬂow rate from an upstream process is 2pt ( , F1 (t) ¼ F þ f sin T

t0

where ( F is an average ﬂow f is the ﬂuctuation about the average ﬂow T is the period of the ﬂuctuations Nominal parameter values for the input ﬂow rate are F ¼ 250 ft3=min, f ¼ 50 ft3=min, and T ¼ 15 min. A holding tank is placed between the source F1(t) and a downstream process that requires a more constant input ﬂow rate, F0(t), as shown in Figure E1.10. The downstream process requires that the sustained ﬂuctuations in the ﬂow F0(t) be no larger than 10 ft3=min. Assume the tank is linear and the ﬂuid resistance R ¼ 0.25 ft per ft3=min. F1(t) From upstream

H(t) A F0(t) To downstream process

FIGURE E1.10

(a) Find the difference equation for F0, A(n), n ¼ 0, 1, 2, 3, . . . . Leave the tank cross-sectional area A as a parameter. (b) Write a program to solve the difference equation with Dt ¼ 0.5 min for a starting value of A ¼ 100 ft2. Graph both F0, A(n) and HA(n), n ¼ 0, 1, 2, . . . for a period of time sufﬁcient to determine if the design criterion is satisﬁed. Assume that the tank is initially empty. (c) Repeat part (b) with a new value of A until the design criterion is satisﬁed. (d) Graph the discrete-time signals F1(n) and F0, A(n), n ¼ 0, 1, 2, 3, . . . for the tank whose area is the value determined in part (c).

1.5 CASE STUDY: POPULATION DYNAMICS (SINGLE SPECIES) The population of a country is under investigation. Unlike the liquid tank example, there is no scientiﬁc principle to serve as a foundation for deriving a mathematical model that can be used to predict future populations. Instead, empirical observations of historical birth and death rates, immigration and emigration patterns, and a host of other pertinent data are utilized.

Simulation of Dynamic Systems with MATLAB® and Simulink®

22

TABLE 1.2 Population Data for 100 Years t (Years) 0 10 20 30 40 50 60 70 80 90 100

Pobs(t), Millions 3.0000 3.2276 4.5759 6.9570 8.7618 9.1536 11.2669 14.5153 16.5059 17.9563 19.5078

One hundred years of observed population data, recorded at intervals of 10 years, are given in Table 1.2. Based on the available data, researchers are convinced that the population is adequately modeled by the following differential equation, referred to in the literature as logistic growth (Haberman 1977). dP ¼ cP(Pm P) dt

(1:43)

P ¼ P(t) is the population ‘‘t’’ years after the initial population was recorded. The parameters c and Pm inﬂuence the speciﬁc growth pattern behavior. The model ignores immigration and emigration and all other external inputs, which inﬂuence dP=dt, the rate at which the population changes. The system model in Equation 1.43 is said to be autonomous, meaning there are no additional terms independent of P as might be the case if immigration or emigration inputs as a function of time were considered. The dynamics depend solely on initial conditions and the system parameters. It is also referred to as an unforced system since there are no external inputs. Statistical analyses of the population data have resulted in estimated values for c and Pm to be 1.25 109 and 25 million, respectively. It is now 100 years since the initial population was measured. Government planners are interested in determining what the likely population will be over the next several decades. A method is needed to obtain an approximate solution of the model, that is, a difference equation for PA(n) P(nDt), n ¼ 0, 1, 2, . . . is required. When the continuous-time model is a ﬁrst-order differential equation, a difference equation for approximating the dynamics at discrete points in time is easily obtained. Simply replace the ﬁrst derivative term with an appropriate ﬁnite difference approximation, remembering to rename the dependent variable in some way since we are now dealing with an approximate solution. This is precisely the way a difference equation for approximating the liquid tank dynamics was obtained in Section 1.3. Substituting a ﬁrst-order ﬁnite difference approximation for dP=dt in Equation 1.43, PA (n þ 1) PA (n) ¼ cPA (n)[Pm PA (n)] Dt

(1:44)

Note the appearance of PA(n) on the right-hand side of the equation in place of P(t). Solving for PA(n þ 1) produces the following difference equation: PA (n þ 1) ¼ PA (n) þ cPA (n)[Pm PA (n)]Dt,

n ¼ 0, 1, 2, 3, . . .

(1:45)

Simplifying Equation 1.45 produces the following desired form: PA (n þ 1) ¼ {1 þ cDt[Pm PA (n)]}PA (n),

n ¼ 0, 1, 2, 3, . . .

(1:46)

Since our interest is in predicting populations for 101 years and beyond, we need to solve Equation 1.46 over a suitable range of values for the discrete-time variable ‘‘n.’’ The appropriate integer values depend on the size of our time step Dt. For simplicity, we shall choose Dt equal to 1 year, necessitating the calculation of PA(101), PA(102), . . . , PA(130) to obtain predictions for a 30 year time span.

23

Mathematical Modeling

TABLE 1.3 Comparison of Observed, Discrete-Time, and Continuous-Time Populations t (Years) 0 10 20 30 40 50 60 70 80 90 100 110 120 130

Pobs(t), Millions

N (at ¼ 1 Year)

PA(n), Millions

P(t), Millions

3.0000 3.2276 4.5759 6.9570 8.7618 9.1536 11.2669 14.5153 16.5059 17.9563 19.5078 — — —

0 10 20 30 40 50 60 70 80 90 100 110 120 130

3.0000 3.9161 5.0493 6.4129 8.0003 9.7778 11.6834 13.6325 15.5321 17.2976 18.8671 20.2076 21.3139 22.2012

3.0000 3.9276 5.0759 6.4570 8.0618 9.8536 11.7669 13.7153 15.6059 17.3563 18.9078 20.2310 21.3226 22.1990

A recursive solution seems like our only alternative, since a general solution is not easily achievable. A computer program to generate the recursive solution is the way to proceed. We are starting from a known population Pobs(0), so PA(0) ¼ Pobs(0) ¼ 3 million. The results are computed in the MATLAB® script ﬁle ‘‘Chap1_CaseStudy.m’’ and shown in Table 1.3. A casual observation of this table indicates that the modelers were justiﬁed in choosing the logistic growth equation to model the country’s population over the time period of one century. Naturally, this assumes that the approximate solution values PA(n) are reasonably close to the exact solution P(t) for t þ nDt, n ¼ 0, 10, 20, 30, . . . . Ordinarily, models used to represent the dynamics of continuous-time systems are not amenable to exact solutions, even with the simplest types of input. However, an analytical solution to Equation 1.43 is as follows: P(t) ¼

Pm P(0) , P(0) þ ½Pm P(0)ecPm t

t0

(1:47)

The solution can be veriﬁed by differentiation and substitution back into Equation 1.43. A quick glance at the solution shows the initial condition P(0) results when t is equal to zero on the righthand side of Equation 1.47. Knowing the exact solution to the continuous-time model, we can evaluate it at t ¼ 0, 10, 20, . . . , 100 years for comparison with the discrete-time model output to determine if our step size needs to be adjusted. The exact solution results are tabulated in the ﬁnal column of Table 1.3. Comparing the last two columns in the table should convince us that the step size Dt does not need to be reduced. While it is possible to reduce the discrepancy between the approximate and exact solutions by lowering Dt, it is hardly justiﬁed in view of the fact that the continuous-time model, Equation 1.43, is itself only an approximate representation of the true population dynamics. The data in Table 1.3 are presented in graphical form in Figure 1.13. The discrete-time system model is used to predict future populations. The projected populations for Years 110, 120, and 130 are included in Table 1.3 and appear as data points in Figure 1.13. The previous point relating to the accuracy of the approximate solution is worth reiterating. Extremely accurate solutions of nonlinear differential equation models are generally not warranted

Simulation of Dynamic Systems with MATLAB® and Simulink®

24 25 Pobs(t)

PA(n), n = 0, 10, 20, ..., 130

Population (millions)

20

P(t)

15

10

5 Δt = 1 year 0

0

20

40

60

80

100

120

140

Time, t (year number)

FIGURE 1.13

Observed, discrete-time (approximate), and continuous-time populations.

unless the continuous-time models were formulated to account for higher-order effects. Even then, one must limit the accuracy requirements in order to keep the computations manageable. Exact solutions to continuous-time models are rare. How can we be certain if the solution of the discrete-time model is in agreement with the exact solution? There is no simple answer; however, there are some things we can do to check the validity of the approximate solution. We know the difference equations in the discrete-time model converge to the differential equations of the continuous-time model in the limiting case when the step size Dt approaches zero. Furthermore, the discrete-time solutions will approach the exact solutions of the continuous-time model as Dt is reduced to zero. Systematically reducing the step size until the changes in the discrete-time outputs are within some tolerance demonstrates this convergence and is an effective way of selecting the step size Dt for future runs. We touched on this in the previous section as a way of choosing an appropriate value for the step size Dt. A word of caution—the step size may have to be readjusted as conditions of the discrete-time system model change. Our intuition about the continuous-time system response may suggest we take a closer look at the discrete-time system model. For example, consider the tank model dH ¼ F1 (t) F0 (t) dt

(1:48)

d 1 H(t) ¼ [F1 (t) F0 (t)] dt A

(1:49)

A )

Using the simple ﬁrst-order difference approximation formula d HA (n þ 1) HA (n) H(t) dt Dt ) HA (n þ 1) ¼ HA (n) þ

Dt ½F1 (n) F0 (n) A

(1:50) (1:51)

25

Mathematical Modeling F1(n) > F0(n)

F1(n)

HA(n + 1) > HA(n)

F0(n)

n

n+1 Level rising

HA(n) HA(n + 1)

Level dropping

n

FIGURE 1.14

n+1

Change in discrete-time approximation of H(t) in violation of Equation 1.52.

8 < > HA (n), ) HA (n þ 1) ¼ HA (n), : < HA (n),

when F1 (n) > F0 (n) when F1 (n) ¼ F0 (n) when F1 (n) > F0 (n)

(1:52)

Equation 1.52 is consistent with our expectation that the level in a tank is rising (dH=dt > 0) when the liquid is coming in faster than it is leaving and falling when the opposite is true. Consequently, a change in tank level like the one shown in Figure 1.14 is the reason to double check the calculations or the code that produced them. Another check on the integrity of an approximate solution to a continuous-time model is to see whether the differential equation itself is satisﬁed within some tolerance. Since the logistic growth model in Equation 1.43 governs population growth at all times, it must apply at the discrete times tn ¼ nDt, n ¼ 0, 1, 2, 3, . . . . Therefore,

d ¼ cP(nDt)½Pm P(nDt), P(t)

dt t¼nDt

n ¼ 0, 1, 2, 3, . . .

(1:53)

We can approximate the ﬁrst derivative term on the left-hand side of Equation 1.53 using a more accurate difference formula than the ﬁrst-order difference quotient used to approximate dH=dt in the case of the liquid tank. Referring to Figure 1.15, dP=dt at t ¼ nDt is approximated using an average of ﬁrst-order difference approximations resulting in

d 1 PA (n þ 1) PA (n) PA (n) PA (n 1) PA (n þ 1) PA (n 1)

P(t)

þ ¼ dt 2 Dt Dt 2Dt t¼nDt

d PA (51) PA (49) ) P(t)

dt 2Dt t¼50Dt

9:9638 106 9:5930 106 2(1)

0:1854 106 people=year

(1:54)

Simulation of Dynamic Systems with MATLAB® and Simulink®

26

P(t) PA(n + 1) PA(n + 1) − PA(n − 1) PA(n) PA(n – 1) 2Δt

d Slope of tangent = — P(t) dt

t=nΔt

Approximated by PA (n + 1) PA(n − 1) 2Δt (n − 1)Δt

FIGURE 1.15

nΔt

t

(n + 1)Δt

Second-order approximation of ﬁrst derivative dP=dt.

The right-hand side of Equation 1.53 with P(50Dt) replaced by PA(50) becomes cP(nDt)[Pm P(nDt)] ¼ cPA (50)[Pm PA (50)] ¼ 1:25 109 (9:7778 106 )[25 106 9:7778 106 ] ¼ 0:1860 106 people=year

(1:55)

in close agreement with the estimate of (d=dt)P(t)jt ¼50Dt. Further scrutiny of the logistic growth model, Equation 1.43, reveals several important and noteworthy characteristics of the underlying population dynamics. Expressing the model in a slightly different form g(P) ¼

1 dP ¼ c(Pm P) p dt

(1:56)

where g(P), the rate of change in population dP=dt divided by the population P, is called the population growth rate. Different population models are normally characterized by the term(s) appearing on the right-hand side of Equation 1.56. The growth rate function is plotted in Figure 1.16. We expect the population to be increasing whenever the growth rate is positive, since a positive growth rate implies the instantaneous rate of change in the population, that is, the ﬁrst derivative is also positive. The logistic population growth rate declines linearly with increasing population, eventually reaching zero when the population reaches Pm or 25 million in this case. In logistic growth models, Pm is called the carrying capacity. Observe from Figure 1.13 that the discrete-time and continuous-time model outputs for 130 years ranged from the initial population of 3 million people to somewhere around 22 million people. Looking at the heavier line segment in Figure 1.16, corresponding to this range of populations, we notice that the growth rate is positive, and, hence, the population should be monotonically increasing, as indeed it was.

27

Mathematical Modeling

g (P) millions of individuals per year per individual

0.04

0.02 0.01 g[P(130)] 0 −0.01 −0.02 −0.03 Pm = 25 million −0.04

FIGURE 1.16

g[P(0)]

0.03

0

5

10

15

20

25 30 P (millions)

35

40

45

50

Plot of population growth rate g(P) vs. population (P).

Is it possible for a population P(t) governed by a logistic growth model to ever assume values on both sides of its carrying capacity? For example, is the population growth shown in Figure 1.13 capable of exceeding Pm ¼ 25 million if we wait long enough? Figure 1.17 shows population time histories for the logistic model considered previously (c ¼ 1.25 109, Pm ¼ 25 106) with different starting populations. It is clear that the population approaches its carrying capacity from below or above in asymptotic fashion. We should not be surprised if we consider what happens to the population growth rate g(P) as the population P(t) approaches the carrying capacity from either direction (see Figure 1.16).

50 45

Population (millions)

40 Carrying capacity: Pm = 25 million

35 30 25 20 15 10 5 0 0

FIGURE 1.17

20

40

60

80 100 t (Year number)

Logistic growth with different initial populations.

120

140

160

180

Simulation of Dynamic Systems with MATLAB® and Simulink®

28 P

Pm

t

FIGURE 1.18

Discrete-time population model output inconsistent with logistic growth.

A discrete-time response PA(n) like the one appearing in Figure 1.18 is inconsistent with the properties of continuous-time logistic growth. However, crossing over the carrying capacity for one or two time increments is not inconsistent with the discrete-time nature of the approximate solution. Why not?

EXERCISES 1.11 Assume that the logistic growth population model accurately predicts future populations. (a) Some time in the future, the population will reach 98% of its carrying capacity. Find how many more years this will take by using the difference equation given in Equation 1.46. Does it make a difference whether you start from PA(0) ¼ 3 million or PA(130) ¼ 22.2012 million from Table 1.3. (b) Compare the answer obtained in part (a) with the analytical solution for P(t). (c) The population growth rate g(P) vs. P in Figure 1.16 does not explicitly involve time. Label the points on the growth rate curve corresponding to {t, P(ti)} where t0 ¼ 0, t1 ¼ 25, t2 ¼ 50, t3 ¼ 75, and t4 ¼ 100. (d) The carrying capacity Pm in a logistic growth model is an equilibrium population, meaning that if the population at some point in time were equal to Pm, it would remain there forever. Investigate whether it is stable or not by supposing the population is slightly less or slightly more than Pm, and determine whether the population returns to the carrying capacity. Obtain several approximate solutions corresponding to different initial populations reasonably close to Pm. (e) Find the other equilibrium population of the logistic growth model and determine if it is stable. 1.12 A simpler model for population growth of a species is one in which the growth rate is assumed constant, that is, independent of the population. Mathematically, this is represented by Growth rate ¼ g(P) ¼

1 dP ¼k P dt

1.13 Suppose a culture of bacteria is increasing in size according to the constant growth rate model above. The initial bacteria population is P0. (a) Develop the difference equation for the discrete-time system approximation of the continuous-time model. Denote the discrete-time population as PA(n). (b) Find the general solution for PA(n), n ¼ 0, 1, 2, 3, . . . . Leave your answer in terms of k and P0. The constant growth rate k ¼ 0.01 bacteria=min per bacteria and the initial number of bacteria is 10,000.

Mathematical Modeling

29

(c) Solve the difference equation recursively using a step size Dt ¼ 1 min for PA(n), n ¼ 1, 2, 3, 4, 5. Compare the result for PA(5) to the value obtained from the general solution found in part (b). (d) The analytical solution to the continuous-time model is P(t) ¼ P0ekt, t 0. How long does it take for the population to reach 1 million? (e) On the same graph, plot the continuous-time model output P(t), 0 t 500 and the discrete-time model output PA(n), n ¼ 0, 50, 100, 150, . . . , 1000 when Dt ¼ 0.5 min. (f) Explain what would happen to a population with constant growth rate k, if k were negative.

This page intentionally left blank

2

Continuous-Time Systems

2.1 INTRODUCTION Before we start our exploration of simulation, it is important for us to have some basic knowledge of how linear time-invariant (LTI) dynamic systems behave. The analysis of linear systems and how they respond to elementary types of inputs is straightforward. Linear systems appear as building blocks in more complex systems. Our intuitive understanding of the entire system is enhanced by recognizing the fundamental behavior of its linear components. Control systems, for example, are oftentimes composed of linear continuous-time components interconnected to produce a desirable response to commanded as well as uncontrollable or disturbance inputs. Speaking of control systems, the mathematical model of the process being controlled is often nonlinear; however, a properly designed regulatory control system will limit excursions of the process variables. In fact, the design of the controller may be based on a linearized model of the nonlinear process owing to the wealth of tools available in the ﬁeld of linear control theory. Simulation can play a valuable role here by shedding light on the validity of using a linearized mathematical model to approximate a nonlinear system model. Modern simulation software contains user interfaces employing graphical icons that serve as building blocks for representing the linear continuous- and discrete-time components within a system. In order to exploit this feature, the simulation builder must understand the meaning and differences between the assortment of linear system blocks (integrators, ﬁrst-order lags, secondorder systems, transfer functions, and state space models) at his or her disposal. The material on ﬁrst- and second-order system response, and state variables covered in this chapter and Chapter 4, is intended as an introduction (or possibly a review) to the topic of linear continuous-time systems. There are literally dozens of excellent books on the subject of linear systems theory and linear control systems. Several are included in the references and the reader is encouraged to consult one or more as necessary. In addition to the focus on linear systems in this chapter, one section includes several examples of nonlinear systems as well. A graphical illustration of how to linearize a nonlinear system model is presented as a preview of what is to come in Chapter 7 where the subject is revisited in more detail. Simulation of continuous-time systems is not discussed in detail until Chapter 3 where the subject of numerical integration is introduced. However, a simulation model based on numerical differentiation, similar to what was done in Chapter 1, is presented. At the conclusion of this chapter, the reader will be capable of representing simple continuous-time systems in state variable form and generate discrete-time model approximations of them, which can be solved in a recursive fashion.

2.2 FIRST-ORDER SYSTEMS Continuous-time dynamic systems are said to be ﬁrst order if the highest derivative of the dependent variable appearing in the mathematical model is ﬁrst order. Systems in which a quantity of material or energy changes at a rate dependent on the amount of material or energy present are typically ﬁrst order in nature. The general representation of a scalar ﬁrst-order system is dy ¼ f (t, y, u) dt

(2:1) 31

Simulation of Dynamic Systems with MATLAB® and Simulink®

32

where t is the continuous-time variable u ¼ u(t) is the system input y ¼ y(t) is the system output f(t, y, u) is the derivative function, which relates the rate of change in y to all three arguments Not all three arguments will be present in every ﬁrst-order model. Furthermore, it is possible for multiple inputs u1(t), u2(t), . . . , ur(t) to be present. We begin our discussion of ﬁrst-order systems with a special case, namely, where the derivative function is an explicit linear function of the input and output given by f (t, y, u) ¼ b0 u(t) a0 y(t)

(2:2)

where a0 and b0 are constants. Combining Equations 2.1 and 2.2 gives d y(t) þ a0 y(t) ¼ b0 u(t) dt

(2:3)

Equation 2.3 is an LTI, ordinary differential equation. In the time-varying case, one or both of the linear system parameters a0 and b0 are functions of the independent variable t. Equation 2.3 is commonly expressed as t

d y(t) þ y(t) ¼ Ku(t) dt

(2:4)

where t and K are easily related to a0 and b0 by t¼

1 a0

and

K¼

b0 a0

(2:5)

Many simple real-world dynamic systems are modeled by the ﬁrst-order differential equation (Equation 2.4). More complex systems often behave similarly to ﬁrst-order systems under certain conditions. Furthermore, higher-order system models can be reduced to a system of coupled ﬁrst-order models. Familiarity with ﬁrst-order system response will prove useful later on when we undertake the task of simulating higher-order linear and nonlinear systems. For this reason, we explore some basic properties of ﬁrst-order systems modeled by Equation 2.4.

2.2.1 STEP RESPONSE

OF

FIRST-ORDER SYSTEMS

When the input u(t) is constant, that is, u(t) ¼ A, t 0, the solution to Equation 2.4 for y(t) is obtained using Laplace transform or classical time-domain methods. It is given below: y(t) ¼ y(0)et=t þ KA(1 et=t ),

t0

(2:6)

where y(0) is the initial value of the output y(t). Several graphs of y(t) are shown in Figure 2.1 for the cases where y(0) ¼ 0, K ¼ 5, A ¼ 2, and t ¼ 0.5, 2, 5, and 10. The graphs of y(t) shown in Figure 2.1 are called the step response because the input resembles a step (changing from 0 to A at t ¼ 0). Note that the initial condition is zero in all the step responses.

33

Continuous-Time Systems First-order system step response for τ = 0.5, 2, 5 and 10 y(∞) = K . A = 10

10 9 τ = 10

8 7

Increasing τ

y(t)

6 5 4 3

Input u(t) = 2, t ≥ 0

2 1 0 0

5

10

15

20

25 t

30

35

40

45

50

FIGURE 2.1 Step response of ﬁrst-order system with different values of t.

The constant A measures the amplitude of the input and is not an inherent system parameter. The system parameters are K and t (or a0 and b0 from which they are computed). The ﬁrst parameter K is called the system DC or steady-state gain. It is so named because the ﬁnal value of the output, y(1), is easily computed from y(1) ¼ K u(1) ¼ K A

(2:7)

which in this case is y(1) ¼ 5 2 ¼ 10 (see Figure 2.1). The ﬁnal value y(1) is unaffected by the initial condition y(0). However, the graph of y(t) in Equation 2.6 certainly depends on y(0), since that is where it starts. A ﬁrst-order system like the one in Equation 2.4 is called a ﬁrst-order lag because of the way the step response in Figure 2.1 lags the step input. There are situations when the input to a ﬁrst-order system is not a step; however, the input remains constant for a period of time that is largely relative to the parameter t. Equation 2.7 enables us to readily compute the ﬁnal output value prior to a change in the input. In essence, we are tracking the ﬁrst-order system from one steady-state level to another, and the transient response (portion of the overall step response that decays to zero) is ignored. Even without knowledge of the transient response, it is possible to predict the amount of time necessary for the new steady state to be established. In the ﬁrst-order system modeled by Equation 2.4, the ﬁrst derivative vanishes when the system u, where yss is the output at steady state in response to the constant is at steady state, leaving yss ¼ K input u. A similar result is obtained from Equation 2.6 with A replaced by and t approaching 1. The ﬁrst-order system step responses shown in Figure 2.1 correspond to four distinct values for the parameter t. It is apparent that while all approach the limiting value y(1) ¼ 10, there is a noticeable difference in the amount of time required for each to get there. The individual step responses are correlated with the system parameter t. This parameter is called the time constant of the ﬁrst-order system. It is a measure of the speed of the step response as well as an indicator of the overall speed of the ﬁrst-order system’s dynamics. A ‘‘rule of thumb’’ for ﬁrst-order systems is that the transient response vanishes after four or ﬁve time constants. The transient response component of the step response in Equation 2.6 with y(0) ¼ 0 is ytr (t) ¼ KAet=t ,

t0

(2:8)

Simulation of Dynamic Systems with MATLAB® and Simulink®

34

when t ¼ 5t, ytr (5t) ¼ KAe5 ¼ KA(0:0067)

(2:9)

y(5t) ¼ KA(1 e5 ) ¼ 0:9933KA

(2:10)

and the step response

is more than 99% complete. After four time constants have elapsed, the step response is slightly over 98% of its ﬁnal value (see Figure 2.1). First-order system models are commonplace in science, engineering, economics, business, etc. The liquid storage tank model in Section 1.2 and the population models considered in Section 1.5 are examples of ﬁrst-order system models. Another example of a physical system described in terms of a ﬁrst-order model is the simple electric circuit shown in Figure 2.2 along with the tank. The circuit components are a capacitor C, a resistor R, and a voltage source e0(t). There is also a switch that connects the source to the rest of the circuit when it is in the closed position. Like the tank that stores its energy as a column of liquid, the circuit’s capacitor stores energy in the form of electric charge. The potential energy of the ﬂuid varies as the tank level changes and the electrical energy stored in the circuit varies with the amount of electrical charge stored in the capacitor. Both systems have a mechanism for dissipating energy. The tank does so whenever the level of ﬂuid is dropping and the circuit dissipates energy in the resistor whenever there is current ﬂowing. The ﬂuid resistance of the tank tells us the amount of effort, that is, height of liquid, required to produce a unit of ﬂow from the tank. A typical unit for ﬂuid resistance is ft per ft3=min. The electrical counterpart is the electrical resistor that also measures the driving force, in this case, the voltage applied to the resistor, necessary to produce a unit of current ﬂow, measured in amperes. The unit of electric resistance is volts=ampere, commonly called ohms. Choosing the voltage across the capacitor vc(t) as the output, the circuit model is easily derived using basic principles of electrical circuits. The result is RC

d vc (t) þ vc (t) ¼ e0 (t) dt

(2:11)

Comparison of Equation 2.11 with the standard form introduced in Equation 2.4 reveals the time constant of the circuit t ¼ RC and the steady-state gain K ¼ 1(V=V). Hence, the transient response lasts for a period of time equal to approximately 5RC. For a constant voltage applied to the circuit, that is, e0(t) ¼ E0, t 0, the steady-state voltage vc(1) is numerically equal to E0 since vc(1) ¼ KE0 ¼ 1 E0.

F1(t)

A

R

H(t)

e0(t)

i(t)

vc(t)

C

R (a)

F0(t) (b)

FIGURE 2.2 Examples of systems with ﬁrst-order system models: (a) storage tank and (b) RC circuit.

35

Continuous-Time Systems

The step response is obtained from Equation 2.6 with y(0) ¼ vc(0) ¼ 0, t ¼ RC, K ¼ 1, and A ¼ E0. The result is vc (t) ¼ E0 (1 et=RC ),

t0

(2:12)

The step response consists of the steady-state component vc (1) ¼ E0

(2:13)

and the transient component vc (t)tr ¼ E0 et=RC ,

t0

(2:14)

The transient response involves the exponential et=RC, which is called the natural mode of the system. To understand this, consider the circuit response with zero applied voltage (E0 ¼ 0) and a nonzero initial voltage across the capacitor vc(0). From Equation 2.6, the solution for vc(t) is vc (t) ¼ vc (0)et=RC ,

t0

(2:15)

a constant times the natural mode. Natural modes of linear systems are exponential functions of time involving the parameters of the system, in this case, R and C. The natural modes do not depend on the system inputs. The unforced response of higher-order system models is referred to as the natural response of the system. It contains a linear combination of the natural modes (only one for the ﬁrstorder system model). In general, the natural modes of linear system models appear in the transient response independent of whether the system is being forced (excited by inputs) or simply responding to initial conditions as in the case of an autonomous system. Example 2.1 A 12 V battery is used to charge the capacitor in the circuit shown in Figure 2.2. When the switch is closed at t ¼ 0, the capacitor voltage is zero. Numerical values of the circuit parameters are R ¼ 5000 V and C ¼ 0.125 106 F (1 F ¼ 1 A per V=s). (a) (b) (c) (d)

Find the time constant t, steady-state gain K, and natural mode of the circuit. Find the steady-state voltage vc(1) across the capacitor. Determine how long it takes for the capacitor to charge up to 50% of vc(1). Find and graph the transient component, steady-state component, and the complete response for the case where the capacitor is initially charged to 3 V.

(a) t ¼ RC ¼ (5000 V) 0.125 106 F ¼ 0.000625 s (625 106 s) K ¼ 1 V=V Natural mode: et=RC ¼ et=0.000625, t 0 (b) vc(1) ¼ KE0 ¼ (1 V=V) 12 V ¼ 12 V 6

(c) vc(t) ¼ E0(1 et=RC) ) 6 ¼ 12(1 et=62510 ), which can be solved using natural logarithms to give t ¼ 0004332 s (d) From Equation 2.6 with initial condition vc(0) ¼ 3 V, the complete response is vc (t) ¼ vc (0)et=RC þ KE0 (1 et=RC ), t=625106

¼ 3e

t0

t=625106

þ (1)(12)(1 e

)

Simulation of Dynamic Systems with MATLAB® and Simulink®

36 14

vc(∞) = 12 V

12 10 8

vc(t) = vc(∞) + vc(t)tr

v(t) (V)

6 4

vc(0) = 3 V

2 0 −2 −4

vc(t)tr = −9e−t/τ

τ = 0.625 ms

−6 −8 −10

0

0.5

1

1.5 t (s)

2

2.5

3 ×10−3

FIGURE 2.3 Steady-state, transient, and total response of an RC circuit.

The transient component is vc (t)tr ¼ [vc (0) KE0 ]et=RC , ¼ [3 (1)(12)]e

t0

t=625106

6

¼ 9et=62510 and the steady-state component is

V vc (1) ¼ KE ¼ 1 (12 V) ¼ 12 V V Graphs of the steady-state, transient, and complete responses are shown in Figure 2.3. Note that the transient response has decayed to essentially zero after ﬁve time constants (5 625 106 ¼ 3.125 103) have elapsed.

EXERCISES 2.1 The tank shown in Figure 2.2 has a constant cross-sectional area A and ﬂuid resistance R. (a) Find expressions for the time constant t and steady-state gain K of the tank in terms of the physical parameters A and R. (b) The empty tank is subject to a constant ﬂow in of F ft3=min. Obtain an expression for the liquid level step response of the tank. (c) The cross-sectional area of the tank is 20 ft2, and the ﬂuid resistance is 0.5 ft per ft3=min. How high must the tank be if the inﬂow is constant at F ¼ 15 ft3=min for it not to overﬂow. (d) How long will it take for the tank level to reach 50% of its ﬁnal height? (e) What size tank is needed if the time required to ﬁll up is increased by 10%?

37

Continuous-Time Systems

2.2 Consider the ﬁrst-order system: (d=dt)y(t) þ a0y(t) ¼ b0u(t) (a) Under what conditions does this system reduce to a pure integrator? (b) For the continuous-time integrator in part (a), express the output y(t) in terms of the input u(t). Assume the initial condition is y(0) ¼ y0. (c) When is a liquid storage tank a pure integrator? 2.3 The amount of salt Q in a well-stirred tank shown in Figure E2.3 depends on c1, the concentration of salt in the brine solution entering the tank, as well as the ﬂow rates F1 and F0 into and out of the tank. The continuous-time model is based on conservation of salt. It equates dQ=dt, the instantaneous rate of change in the amount of salt in the tank to the difference in the rate of salt entering the tank, c1F1, and the rate of salt ﬂowing out of the tank, cF0. The tank initially contains 100 lb of salt-free water. The concentration of salt in the brine solution ﬂowing in is 0.25 lb=ft3. Both the ﬂow into and the ﬂow out of the tank are both 1 ft3=min. Note that 1 ft3 of water weighs approximately 62.4 lb. (a) Find Q(t), the amount of salt in the tank as a function of time. (b) Find the amount of salt in the tank at steady state.

c1, F1

dQ = c1F1 – cF0 dt

c, Q

c, F0

FIGURE E2.3

2.4 A temperature-controlled chamber is shown in Figure E2.4: The air temperature inside the chamber is assumed to be the same everywhere, namely, T(t). The chamber walls are insulated to reduce heat loss or gain with its surroundings. Temperature control is achieved by circulating hot or cold water through pipes located inside the chamber. Heat exchange occurs between the air inside the chamber and the circulating water in the pipes. The heat ﬂow from the circulating hot water is Qh(t), and Qc(t) is the heat ﬂow to the cold water. Heat exchange Q0(t) also occurs between the air inside and outside the chamber. Ambient temperature outside the chamber is denoted T0(t).

Q0(t)

T0(t) Cold water m , T c c

mh, Th

Qc(t)

Qh(t) m c , Tc

FIGURE E2.4

T(t)

Hot mh, Th water

Simulation of Dynamic Systems with MATLAB® and Simulink®

38

A suitable model for this thermal system is based on the conservation of energy. cA V

dT ¼ Qh Qc Q0 dt

V is the volume (ft3) of air in the chamber, and cA is the thermal capacitance of air (0.01375 Btu=8F=ft3). The heat ﬂow terms on the right-hand side are given by Qh ¼ m_ h cp (Th T) Qc ¼ m_ c cp (T Tc ) Q0 ¼

1 (T T0 ) R

where m_ h and m_ c are the mass ﬂow rates (lb=min) of the hot and cold water cp is the speciﬁc heat of water (1 Btu=lb=8F) R is the thermal resistance (8F=Btu=min) of the chamber walls The expressions for Qh and Qc assume that the ﬂow rates of the circulating ﬂuids are great enough that both ﬂuids exit at the same temperature at which they entered the chamber. (a) Express the mathematical model in the form of a differential equation relating the output T and its derivative to the inputs Th, Tc, and T0. (b) Find the time constant and the three steady-state gains of the system. Check the units to verify that the time constant is in minutes and the steady-state gains are dimensionless (8F=8F). (c) Show that the air temperatures inside and outside the chamber eventually equalize after both the hot and cold circulating water ﬂows are turned off. (d) Suppose the chamber air temperature is required to be higher than the outside ambient air temperature, which remains constant, that is, T0(t) ¼ T 0, t 0. The hot water temperature entering the chamber is three times greater than the ambient temperature. The initial air temperature inside the chamber is the same as the outside ambient temperature. Find the analytical solution for T(t), t 0, the air temperature inside the chamber. (e) Graph the solution for T(t), t 0 in part (d) using the following values: V ¼ 5000 ft3 ,

R ¼ 0:025 F=Btu=min,

m_ h ¼ 50 lb=min, and

T 0 ¼ 60 F

2.3 SECOND-ORDER SYSTEMS Input–output models of continuous-time dynamic systems where the highest derivative of the dependent variable is second order are classiﬁed as second-order systems. Second-order systems result when there are two energy storage elements present. Our interest for now is in linear secondorder systems, which can be manipulated into the form shown in Equation 2.16 relating an output y(t) to an input u(t) involving generic system parameters z, vn, and K. d2 d y(t) þ 2zvn y(t) þ v2n y(t) ¼ Kv2n u(t) dt 2 dt

(2:16)

For an actual second-order system (mechanical, electrical, biological, etc.), the generic parameters can be expressed in terms of the system’s physical parameters. The importance of each will be explained shortly.

39

Continuous-Time Systems

The unit step response of the second-order system is the solution for y(t) in Equation 2.16 when y(0) ¼ 0 and the input u(t) ¼ 1, t 0, hereafter denoted by û(t). It can be found in any text related to linear systems or controls (Palm 1983; Franklin et al. 2002; Dorf and Bishop 2005). The unit step response assumes one of three forms depending on the location of the roots of the algebraic equation s2 þ 2zvn s þ v2n ¼ 0

(2:17)

known as the characteristic equation of the system. The characteristic roots are the solution to Equation 2.17 and are given by s1 , s2 ¼ zvn

qﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ z2 1vn

(2:18)

The natural modes of the second-order system are es1 t and es2 t . The step response depends on the value of the parameter z. There are three cases to consider. Case 1: z > 1 pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ If we let s1 ¼ zvn z2 1vn and s2 ¼ zvn z2 1vn , then both roots are negative (assuming vn > 0) and s1 < s2 < 0. Introducing time constants t1 and t2 as the reciprocals of the characteristic roots s1 and s2, respectively, t1 ¼

1 , s1

t2 ¼

1 s2

(2:19)

The unit step response is t2 et=t2 t2 et=t1 , y(t) ¼ K 1 þ t1 t2

t0

(2:20)

Case 2: 0 < z < 1 The characteristic roots are complex conjugates and can be expressed as qﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ s1 , s2 ¼ zvn j 1 z2 vn

(2:21)

It is convenient to deﬁne a new quantity vd in terms of z and vn according to vd ¼

qﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 1 z2 vn

(2:22)

The unit step response is zvn y(t) ¼ K 1 ezvn t cos vd t þ sin vd t , vd

t0

(2:23)

An alternate form of Equation 2.23 is vn zvn t sin (vd t þ w) , t 0 y(t) ¼ K 1 e vd

(2:24)

Simulation of Dynamic Systems with MATLAB® and Simulink®

40

2 0.8

Step response

Step response

1

0.6 Increasing ζ 0.4

1

0.2 0

Decreasing ζ 0

5

(a)

10 ωnt

15

0

20

5

10 ω nt

15

20

0

5

10 ω nt

15

20

2

1 0.8

Step response

Step response

0

(b)

0.6 0.4

1.5 1 0.5

0.2 0 (c)

0 0

5

10 ωnt

15

20 (d)

FIGURE 2.4 Unit step response of second-order system in Equation 2.16. (a) Overdamped, z ¼ 1:5, 2, 3. (b) Underdamped, z ¼ 0:1, 0.3, . . . , 0.9. (c) Critically damped, z ¼ 1. (d) Zero damping, z ¼ 0.

where the phase angle term w is given by w ¼ tan

1

vd ¼ tan1 zvn

pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ! 1 z2 z

(2:25)

Case 3: z ¼ 1 From Equation 2.18, the characteristic roots are repeated, s1 ¼ s2 ¼ vn. The unit step response is y(t) ¼ K ½1 evn t (vn t þ 1),

t0

(2:26)

A graph of the unit step responses given in Equations 2.20, 2.23, and 2.26 with K ¼ 1 is shown in Figure 2.4. The abscissa is vnt, a dimensionless variable, which allows us to visualize the effect of the parameter z on the step response independent of vn. Note that all three step responses start from zero. Furthermore, the initial slope given by dy(0)=dt is also zero for all three cases (see Exercise 2.6). There are no oscillations in Case 1 (z > 1), that is, the response is monotonically increasing without overshooting the ﬁnal value y(1) ¼ K u ¼ 1 for a unit step input. The transient period increases with increasing z. The system is said to be overdamped. An oscillatory step response occurs in Case 2 (0 < z < 1), and the system is referred to as underdamped. As the value of z decreases, the oscillations become more pronounced, and the settling time for the transient component to die out becomes larger. The case when z ¼ 1 represents the transition from Case 1 to Case 2 (or vice versa). The secondorder system is called critically damped in this situation. The graph in Figure 2.4d is the unit step response for the case when z ¼ 0. From Equation 2.23 with z ¼ 0, y(t) ¼ K(1 cos vn t),

t0

(2:27)

41

Continuous-Time Systems

resulting in sustained oscillations from 0 to 2 when K ¼ 1. The differential equation of the unforced system is d2 y(t) þ v2n y(t) ¼ 0 dt 2

(2:28)

and the natural response resulting from the presence of initial conditions is that of harmonic motion, that is, sustained oscillations about zero at a frequency of vn rad=s. Except for the case when z ¼ 0, the unit step response approaches the limiting or steady-state value y(1) ¼ K, which means that K is the DC or steady-state gain of the second-order system in Equation 2.16. The parameter z, which determines the existence and extent of the oscillations as well as the duration of the transient response, is called the damping ratio of the system. The last two parameters vn and vd are the natural frequency and damped natural frequency of the second-order system, respectively. The ﬁrst, vn, is the frequency of the sustained oscillations (z ¼ 0) in Equation 2.27, and the second, vd, is the frequency of the decaying oscillations (0 < z < 1) in Equation 2.24. It follows from Equation 2.22 that vd < vn. The natural frequency vn is an indication of the speed of the step response (and the system in general) since the oscillatory natural modes are damped by the exponential term with time constant 1=zvn in Equation 2.23. Example 2.2 Figure 2.5 shows a delicate instrument placed on a table that moves as a result of a vertical force acting on it. Springs and dampers connect the table to the ground to limit the table’s movement. The combined mass of the table and instrument is m. The total stiffness of the springs is k and the total damping is c. The mechanical system is modeled by m

d2 d x(t) þ c x(t) þ kx(t) ¼ f (t) dt2 dt

(2:29)

where x(t) is the displacement of the table (from its static equilibrium position) f(t) is the force acting on the platform resulting in the motion x(t) (a) Find expressions for the steady-state gain K, the damping ratio z, and the natural frequency vn in terms of the physical parameters m, c, and k. (b) Numerical values of the physical parameters are m ¼ 40 lbm, k ¼ 45 lbf=ft, and c ¼ 4 lbf s=ft. Find the response of the table when the platform is subjected to a sudden deﬂection due to a force of 12 lbf. (c) Graph the solution and estimate the duration of the transient. (d) The instrument is not usable if it is moving faster than 0.04 ft=s. How long a period of time must pass after the force is applied before the instrument will function properly?

mI m = mT + mI

k 2

FIGURE 2.5 Mechanical system for Example 2.2.

x(t)

mT c f (t)

k 2

Simulation of Dynamic Systems with MATLAB® and Simulink®

42

(a) Dividing Equation 2.29 by m for comparison with the standard form of a second-order system in Equation 2.16 gives d2 c d k 1 x(t) þ x(t) þ x(t) ¼ f (t) dt2 m dt m m ) 2zvn ¼

c , m

v2n ¼

k , m

Kv2n ¼

(2:30)

1 m

(2:31)

Solving for the parameters K, vn, and z yields vn ¼

rﬃﬃﬃﬃ k , m

c z ¼ pﬃﬃﬃﬃﬃﬃﬃ , 2 km

K¼

1 k

(2:32)

(b) Substituting the given values for m (in slugs), k, and c, rﬃﬃﬃﬃ sﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ k 45 ¼ vn ¼ ¼ 6:0187 rad=s m 40=32:2 c 4 z ¼ pﬃﬃﬃﬃﬃﬃﬃ ¼ pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ ¼ 0:2675 2 km 2 45:40=32:2 K¼

1 ¼ 0:0222 in=lbf 45

The damping ratio z ¼ 0.2675 indicates the system is underdamped. From Equation 2.22, the damped natural frequency is vn ¼

qﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 1 0:26752 6:0187 ¼ 5:7994 rad=s 1 z2 vn ¼

and the response to a step input f(t) ¼ F ¼ 12 lbf, t 0 is zvn x(t) ¼ K F 1 ezvn t cos vd t þ sin vd t , vd

t0

(2:33)

Substituting the numerical values for K, F, z, vn, and vd results in x(t) ¼ 0:2667 1 e1:6100t ( cos 5:7994t þ 0:2776 sin 5:7994t) , t 0

(2:34)

(c) A graph of the step response is generated in the script ﬁle ‘‘Chap2_Ex3_1.m’’ and shown in Figure 2.6. The transient period can be approximated from the graph as roughly 3 s, or it can be computed from the time constant of the exponential envelope as Transient period 5

1 1 ¼5 ¼ 3:1056 s zvn 0:2675(6:0187)

(d) The ﬁrst derivative is obtained by differentiation of the underdamped step response in Equation 2.24. The result is d vn y(t) ¼ K pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ ezvn t sin vd t, dt 1 z2

t0

(2:35)

Substituting the numerical values for the system parameters K, z, vn, and vd gives d y(t) ¼ 0:1388e1:61t sin 5:7994t, dt

t0

(2:36)

43

Continuous-Time Systems 0.4

x(t) (ft)

0.3 0.2 0.1 (a)

0

0

0.5

1

1.5

2

2.5

3

2

2.5

3

dx/dt (ft/s)

0.1 0.04 ft/s

0.05 0

−0.04 ft/s −0.05

0

0.5

(b)

1

1.5 t (s)

FIGURE 2.6 (a) Position and (b) velocity response of table and instrument (F ¼ 12 lbf).

The ﬁrst derivative is graphed in the lower half of Figure 2.6. From the graph, it appears that approximately 0.77 s must elapse for the instrument to be usable, that is, the instrument is moving at less than 0.04 ft=s in either direction after that period of time. (A closeup of the response in the neighborhood of dx=dt ¼ 0.04 ft=s reveals that the instrument’s velocity actually falls a bit short of 0.04 ft=s.)

2.3.1 CONVERSION

OF

TWO FIRST-ORDER EQUATIONS

TO A

SECOND-ORDER MODEL

A linear second-order system is sometimes represented as a system of two ﬁrst-order differential equations like those in Equations 2.37 and 2.38: dx ¼ ax þ by þ f (t) dt

(2:37)

dy ¼ cx þ dy þ g(t) dt

(2:38)

Suppose a single equation relating the dependent variable x ¼ x(t) and the inputs f ¼ f(t) and g ¼ g(t) is required. The ﬁrst step is to solve for y ¼ y(t) in Equation 2.37, 1 dx ax f y¼ b dt

(2:39)

dy 1 d2 x dx df a ¼ ¼ cx þ dy þ g dt b dt 2 dt dt

(2:40)

Differentiating Equation 2.39,

Simulation of Dynamic Systems with MATLAB® and Simulink®

44

Replacing y in Equation 2.40 with Equation 2.39 gives 1 d2 x dx df 1 dx ¼ cx þ d ax f þg a b dt 2 dt dt b dt

(2:41)

and simplifying leads to the second-order differential equation, d2 x dx df (a þ d) þ (ad bc)x ¼ df þ bg dt 2 dt dt

(2:42)

A similar procedure is used to eliminate x from Equations 2.37 and 2.38 to give a second-order differential equation in y. Example 2.3 The well-mixed tanks shown in Figure 2.7 contain uniform salt concentrations of c1 ¼ c1(t) and c2 ¼ c2(t), respectively. Concentration of salt in the input to the ﬁrst tank is c ¼ c(t). The ﬂow rates between the tanks are Q1 and Q2, where Q1 > Q2 > 0. The liquid volumes in both tanks remain constant at V1 and V2. (a) (b) (c) (d)

Write the differential equations for the conservation of salt in each tank. Find the differential equation relating c2(t) and the input c(t). Find expressions for the damping ratio, natural frequency, and steady-state gain. Find and plot the step response for c2 under the following conditions: Q1 ¼ 10 gal=min,

Q2 ¼ 5 gal=min,

c1 (0) ¼ c2 (0) ¼ 0 lb of salt=gal,

V1 ¼ 15 gal,

and

V2 ¼ 15 gal

c(t) ¼ c ¼ 0:25 lb salt=gal,

t0

(a) Equating the accumulation of salt in each tank to the difference between the rates of salt in and out of the tanks, d (c1 V1 ) ¼ Qin c þ Q2 c2 Q1 c1 dt

(2:43)

d (c2 V2 ) ¼ Q1 c1 Q2 c2 Qout c2 dt

(2:44)

Since the holdup of liquid in both tanks is constant, the ﬂows Qin and Qout are equal, Qin ¼ Qout ¼ Q1 Q2

(2:45)

Q1 ∞ c1(t)

Qin, c1(t) V1

FIGURE 2.7 Two-tank mixing system.

Q2 V2

∞ c2(t)

Qout, c2(t)

45

Continuous-Time Systems And, therefore, Equations 2.43 and 2.44 become dc1 ¼ (Q1 Q2 )c þ Q2 c2 Q1 c1 dt

(2:46)

dc2 ¼ Q1 c1 Q2 c2 (Q1 Q2 )c2 dt

(2:47)

V1 V2

(b) Rearranging Equations 2.46 and 2.47 into the form of Equations 2.37 and 2.38, dc2 Q1 Q1 ¼ c2 þ c1 dt V2 V2

(2:48)

dc1 Q2 Q1 (Q1 Q2 ) c2 c1 þ c ¼ V1 dt V1 V1

(2:49)

Comparing Equations 2.48, 2.49, and 2.37, Equation 2.38 implies a¼

Q1 , V2

b¼

Q1 , V2

c¼

Q2 , V1

d¼

Q1 , V1

f (t) ¼ 0, g(t) ¼

(Q1 Q2 ) c(t) V1

(2:50)

From Equation 2.42, the second-order differential equation relating c2 and c is d2 c2 1 1 dc2 Q1 (Q1 Q2 ) Q1 (Q1 Q2 ) þ Q þ c2 ¼ c þ 1 dt2 V1 V2 dt V1 V2 V1 V2

(2:51)

(c) Comparing the left-hand side of Equation 2.51 with the standard form in Equation 2.16 gives 2zvn ¼ Q1

) vn ¼

1 1 , þ V1 V2

Q1 (Q1 Q2 ) 1=2 , V1 V2

z¼

v2n ¼

Q1 (Q1 Q2 ) V1 V2

1=2 (V1 þ V2 ) Q1 (Q1 Q2 )V1 V2 2

(2:52)

(2:53)

For c(t) ¼ c, the steady-state value of c2 is obtained from Equation 2.51 by setting the derivatives equal to zero resulting in Q1 (Q1 Q2 ) (Q1 Q2 ) Q1 (c2 )ss ¼ c V2 V1 V2 V1

(2:54)

) (c2 )ss ¼ c

(2:55)

Hence, the steady-state gain K ¼ 1 lb salt=lb salt as expected. (d) For the given conditions, that is, Q2 ¼ Q ¼ 5, Q1 ¼ 2Q ¼ 10, and V1 ¼ V2 ¼ V ¼ 15 vn ¼

2Q(2Q Q) VV z¼

1=2 ¼ (2)1=2

Q 5 ¼ (2)1=2 ¼ 0:4714 rad=min V 15

1=2 (V þ V) 2Q ¼ (2)1=2 ¼ 1:4142 2 (2Q Q)VV

(2:56)

(2:57)

Simulation of Dynamic Systems with MATLAB® and Simulink®

46

_ c = 0.25 lb salt per gal

0.25 c(t)

c2(t), lb salt per gal

0.2

c2(t)

0.15

0.1

0.05

0 0

5

10

15

20

25

t (min)

FIGURE 2.8 Response of salt concentration in second tank to step input c(t) ¼ 0.25, t 0.

From Equation 2.18, the characteristic roots of the overdamped system are

s1 , s2 ¼ zvn

qﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ z2 1vn ¼ 1:1381 rad=min, 0:1953 rad=min

(2:58)

The time constants in Equation 2.19 are t1 ¼ 1=s1 ¼ 0.8787 min and t2 ¼ 1=s2 ¼ 5.1213 min, and from the unit step response in Equation 2.20, the response to a step of magnitude c is t2 et=t2 t1 et=t1 c2 (t) ¼ Kc 1 þ t1 t2 5:1213et=5:1213 0:8787et=0:8787 ¼ 0:25 1 , 4:2426

(2:59)

t0

(2:60)

The second-order differential equation in Equation 2.51 is in standard form; however, the secondorder differential equation for c1(t) contains the ﬁrst derivative dc=dt on the right-hand side of the equation (see Exercise 2.6). The implication of input derivatives in the system model will be discussed in a later section. A graph of the step response is shown in Figure 2.8.

EXERCISES 2.5 Starting with Equations 2.37 and 2.38, obtain the second-order differential equation relating the output y ¼ y(t) and its derivatives to the inputs f ¼ f(t) and g ¼ g(t). 2.6 In Example 2.3, (a) Find the differential equation relating c1(t) and the input c(t). (b) Find the step response in c1(t) for the same initial conditions, system parameters, and input c(t). Graph the step response for c1(t) and c2(t). (c) Show that the ﬁrst derivative dc1=dt is discontinuous at t ¼ 0 while the ﬁrst derivative dc2=dt is continuous at t ¼ 0.

47

Continuous-Time Systems

2.7 The two-tank system in Exercise 1.2 is second order. (a) Convert the model of the system from two ﬁrst-order differential equations to one secondorder differential equation with input F1(t) and output H2(t). (b) Find expressions for the damping ratio, natural frequency, and steady-state gain in terms of the physical parameters A1, A2, R1, and R2. (c) Use the results from part (b) to express the damping ratio in terms of the tank time constants t1 ¼ A1R1 and t2 ¼ A2R2. (d) Show that the system can never be underdamped. For parts (e) and (f), assume the following values for the system parameters: A1 ¼ 100 ft2,

R1 ¼ 0.25 ft per ft3=min,

A2 ¼ 50 ft2,

and

R2 ¼ 0.1 ft per ft3=min

(e) Find and graph the response H2(t) of the unforced system, that is, F1(t) ¼ 0, t 0 starting from H1(0) ¼ 40 ft and H2(0) ¼ 0 ft. (f) Find and graph the step response of H2(t) when F1(t) ¼ 75 ft3=min. Both tanks are initially empty. Does the ﬁrst tank achieve steady state in roughly 5t1? Does the second tank achieve steady state in roughly 5t2? Explain. 2.8 A fundamental difference between the step response of ﬁrst- and second-order linear systems in standard form is the initial rate of change, that is, the ﬁrst derivative at t ¼ 0. (a) Show that the ﬁrst-order system step response undergoes the maximum rate of change at t ¼ 0. (b) Show that the initial derivative of the second-order system step response is zero regardless of whether the system is underdamped, critically damped, or overdamped.

2.4 SIMULATION DIAGRAMS In many cases, dynamic systems are composed of individual components and subsystems. The relationship of a system’s components to each other and the role they serve in the overall system design are oftentimes easier to comprehend when presented in visual form rather than by inspection of the mathematical models. Control systems for ground vehicles, aircraft, robotic devices, building environments, and so forth are typically presented in graphical form as block diagrams. The blocks are both static and dynamic depending on the component it represents. Modern continuous-time system simulation languages include extensive libraries of special purpose blocks to represent the dynamics of commonly occurring components. It is useful to reduce the blocks in a block diagram of a continuous-time dynamic system to a level that exposes the pure integrators. The simulationist is then given the ﬂexibility of approximating individual integrators using different numerical algorithms. This is especially useful in applications where simulation code is developed manually instead of relying on a general purpose simulation language. This point will be revisited in Chapter 3 following a discussion of numerical integration. A block diagram of a continuous-time dynamic system comprising algebraic blocks and integrators is referred to as a simulation diagram. We begin with the ﬁrst-order system of Equation 2.61: d d y(t) þ a0 y(t) ¼ b1 u(t) þ b0 u(t) dt dt

(2:61)

Equation 2.61 is a more general form than the ﬁrst-order models introduced in Section 2.2 due to the presence of the ﬁrst derivative term on the right-hand side. If we introduce a new variable z ¼ z(t) where d z(t) þ a0 z(t) ¼ u(t) dt

(2:62)

Simulation of Dynamic Systems with MATLAB® and Simulink®

48

b1

dz/dt

u

z

∫

b0

y

−a0

FIGURE 2.9 Simulation diagram of ﬁrst-order system: (d=dt)y(t) þ a0y(t) ¼ b1(d=dt)u(t) þ b0u(t).

the output y is related to z by y(t) ¼ b0 z(t) þ b1

d z(t) dt

(2:63)

It is left as an exercise to show that Equations 2.62 and 2.63 are equivalent to Equation 2.61. In addition to the blocks required to implement Equations 2.62 and 2.63, an integrator block is needed to integrate the ﬁrst derivative dz=dt to generate z(t), that is, ð z(t) ¼

dz dt dt

(2:64)

The simulation diagram in Figure 2.9 is constructed by ﬁrst drawing an integrator block and labeling the input dz=dt and output z corresponding to Equation 2.64. Next, we solve for the derivative term dz=dt in Equation 2.62 and draw a portion of the diagram to implement the result. Finally, the output y is generated from Equation 2.63 using the b0 and b1 gain blocks and a summing block. The simulation diagram representation of the ﬁrst-order system’s dynamics involves a single dynamic block, namely, the integrator. The remaining blocks are sum blocks and gains that are algebraic in nature. A block diagram for the same ﬁrst-order system is shown in Figure 2.10. The block diagram is a direct implementation of Equation 2.61 after solving for the ﬁrst derivative dy=dt. An additional variable z is not required in this case. The diagram in Figure 2.10 is not a simulation diagram because of the presence of the differentiator. In digital simulation, the differentiator (like the integrator) must be implemented using a numerical approximation. Numerical methods for approximating the derivative of a continuous-time function are available. However, they are rarely implemented in simulation applications due to their sensitivity to high-frequency noise components often present in continuous-time signals.

d dt

u

b1

b0

dy/dt

∫

y

−a0

FIGURE 2.10

Block diagram of ﬁrst-order system: (d=dt)y(t) þ a0y(t) ¼ b1(d=dt)u(t) þ b0u(t).

49

Continuous-Time Systems

A ﬁnal observation relates to the special case when b1 in Equation 2.61 is zero. The input derivative is absent, and the ﬁrst-order system assumes the simpler form of Equation 2.3 or 2.4. Recall that this form was sufﬁcient to model the dynamics of the linear tank in Chapter 1 and the simple RC circuit of Example 2.1. Example 2.4 Draw a simulation diagram of the linear tank modeled by A

d 1 H(t) þ H(t) ¼ F1 (t) dt R

(2:65)

The diagram is shown in Figure 2.11. Dividing Equation 2.65 by the parameter A and comparing the result to Equation 2.61 show a0 ¼

1 , AR

b0 ¼

1 , A

b1 ¼ 0

leading to the simulation diagram shown in Figure 2.11. The simulation diagram in Figure 2.11 is not unique. The ‘‘1=A’’ block can be moved from the location where z is its input to the left of the summer where F1 becomes its input. In that case, z and H are identical. The alternate simulation diagram can be obtained directly by solving the differential equation of the tank for the ﬁrst derivative, d 1 1 H(t) ¼ F1 (t) H(t) dt A R

(2:66)

and implementing Equation 2.66 directly. Integrating the derivative dH=dt to get H completes the diagram.

Example 2.5 Suppose the current i(t) in the RC circuit of Figure 2.2 is considered the output. The differential equation for the circuit becomes d 1 1 d i(t) þ i(t) ¼ e0 (t) dt RC R dt

(2:67)

Draw the simulation diagram for the circuit described by Equation 2.67. From Equation 2.61, a0, b0, and b1 are a0 ¼

1 , RC

b0 ¼ 0, b1 ¼

1 R

and the simulation diagram is drawn in Figure 2.12.

F1

dz/dt

∫

−

FIGURE 2.11

z

1 A

1 AR

Simulation diagram of linear tank: A(d=dt)H(t) þ (1=R)H(t) ¼ F1(t).

H

Simulation of Dynamic Systems with MATLAB® and Simulink®

50

1 R

e0

FIGURE 2.12

z

∫

−

i

1 RC

Simulation diagram for an RC circuit: (d=dt)i(t) þ (1=RC)i(t) ¼ (1=R)(d=dt)e0(t).

When the differential equation model of a ﬁrst-order system contains a term involving the ﬁrst derivative of the input, a direct link or coupling exists from the input directly to the output. In other words, when b1 6¼ 0 in Equation 2.61, sudden changes in the input are immediately reﬂected in the output. Notice the path of heavy solid lines in Figure 2.9 illustrating this point. A similar path in Figure 2.12 indicates the direct coupling from the applied voltage e0(t) to the output current i(t). In contrast, there is no direct connection from input to output in the simulation diagram shown in Figure 2.11 for the linear tank model. This is expected since changes in the inﬂow F1(t) must work their way through the tank dynamics, that is, the integrator, prior to affecting the output level H(t). Hence, the tank prevents abrupt changes like a step or other inputs with high-frequency components from immediately causing any signiﬁcant changes in the output H(t). The tank behaves like a low-pass ﬁlter (see Exercise 1.10). Obtaining a simulation diagram for a second-order system in the standard form d2 d y(t) þ 2zvn y(t) þ v2n u(t) ¼ Kv2n u(t) dt2 dt

(2:68)

is straightforward. We begin by drawing two consecutive integrators, labeling the input and output of the ﬁrst with d2y=dt2 and dy=dt, respectively. The second integrator integrates the ﬁrst derivative dy=dt producing y and is labeled accordingly. The next step is to solve for the second derivative term in Equation 2.68 resulting in d2 d y(t) ¼ Kv2n u(t) 2zvn y(t) v2n y(t) dt2 dt

(2:69)

Algebraic blocks (gains and summers) are used to implement Equation 2.69 leading to the simulation diagram shown in Figure 2.13. The simulation diagram for a second-order system with ﬁrst- or second-order derivatives of the input appearing in the differential equation model is not as straightforward. Starting with Equation 2.70 d2 d d d2 y(t) þ a1 y(t) þ a0 y(t) ¼ b0 u(t) þ b1 u(t) þ b2 2 u(t) 2 dt dt dt dt

u

Kωn2

d2y/dt2

∫

dy/dt

∫

−2ζωn −ωn2

FIGURE 2.13

Simulation diagram of a second-order system in standard form.

(2:70)

y

51

Continuous-Time Systems b2 b1 u

..

z

.

z

∫

∫

z

b0

y

−a1 −a0

FIGURE 2.14

Simulation diagram for a second-order system with input derivatives present.

an approach similar to the method used for ﬁrst-order systems with an input derivative term present is employed. An artiﬁcial variable z(t) is introduced, and the output y(t) is expressed as a linear combination of z(t) and its two derivatives. The result is d2 d z(t) þ a1 z(t) þ a0 z(t) ¼ u(t) dt2 dt y(t) ¼ b0 z(t) þ b1

d d2 z(t) þ b2 2 z(t) dt dt

(2:71)

(2:72)

The simulation diagram of the second-order system in Equation 2.70 is shown in Figure 2.14. Note the use of the dot notation, short for differentiation with respect to time. It is clear that a direct connection from the input u(t) to the output y(t) exists only when b2, the coefﬁcient of the input second derivative in Equation 2.70, is nonzero. Looking at the simulation diagrams in Figures 2.9 and 2.14 for the ﬁrst- and second-order systems in Equations 2.61 and 2.70, a general pattern emerges for creating the simulation diagram of an nth-order system modeled by dyn dyn1 dy du dun1 dun þ an1 n1 þ þ a1 þ a0 y ¼ b0 u þ b1 þ þ bn1 n1 þ bn n n dt dt dt dt dt dt

(2:73)

The two equations equivalent to Equation 2.73 are dzn dzn1 dz þ an1 n1 þ þ a1 þ a0 z ¼ u n dt dt dt y ¼ b0 z þ b1

dz dzn1 dzn þ þ bn1 n1 þ bn n dt dt dt

(2:74) (2:75)

The simulation diagram follows directly from Equations 2.74 and 2.75.

Example 2.6 A unicycle is traveling over an uneven road as shown in Figure 2.15. The input is the road elevation xr(t) above some reference. The output is the vertical movement x(t) of the rider and seat combination (with respect to its equilibrium position). Ignoring the compliance of the tire makes the wheel deﬂection xw(t) ¼ xr(t). Assume that the wheel remains

Simulation of Dynamic Systems with MATLAB® and Simulink®

52

x(t)

m c

k

xw(t)

xr(t)

FIGURE 2.15

Unicycle traveling along an uneven road surface.

in contact with the road surface. The mass of the rider and seat is m, and c and k are suspension parameters. (a) Find the differential equation relating the output x(t) and input xr(t). (b) Draw a simulation diagram of the system. (c) Is there a direct coupling between the input and output? Explain. (a) The differential equation is obtained by equating the sum of the suspension forces acting on the rider and seat to the product of its mass and acceleration. d2 d d (2:76) xw (t) x(t) þ k½xw (t) x(t) m ¼ 2 x(t) ¼ c dt dt dt Replacing xw(t) with xr(t) gives d2 d d m 2 x(t) ¼ c xr (t) x(t) þ k½xr (t) x(t) dt dt dt

(2:77)

(b) Rearranging terms in Equation 2.77 gives d2 c d k k c d x(t) þ x(t) þ x(t) ¼ xr (t) þ xr (t) dt2 m dt m m m dt

(2:78)

Comparing Equations 2.78 and 2.70 leads to expressions for a0, a1, b0, b1, and b2 in terms of the system parameters, a0 ¼

k c , a1 ¼ , m m

b0 ¼

k , m

b1 ¼

c , m

b2 ¼ 0

(2:79)

and eventually the simulation diagram shown in Figure 2.16. (c) Since both paths from xr to x contain an integrator, there is no direct coupling between input and output. Consequently, an abrupt change in xr such as a vertical jump in the road surface height does not result in a similar type of displacement of the rider and seat combination. c m xr

.. z

∫

. z

∫

z

k −m c −m

FIGURE 2.16

Simulation diagram for a unicycle suspension.

k m

x

53

Continuous-Time Systems

2.4.1 SYSTEMS OF EQUATIONS System models can assume the form of coupled differential and algebraic equations. The simulation diagram representation is straightforward. Example 2.7 A two-room building with temperatures T1(t) and T2(t) is shown in Figure 2.17. The simpliﬁed model relating the uniform room temperatures T1(t) and T2(t) to the heat supplied from the furnace Qf(t) and outside temperature T0(t) is based on conservation of energy. It consists of the following differential and algebraic equations: C1

d T1 (t) ¼ Qf (t) Q1 (t) Q12 (t) dt

(2:80)

d T2 (t) ¼ Q12 (t) Q2 (t) dt

(2:81)

C2

Q12 (t) ¼

T1 (t) T2 (t) R12

(2:82)

Q1 (t) ¼

T1 (t) T0 (t) R1

(2:83)

Q2 (t) ¼

T2 (t) T0 (t) R2

(2:84)

where C1, C2, R1, R2, and R12 are thermal parameters of the system. The simulation diagram shown in Figure 2.18 follows directly from Equations 2.80 through 2.84. Combining Equations 2.80 through 2.84 and solving for the ﬁrst derivatives give d 1 T1 (t) T0 (t) T1 (t) T2 (t) Qf (t) T1 (t) ¼ dt C1 R1 R12 1 1 1 1 1 ¼ T1 (t) þ þ T2 (t) þ T0 (t) þ Qf (t) C1 R1 R12 R12 R1 d 1 T1 (t) T2 (t) T2 (t) T0 (t) T2 (t) ¼ dt C2 R12 R2 1 1 1 1 1 ¼ T2 (t) þ T0 (t) T1 (t) þ C2 R12 R2 R12 R2

(2:85) (2:86)

(2:87) (2:88)

Equations 2.86 and 2.88 are of the form x_ 1 ¼ a11 x1 þ a12 x2 þ b11 u1 þ b12 u2 x_ 2 ¼ a21 x1 þ a22 x2 þ b21 u1 þ b22 u2

Q1(t)

Qf (t)

T2(t)

T1(t) Q12(t)

T0(t)

FIGURE 2.17

(2:89)

Heat ﬂows and temperatures in a two-room building.

Q2(t) T0(t)

Simulation of Dynamic Systems with MATLAB® and Simulink®

54

Q1

– Qf − Q1 − Q12

Qf

–

1 R1 . T1

1 C1 Q12

Q12 − Q2

. T2

1 C2

–

1 R12

Q2

FIGURE 2.18

T1 − T0 –

∫

T1 − T2

T0

–

∫

1 R2

T1

T2

T2 − T0

–

Simulation diagram for building room temperature model.

where x1 ¼ T1, x2 ¼ T2, u1 ¼ T0, and u2 ¼ Qf and the coefﬁcients aij and bij ( j ¼ 1, 2) depend on the system parameters according to a11 ¼ a21 ¼

1 1 1 , þ C1 R1 R12

1 , R12 C2

a22

1 1 1 , b11 ¼ , b12 ¼ R12 C1 R1 C1 C1 1 1 1 1 , b21 ¼ ¼ þ , b22 ¼ 0 C2 R2 R12 R2 C2 a12 ¼

(2:90) (2:91)

Suppose we need to draw a simulation diagram for the system in Equation 2.89 with only x1 or x2 present. Using an approach similar to the one presented in Section 2.2 for converting two coupled ﬁrst-order differential equations into a second-order differential equation, the second-order system in Equation 2.89 is equivalent to €x1 þ a1 x_ 1 þ a0 x1 ¼ b11 u_ 1 þ b10 u1 þ b21 u_ 2 þ b20 u2

(2:92)

where a1 ¼ (a11 þ a22 ), b11 ¼ b11 ,

b10 ¼ a12 b21 a22 b11 ,

a0 ¼ a11 a22 a12 a21 b21 ¼ b12 ,

b20 ¼ a12 b22 a22 b12

(2:93) (2:94)

The simulation diagram for Equation 2.92 is constructed in two steps. From superposition, the output x1 can be viewed as the sum of x11 and x12 where €x11 þ a1 x_ 11 þ a0 x11 ¼ b11 u_ 1 þ b10 u1

(2:95)

€x12 þ a1 x_ 12 þ a0 x12 ¼ b21 u_ 2 þ b20 u2

(2:96)

Simulation diagrams for Equations 2.95 and 2.96 are drawn separately, and outputs x11 and x12 are added to yield the complete output x1. The result is shown in Figure 2.19. Do not be misled into thinking that the simulation diagram shown in Figure 2.19 corresponds to a fourth-order system due to the presence of four integrators. There are two decoupled secondorder systems, one with input u1 and output x11 and the other with input u2 and output x12.

55

Continuous-Time Systems β11 u1

∫

∫

β10

x11

−α1 x1

−α0 β21 u2

∫

∫

β20

x12

−α1 −α0

FIGURE 2.19

Simulation diagram for second-order system in Equation 2.92.

In reality, they are the same system, that is, the second-order system governed by the second-order model in Equation 2.92. On the other hand, if the feedback coefﬁcients in the two systems are not identical, that is, a0 and a1 in both cases, the result is indeed a fourth-order system (see Exercise 2.13).

EXERCISES 2.9

Show that the system of equations d z(t) þ a0 z(t) ¼ u(t) dt

and

y(t) ¼ b0 z(t) þ b1

d z(t) dt

used to construct the simulation diagram for the ﬁrst-order system d d y(t) þ a0 y(t) ¼ b1 u(t) þ b0 u(t) dt dt is equivalent to the ﬁrst-order differential equation above. Hint: The variable z(t) must be eliminated from the two equations. 2.10 An alternate simulation diagram for the second-order system d d y(t) þ 2zvn y(t) þ v2n y(t) ¼ Kv2n u(t) dt 2 dt when it is critically damped or overdamped is shown in Figure E2.10: Find expressions for K1, a, and b in terms of the parameters z, vn, and K. u

FIGURE E2.10

K1

∫

∫

−α

−β

y

Simulation of Dynamic Systems with MATLAB® and Simulink®

56

2.11 The circuit shown in Figure E2.11 is governed by the differential equation:

RC

d2 d R d vC þ v C þ vC ¼ eS 2 dt dt L dt

Draw a simulation diagram for the circuit. R

+ _

eS

C

+ _ νC

L

FIGURE E2.11

2.12 Consider the building temperature example with room temperatures described by Equations 2.86 and 2.88. (a) Find the second-order differential equation relating T2(t) and the system inputs T0(t) and Qf (t). (b) Draw a simulation diagram like the one shown in Figure 2.19. 2.13 Simulation diagrams are shown in Figure E2.13a through c. (a) Find the differential equation relating x and inputs u1 and u2 in Figure E2.13a. (b) Find the differential equation relating x and input u in Figure E2.13b. (c) Find the differential equation relating x and inputs u1 and u2 in Figure E2.13c. (d) Comment on the differences between the systems represented by each diagram.

u1

∫ u

−a0 u2

(a)

∫ −a0

u1

∫

x

(b)

−a0

−a0

∫ −a1

∫

x

u2

∫

(c)

−a1

x

FIGURE E2.13

2.5 HIGHER-ORDER SYSTEMS To this point, we have looked at linear continuous-time systems with ﬁrst- and second-order dynamics only. Linear systems and linear controls texts include extensive coverage of lowerorder system response. In particular, the response of ﬁrst- and second-order systems to impulse, step, and sinusoidal inputs is fully developed. The dynamics of complex systems with linear differential equation models are invariably higher than second order. One may question why so much attention is devoted to ﬁrst- and second-order systems. The explanation is simple.

57

Continuous-Time Systems

xc

e

τ2 du + u = Kc τ1 de + e dt dt

–

Controller xs

FIGURE 2.20

u

d2x + 2ζω dx + ω 2x = K ω 2u n n p n dt dt2

x

Process τs

dxs + x s = Ks x dt

A control system consisting of ﬁrst- and second-order components.

High-order linear systems are oftentimes a collection of components or subsystems that are intrinsically ﬁrst or second order. An electrical circuit with several capacitors and inductors is a good example. The circuit dynamics will depend on the number of these energy storage elements and their location in the circuit. In general, its order will be equal to the number of energy storage elements since each element is itself modeled as a ﬁrst-order component. With n nonredundant energy storage elements, an nth-order differential equation involving an output (a voltage or current in the circuit) and an input (if an independent source is present) governs the behavior of the circuit. The same principle applies to ﬂuid, thermal, mechanical, chemical, and so forth, systems made up of components analogous to the resistor, capacitor, and inductor of the electrical circuit. The block diagram of a simple feedback control system is shown in Figure 2.20. The controller, process, and sensor are the subsystem components, which are individually modeled as either ﬁrst or second order. The control system model comprises the three coupled differential equations du de (2:97) t2 þ u ¼ Kc t1 þ e dt dt d2 x dx þ 2zvn þ v2n x ¼ Kp v2n u 2 dt dt dxs ts þ xs ¼ K s x dt

(2:98) (2:99)

and the summer equation e ¼ xc x s

(2:100)

The command input xc ¼ xc(t) is the control system input, and the output of the process x ¼ x(t) is the control system output. Dependent variables e(t), the error signal, u(t), the output from the controller and input to the process, and xs(t), the sensor output are internal to the control system. Eliminating these variables produces a single fourth-order (1 þ 2 þ 1) differential equation model of the control system in the form d4 x d3 x d2 x dx d4 x c d 3 xc d2 x c dxc þ b0 x c þ a þ a þ a þ a x ¼ b þ b þ b þ b1 3 2 1 0 4 3 2 dt 4 dt 3 dt 2 dt dt 4 dt 3 dt 2 dt

(2:101)

where several of the coefﬁcients ai, i ¼ 0, 1, 2, 3 and bi, i ¼ 0, 1, 2, 3, 4 may be zero. A simulation diagram of the control system can be obtained from Equation 2.101 using the procedure from the previous section. Alternatively, simulation diagrams can be developed for the individual components in Figure 2.20 and properly connected to produce a simulation diagram for the control system. Simulation of the system based on a simulation diagram using the second approach is preferable since the internal variables are readily identiﬁable. We can check the simulation results to verify that inputs and outputs of the controller and sensor remain within proper operating ranges.

Simulation of Dynamic Systems with MATLAB® and Simulink®

58 θcom

e

uc

. τ2uc + uc = Kc (τ1e + e)

–

. τaua + ua = Ka uc

Controller

FIGURE 2.21

ua

.. . . θ + 2ζωnθ + ωn2 θ = K (τua + ua)

Actuator

θ

Aircraft

Control system for an aircraft pitch.

Kcτ1 τ2 θcom

e

uc

Kc τ2

∫ 1 −τ

Ka τa

∫

ua

−1 τa

2

–1

Kτ

∫

∫

K

θ

−2ζωn

−ωn2

FIGURE 2.22

Simulation diagram for an aircraft pitch control system.

Example 2.8 The control system for the pitch of an aircraft is shown in Figure 2.21. Draw a simulation diagram for the aircraft pitch control system block diagram. Simulation diagrams of each component are connected to produce the simulation diagram of the entire control system shown in Figure 2.22.

EXERCISES 2.14 For the control system shown in Figure 2.20. (a) Find the coefﬁcients ai, i ¼ 0, 1, 2, 3 and bi, i ¼ 0, 1, 2, 3, 4 in Equation 2.101 in terms of the system parameters t1, t2, Kc, z, vn, Kp, ts and Ks. Hint: The use of Laplace transforms (see Chapter 4) signiﬁcantly reduces the amount of work necessary to eliminate the variables e, u, and xs. (b) Draw a simulation diagram based on the fourth-order differential equation model.

59

Continuous-Time Systems

2.15 Find the differential equation for the control system in Figure 2.21 relating the output u and its derivatives to the input ucom and its derivatives. Draw the simulation diagram based on the resulting differential equation. Hint: The use of Laplace transforms (see Chapter 4) signiﬁcantly reduces the amount of work necessary to eliminate the variables e, uc, and ua. 2.16 For the railroad cars shown in Figure E2.16, P (a) Write the differential equation expressing k Fi,k ¼ mi€xi , i ¼ 1, 2, 3 for each car where Fi,k is the kth force acting on the ith car. (b) Draw a simulation diagram of the system with integrators for xi, x_ i, i ¼ 1, 2, 3. (c) Find the differential equation relating the input F(t) and output x1(t). Hint: The use of Laplace transforms (see Chapter 4) signiﬁcantly reduces the amount of work necessary to eliminate the variables x2 and x3. x3(t)

x2(t) k

x1(t) k

m3

m2

m1

F (t)

B

B

FIGURE E2.16

2.6 STATE VARIABLES In everyday terms, one’s state of mind on a given day is determined by the history of numerous psychological factors that inﬂuence our mental well-being. The state of the national economy (weak, moderate, strong) depends on numerous factors such as energy prices, inﬂation, trade balances, employment, productivity, housing, tax policies, corporate earnings, transportation, agriculture, and so forth. Imagine that all the economic factors (inputs) affecting the national economy were measurable and the complex interrelationships among those variables that determine the state of the economy were fully understood. If the state of the economy were known at some point in time and the complete set of aforementioned economic factors were observed from that time forward, knowledgeable economists would (in principle) be able to predict the state of the national economy at future times. The essential point is that if we know the state of a system at some point in time and wish to predict its future, then knowledge of the system inputs only from that time onward is required. The current state of a system reﬂects the effect of prior inputs that are responsible for the system’s transition from some previous state to the current state. Consider a simple spring-mass-damper system subject to an applied force acting on the mass like the one shown in Figure 2.23. The spring and mass are both capable of storing energy. At any time,

c

k x

dx dt

1 kx2 + — 1 m dx E= — 2 dt 2

m f (t)

FIGURE 2.23

A spring-mass-damper system with applied force f(t).

2

Simulation of Dynamic Systems with MATLAB® and Simulink®

60

the instantaneous energy E(t) stored in the system is given in Equation 2.102 where x is the position of the mass (relative to its equilibrium position) and dx=dt is the velocity of the mass. 2 1 1 dx E ¼ kx2 þ m 2 2 dt

(2:102)

A possible choice of state variables for the mechanical system is x and dx=dt. Given both state variables at time t0 determines the energy E(t0). The applied force f(t) for t t0 must be known to solve the initial value problem m

d2 x dx dx (t0 ) (t) þ c (t) þ kx(t) ¼ f (t) given x(t0 ) and 2 dt dt dt

(2:103)

and determine both state variables x and dx=dt as well as E(t) for t t0. The same cannot be said if only the position or the velocity of the mass were known at t0. In that case, the initial energy in the system E(t0) would be unknown, and it would be impossible to predict future values of x and dx=dt even if the force f(t) were known for t t0. Consequently, x or dx=dt alone is not a suitable choice for the state of the system. The situation is illustrated for the general case of a system with two state variables x1(t) and x2(t) and single input u(t) in Figure 2.24. Given x1(t0), x2(t0), and u(t), t t0, both states can be determined from t0 on. The choice of state variables for a dynamic system model is not unique; however, the number of state variables is limited to the minimum number of variables, which satisfy the requirement of predicting future states given the current state and future inputs. This number of state variables is equal to the number of independent energy storage components present in the system. It is advantageous to choose physical (measurable) quantities as in the case of the mechanical system in Figure 2.23 whenever possible. A simulation diagram is a valuable tool when it comes to choosing the state variables of a system. The outputs of each integrator in a simulation diagram representation of a system is a valid choice for the state variables. The choice of which integrator output is x1, x2, and so forth is arbitrary. Consider a second-order system governed by d2 d y(t) þ a1 y(t) þ a0 y(t) ¼ b0 u(t) dt dt 2

(2:104)

x1(t)

Given: x1(t0), x2 (t0) and u(t), t ≥ t0 t0

u(t)

t

x2(t)

t0

FIGURE 2.24

t

Dynamic system with state variables x1(t) and x2(t).

t0

t

61

Continuous-Time Systems u

b0

∫

x2 = dy/dt

∫

x1 = y

−a1 −a0

FIGURE 2.25

Simulation diagram of second-order system with state x1 ¼ y and x2 ¼ dy=dt. u

K

∫

x2

∫

x1

y

−β

−α

FIGURE 2.26 Simulation diagram for critically damped or overdamped second-order system using two ﬁrstorder systems in a series.

A simulation diagram like the one shown in Figure 2.25 is easily constructed. State variables x1 and x2 are chosen as the output y and ﬁrst derivative dy=dt, respectively. The second-order system is critically damped or overdamped if a21 4a0 0. In this case, it is equivalent to two cascaded ﬁrst-order systems as shown in Figure 2.26. The parameters K, a, and b are related to a0, a1, and b0 according to K ¼ b0 ,

a¼

a1

pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ a21 4a0 , 2

b¼

a1

pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ a21 4a0 2

(2:105)

State variable x1 is again the system output y; however, the second state variable x2 is no longer the output derivative dy=dt. For an nth-order linear system model with constant coefﬁcients, the state derivatives are expressible as a linear combination of the state variables and input(s). For example, from Figure 2.25, the state derivatives are equal to dx1 ¼ x2 dt dx2 ¼ b0 u a 0 x 1 a 1 x 2 dt

(2:106)

whereas in Figure 2.26, the appropriate expressions are dx1 ¼ x2 bx1 dt dx2 ¼ Ku ax2 dt

(2:107)

In the general linear case with n states x1, x2, . . . , xn and r inputs, dx1 ¼ f1 (x, u) ¼ a11 x1 þ a12 x2 þ þ a1n xn þ b11 u1 þ b12 u2 þ þ b1r ur dt

(2:108)

dx2 ¼ f2 (x, u) ¼ a21 x1 þ a22 x2 þ þ a2n xn þ b21 u1 þ b22 u2 þ þ b2r ur dt

(2:109)

dxn ¼ fn (x, u) ¼ an1 x1 þ an2 x2 þ þ ann xn þ bn1 u1 þ bn2 u2 þ þ bnr ur dt

(2:110)

Simulation of Dynamic Systems with MATLAB® and Simulink®

62

where 2

3 x1 6 x2 7 6 7 x is the n 1 state vector6 .. 7 4 . 5 xn 2

3 u1 6 u2 7 6 7 u is the r 1 input vector6 .. 7 4 . 5 ur and fi(x, u), i ¼ 1, 2, 3, . . . , n is the state derivative function of the ith state variable. Equations 2.108 through 2.110 can be written in the compact form x_ ¼ f (x, u) ¼ Ax þ Bu

(2:111)

where 2

3 dx1 6 dt 7 6 7 6 dx2 7 6 7 6 7 x_ ¼ 6 dt 7, 6 . 7 6 . 7 6 . 7 4 5 dxn dt

2

a11

6 6 a21 6 6 6 A¼6 6 6 6 4 an1

a1n

3

a12

a22

7 a2n 7 7 7 7 7, 7 7 7 5

an2

ann

2

b11

6 6 b21 6 6 6 B¼6 6 6 6 4 bn1

b1r

3

b12

b22

7 b2r 7 7 7 7 7 7 7 7 5

bn2

bnr

The n n matrix A is called the system matrix, and the n r matrix B is the input matrix. Multivariable, LTI systems involve multiple inputs u1, u2, . . . , ur and outputs y1, y2, . . . , yp. The outputs are linearly related to the states and the inputs according to y ¼ Cx þ Du

(2:112)

where 2

c11 6 c21 y1 6 6 6 y2 7 6 6 7 y ¼ 6 . 7, C ¼ 6 6 4 .. 5 6 4 yp cp1 2

3

c12 c22 cp2

3 c1n c2n 7 7 7 7 7, 7 7 5 cpn

2

d11 6 d21 6 6 6 D¼6 6 6 4 dp1

d12 d22 dp2

3 d1r d2r 7 7 7 7 7 7 7 5 dpr

The p n constant matrix C is called the output matrix, and the p r matrix D is the direct transmission matrix. Equations 2.111 and 2.112 taken together are the state equations of the system. Note that the states x1, x2, . . . , xn are internal to the system as shown in Figure 2.27. Multivariable systems are easier to analyze in terms of state variables compared to the input–output model description of the system, that is, dyi=dt ¼ fi(y, u), i ¼ 1, 2, . . . , n.

63

Continuous-Time Systems

FIGURE 2.27

x –

. x = Ax – – + Bu –

u –

y –

y = Cx – + Du – –

Dynamic system with input u, output y, and state x.

Example 2.9 Interacting tanks with inﬂows into both tanks are shown in Figure 2.28. Choose the states to be the levels H1 ¼ H1(t) and H2 ¼ H2(t) and the single output as the volume of liquid in both tanks. Write the state equations for the system. The continuous-time model of the linear tanks consists of the following equations: A1

dH1 þ F0,1 ¼ F1 dt

F0,1 ¼ A2

(2:113)

1 (H1 H2 ) R12

(2:114)

dH2 þ F0,2 ¼ F0,1 þ F2 dt F0,2 ¼

(2:115)

1 H2 R2

(2:116)

Eliminating F0,1 and F0,2 from Equations 2.113 and 2.115 yields dH1 1 þ (H2 H2 ) ¼ F1 dt R2

(2:117)

dH2 1 1 (H1 H2 ) þ F2 þ H2 ¼ dt R2 R12

(2:118)

A1 A2

Solving for the state derivatives in Equations 2.117 and 2.118 dH1 1 1 1 ¼ H1 þ H2 þ F1 dt A1 R12 A1 R12 A1 dH2 1 1 1 1 ¼ H2 þ F2 H1 þ dt A2 R12 A2 R2 A2 R12 A2

A1

(2:120)

F2(t)

F1(t)

H1(t)

(2:119)

R12

H2(t)

A2 F0,1(t)

R2 F0,2(t)

FIGURE 2.28

A system of interacting tanks.

Simulation of Dynamic Systems with MATLAB® and Simulink®

64

Writing Equations 2.119 and 2.120 in matrix form gives the ﬁrst part of the state equations, 3 2 1 dH1 6 dt 7 6 A1 R12 7 6 6 4 dH 5 ¼ 4 1 2 A2 R12 dt 2

3 2 1 1 " # 7 H1 6 A1 A1 R12 7 þ6 4 1 1 5 H2 0 A2 R2 A2 R12

3

" # 7 F1 7 1 5 F2 A2 0

(2:121)

The single output VT, which represents the volume of liquid in both tanks, is VT ¼ A1 H1 þ A2 H2 ¼ [A1 A2 ]

H1 H2

(2:122)

The transmission matrix D is a 1 2 matrix of zeros due to the absence of a direct coupling from either input F1 or F2 to the output VT.

2.6.1 CONVERSION FROM LINEAR STATE VARIABLE FORM OUTPUT FORM

TO

SINGLE INPUT–SINGLE

In Section 2.3, an example was presented illustrating the conversion of a second-order state variable model into a second-order differential equation by eliminating one of the state variables (see Equations 2.37, 2.38, and 2.42). The procedure involved manipulation and substitution of terms in the time domain, an approach that quickly becomes unwieldy as the number of state variables increases. Simpler methods are described in Chapter 4. For a linear, third-order system with a single input, the starting point is the state variable model consisting of three coupled ﬁrst-order differential equations expressing the state derivatives as a linear function of the states and input x_ 1 ¼ a11 x1 þ a12 x2 þ a13 x3 þ b1 u x_ 2 ¼ a21 x1 þ a22 x2 þ a23 x3 þ b2 u x_ 3 ¼ a31 x1 þ a32 x2 þ a33 x3 þ b3 u

(2:123)

where the output y is x1, x2, or x3. A third order, input–output differential equation model equivalent to Equation 2.123 is €y_þ a2€y þ a1 y_ þ a0 y ¼ b2 €u þ b1 u_ þ b0 u

(2:124)

Expressions for the system coefﬁcients a2, a1, and a0 and input coefﬁcients b2, b1, and b0 are summarized in Equations 2.125 through 2.127 and Table 2.1.

TABLE 2.1 Input Coefﬁcients on Right-Hand Side of Equation 2.125 for y ¼ x1, x2, x3 y

b2

b1

b0

x1 x2 x3

b1 b2 b3

(a22 þ a33)b1 þ (a12b2 þ a13b3) a21b1 (a11 þ a33)b2 þ a23b3 a31b1 þ a32b2 (a11þ a22)b3

(a22a33 a23a32)b1 þ (a13a32 a12a33)b2 þ (a12a23 a13a22)b3 (a23a31 a21a33)b1 þ (a11a33 a13a31)b2 þ (a13a21 a11a23)b3 (a21a32 a22a31)b1 þ (a12a31 a11a32)b2 þ (a11a22 a12a21)b3

65

Continuous-Time Systems

a2 ¼ (a11 þ a22 þ a33 )

(2:125)

a1 ¼ a11 (a22 þ a33 ) a12 a21 a13 a31 þ a22 a33 a23 a32

(2:126)

a0 ¼ a11 (a23 a32 a22 a33 ) þ a12 (a21 a33 a23 a31 ) þ a13 (a22 a31 a21 a32 )

(2:127)

2.6.2 GENERAL SOLUTION

OF THE

STATE EQUATIONS

A solution to the state equation, Equation 2.111 can be found in any one of the texts on linear control theory listed in References. The solution is expressed in terms of an n n matrix F(t), called the transition matrix of the system. ðt x(t) ¼ F(t)x(0) þ F(t t)Bu(t) dt

(2:128)

0

The transition matrix depends solely on the system matrix A. One method for ﬁnding F(t) uses a deﬁnition based on an inﬁnite series, F(t) ¼ I þ (tA) þ

1 1 (tA)2 þ (tA)3 þ 2! 3!

(2:129)

As an illustration of how the transition matrix is used to solve the linear state equations, suppose the system matrix for an autonomous system (u ¼ 0) is

0 A¼ 2

1 3

Using the inﬁnite series expansion in Equation 2.129 or some other method (see Chapter 4) for ﬁnding F(t), the result is

2et e2t F(t) ¼ 2et þ 2e2t

et e2t et þ 2e2t

(2:130)

and from Equation 2.128, the state x(t), t 0 is

x1 (t) 2et e2t ¼ x2 (t) 2et þ 2e2t

et e2t et þ 2e2t

x1 (0) x2 (0)

(2:131)

The state trajectory or state portrait is a plot showing the path of the state vector in state space. In the general case, there is a separate coordinate axis for each of the state variables. The time variable ‘‘t’’ does not appear explicitly; however, each point along the state trajectory corresponds to a speciﬁc point in time. Figure 2.29 shows four different state trajectories starting from different initial states. Note that the four state trajectories all terminate at the origin, the equilibrium point of the system.

EXERCISES 2.17 For the system of interacting tanks in Example 2.9. (a) Draw the simulation diagram of the system. (b) Choose a new set of state variables as z1 ¼ H1 þ H2 , z2 ¼ H1 H2

Simulation of Dynamic Systems with MATLAB® and Simulink®

66

5

5

2.5 x2

x2

2.5

x1(0) = 3 x2(0) = 4 =

0

−2.5

−2.5 −2.5

0 x1

5

2.5

2.5

0

−5 −5

x1(0) = –4 x2(0) = –3 −2.5

0 x1

x1(0) = 3 x2(0) = –4

−5 −5

5

5

−2.5

FIGURE 2.29

2.5

x2

x2

−5 −5

0

−2.5

0 x1

2.5

5

x1(0) = –4 x2(0) = –2

0 −2.5

2.5

−5 −5

5

−2.5

0 x1

2.5

5

State trajectory in Equation 2.131 for different initial states.

and ﬁnd the new system and input matrices A and B where

z_ 1 z_ 2

z1 F ¼A þB 1 z2 F2

Hint: Find H1 and H2 in terms of z1 and z2. (c) Find the new output matrix C where

z VT ¼ C 1 z2

2.18 Write the state equations for the system of three railroad cars in Exercise 2.16. Choose the outputs to be the positions of each car. 2.19 An ecosystem consists of three species whose populations are denoted by F, S, and G. The growth rates of each specie are given by 1 dF ¼ a cS uF F dt 1 dS ¼ k þ lF mG uS Growth rate of S ¼ S dt 1 dG ¼ e þ sS þ uG Growth rate of G ¼ G dt Growth rate of F ¼

Write the system in state variable form x_ ¼ f(x, u) y ¼ g(x, u) with the state x ¼ [F S G]T, input u ¼ [uF uS uG]T, and output chosen as y ¼ F þ S þ G. 2.20 Limestone is reduced to calcium oxide (CaO), magnesium oxide (MgO), and carbon dioxide (CO2) by heating it in a reaction vessel maintained at a constant high temperature (McClamroch 1980). The limestone is made up of a ﬁxed fraction b of calcium carbonate

67

Continuous-Time Systems CO2

u MgO(x4)

CaO(x3)

MgCO3(x2)

CaCO3(x1)

FIGURE E2.20

(CaCO3), and the rest is magnesium carbonate (MgCO3). The process is described by the ﬁrstorder irreversible chemical reactions k1

CaCO3 ! CaO þ CO2 k2

MgCO3 ! MgO þ CO2 where k1 and k2 are the rate constants for the two reactions. Limestone is added to the reaction vessel at a rate of u mol=h. The mass (in moles) of CaCO3, MgCO3, CaO, and MgO in the vessel are denoted by x1, x2, x3, and x4, respectively (see Figure E2.20). Since each mole of reactant that decomposes yields one mole of product (plus one mole of carbon dioxide), the state equations are x_ 1 ¼ k1 x1 þ bu x_ 2 ¼ k2 x2 þ (1 b)u x_ 3 ¼ k1 x1 x_ 4 ¼ k2 x2 (a) Draw a simulation diagram of the system. What is the order of the system? (b) Find the matrices A, B, C, and D in the state equation model if the outputs are y1 ¼ x3 and y 2 ¼ x 4. (c) Find the differential equation relating y1 and u. Comment on the result. (d) Repeat part (c) for y2 and u. (e) The vessel is initially empty and u(t) ¼ A, t 0. Find analytic expressions for the state variables. 2.21 The populations of three species in a restricted area are governed by the differential equations P_ 1 (t) ¼ a11 P1 (t) þ a12 P2 (t) þ a13 P3 (t) þ c1 u(t) P_ 2 (t) ¼ a21 P1 (t) þ a22 P2 (t) þ a23 P3 (t) þ c2 u(t) P_ 3 (t) ¼ a31 P1 (t) þ a32 P2 (t) þ a33 P3 (t) þ c3 u(t) 0 c1 1, 0 c2 1, 0 c3 1, and c1 þ c2 þ c3 ¼ 1 where u(t) is the total immigration rate for all species. The constants c1, c2, and c3 represent the fraction of u(t) immigrating to each of the species populations. (a) Draw a simulation diagram of the system. (b) Find the third-order differential equation relating P1(t) and u(t). (c) Draw a simulation diagram of the system containing three integrators in series where the €_1(t) input to the ﬁrst integrator is P

Simulation of Dynamic Systems with MATLAB® and Simulink®

68

2.7 NONLINEAR SYSTEMS Real-world dynamic systems exhibit nonlinear behavior. The continuous-time models that relate inputs and outputs of actual systems are (entirely or partially) composed of nonlinear algebraic and differential equations. We may well choose to employ a linear model as an approximation of a nonlinear system because it is far simpler to work with. A uniﬁed approach to solving nonlinear algebraic equations does not exist, to say nothing of nonlinear differential equations. The principle of superposition states that if a system responds to inputs u1(t) and u2(t) with outputs y1(t) and y2(t), then the system’s response to a linear combination of the inputs u(t) ¼ c1u1(t) þ c2u2(t) is y(t) ¼ c1y1(t) þ c2y2(t). Superposition is a property of linear system models. It is not applicable to models of nonlinear systems. Unlike linear system models, a nonlinear system model exhibits dynamic response properties whose nature is dependent on the magnitude of its inputs and the initial state. Consider the two simple ﬁrst-order systems, one linear and the other nonlinear, in Figure 2.30. Both systems are driven by the identical input. Discrete-time system approximations for both continuous-time systems can be obtained by replacing the ﬁrst derivative terms with divided differences, that is, dy yA [(n þ 1)T] yA [(nT)] yA (n þ 1) yA (n) ¼ dt (n þ 1)T nT T

(2:132)

dz zA [(n þ 1)T] zA [(nT)] zA (n þ 1) zA (n) ¼ dt (n þ 1)T nT T

(2:133)

resulting in difference equations yA (n þ 1) ¼ yA (n) þ T[u(n) yA (n)]

(2:134)

zA (n þ 1) ¼ zA (n) þ T[u(n) z2A (n)]

(2:135)

Equations 2.134 and 2.135 can be solved recursively for yA(n) and zA(n), n ¼ 1, 2, 3, . . . given initial values for yA(0) and zA(0). The results (every third point) are plotted in Figure 2.31 when the initial condition is zero for inputs u(t) ¼ 1 and u(t) ¼ 10. Approximate responses yA(nT ) for both inputs are typical linear ﬁrst-order system step responses, namely, they each require roughly four to ﬁve time constants (t ¼ 1 s) to reach steady state. Furthermore, the response yA(nT ) in the lower left corner where u(t) ¼ 10 is 10 times the response yA(nT) in the upper left corner where u(t) ¼ 1. For a constant input u(t) ¼ u, the steady-state value is u for the linear system. yA(1) ¼ In contrast to the linear system, the transient period of the nonlinear system is shorter when the 1 input u(t) ¼ 10 compared to when u(t) ¼ 1. Furthermore, zA (1) ¼ u2 for the nonlinear system when the input is u(t) ¼ u, in violation of the principle of superposition.

dy = u−y dt

y(t)

dz = u −z2 dt

z(t)

u(t)

FIGURE 2.30

Linear and nonlinear system subject to identical input.

69

1

1

0.75

0.75

0.5

u(t) = 1 T = 0.05

0.25 0

zA(nT )

yA(nT )

Continuous-Time Systems

0

1

2

3

0.5

u(t) = 1 T = 0.05

0.25 4

0

5

10

0

0.5

1

1.5

2

2.5

3

2.5

3

3 zA(nT )

yA(nT )

8 6 4

u(t) = 10 T = 0.05

2 0

0

1

2

3

2 u(t) = 10 T = 0.05

1

4

5

0

0

0.5

t

FIGURE 2.31

1

1.5 t

2

Approximation of linear and nonlinear system step responses.

A linear model approximation of a nonlinear system is often acceptable provided the system variables (inputs, states, outputs) are conﬁned to a restricted operating region. A simple example serves to illustrate the point. Consider a system with input u ¼ u(t) and state x ¼ x(t) described by dx þ 0:2x1=2 ¼ u dt

(2:136)

The state derivative function is a nonlinear function of x, that is, dx ¼ f (x, u) ¼ 0:2x1=2 þ u dt

(2:137)

For arbitrary input u(t), the solution to Equation 2.137 can be approximated in a way similar to what we did in Chapter 1 using difference equations. However, suppose the input u(t) is conﬁned to a range that results in the state x(t) varying between xl and xu as shown in Figure 2.32. It is reasonable to assume the term 0.2x1=2 in Equation 2.136 could be replaced by a linear function of x resulting in a simpler model. We will have more to say about linearization of nonlinear system models in Chapter 7. Another distinguishing property of linear systems is the way they respond to sinusoidal inputs. At steady state, the output of a linear system forced by a sinusoidal input with radian frequency v0 is itself a sinusoid at the same frequency. In general, the output is shifted in time (out of phase) with respect to the input, and the amplitude is either attenuated or ampliﬁed compared to the amplitude of the input. This property is the foundation of linear AC steady-state analysis and the design of linear control systems by the method of frequency response. In the case of nonlinear systems, the output includes harmonics (sinusoidal terms at frequencies nv0, n ¼ 1, 2, 3, . . . ). The type of nonlinearity portrayed in Figure 2.32 has been classiﬁed as ‘‘progressive’’ (Buckley 1964). The distinguishing characteristics of progressive nonlinearities are their monotonic continuous nature over the range of input and output values of interest. Furthermore, state derivative functions which are progressive nonlinearities can be approximated by linearization methods. ‘‘Essential’’ nonlinearities are those that cannot be represented by a simple continuous analytical function. Phenomena such as friction, dead zone and saturation in valves, and backlash in gears in mechanical systems; hysteresis in electrical components; and analog-to-digital quantization are examples of essential nonlinearities.

Simulation of Dynamic Systems with MATLAB® and Simulink®

70 1 0.9 0.8 0.7

y=x

y

0.6

1/2

0.5 0.4 Region of linear approximation

0.3 0.2 0.1 0

FIGURE 2.32

0

2.5

5

7.5

10 xl

12.5

15 xu

17.5

20 x

Linearizing the nonlinear function 0.2x1=2 in an interval xl x xu.

2.7.1 FRICTION The ﬁrst example illustrates a type of friction called coulomb friction. An object of mass m, resting on a ﬂat surface, is subject to an external horizontal force f(t) and a resisting frictional force fm as shown in Figure 2.33. The velocity of the mass obeys the relation in Equation 2.138 m

dv þ fm ¼ f dt

(2:138)

The friction force fm is equal in magnitude to the force f until a breakaway force fB is applied (see Figure 2.34), and the mass begins to slide along the surface. The breakaway force fB depends on the coefﬁcient of static friction m0 and the object’s weight, fB ¼ m0 mg

m

f

FIGURE 2.33

m dv + fμ = f dt

Nonlinear system example—coulomb friction. fμ

B

fB μs mg

v=0

v>0

C A

FIGURE 2.34

fμ

(2:139)

0

fB

fμ = D

f when f ≤ fB (v = 0) μs mg when f > fB (v > 0)

f

Friction force fm vs. increasing f applied to a mass initially at rest.

71

Continuous-Time Systems

While in motion, the friction force fm is a constant dependent on the coefﬁcient of sliding friction ms and the weight mg of the object as seen in Equation 2.140. Note that fm is also equal to msmg when f fB and v > 0. ( f when f fB (v ¼ 0) fm ¼ (2:140) ms mg when f > fB (v > 0) Example 2.10 The applied force f(t) is shown in Figure 2.35. Find the velocity of the object. 8 t > > 2fB > > t > < 1 f (t) ¼ t > 2fB 2 > > t > 1 > : 0

0 t < t1 (2:141)

t1 t < 2t1 t 2t1

The difference equation resulting from the substitution of the divided difference [vA(n þ 1) vA(n)]=T for the ﬁrst derivative dv=dt in Equation 2.138 is vA (n þ 1) ¼ vA (n) þ

T [f (n) fm (n)] m

(2:142)

A recursive solution for vA(n), n ¼ 1, 2, 3, . . . given vA(0) ¼ v(0) ¼ 0 is not as straightforward as it was in previous examples owing to the nature of the friction force. The MATLAB® M-ﬁle ‘‘Chap2_ Ex7_1.m’’ includes the necessary conditional statements to handle the discontinuity in fm. Results are shown in Figure 2.36. The analytical solution for the velocity v(t) is plotted along with the approximate solution vA(n). It can be found by integrating the differential equation (Equation 2.138) over consecutive intervals using the appropriate value for the friction force ( f or msmg) and the correct initial velocity for each interval. The details are left for an exercise; the results are as follows. 8 0, > > > " # > > > t 2 t 2ms m0 > > > þ gt1 m0 ms , > > 4 t1 t1 > > > > > # < " 2 t t 9m 2m 0 s v(t) ¼ gt1 m þ (4m0 ms ) , 0 > > 4 t1 t1 > > > > > > > t 7m0 þ 2ms > > þ gt m , 1 > s > 4 t1 > > > : 0, f(t) 2fB

f(t) =

fB 0.5t1 t1

FIGURE 2.35

Applied force f(t) vs. t.

t 2t1

0 t 0:5t1 0:5t1 t < t1 t1 t < 2t1 2t1 t < Tf Tf < t

2fB (t/t1)

0 ≤ t < t1

2fB [2 − (t/t1)]

t1 ≤ t < 2 t1

0

t ≥ 2t1

(2:143)

Simulation of Dynamic Systems with MATLAB® and Simulink®

72

Applied force 40 m = 2 slugs, μ0 = 0.3, μs = 0.1 fB = μ0 mg

f (lb)

30

t1 = 1 s

20 10 0 0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

5.5

Velocity 12.5

vA(n), n = 0, 4, 8,...

vA(n) (ft/s)

10

v(t)

7.5 T = 0.025 s

5 2.5 0 0

0.5

1

1.5

2

2.5

3 t (s)

3.5

4

4.5

5

5.5

Approximate solution vA(n), n ¼ 0, 4, 8, . . . and exact solution v(t), t 0.

FIGURE 2.36

The time Tf when the velocity returns to zero is obtained from Tf ¼

t1 (7m0 þ 2ms ) 4ms

(2:144)

2.7.2 DEAD ZONE AND SATURATION The next example of mechanical (pneumatic) nonlinearity is a valve that contains two nonlinear elements, dead zone and saturation. First, consider the nonlinear elements individually. An ideal dead zone nonlinearity is shown in Figure 2.37. The dead zone is the region between t1 and t2. 8 t t2 > > f3 > > > t3 t2 < f (t) ¼ 0 > > > t t1 > > : f0 t0 t1

f(t)

t2 t t1 < t < t2

(2:145)

t t1

An ideal saturation nonlinearity is shown in Figure 2.38. f3 t0

t1 t t2

t3

f0

FIGURE 2.37 linearity.

Dead zone non-

8 ts

(2:146)

The saturated regions are when jtj > ts, that is, for t < ts, the value of f (t) does not change and for t > ts, the value of f(t) does not change. Together, these nonlinearities (saturation and dead zone) form an approximation to the pneumatic behavior of a valve shown in Figure 2.39.

73

Continuous-Time Systems

Io is the opening current, that is, the current needed to open the valve. Is is the saturation current where any additional current (more than Is or less than Is) does not open the valve any further. The region between Io and Is(Io and Is) is appropriately called the active region. The region between Io and Io is called the dead zone. However, in practice, leakage occurs below the opening current.

f(t)

f –ts

t

ts –f

2.7.3 BACKLASH Backlash nonlinearity often occurs in gears due to the spacing between individual teeth. The spacing is needed for the gears to mesh without binding. This spacing (d) is shown in Figure 2.40. Figure 2.41 shows a plot of the backlash nonlinearity. Assume the space d exists in the initial condition as in Figure 2.40. As the leading gear moves in one direction, the following gear does not move until contact is made after the leading gear is displaced by d. Then, the following gear tracks the leading gear as indicated by section 1 of Figure 2.41. When the leading gear reverses direction, it must be displaced by a distance 2d before contact is reestablished with the following gear, as indicated by section 2 of Figure 2.41. Similar to before, the following gear tracks the leading gear as indicated by section 3 of Figure 2.41. Another reversal of directions leads to section 4 in Figure 2.41.

FIGURE 2.38 linearity.

Saturation non-

Q

–I3

–I0

i I0

I3

2.7.4 HYSTERESIS The graph of fm vs. f in Figure 2.34 is applicable so long as the applied force f and resulting velocity v are increasing along the path A-B-C-D. Once the block is in motion and the applied force f diminishes to zero, the return path does not follow D-C-B-A. That is, the sliding block does not abruptly stop when the applied force is reduced to fB. Rather, the friction force remains at msmg until the block decelerates to zero velocity. This type of nonlinear phenomenon is referred to as hysteresis. An example of a real system with hysteresis, present by design, is a thermostatically controlled furnace supplying heat to a building. A simpliﬁed diagram of the system is depicted in Figure 2.42. An energy balance on the building interior space relates the accumulation of thermal energy to the heat ﬂow from the furnace and heat loss to the outside. The equation is C

dT ¼ Q Q0 dt

FIGURE 2.39 current.

Valve ﬂow vs.

d

Leading gear

FIGURE 2.40 teeth.

Following gear

Backlash in gear

(2:147)

where C is the thermal capacitance of the air and contents inside the building, all of which are assumed to be at temperature T. The heat loss Q0 is assumed proportional to the temperature difference T T0, that is, Q0 ¼

T T0 R

(2:148)

Simulation of Dynamic Systems with MATLAB® and Simulink®

74 F

with R the overall thermal resistance of the exterior walls and insulation. Combining Equations 2.147 and 2.148 and introducing the thermal system time constant t ¼ RC result in the ﬁrstorder model

2 1

3

L

d

–d 4

FIGURE linearity.

t

2.41

Backlash

( Q¼

non-

dT þ T ¼ RQ þ T0 dt

(2:149)

The furnace operates in one of two modes, on or off, depending on whether the building temperature T is below or above some tolerance D about a desired temperature Td and whether the building temperature is increasing or decreasing. When it is on, a constant amount of heat Q is supplied; conversely, no heat is produced when the furnace is off. In mathematical terms,

Q, T Td D or Td D < T < Td þ D and dT=dt > 0 0, T > Td þ D or Td D < T < Td þ D and dT=dt < 0

(2:150)

The hysteresis effect is evident from the graph in Figure 2.43 (McClamroch 1980). From Equations 2.149 and 2.150, it follows that the state derivative dT=dt depends not only on the input T0 and the state T but also on its own sign. Furthermore, since the furnace output Q in Figure 2.43 is multi-valued whenever the building temperature T falls within Td D to Td þ D, the initial state T(0) and the initial state of the furnace (on=off) must be speciﬁed to simulate or obtain analytical solutions for T(t), t 0.

Building temperature: T(t) Heat loss: Q0 (t) R Heat from furnace: Q(t)

Outside temperature: T0 (t)

Furnace

FIGURE 2.42

Temperature regulation in a building.

Q – Q

dT > 0 dt

dT < 0 dt Td − Δ

FIGURE 2.43

Td + Δ

Hysteresis in furnace output vs. building temperature.

T

75

Continuous-Time Systems

The example that follows illustrates a method for obtaining an approximate solution and the exact solution for the building temperature T(t) when the outside temperature T0(t) is constant. Example 2.11 A building’s thermostat has been off for a period of time sufﬁcient to allow the inside and outside temperatures to equalize. The thermostat is then set to 758F. It is programmed to turn off when the interior temperature reaches 788F and back on when it falls below 728F. The furnace produces 36,000 Btu=h. Thermal capacitance of the occupied space and interior furnishings is 300 Btu=8F, and the thermal resistance of the walls is 8 1048F per Btu=h. The outside temperature is a constant 508F. (a) Find the time constant of the system. (b) Show that the furnace is capable of raising the building temperature to 788F. (c) Find the temperature response and the time required for the building temperature to reach 788F. (d) Find the temperature response and the time required for the building temperature to cool down to 728F. (e) Find the temperature response and the time required for the building temperature to go back to 788F. (f) Simulate the temperature responses in parts (c), (d), and (e) by solving a difference equation with appropriate step size and compare the approximate and exact solutions. (a) The time constant, a measure of the speed of the system’s dynamics is t ¼ RC ¼ 8 104

F Btu 300 ¼ 0:24 h F Btu=h

(b) The steady-state temperature differential (inside minus outside) that the furnace is capable of maintaining is obtained from the ﬁrst-order differential equation model in Equation 2.149 with the derivative set to zero and the furnace on, that is, Q(t) ¼ Q. Tss ¼ RQ þ T 0

(2:151)

) Tss T 0 ¼ RQ

(2:152)

where T 0 is the constant outside temperature Tss is the steady-state inside temperature In this example, Tss T 0 ¼ RQ ¼ 8 104

F Btu 36,000 ¼ 28:8 F Btu=h h

Hence, the furnace is capable of raising the inside temperature from 508F to 78.88F, which is slightly higher than the 788F shutoff setting of the thermostat. (c) From Equation 2.6, the step response of the ﬁrst-order system is T(t) ¼ T(0)et=t þ (T 0 þ RQ)(1 et=t )

(2:153)

which describes the building temperature from time t ¼ 0 up to t ¼ t1 where T(t1 ) ¼ Td þ D ¼ 75 F þ 3 F ¼ 78 F

(2:154)

Simulation of Dynamic Systems with MATLAB® and Simulink®

76 Solving for t1 gives

(T 0 þ RQ) T(0) (T 0 þ RQ) (Td þ D) (50 þ 28:8) 50 ¼ 0:24 ln ¼ 0:86 h (50 þ 28:8) (75 þ 3)

t1 ¼ t ln

(2:155)

From Equation 2.153 with T(0) ¼ 508F, the temperature response is T(t) ¼ 50et=0:24 þ 78:8(1 et=0:24 ),

0 t 0:86

(2:156)

(d) The furnace shuts off when the temperature reaches Td þ D ¼ 788F and the subsequent cooling from 788F to Td D ¼ 728F follows the step response in Equation 2.153 with Q ¼ 0 and T(0) ¼ Td þ D ¼ 788F. Thus, T(t) ¼ (Td þ D)e(tt1 )=t þ T 0 [1 e(tt1 )=t ],

t1 t t2

¼ 78e(t0:86)=0:24 þ 50[1 e(t0:86)=0:24 ],

0:86 t t2

(2:157) (2:158)

where t2 is the time when the building temperature is Td D 728F. Note the (t t1) in the exponent of Equation 2.157 since t1 is the initial time of the step response. From Equation 2.157 with t ¼ t2, T(t2) ¼ Td D, the time t2 is given by (Td þ D) T 0 (Td D) T 0 (75 þ 3) 50 ¼ 0:86 þ 0:24 ln ¼ 0:92 h (75 3) 50

t2 ¼ t1 þ t ln

(2:159)

(e) The cycle is completed when the building temperature returns to Td þ D ¼ 788F. Using the same approach as before, the result is h i T(t) ¼ (Td D)e(tt2 )=t þ (T 0 þ RQ) 1 e(tt2 )=t , t2 t t3 ¼ 72e(t0:92)=t þ 78:8[1 e(t0:92)=t ],

0:92 t t3

(2:160)

Setting T(t3) ¼ Td þ D and solving for t3, (T 0 þ RQ) (Td D) t3 ¼ t2 þ t ln (T 0 þ RQ) (Td þ D) (50 þ 28:8) (75 3) ¼ 0:92 þ 0:24 ln ¼ 1:43 h (50 þ 28:8) (75 þ 3)

(2:161)

(f) The approximate solution for the building temperature is based on the difference equation obtained by replacing the ﬁrst derivative dT=dt in Equation 2.149 with the ﬁnite difference [TA (n þ 1) TA (n)]=T. The result is DT DT (2:162) TA (n) þ [RQ(n) þ T 0 ] TA (n þ 1) ¼ 1 t t where Q(n) is based on the logic in Equation 2.150. The MATLAB M-ﬁle ‘‘Chap2_Ex7_2.m’’ evaluates the exact and approximate solutions and generates the graph shown in Figure 2.44. The building temperature experiences periodic ﬂuctuations between Td D ¼ 728F and Td þ D ¼ 788F as long as the outside temperature remains constant. The period is equal to t3 t1 ¼ 1.43 0.86 ¼ 0.57 h.

77

Continuous-Time Systems

80

Td + Δ

75

Td – Δ t2

T (°F)

70 65

Step size ΔT = 0.001 h

60

TA(n), n = 0, 25, 50, ... T(t), t ≥ 0

55 50

FIGURE 2.44

t3

t1

0

0.25

0.5

0.75 t (h)

1

1.25

1.5

Exact and approximate solutions for building temperature.

2.7.5 QUANTIZATION In digital control, it is often desired to discretize the continuous signal of a sensor for use by a computer or microprocessor. Conversion of this signal is achieved by an analog-to-digital converter (ADC) where the signal is quantized. The quantization nonlinearity is shown in Figure 2.45. In this example, a voltage range between V0 and V1 is designated as state zero, S0; a voltage range between V1 and V2 is designated as state one, S1; and so on. Each state is represented by a binary expression according to the number of bits used by the data type assigned to the state. For example, an 8-bit representation for state zero is 00000000, while state one is represented by 00000001. The more bits that are available for quantization yield a better resolution of the sensor’s range, in this case, voltage. There are 2n states where n is the number of bits. Therefore, an 8-bit ADC has 256 states, 0–255. The resolution is the sensor’s range divided by the number of states. For example, a sensor with a voltage range from 0 to 10 V has a resolution of 0.04 V for an 8-bit ADC.

S3 S2 S1 S0 V0

FIGURE 2.45

Quantization.

V1

V2

V3

V4

Simulation of Dynamic Systems with MATLAB® and Simulink®

78

2.7.6 SUSTAINED OSCILLATIONS AND LIMIT CYCLES Both linear and nonlinear system differential equation models are capable of producing solutions involving sustained oscillations of the state variables. This comes as no surprise for linear systems. Indeed, we have already seen how the natural response of an undamped second-order system continues to oscillate forever (see Figure 2.4). Examples will be presented in Chapter 4 of forced linear systems with sustained sinusoidal oscillations in the output after the transient response has died out. State trajectories of the autonomous system governed by the differential equation €x þ v2n x ¼ 0

subject to x(0) ¼ x0 , x_ (0) ¼ x_ 0

(2:163)

are closed orbits in the x_ vs. x state space. Figure 2.46 shows state trajectories, also known as orbits, for the undamped system in Equation 2.163 with vn ¼ 1 rad=s starting from four different initial points in the state space. The orbits are typically elliptical; however, those in Figure 2.46 are circular because the natural frequency vn ¼ 1 rad=s. Sustained oscillations of the state components x and dx=dt are shown in Figure 2.47. Nonlinear systems can experience two types of sustained oscillations. The ﬁrst class is similar to the case of linear systems. In the unforced case, the oscillations are sensitive to the initial conditions. That is, the particular points along the closed path of the state trajectory vary depending on the location of the initial point in state space. The initial point is always on the closed orbit. The amplitude and period of the oscillations depend on the system parameters and initial conditions. The state trajectories of the nonlinear system described by the coupled ﬁrst-order differential equations x_ 1 ¼ x1 (a bx2 )

(2:164)

x_ 2 ¼ x2 (cx1 d)

(2:165)

State trajectories of undamped second-order systems 1

ωn= 1 rad/s

0.8 0.6 0.4

b

dx/dt

0.2

a

0 d

−0.2 −0.4 c

−0.6 −0.8

. Initial state: x(0), x(0)

−1 −1

FIGURE 2.46

−0.5

0 x

0.5

Closed orbits for the system €x þ v2n x ¼ 0 (vn ¼ 1 rad=s).

1

79

Continuous-Time Systems 1

x

0.5

b

a

d

c

0

−0.5 (a)

−1

0

1

2

3

4

5

6

7

6 t

7

8

9

10

11

12

8

9

10

11

12

1

dx/dt

0.5 0

a b

−0.5

c

d

−1 0

1

2

3

4

5

(b)

FIGURE 2.47

Sustained oscillations of x (a) and dx=dt (b) for undamped second-order systems.

are concentric closed curves ‘‘spun out’’ in a clockwise rotation from the initial point. The center of rotation is the equilibrium point located at (d=c, a=b). The MATLAB M-ﬁle ‘‘Chap2_Figs7_ 13and14.m’’ uses a difference quotient with step size T ¼ 5105 to approximate the ﬁrst derivatives in Equations 2.164 and 2.165. The approximate solutions in Figure 2.48 show four orbits starting from different initial states. Time histories of the state variables are shown in Figure 2.49. In contrast to the sinusoidal oscillations of the LTI system governed by Equation 2.163, the oscillations of the nonlinear system in Equations 2.164 and 2.165 are not of a sinusoidal nature.

20

Initial state: x1(0), x2(0)

a = 10, b = 2, c = 4, d = 12 x1,e = d/c = 3, x2,e = a/b = 5

18 16 14

x2

12 (x1,e, x2,e)

10 8 6

a

+

b

c

d

4 2 0

FIGURE 2.48

0

1

2

3

4

5

6 x1

7

8

9

10

11

Closed orbits and sustained oscillations for the nonlinear system.

12

Simulation of Dynamic Systems with MATLAB® and Simulink®

80

d

10

c

x1

7.5

b a

5 2.5

(a)

0

0

0.25

0.5

20

0.75

1

1.5

d c

15 x2

1.25

b

10

a

5 0

0

0.25

0.5

(b)

FIGURE 2.49

0.75 t

1

1.25

1.5

Sustained oscillations of x1 (a) and x2 (b) for nonlinear second-order system.

Another type of sustained oscillation is possible for an unforced nonlinear system. In this case, there is a single closed orbit in the state space independent of the initial conditions. If the initial state is located on this closed path, the state vector remains on it forever, periodically returning to the starting point. When the initial state is inside the closed curve, the state trajectory may be asymptotically attracted to the closed curve or repelled from it towards a stable equilibrium point in its interior. Should the initial state be located outside the closed curve, the state trajectory either converges to it in a ﬁnite time period or else spirals outward from it. Sustained oscillations of this nature are called limit cycles. If the initial state is not on the limit cycle, the state trajectory is either attracted to or repelled from it. Limit cycles are either stable or unstable depending on which of the two situations applies. An autonomous mechanical system with a stable limit cycle is given in Tse et al. (1963). Referring to Figure 2.50, the mass m is acted upon by a linear spring force Fk, a nonlinear damping force Fc, and a self-excitation force F, that is, a force with explicit dependence solely on the internal state of the system. Note that there are no external forces present. The differential equation model is m€x ¼ F Fc Fk ¼ F0 x_ (cx2 )_x kx

(2:166)

) m€x þ (cx2 F0 )_x þ kx ¼ 0

(2:167)

The effective damping force is (cx2 F0)_x. In the neighborhood of the equilibrium point x ¼ 0, x_ ¼ 0, the term (cx2 F0) < 0. The negative damping results in an increase of energy in the system

. . F = F (x, x) = F0 x

FIGURE 2.50

m

Fk = kx . Fc = (cx2)x

An autonomous nonlinear system with self-excitation force.

81

Continuous-Time Systems

making the equilibrium point inherently unstable. Consequently, the state trajectory will move outwards from the origin in state space. The reverse is true whenever (cx2 F0) > 0. In this case, the damping term is positive and energy is dissipated from the system. The state trajectory spirals inward to points where the total energy in the system is lower. Clearly, a locus of points must exist in state space to function as a transition between the two phenomena. The locus must be a closed curve, namely, the limit cycle. Example 2.12 For the mechanical system described by Equation 2.167 (a) Convert the system model to state variable form. (b) Numerical values of the system parameters are m ¼ 1, k ¼ 2, c ¼ 0.5, and F0 ¼ 3. Approximate the state derivatives numerically with appropriate step size to determine the state trajectories when the initial state is located at (i) x(0) ¼ 1, x_ (0) ¼ 5 (ii) x(0) ¼ 2, x_ (0) ¼ 5 (iii) x(0) ¼ 2, x_ (0) ¼ 15 (iv) x(0) ¼ 5, x_ (0) ¼ 20 Plot the trajectories in the state space. (c) Estimate the period of the limit cycle. (a) Choosing the state vector as x1 ¼ x, x2 ¼ x_ yields the state derivative functions x_ 1 ¼ f1 (x1 , x2 ) ¼ x2 x_ 2 ¼ f2 (x1 , x2 ) ¼

1 [kx1 þ (cx21 F0 )x2 ] m

(2:168) (2:169)

(b) Replacing x_ 1 and x_ 2 by difference quotients leads to the following difference equations for the discrete-time system x1,A (n þ 1) ¼ x1,A (n) þ Tf1 [x1,A (n), x2,A (n)]

(2:170)

¼ x1,A (n) þ Tx2,A (n)

(2:171)

x2,A (n þ 1) ¼ x2,A (n) þ Tf2 [x1,A (n), x2,A (n)] ¼ x2,A (n)

n o i Th kx1,A (n) þ cx21,A (n) F0 x2,A (n) m

(2:172) (2:173)

The difference equations are solved recursively in ‘‘Chap2_Ex7_3.m’’ for the given initial states. The limit cycle and the four state trajectories are shown in Figure 2.51. As expected, the state trajectories eventually converge to the limit cycle. (c) Figure 2.52 shows the time responses for the state components starting from the initial state x1(0) ¼ 5, x2(0) ¼ 20. The period of sustained oscillations can be approximated from the graph by estimating the difference in successive zero crossings of either state component once the state ‘‘locks into’’ the limit cycle. By zooming in on Figure 2.46, the period is approximated as 11.94 6.43 ¼ 5.51. Can you determine the approximate time the state enters the limit cycle?

Simulation of Dynamic Systems with MATLAB® and Simulink®

82

Nonlinear system with limit cycle

25

m = 1, k = 2, c = 0.5, F0 = 3

20 (−2, 15)

15 10

Limit cycle

(2, 5)

x2

5 0

(−1, −5) −5 −10 −15 (5, −20)

−20 −6

FIGURE 2.51

−5

−4

−3

−2

−1

0 1 x1

2

3

4

5

6

Approaches to limit cycle from several initial states. x1 vs. t for system with limit cycle starting at (5, −20) 5

x1

2.5 0 −2.5 Period

−5 0

1

2

3

4

5

6

7

8

9

10 11 12 13 14 15 16

x2 vs. t for system with limit cycle starting at (5, −20)

x2

10 0 −10 −20 0

1

2

3

4

5

6

7

8

9

10 11 12 13 14 15 16

t

FIGURE 2.52

Time histories of state components [initial state: x1(0) ¼ 5, x2(0) ¼ 20].

EXERCISES 2.22 Examine the effect of changing the initial condition on the unit step response of the nonlinear system dx þ x2 ¼ u, dt

u(t) ¼ 1,

0

Plot xA(n), n ¼ 0, 1, 2, 3, . . . when x(0) ¼ 2, 1, 0, 1, 5 on the same graph. Use T ¼ 0.05.

83

Continuous-Time Systems

2.23 In Example 2.10, suppose instead of a constant friction force applied to the object as it slides, there is a variable friction force given by fm ¼ avb Find and plot vA(n), n ¼ 1,2,3, . . . in response to the force f(t) in Example 2.10 when (i) a ¼ 2, b ¼ 0.5 (ii) a ¼ 1, b ¼ 1 (iii) a ¼ 2, b ¼ 2 2.24 Nonlinear dynamic system is shown in the ﬁgure below. The input u(t) ¼ sin 100pt, t 0. (a) Is the output y(t) a sinusoidal function of the same frequency as the input like it would be in a linear system? Explain (b) Is the output y(t) a periodic function? If so, what is the frequency? u(t)

y(t)

y1/2 = u

2.25 In Example 2.10, ﬁnd the displacement of the mass, x(t), t 0. 2.26 In Example 2.10, the applied force is ( f (t) ¼

2.27

2.28

2.29

2.30

2fB sin 0:25pt,

0t0

k

W x(0)

μmg

x

0

x

fμ

−μmg

FIGURE E2.30

(c) The exact solution for x(t) over the ﬁrst cycle (0 t t2) is 8 mmg mmg > , 0 t t1 cos vn t < x0 þ k k x(t) ¼ > : x1 mmg cos vn (t t1 ) þ mmg , t1 t t2 k k where p t1 ¼ vn p t2 ¼ t1 þ vn x1 ¼ x0 2

mmg k

Plot the exact solution for x(t) over the ﬁrst cycle and compare it to the approximate solution. 2.31 For the undamped second-order system modeled by €x þ v2n x ¼ 0

subject to x(0) ¼ x0 , x_ (0) ¼ x_ 0

show the equation of the closed trajectories are ellipses in the x x_ plane that reduce to the circular orbits in Figure 2.40 when vn ¼ 1 rad=s.

85

Continuous-Time Systems

2.32 Generate the state trajectory shown in Figure 2.45 starting at (2,15) by ﬁnding an approximate solution to the differential equation dx2 1 x1 2 k þ cx1 F0 ¼ dx1 m x2 obtained as a result of dividing dx2=dt in Equation 2.169 by dx1=dt in Equation 2.168. 2.33 Generate 500 state trajectories starting from initial points randomly selected in the region 10 x(0) 10, 10 x_ (0) 10 for the system governed by m€x þ (F0 cx2 )_x þ kx ¼ 0 with the same parameter values as those in Example 2.12. Comment on the existence of a limit cycle and its effect on the trajectories. 2.34 Find the period of oscillations for the system modeled by x_ 1 ¼ x1 (10 2x2 ) x_ 2 ¼ x2 (4x1 12) when the initial state is (i) x1(0) ¼ 10, x2(0) ¼ 15 and (ii) x1(0) ¼ 4, x2(0) ¼ 6.

2.8 CASE STUDY: SUBMARINE DEPTH CONTROL SYSTEM Automatic depth control of a submarine is the focus of this section. Figure 2.53 illustrates a representative situation, where the actual depth of the submarine, denoted c(t), is measured by a sensor and compared with the desired depth r(t). A simpliﬁed block diagram of the depth control system is shown in Figure 2.54. The error signal e(t) is the difference between the commanded depth r(t) and the actual depth c(t). It is fed back to the controller that sends a signal to the stern plane actuator motor that controls the stern plane actuator angle u(t). The submarine depth responds to changes in the stern plane angle. The controller and stern plane actuator combination are modeled by ð u ¼ KC e þ KI e dt

(2:174)

c(t) Submarine axis Center of gravity Velocity

Stern plane θ(t)

FIGURE 2.53

Depth control of a submarine.

Simulation of Dynamic Systems with MATLAB® and Simulink®

86

e(t)

r(t) Desired depth

FIGURE 2.54

–

Controller and stern plane actuator

θ(t)

Submarine dynamics

c(t) Actual depth

Block diagram of a submarine depth control system.

and the submarine dynamics are approximated by the simple ﬁrst-order model t

dv du þ v ¼ Ku_ þ Ku u dt dt

(2:175)

where v ¼ v(t) is the depth rate of the submarine. Integrating the depth rate yields the depth of the submarine ð c ¼ v dt

(2:176)

The error signal is output from the summer as e¼rc

(2:177)

Equations 2.174 through 2.177 constitute the mathematical model of the simpliﬁed submarine depth control system. The goal is to choose the parameters KC and KI, so that the submarine responds to step changes in commanded depth in an acceptable manner. A simulation diagram of the control system is a useful ﬁrst step in helping choose a set of state variables. Employing the technique discussed in Section 2.4 for drawing a simulation diagram with input derivative terms present, the diagram is shown in Figure 2.55. From the simulation diagram, the state equations are x_ 1 ¼ v ¼ Ku x2 þ Ku_ x_ 2 1 ¼ Ku x2 þ Ku_ (u x2 ) t

(2:178) (2:179)

The stern plane angle u is expressible in terms of the states x1, x2, and x3 and input r by u ¼ KC e þ KI x3 ¼ KC (r x1 ) þ KI x3

Kθ.

KC r

e

∫

x3

θ

KI

1 τ

∫

x2

Kθ

−1 −1

FIGURE 2.55

(2:180)

Simulation diagram of a submarine depth control system.

ν

∫

x1

c

87

Continuous-Time Systems

Combining Equations 2.179 and 2.180 gives 1 {KC (r x1 ) þ KI x3 x2 } t Ku_ KC K_ Ku_ KI Ku_ KC x 1 þ Ku u x 2 þ x3 þ r ) x_ 1 ¼ t t t t 1 x_ 2 ¼ (u x2 ) t 1 ¼ {KC (r x1 ) þ KI x3 x2 } t KC 1 K1 KC x1 x3 þ r x2 þ ) x_ 2 ¼ t t t t x_ 1 ¼ Ku x2 þ Ku_

x_ 3 ¼ r x1

(2:181)

(2:182)

(2:183)

(2:184)

(2:185) (2:186)

Equations 2.182, 2.185, and 2.186 represent the dynamic portion of the state variable model, that is, x_ ¼ Ax þ Br. Choosing the outputs as y1 ¼ u, y2 ¼ v, and y3 ¼ c determines the matrices C and D in the output equation y ¼ Cx þ Dr. y1 ¼ u ¼ KC (r x1 ) þ KI x3 ¼ KC x1 þ KI x3 þ KCr y2 ¼ v ¼ x_ 1 ¼

Ku_ KC Ku_ Ku_ KI Ku_ KC x1 þ Ku x2 þ x3 þ r t t t t y 3 ¼ c ¼ x1

(2:187) (2:188) (2:189) (2:190)

In summary, the state equations are 2 3 3 Ku_ KC Ku_ Ku_ KI 2 3 Ku_ KC K u x1 x_ 1 6 7 6 t t t 7 76 7 6 t 7 6 7 6 6 7 6 x_ 2 7 ¼ 6 6 7 KC 1 K I 7 4 x2 5 þ 6 K C 7 7r 4 5 6 6 7 6 7 4 t 5 4 t t 5 t x3 x_ 3 1 1 0 0 3 2 3 2 3 2 K 0 KI 2 x1 3 KC C u 7 6 7 6 7 6 K _ KC 7 Ku_ KC Ku Ku_ KI 76 7 6v7 ¼ 6 6 x2 7 þ 6 6 7 6 u 7r K u 4 5 4 t 4 5 5 4 t t t 5 c x3 1 0 0 0 2

3

2

(2:191)

(2:192)

The exact solution for the outputs u, v, and c in response to a given depth command r can be approximated by solving a system of difference equations obtained using the same approach we employed on previous occasions, that is, the ﬁrst derivatives x_ 1, x_ 2, x_ 3 in Equation 2.191 are replaced

Simulation of Dynamic Systems with MATLAB® and Simulink®

88

by ﬁrst-order difference quotients, and the resulting difference equations are solved recursively for x1,A(n), x2,A(n), x3,A(n). The result is 2

3 1 2 K K {x1, A (n þ 1) x1, A (n)} u_ C 6T 7 6 7 6 t 61 7 6 6 {x2, A (n þ 1) x2, A (n)} 7 ¼ 6 KC 6T 7 6 6 7 4 t 41 5 1 {x3, A (n þ 1) x3, A (n)} T

Ku_ t 1 t 0

Ku

2K K 3 Ku_ KI 32 u_ C 3 x1, A (n) 6 t 7 t 7 7 76 7 6 7 6 KI 7 74 x2, A (n) 5 þ 6 KC 7r(n) 5 4 t 5 t x3, A (n) 1 0 (2:193)

The difference equations are updated according to Ku_ KC T K_ x1, A (n þ 1) ¼ x1, A (n) x1, A (n) þ Ku_ u Tx2, A (n) t t Ku_ KI T Ku_ KC T x3, A (n) þ r(n) (2:194) þ t t KC T T KI T KC T x2, A (n þ 1) ¼ x2, A (n) x1, A (n) x2, A (n) þ x3, A (n) þ r(n) (2:195) t t t t x3, A (n þ 1) ¼ x3, A (n) Tx1, A (n) þ Tr(n)

(2:196)

From Equation 2.192, the discrete-time outputs are 2

uA (n)

3

2

KC

6 7 6 K _ KC u 6 vA (n) 7 ¼ 6 4 5 6 4 t cA (n) 1

0 Ku 0

32 3 2 K 3 C x1, A (n) 76 6 7 7 Ku_ K1 76 6K K 7 þ 6 u_ C 7r(n) 74 x2, A (n) 7 5 4 t 5 t 5 x (n) 3, A 0 0 K1

Ku_ t

(2:197)

Equations 2.194 through 2.197 are solved recursively in the M-ﬁle ‘‘Chap2_Case_Study.m’’ for the case where r(t) ¼ 100, t 0. The baseline parameter values are Sub dynamics: t ¼ 10 s, Ku_ ¼ 20 ft=s per deg=s, Ku ¼ 10 ft=s per deg Controller gains: KC ¼ 0.6 deg=ft, KI ¼ 0.1 deg=ft s Step size: T ¼ 0.0025 s Graphs of the discrete-time outputs uA(n), vA(n), cA(n) are shown in Figure 2.56. For clarity, every 100th value of discrete-time output is plotted. The discontinuity in stern plane angle u at t ¼ 0 is a consequence of lumping the controller and stern plane actuator dynamics into a single equation as we did in Equation 2.174. The ﬁrst term KCe is responsible for the direct (strictly algebraic) connection from the error e to the stern plane angle u and ultimately from r to u in Figure 2.55. The discontinuity is calculated from u(0) ¼ KC e(0) ¼ KC [r(0) c(0)] ¼ 0:6 deg=ft (100 ft 0) ¼ 60 deg

(2:198)

There is a direct connection from u to v and, therefore, a direct path from r to v explaining the initial jump in depth rate as well. Figure 2.55 shows the term involving Ku_ in the sub dynamics is responsible for this. Exercise 2.36 presents an alternate representation of the stern plane actuator that eliminates the discontinuity in both u and v.

89

Continuous-Time Systems

θA (deg)

100 50 0 −50

0

1

2

3

4

5

6

7

8

9

10

11

12

0

1

2

3

4

5

6

7

8

9

10

11

12

0

1

2

3

4

5

6

7

8

9

10

11

12

vA (ft/s)

200 100 0 −100

cA (ft)

150 100 50 0

t (s)

FIGURE 2.56

Discrete-time approximation of subdepth control system step response.

EXERCISES 2.35 Suppose the model of the controller and stern plane actuator in Equation 2.174 is replaced by the following equation: ð u ¼ KC e þ K1 e(t)dt þ KD

d e(t) dt

The differential equation relating the control system output c(t) and input r(t) is a3 c þ a2€c þ a1 c_ þ a0 c ¼ b3 r þ b2€r þ b1 r_ þ b0 r a3 ¼ t þ KD Ku_

b3 ¼ KD Ku_

a2 ¼ 1 þ KC Ku_ þ KD Ku_ b2 ¼ KC Ku_ þ KD Ku a1 ¼ KC Ku þ KI Ku_ b1 ¼ KC Ku þ KI Ku_ a0 ¼ KI Ku

b0 ¼ KI Ku

(a) Draw a simulation diagram of the system with three integrators in series. (b) Choose the state variables as x1 ¼ z, x2 ¼ z_ , x3 ¼ _z_ where z, z_ , _z_ are the outputs of the integrators. Deﬁne the output as y ¼ c. Find the matrices A, B, C, and D in the state equations. (c) Find the difference equations for the discrete-time states x1,A(n þ 1), x2,A(n þ 1), x3,A(n þ 1) and discrete-time output cA(n) similar to Equations 2.194 through 2.197. (d) Choose the same values for KC and KI used to generate Figure 2.56 along with KD ¼ 0. Solve the difference equations recursively to obtain the sub response y(n) for the same input r(t) and compare your result with the graph for cA(n) in Figure 2.56. (e) Experiment with new values for KC, KI, and KD. Plot the results for cA(n).

Simulation of Dynamic Systems with MATLAB® and Simulink®

90

2.36 The controller and stern plane actuator are modeled separately as shown Figure E2.36:

e

m = KC e + KI ∫ e dt Controller

m

τA dθ + θ = KAm dt

θ

Stern plane actuator

FIGURE E2.36

(a) Redraw the simulation diagram of the subdepth control system. Comment on whether m, u, or v is discontinuous at t ¼ 0 when the commanded depth r(t) is a step input. (b) Determine the state variables and ﬁnd the new matrices A, B, C, and D in the state equations assuming the output vector y ¼ [m u v c]T.

3

Elementary Numerical Integration

3.1 INTRODUCTION Dynamic systems with continuous-time models in the form of differential equations possess memory. For systems with memory, knowledge of the system’s inputs at a given point in time is insufﬁcient to determine the state of the system at the same time. For example, a circuit with capacitors and inductors possesses memory. The instantaneous energy stored in the circuit is a function of the current state (capacitor voltages and inductor currents), which depends on the history of its sources (inputs) from the time when the complete state was last known. An nth-order dynamic system with state variables x1, x2, . . . , xn and input u1, u2, . . . , um is modeled by expressions for the state derivatives, that is, 3 dx1 6 dt 7 7 6 6 dx 7 6 27 7 6 dt 7 ¼ f (x, u) x_ (t) ¼ 6 7 6 6 .. 7 6 . 7 7 6 4 dx 5 n dt 2

(3:1)

where 2

3 x1 6 x2 7 6 7 x ¼ 6 .. 7, 4 . 5 xn

2

3 2 3 f1 (x, u) u1 6 u2 7 6 f2 (x, u) 7 6 7 6 7 u ¼ 6 .. 7, f (x, u) ¼ 6 . 7 4 . 5 4 .. 5 um

(3:2)

fn (x, u)

In a formal sense, n distinct integrations are required to obtain the state x, namely ðt

x1 (t) ¼ x1 (t0 ) þ f1 (x, u)dt 0

(3:3)

t0

ðt

x2 (t) ¼ x2 (t0 ) þ f2 (x, u)dt 0

(3:4)

t0

ðt

xn (t) ¼ xn (t0 ) þ fn (x, u)dt 0

(3:5)

t0

91

Simulation of Dynamic Systems with MATLAB® and Simulink®

92

For time-varying systems, a number of the system parameters are explicit functions of time. For example, the amount of fuel in a rocket or aircraft diminishes with time, thereby affecting its dynamic properties. The state derivative vector is generally denoted by f(t, x, u), and Equations 3.3 through 3.5 are more appropriately expressed as ðt

x1 (t) ¼ x1 (t0 ) þ f1 (t 0 , x, u)dt 0

(3:6)

t0

ðt

x2 (t) ¼ x2 (t0 ) þ f2 (t 0 , x, u)dt 0

(3:7)

t0

ðt

xn (t) ¼ xn (t0 ) þ fn (t 0 , x, u)dt 0

(3:8)

t0

Equations 3.3 through 3.8 remind us that if we know the complete state at some initial time t0, then at some future time t, the state can be determined provided we know the inputs from t0 to t. The n integrals to be evaluated in Equations 3.3 through 3.8 constitute the process of advancing or updating the state through time. This chapter looks at various alternatives for approximating these integrals.

3.2 DISCRETE-TIME SYSTEM APPROXIMATION OF A CONTINUOUS-TIME INTEGRATOR The continuous-time integrator shown in Figure 3.1 is a special case of a ﬁrst-order dynamic system in which the state derivative function is equal to the system input. dx ¼ f (x, u) ¼ f (u) ¼ u(t) dt

(3:9)

Alternatively, it can be thought of as the simple linear ﬁrst-order system d x(t) þ a0 x(t) ¼ Ku(t) dt

(3:10)

discussed in Section 2.2 where a0 ¼ 0 and K ¼ 1. The solution for x(t) is given by ðt x(t) ¼ x(t0 ) þ u(t 0 )dt 0

(3:11)

t0

where t0 is some initial time x(t0) is the initial state

u(t)

FIGURE 3.1 A continuous-time integrator.

dx = u(t) dt

x(t)

93

Elementary Numerical Integration

Example 3.1 The input to an integrator is u(t) ¼ A sin vt, t 0. Find the output if x(0) ¼ 0. ðt x(t) ¼ 0 þ u(t0 )dt0

(3:12)

0

ðt ¼ A sin vt0 dt0

(3:13)

t 1 A ¼ A cos vt0 ¼ (1 cos vt) v v 0 0

(3:14)

The continuous-time input u(t) and the integrator output are graphed in Figure 3.2 for the case where the amplitude A is unit and the radian frequency v ¼ 2p rad=s. The integrator output at any point in time t1 is simply the area under the input from t ¼ 0 to t ¼ t1. The output and corresponding area are shown in Figure 3.2 for t1 ¼ 0.4. System simulation using analog computers was popular years ago. They were capable of implementing Equation 3.11 using electronic components (operational ampliﬁers, resistors, capacitors, and potentiometers). In fact, an analog computer simulation diagram is similar to the simulation diagram presented in the previous chapter. However, there are a number of hardware-related issues inherent in analog simulation, not present with digital simulation. The popularity and widespread use of digital computers has produced a shift from analog to digital as the primary means of continuous-time system simulation. Digital computers, however, are sequential machines. Unlike analog computers, they are not capable of solving Equations 3.3 through 3.5 in a continuous fashion. Digital simulation of continuous-time systems relies on numerical algorithms to approximate the integral of the state derivative function using sampled values at discrete points in time. Figure 3.3 illustrates the process for the simple integrator in Equation 3.9. The approximation block in Figure 3.3 is a discrete-time system with input u(nT ) and output xA(nT) designed to approximate the output of the continuous-time integral x(t). A difference equation for the discrete-time system is needed. Integrator input u(t) = sin 2πt 1

u(t)

0.5 0 −0.5 −1 0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0.8

0.9

1

Integrator output x(t) = (1−cos 2πt)/2π 0.4 Area under input from t = 0 to t = 0.4

x(t)

0.3 0.2 0.1 0

0

0.1

0.2

0.3

0.4

0.5 t

0.6

0.7

FIGURE 3.2 Continuous-time integrator u(t) ¼ sin 2pt, x(t) ¼ (1 cos 2pt)=2p.

Simulation of Dynamic Systems with MATLAB® and Simulink®

94 u(t)

x(t) = ∫u(t)dt

∫ T

u(nT )

Discrete-time approximation of integral

xA(nT ), n = 0, 1, 2, 3, ...

FIGURE 3.3 A continuous-time integrator and a discrete-time approximation. u(t)

u(n) u(n + 1)

0

T

nT (n + 1)T

2T

FIGURE 3.4 Interval of integration with subintervals of width T. We begin by dividing the interval 0 to (n þ 1)T into n þ 1 equal subintervals of width T as shown in Figure 3.4. Note that u(n) and u(n þ 1) are short for u(nT ) and u[(n þ 1)]T. The integral of a continuous-time function u(t) over the interval 0 to (n þ 1)T is equal to the area bounded by the function and the t-axis. Dividing the area into two pieces gives (nþ1)T ð

nT ð

u(t)dt ¼ 0

(nþ1)T ð

u(t)dt þ 0

u(t)dt

(3:15)

nT

The integrals in Equation 3.15 with lower limits of zero represent the output of a continuous integrator with input u(t) and both t0 and x(t0) equal to zero (see Equation 3.11). Consequently, Equation 3.15 is expressible as (nþ1)T ð

x[(n þ 1)T ] ¼ x(nT) þ

u(t)dt

(3:16)

nT

Several algorithms for approximating the integral in Equation 3.16 (shaded area in Figure 3.4) are presented in the following section. Each algorithm will result in a unique difference equation relating the discrete-time input u(nT ) and discrete-time output xA(nT ) shown in Figure 3.3. The resulting discrete-time systems are the foundation of our venture into the ﬁeld of numerical integration.

EXERCISES 3.1 Consider the ﬁrst-order system d y(t) þ a0 y(t) ¼ u(t) dt (a) Find the response of the system to a step input u(t) ¼ 1, t 0. (b) Find the response of the system to a ramp input u(t) ¼ t, t 0. (c) In the limit as a0 approaches zero, the ﬁrst-order system reduces to a pure Ð t integrator.Ð Show t that the step and ramp responses in parts (a) and (b) approach 0 1 dt 0 and 0 t 0 dt 0 , respectively.

95

Elementary Numerical Integration

3.2 The signal u(t) ¼ c0 þ c1(t t0)2, t 0 in Figure E3.2 is input to a system governed by dy=dt ¼ u(t), that is, a continuous-time integrator:

Input u(t) 15

u(t)

10

B 5

D C

0

0

1

A 2

3

4

F 5 t

E 6

7

8

9

10

FIGURE E3.2

The change in output y(t) from t ¼ t0 to t ¼ t0 þ D1 to t ¼ t0 þ D2 is of interest. Using the values c0 ¼ 2, c1 ¼ 1=2 t0 ¼ 5, D1 ¼ 3, and D2 ¼ 2, approximate the difference y(t0 þ D2) y(t0 D1) (a) By replacing u(t) with a piecewise linear function u1(t) through points B and C, and C and D and then integrating u1(t) between appropriate limits (b) As the areas of trapezoids ABCF and CDEF (c) By comparing your answers in parts (a) and (b) to the true value t0 þD ð 2

y(t0 þ D2 ) y(t0 D1 ) ¼

u(t)dt t0 D1

3.3 A tank with cross-sectional area A1 and resistance R1 empties into a second tank with crosssectional area A2. The ﬁrst tank has no inﬂow and is initially ﬁlled to a height h1(0). The second tank is initially empty and has no outﬂow. The ﬂow between the tanks is denoted by f1(t), and the tank levels are h1(t) and h2(t). (a) Find the ﬁrst-order differential equations for f1(t) and h2(t). (b) Show that the second tank is an integrator. (c) Find expressions for the transient responses of f1(t) and h2(t). (d) For system parameter values A1 ¼ 100 ft2, R1 ¼ 0.25 ft per ft3=min, A2 ¼ 50 ft2, and h1(0) ¼ 20 ft, the responses f1(t) and h2(t) are plotted in Figure E3.3. Estimate the level in tank 2 after 50 min by approximating the area under f1(t), 0 t 50 and dividing by A2. Approximate the area using simple geometric shapes like rectangles and trapezoids. (e) Compare your answer from part (d) with the true value h2(50).

Simulation of Dynamic Systems with MATLAB® and Simulink®

96

f1(t), (cu ft per min)

f1(t) vs. t 80 60

t

Area = ∫ f1(t)dt

40

0

20 0

0

10

20

30

40

50

60

70

80

90

100

h2(t) vs. t

h2(t), (ft)

40

h2(50)

30 20

h2(50) = 1 × Area A2

10 0

0

10

20

30

40

50 t (min)

60

70

80

90

100

FIGURE E3.3

3.3 EULER INTEGRATION The previous section presented a framework for ﬁnding a discrete-time system approximation of a continuous-time integrator. An approximation to the integral term in Equation 3.16 is needed. The simplest approach assumes the integrator input u(t) is constant over the interval, that is, u(t) u(n), nT t (n þ 1)T where u(n) is short for u(nT ) as shown in Figure 3.5. The exact area under the function u(t), nT t (n þ 1)T is being approximated by the area of the rectangle shown in Figure 3.5. Hence, Equation 3.16 becomes x[(n þ 1)T] x(nT) þ Tu(n)

(3:17)

A difference equation results if we denote the approximation to x(nT) by xA(n). By implication, x[(n þ 1)T ] is approximated by xA(n þ 1) and the difference equation reads xA (n þ 1) ¼ xA (n) þ Tu(n)

u(n − 1)

u(n)

u(n + 1)

(3:18)

u(t)

(n+1)T

Approximation of

∫ nT

(n − 1)T nT

(n + 1)T

FIGURE 3.5 Approximation of area under u(t) assuming u(t) u(nT ).

t

u(t)dt

97

Elementary Numerical Integration

Equation 3.18 is the difference equation of a numerical integrator that can be solved recursively to generate an approximation to the continuous-time integrator output x(t) at discrete points in time, that is, xA (n) x(nT), n ¼ 0, 1, 2, . . .

(3:19)

The discrete-time system modeled in Equation 3.18 is commonly referred to as an Euler or rectangular integrator. The subinterval width T is termed the integration step size. Euler integration can be derived by means other than approximating the integral in Figure 3.5 as the area of a rectangle. Alternatively, Euler integration is a consequence of assuming that the state derivative function is constant during each integration step. The starting point is the equation for the state derivative of a pure integrator dx ¼ f (x, u) ¼ u(t) dt

(3:20)

with initial condition x(0) and input u(t) known at the beginning of each integration step. Calculating the initial state derivative, dx (0) ¼ f [x(0), u(0)] ¼ u(0) dt

(3:21)

The approximation to the continuous-time state x(t) is updated under the assumption the derivative dx(0)=dt remains constant over the integration time step, that is, xA (T) ¼ x(0) þ T

dx (0) dt

¼ x(0) þ Tu(0)

(3:22) (3:23)

The situation is illustrated in Figure 3.6. The estimate xA(T ) is the result of ‘‘riding’’ the tangent to x(t) from the initial point x(0) to the end of the interval. The process is repeated to generate the updated states xA(2T ), xA(3T ), etc. A similar graphical interpretation applies with the exception that subsequent movements along the computed directions start from the approximate values xA(T ), xA(2T ), . . . as opposed to the actual points x(T ), x(2T ), . . . on the solution x(t). The result for xA(2T ) is xA (2T) ¼ xA (T) þ T

dx (T) dt

¼ xA (T) þ Tu(T)

(3:24) (3:25)

Based on Equations 3.23 and 3.25, it follows that the (n þ 1)st state update is xA [(n þ 1)T] ¼ xA (nT) þ Tu(nT)

(3:26)

Dropping T from the arguments in Equation 3.26 yields a result identical to Equation 3.18. The two ways of deriving the difference equation for Euler integration are essentially the same. Approximating the shaded area in Figure 3.5 by a rectangle stems from assuming that the integrator input u(t) is constant over each integration step. However, the derivative is equal to the input for a pure integrator. Hence, assuming that the input is constant is equivalent to making the same assumption about the derivative.

Simulation of Dynamic Systems with MATLAB® and Simulink®

98

u(t) u(3T ) u(2T )

u(T ) u(0)

t

dx (2T ) dt

dx (T ) dt

dx (0) dt

dx (0) = f [x(0), u(0)] = u(0) dt dx (T ) = f [x(T), u(T)] = u(T ) dt dx (2T ) = f [x(T ), u(2T )] = u(2T ) dt t x(t) xA(3T )

xA(T ) = x(0) + T · u(0) xA(2T ) = xA(T ) + T · u(T ) xA(3T ) = xA(2T ) + T · u(2T )

xA(2T ) xA(T )

x(0) 0

T

2T

3T

t

FIGURE 3.6 Euler approximation of continuous-time integrator dx=dt ¼ u(t).

According to Equation 3.18, the Euler integrator simply adds a rectangular area Tu(n) to the current state xA(n) to produce the updated state xA(n þ 1). A general formula for xA(n þ 1) is easily obtained by observing xA (1) ¼ xA (0) þ Tu(0)

(3:27)

xA (2) ¼ xA (1) þ Tu(1)

(3:28)

¼ [xA (0) þ Tu(0)] þ Tu(1)

(3:29)

¼ xA (0) þ T[u(0) þ u(1)]

(3:30)

leading to the general result xA (n þ 1) ¼ x(0) þ T[u(0) þ u(2) þ þ u(n 1) þ u(n)] ¼ x(0) þ T

n X

u(k)

(3:31) (3:32)

k¼0

The simplistic nature of Equation 3.32 results from the simple model describing the state derivative of a pure integrator, that is, dx=dt ¼ u(t).

99

Elementary Numerical Integration

Example 3.2 The input to a continuous-time integrator is a sinusoidal function u(t) ¼ sin 2pt, 0 t 0.5. The initial condition is x(0) ¼ 0. (a) Use Euler integration with a step size T ¼ 0.05 s to approximate the integrator output x(t) at t ¼ 0.1, 0.2, . . . , 0.5 s. (b) Compare your answers for xA(n) from part (a) with the continuous-time integrator output x(t) at t ¼ 0.1, 0.2, . . . , 0.5 s. xA (n þ 1) ¼ xA (n) þ Tu(n), n ¼ 0, 1, 2, 3, . . . ¼ xA (n) þ T sin (2p nT) n ¼ 0, 1, 2, 3, . . .

(a)

n ¼ 0:

xA (1) ¼ xA (0) þ Tu(0) ¼ 0 þ 0:05{[ sin (2p)(1)(0:05)]} ¼0

n ¼ 1:

xA (2) ¼ xA (1) þ Tu(1) ¼ 0 þ 0:05{[ sin (2p)(1)(0:05)]} ¼ 0:0155

n ¼ 2:

xA (3) ¼ xA (2) þ Tu(2) ¼ 0:0155 þ 0:05{[ sin (2p)(2)(0:05)]} ¼ 0:0448

The process is continued for n ¼ 3, 4, . . . , 9 in order to obtain the required estimates of x(t) at 0.1 s intervals. The results are tabulated in column 3 of Table 3.1. (b) The exact values for x(t) are calculated using Equation 3.14 with A ¼ 1 and v ¼ 2p (see last column in Table 3.1).

3.3.1 BACKWARD (IMPLICIT) EULER INTEGRATION If we can approximate the integrator input u(t) by its numerical value at the beginning of an integration interval (see Figure 3.5), then we should be able to choose another value of the input at a different point in time within the interval. Two other points on the interval appear to be logical choices. One is the midpoint and the other is the endpoint of the interval. The latter choice will now be explored.

TABLE 3.1 Outputs of Euler Integrators (T ¼ 0.05) and Continuous-Time Integrator N

Forward Euler tn ¼ nT

Backward Euler xA(n)

Continuous-Time xA(n)

x(tn)

0 2 4 6 8 10

0 0.1 0.2 0.3 0.4 0.5

0 0.0155 0.0853 0.1828 0.2708 0.3157

0 0.0448 0.1328 0.2304 0.3002 0.3157

0 0.0304 0.1100 0.2083 0.2879 0.3183

Simulation of Dynamic Systems with MATLAB® and Simulink®

100

Referring to Figure 3.5, suppose the input u(t) is assumed equal to u(n þ 1) instead of u(n) in the interval nT t (n þ 1)T. The area of the rectangular strip intended to approximate the true area under the input is now Tu(n þ 1), that is, (nþ1)T ð

u(t)dt Tu(n þ 1)

(3:33)

nT

resulting in the numerical integrator xA (n þ 1) ¼ xA (n) þ Tu(n þ 1)

(3:34)

Since the input is assumed constant over the integration interval, Equation 3.34 is also a difference equation for an Euler integrator. It differs from the previous Euler integrator in Equation 3.18 in that u(n þ 1) replaces u(n) in the calculation of the new state xA(n þ 1). The numerical integrator in Equation 3.18 is referred to as forward Euler whereas the difference equation in Equation 3.34 is that of a backward Euler integrator. Unlike a pure continuous-time integrator, the derivative dx=dt of ﬁrst and higher order systems is dependent on the state x(t) and possibly one or more inputs. Difference equations for updating the discrete-time state using Euler integration depend on whether forward or backward integration is used. The two cases are Forward Euler: xA (n þ 1) ¼ xA (n) þ Tf [(xA (n), u(n)]

(3:35)

Backward Euler: xA (n þ 1) ¼ xA (n) þ Tf [(xA (n þ 1), u(n þ 1)]

(3:36)

Equation 3.36 leads to implicit algebraic equations involving xA(n þ 1), which, depending on the state derivative function f (x, u), may be difﬁcult or impossible to solve analytically. For this reason, the backward Euler integrator in Equation 3.34 is also known as implicit Euler integration and the forward Euler integrator in Equation 3.18 is called explicit Euler integration. Example 3.3 Rework Example 3.2 using the backward Euler integrator. xA (n þ 1) ¼ xA (n) þ Tu(n þ 1), n ¼ 0, 1, 2, 3, . . . ¼ xA (n) þ T sin [2p(n þ 1)T], n ¼ 0, 1, 2, 3, . . . n ¼ 0:

n ¼ 1:

xA (1) þ xA (0) þ Tu(1) ¼ 0 þ 0:05{ sin [(2p)(1)(0:05)]} ¼ 0:0155

xA (2) ¼ xA (1) þ Tu(2) ¼ 0:0155 þ 0:05{[ sin (2p)(2)(0:05)] ¼ 0:0448

The remaining values are presented in column 4 of Table 3.1. Both numerical integrators produce signiﬁcant errors in comparison to the analytical solution. Greater accuracy is possible by reducing the integration step size. The trade-off is, of course, the additional computations required.

101

Elementary Numerical Integration

EXERCISES 3.4 In Examples 3.2 and 3.3, (a) Explain why the implicit Euler integrator produces higher estimates of the continuous-time integrator output than the explicit Euler integrator. Is this true in general? (b) Find xA(5) for both numerical integrators and compare the results to x(0.25). Explain why both integrators incur the maximum error jx(nT) xA(n)j for n ¼ 5. (c) Repeat Examples 3.2 and 3.3 with a step size T ¼ 0.01. Enter the numerical results in a table rounded to six places after the decimal point. 3.5 The RC circuit shown in Figure E3.5 is a ﬁrst-order low-pass ﬁlter. The differential equation relating the output voltage v0(t) and input voltage vi(t) is RC

dv0 þ v0 ¼ vi dt

A discrete-time integrator is used to approximate the continuous output v0(t) when the input vi(t) is an AC signal sin vt. R = 10 kΩ

νi(t)

C = 0.1 μF

ν0(t)

FIGURE E3.5

(a) Find the difference equation used to obtain v0, A(n) if forward Euler integration is used with a step size of T. (b) For vi(t) ¼ sin vt, ﬁnd and plot v0, A(n) corresponding to 0 n 4 p=vT when (i) v ¼ 100 rad=s, T ¼ RC=10 (ii) v ¼ 1000 rad=s, T ¼ RC=100. 3.6 The ﬂow out of the tank shown in Figure E3.6 is given by F0 ¼ cH1=2. The cross-sectional area of the tank A ¼ 50 ft2 and the constant c ¼ 2 ft3=min per ft1=2. The tank is 25 ft in height and the initial level in the tank H(0) ¼ 16 ft. F1(t)

A

H(t) F0(t)

FIGURE E3.6

(a) The ﬂow into the tank is F1(t) ¼ F 1 ¼ 10 ft3 = min, t 0. Find the steady-state height of liquid in the tank, H(1). (b) Use forward Euler integration with a suitable step size and compare limn!1 HA (n) with the result from part (a). (c) The ﬂow into the tank is F1(t) ¼ 4 þ (t=10), t 0. Use forward Euler integration with a step size T and ﬁnd the difference equation for updating the state HA(n). Leave your answer in terms of c, A, and T.

Simulation of Dynamic Systems with MATLAB® and Simulink®

102

(d) For the input ﬂow rate in part (c), using forward Euler integration with T ¼ 0.1 min, ﬁnd nf, where nfT is the time required to ﬁll the tank, that is, HA(nf 1) < 25 and HA(nf ) 25. Plot the results. 3.7 The input to the integrator shown in Figure E3.7 is the continuous-time signal u(t) ¼ 1=(t þ 1), t 0: u(t)

∫

x(t)

FIGURE E3.7

(a) Find the difference equation for computing the state xA(n) recursively when implicit Euler integration with a step size T is used. (b) Find xA(1), xA(2), and xA(3) if T ¼ 0.1. (c) Compare your answer for xA(3) to the exact value x(3T ). ðt Note:

(t 0

1 ¼ 1n(1 þ t): þ 1)dt 0

0

3.4 TRAPEZOIDAL INTEGRATION Of the numerical integrators, the Euler integrators are the simplest to implement; however, for a given integration step size, they are also the least accurate. This is not necessarily a reason to choose another integrator since any desired level of accuracy is achievable with Euler integrators (in principle) simply by reducing the step size and performing additional calculations. Indeed, the simplicity of Euler integration is responsible for its widespread use in far-ranging applications. There may be circumstances that dictate the integration step size in a simulation study and thus compel the developer to consider other methods for approximating the dynamics of a continuoustime system. Accordingly, we shall investigate other formulas and algorithms for numerical integration. Starting with (nþ1)T ð

xA (n þ 1) ¼ xA (n) þ estimate of

u(t)dt

(3:37)

nT

a more accurate (compared with Euler integration) estimate of the integral in Equation 3.37 is attainable by approximating the input u(t) by a piecewise linear function u1(t) where u1 (t) ¼ u(n) þ

u(n þ 1) u(n) (t nT), T

nT t (n þ 1)T

(3:38)

as shown in Figure 3.7. It is left as an exercise to show that (nþ1)T ð

u1 (t)dt ¼ nT

T [u(n) þ u(n þ 1)] 2

(3:39)

103

Elementary Numerical Integration u(n + 1) u(n)

u(t) u(n − 1)

(n+1)T

Approximation of

∫

u(t)dt

nT

(n − 1)T nT

(n + 1)T

t

FIGURE 3.7 Trapezoidal approximation of area under u(t), nT t (n þ 1)T.

The shaded area in Figure 3.7 used to approximate the true area under the input u(t) is a trapezoid (rotated 908) with bases u(n) and u(n þ 1) and height of T. The expression on the right-hand side of Equation 3.39 is simply the area of the corresponding trapezoid. Using the trapezoidal approximation, Equation 3.37 becomes xA (n þ 1) ¼ xA (n) þ

T [u(n) þ u(n þ 1)] 2

(3:40)

Equation 3.40 is known as trapezoidal integration. Similar to backward Euler integration, the difference equation leads to an implicit algebraic equation in xA(n þ 1) for all continuous-time systems other than a pure integrator. Example 3.4 demonstrates the use of trapezoidal integration to approximate a deﬁnite integral. The integrand can be thought of as the input u(t) to a continuous-time integrator, while xA(n) n ¼ 0, 1, 2, 3, . . . represents the discrete-time approximation to the output x(t), at t ¼ nT, n ¼ 0, 1, 2, 3, . . . Example 3.4 Ðt 0 Approximate the deﬁnite integral x(t) ¼ 0 e2t dt0 at t ¼ 0, 1, 2, 3, . . . , 1.0 using trapezoidal integration with an integration step size T ¼ 0.1.

u(n) ¼ utjt¼nT ¼ e2t t¼nT ¼ e2nT

u(n þ 1) ¼ u(t)jt¼(nþ1)T ¼ e2t t¼(nþ1)T ¼ e2(nþ1)T

(3:41) (3:42)

From Equation 3.40, xA (n þ 1) ¼ xA (n) þ

T 2nT þ e2(nþ1)T e 2

Setting xA(0) ¼ x(0) ¼ 0, n ¼ 0: n ¼ 1:

xA (1) ¼ 0 þ

0:1 2(0)(0:1) þ e2(0þ1)(0:1) ¼ 0:09093654 e 2

xA (2) ¼ xA (1) þ

0:1 2(1)(0:1) þ e2(1þ1)(0:1) ¼ 0:16538908 e 2

(3:43)

Simulation of Dynamic Systems with MATLAB® and Simulink®

104

TABLE 3.2 Approximations to a Deﬁnite Integral Using Three Numerical Integrators (Explicit and Implicit Euler, Trapezoidal) and the Exact Solution

n

tn ¼ nT

Euler (Explicit) xA(n)

0 1 2 3 4 5 6 7 8 9 10

0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

0.0 0.10000000 0.18187308 0.24890508 0.30378624 0.34871914 0.38550708 0.41562651 0.44028620 0.46047585 0.47700574

Euler (Implicit) xA(n)

Trapezoidal xA(n)

Exact x(tn)

0.0 0.08187308 0.14890508 0.20378624 0.24871914 0.28550708 0.31562651 0.34028620 0.36047585 0.37700574 0.39053927

0.0 0.09093654 0.16538908 0.22634566 0.27625269 0.31711311 0.35056679 0.37795635 0.40038103 0.41874080 0.43377251

0.0 0.09063462 0.16483998 0.22559418 0.27533552 0.31606028 0.34940289 0.37670152 0.39905174 0.41735056 0.43233236

The remaining values xA(3), xA(4), . . . , xA(10) are calculated in the same manner and shown in Table 3.2, which also includes the results obtained using both types of Euler integrators. The last column contains the exact values of the deﬁnite integral, ðt

0

x(t) ¼ e2t dt0 ¼ 0

2t0 t e 1 ¼ (1 e2t ) 2 0 2

(3:44)

For the same step size, the trapezoidal integrator is superior to the Euler integrators. An advantage of trapezoidal integration compared with Euler is the increased step size that can be used while maintaining comparable accuracy. The following example illustrates the use of trapezoidal integration for a ﬁrst-order system modeled by a differential equation with time-varying parameters.

Example 3.5 A nonlinear, time-varying dynamic system is modeled by the differential equation t2

dy dy þ y þ 2ty ¼ u(t) dt dt

(3:45)

(a) Find the difference equation of the discrete-time system based on trapezoidal integration for approximating the response of the continuous-time system. (b) Solve the difference equation for yA(n), n ¼ 0, 1, 2, . . . when the continuous-time input is u(t) ¼ 3t 2=2. The initial condition is y(0) ¼ 1 and the step size is T ¼ 0.01. (c) Plot the discrete-time response yA(n), n ¼ 0, 1, 2, . . . , 100 and the exact solution y(t) ¼ t 2 þ (t4 t3 þ 1)1=2, 0 t 1 on the same graph.

105

Elementary Numerical Integration (a) Solving for the state derivative, dy 1 [u(t) 2ty(t)] ¼ f (t, y, u) ¼ 2 dt t þ y(t)

(3:46)

From Equation 3.40 with u replaced by the derivative function f(t, y, u), the difference equation for trapezoidal integration is T yA (n þ 1) ¼ yA (n) þ {f [nT, yA (nT ), u(nT )] þ f [nT þ T, yA (nT þ T ), u(nT þ T )]} 2 T 1 [u(n) 2(nT )yA (n)] ¼ yA (n) þ 2 (nT )2 þ yA (n)

1 [u(n þ 1) 2[(n þ 1)T ]y þ (n þ 1)] A [(n þ 1)T ]2 þ yA (n þ 1)

(3:47)

(3:48)

(b) Equation 3.48 is an implicit equation for yA(n þ 1), which generally means some type of iterative, numerical root-solving algorithm is required to ﬁnd yA(n þ 1) at each time step. This can increase the computational requirements dramatically, not to mention the additional programming required to implement the algorithm. In this example, however, Equation 3.48 can be manipulated to produce a quadratic function of the form a[yA (n þ 1)]2 þ byA (n þ 1) þ c ¼ 0

(3:49)

where a, b, and c are expressible in terms of u(n), yA(n), and u(n þ 1), all of which can be calculated at time tn ¼ nT. ‘‘Chap3_Ex4_2.m’’ includes the statements to determine a, b, and c and solve Equation 3.49 at each time step for the positive root. (c) The approximate and exact solutions are shown in Figure 3.8. The exact continuous-time response y(t) and the approximate discrete-time response yA(n) are indistinguishable from each other at times tn ¼ nT, n ¼ 0, 1, 2, . . . , 100. Let us not forget that the discrete-time signal yA(n) is deﬁned solely at the discrete times 0, T, 2T, 3T, . . . , which explains why discrete-time signals should always be plotted as discrete data points. A dotted line should be used whenever the points are connected to emphasize this point.

1 yA(n)

0.9

y(t)

0.8 0.7 0.6 0.5 0.4 T = 0.01

0.3 0.2 0.1 0 0

0.1

0.2

0.3

0.4

0.5 t

0.6

0.7

0.8

0.9

FIGURE 3.8 Graph of approximate (trapezoidal integration) and exact solutions.

1

Simulation of Dynamic Systems with MATLAB® and Simulink®

106

EXERCISES 3.8 Referring to Figure 3.7, (a) Find the equation of the linear approximation u1(t) through the end points [nT, u(n)] and [(n þ 1)T, u(n þ 1)]. (b) Verify Equation 3.39 by integrating u1(t) from nT to (n þ 1)T. 3.9 The ﬁrst-order system dx=dt ¼ lx with initial condition x(0) ¼ x0 is to be simulated using trapezoidal integration with step size T. The truncation error after n steps is en ¼ xA(n) x(nT ), where x(t), t 0 is the exact solution and xA(n), n ¼ 0, 1, 2, . . . is the approximate (simulated) solution, that is, xA(n) x(nT ), n ¼ 0, 1, 2, 3, . . . . Suppose the truncation error after the ﬁrst step is equal to a fraction of the initial condition, that is, e1 ¼ xA (1) x(T) ¼ ax0

(0 < a 1)

lT satisﬁes the condition elT ¼

alT þ b lT þ c

Express the constants a, b, and c in terms of a and x0. 3.10 The population of a city P(t) is modeled by the differential equation dP=dt ¼ kP. (a) Find the equation for updating PA(n), the approximate population at the end of year nT, using trapezoidal integration with step size T. Leave your answer in terms of k and T. (b) Suppose k ¼ 0.01 people=year per person, the initial population is one million people and the step size T ¼ 1 year. Find PA(1) and PA(2) to the nearest person. (c) Find the general solution for PA(n) and use it to ﬁnd PA(100). (d) Compare the result from part (c) to the exact value P(100). 3.11 The mass m in Figure E3.11 is subjected to a time-varying damping force fd (t). The differential equation describing the motion is m(d=dt)v(t) ¼ fd (t) where v(t) is the velocity of the mass and fd (t) ¼ [t=(1 þ t)]v(t). (a) Use trapezoidal integration with suitable step size T to approximate the velocity v(t), t 0. Note that m ¼ 1 slug and the initial velocity v(0) ¼ 10 ft=s. (b) Compare the simulated response vA(n), n ¼ 0, 1, 2, . . . in part (a) to the exact solution v(t) ¼ 10(1 þ t)et, t 0. v(t) m

fd(t)

FIGURE E3.11

3.12 Find the largest step size T in Example 4.5 for which jy(nT) yA (n)j < 0:005,

n ¼ 0, 1, 2, . . . , 1=T

107

Elementary Numerical Integration

3.5 NUMERICAL INTEGRATION OF FIRST-ORDER AND HIGHER CONTINUOUS-TIME SYSTEMS The trapezoidal and two Euler integrators developed in the previous two sections were used to approximate the dynamics of the ﬁrst-order system described by dx ¼ f (x, u) ¼ u dt

(3:50)

that is, a continuous-time integrator. We now consider the more general case when the state derivative function f(x, u) is a function of the state x as well as the input u. For example, dx ¼ f (x, u) ¼ b0 u a0 x dt

(3:51)

In the case of Euler integrators, the state derivative function f (x, u) is assumed constant over the time interval corresponding to a single integration step. This assumption is responsible for Equations 3.35 and 3.36, which are repeated in Equations 3.52 and 3.55. The two equations are the starting points for deriving the difference equations for Euler integration to approximate the ﬁrst-order system in Equation 3.51. Explicit Euler: xA (n þ 1) ¼ xA (n) þ Tf [xA (n), u(n)]

(3:52)

¼ xA (n) þ T[b0 u(n) a0 xA (n)]

(3:53)

) xA (n þ 1) (1 a0 T)xA (n) ¼ b0 Tu(n)

(3:54)

Implicit Euler: xA (n þ 1) ¼ xA (n) þ Tf [xA (n þ 1), u(n þ 1)]

(3:55)

¼ xA (n) þ T[b0 u(n þ 1) a0 xA (n þ 1)]

(3:56)

) (1 þ a0 T)xA (n þ 1) xA (n) ¼ b0 Tu(n þ 1)

(3:57)

Note that xA(n þ 1) in Equation 3.52 is expressed explicitly in terms of xA(n) in contrast to Equation 3.55, which is an implicit equation with xA(n þ 1) appearing on both sides. In the case of nonlinear systems, f (x, u) is a nonlinear function of x, and the implicit equation is more of a challenge to solve for xA(n þ 1) than is the explicit equation. For a linear ﬁrst-order system, Equation 3.57 is easily solvable for xA(n þ 1) resulting in xA (n þ 1) ¼

1 [xA (n) þ b0 Tu(n þ 1)] 1 þ a0 T

(3:58)

3.5.1 DISCRETE-TIME SYSTEM MODELS FROM SIMULATION DIAGRAMS Recall that a simulation diagram represents the dynamics of a continuous-time system as a connection of algebraic blocks and integrators. Discrete-time systems for approximating the behavior of continuous-time systems can be obtained by replacing the continuous-time integrators with discrete-time (numerical) integrators. The continuous-time signals are converted to discrete-time signals. To illustrate the process, consider the ﬁrst-order system modeled by Equation 3.51. The simulation diagram is shown in Figure 3.9.

Simulation of Dynamic Systems with MATLAB® and Simulink®

108

. x(t)

b0

u(t)

∫

x(t)

−a0

FIGURE 3.9 Simulation diagram of ﬁrst-order system: dx=dt ¼ f(x, u) ¼ b0u a0x.

b0

u(n)

z(n)

Discrete-time integrator

xA(n)

−a0

FIGURE 3.10

Discrete-time system approximation of ﬁrst-order continuous-time system.

The discrete-time system approximation is shown in Figure 3.10. The continuous-time integrator is replaced by a discrete-time integrator, and all signals are discrete time. The input to the discretetime integrator is labeled z(n) for convenience. The difference equation of the discrete-time integrator in Figure 3.10 depends on which numerical integrator is chosen to approximate the continuous-time integrator. For an explicit Euler integrator with input z(n) and output xA(n), xA (n þ 1) ¼ xA (n) þ Tz(n)

(3:59)

z(n) ¼ b0 u(n) a0 xA (n)

(3:60)

where z(n) is given by

Substitution of Equation 3.60 into Equation 3.59 results in the explicit Euler integrator in Equation 3.53. For an implicit Euler integration, the continuous-time integrator is replaced by a discrete-time integrator block described by xA (n þ 1) ¼ xA (n) þ Tz(n þ 1)

(3:61)

With z(n) given by Equation 3.60, it follows that z(n þ 1) ¼ b0 u(n þ 1) a0 xA (n þ 1)

(3:62)

Combining Equations 3.61 and 3.62 leads to the implicit Euler integrator Equation 3.56. If trapezoidal integration is preferred, the discrete-time integrator in Figure 3.10 with input z(n) and output xA(n) is governed by T xA (n þ 1) ¼ xA (n) [z(n) þ z(n þ 1)] 2

(3:63)

Eliminating z(n) and z(n þ 1) from Equations 3.60, 3.62, and 3.63 results in the implicit relation xA (n þ 1) ¼

a0 T a0 T b0 T xA (n þ 1) þ [u(n) þ u(n þ 1)] 1 xA (n) 2 2 2

(3:64)

109

Elementary Numerical Integration

Solving Equation 3.64 for xA(n þ 1) enables the state to be updated explicitly with trapezoidal integration according to xA (n þ 1) ¼

(1 a0 T=2) b0 T=2 xA (n) þ [u(n) þ u(n þ 1)] (1 þ a0 T=2) (1 þ a0 T=2)

(3:65)

Example 3.6 The velocity v ¼ v(t) of an object sinking in a body of water is described by dv cg g þ v ¼ (W FB ) dt W W

(3:66)

where W is the weight of the object c is the drag coefﬁcient FB is the buoyant force g is the gravitational constant (32.2 ft=s2) The buoyant force is a constant that equals the weight of the volume of water displaced by the object. The object is a drum full of hazardous materials (Braun 1978) weighing 350 lb, and its volume is such that the buoyant force is 275 lb. The drag coefﬁcient c was determined experimentally to be 0.8 lb=(ft=s). The drum is released at the surface with zero velocity. (a) Find a difference equation based on trapezoidal integration to approximate the dynamics of the sinking drum. Choose a step size of T ¼ 0.5 s. (b) Find the approximate velocity, vA(nT), n ¼ 0, 10, 20, 30, . . . , 150. (c) Find the true velocity v(t). Use it to ﬁnd the terminal velocity v(1) and v(nT ), n ¼ 0, 10, 20, 30, . . . , 150. (d) Graph the approximate and true velocity over a period of time sufﬁcient for the drum to reach its terminal velocity. (e) If the drum impacts the ocean ﬂoor, 1 mi below the surface, at greater than 60 mph, it will break apart. Comment on the possibility of this happening. (a) Equation 3.66 can be expressed in the form dv ¼ f (v, u) ¼ b0 u a0 v dt

(3:67)

where a0 ¼

cg 0:8(32:2) ¼ ¼ 0:0736, W 350

b0 ¼

g 32:2 (W FB ) ¼ (350 275) ¼ 6:9 W 350

and the input u treated as the function u(t) ¼ 1, t 0. Evaluating the coefﬁcient terms in Equation 3.65, 1

a0 T 0:0736(0:5) a0 T 0:0736(0:5) ¼1 ¼ 0:9816, 1 þ ¼1þ ¼ 1:0184, 2 2 2 2 b0 T 6:9(0:5) ¼ ¼ 1:725 2 2

From Equation 3.65, the difference equation for approximating the dynamics of the sinking drum using trapezoidal integration is vA (n þ 1) ¼

0:9816 1:725 vA (n) þ [1 þ 1] 1:0184 1:0184

¼ 0:9639vA (n) þ 3:3877, n ¼ 0, 1, 2, 3, . . .

Simulation of Dynamic Systems with MATLAB® and Simulink®

110

TABLE 3.3 Data Points from Trapezoidal Integration (T ¼ 0.5 s) and Exact Solution n 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150

tn ¼ nT

vA(n)

v(tn)

0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75

0.0 28.8667 48.8450 62.6718 72.2411 78.8640 83.4475 86.6198 88.8153 90.3347 91.3863 92.1141 92.6178 92.9664 93.2077 93.3747

0.0 28.8640 48.8413 62.6679 72.2376 78.8609 83.4450 86.6177 88.8136 90.3334 91.3853 92.1134 92.6173 92.9660 93.2074 93.3745

(b) Table 3.3 shows the results for vA(n) at discrete times n ¼ 0, 1, 2, 3, . . . The numerical values were generated by running ‘‘Chap3_Ex5_1.m.’’ (c) The exact solution of Equation 3.67 is v(t) ¼ ¼

b0 (1 ea0 t ) a0

(3:68)

W FB [1 e(cg=W)t ] c

(3:69)

The terminal velocity from Equation 3.69 is v(1) ¼

W FB 350 275 ¼ ¼ 93:75 ft=s c 0:8

(3:70)

The analytical solution v(t) is evaluated at t ¼ 0, 5, 10, . . . , 75 s and the values entered in Table 3.3. (d) Graphs of v(t) and the approximate solution (every ﬁfth point) are shown in Figure 3.11. (e) Since the terminal velocity of the drum exceeds 88 ft=s (60 mph), the possibility exists of it breaking when it reaches the ocean ﬂoor. It remains to be determined what the velocity of the drum is at the 1 mi depth of the ocean ﬂoor. From Table 3.3, it is apparent that trapezoidal integration with a step size of T ¼ 0.5 s results in a very accurate approximation of the true solution. However, in most simulation studies, an exact solution is not available. In that case, what can we do to assure accurate simulation results? An iterative method to determine an acceptable integration step size requires that the simulation be executed with different values of T until changes in the output are deemed insigniﬁcant. For example, the step size can be continually reduced (say by one half, or a factor of 10) until graphs of consecutive outputs appear to coincide. The next to last step size is used in subsequent

111

Elementary Numerical Integration 100 90 vA(n), n = 0, 5, 10, ..., 150

80

v(t), 0 ≤ t ≤ 75

v(t), vA(n) ft/s

70 60 50

v(t) = 93.75(1 − e–t/13.587)

40

T = 0.5 s

30 20 10 0

0

10

20

30

40 t (s)

50

60

70

80

FIGURE 3.11 Approximate solution vA(n), n ¼ 0, 5, 10, . . . , 150 using trapezoidal integration (T ¼ 0.5 s) and exact solution v(t), 0 t 75.

investigations. The method is not foolproof and should be repeated if the simulation conditions change as a result of signiﬁcant changes in the system inputs or initial conditions. We will have more to say about how to select the integration step size in Chapters 6 and 8 when we investigate the subject of truncation errors and dynamic errors.

3.5.2 NONLINEAR FIRST-ORDER SYSTEMS We now turn our attention to nonlinear ﬁrst-order systems, that is, systems in which the state derivative f (x, u) is a nonlinear function of the state x. The implicit numerical integrators produce implicit difference equations for updating the state. Consider a ﬁrst-order system governed by dx þ N(x) ¼ Ku dt

(3:71)

where N(x) is a nonlinear function of the state x. The derivative function is f (x, u) ¼ Ku N(x)

(3:72)

and the equation for updating the state using implicit Euler integration is from Equation 3.55 xA (n þ 1) ¼ xA (n) þ T{Ku(n þ 1) N[xA (n þ 1)]}

(3:73)

Rearranging Equation 3.73 gives xA (n þ 1) þ TN[xA (n þ 1)] ¼ xA (n) þ KTu(n þ 1)

(3:74)

a nonlinear equation that may prove difﬁcult or impossible to solve for xA(n þ 1). To complicate matters further, multiple solutions may exist. The situation is illustrated in the following example.

Simulation of Dynamic Systems with MATLAB® and Simulink®

112

Example 3.7 The continuous-time model for the sinking drum in Example 3.6 governed its motion v(t) as a function of time t. A relationship between its velocity v ¼ v(t) and depth y ¼ y(t) is obtained by solving the differential equation (Braun 1978) W dv v þ cv ¼ W FB g dy

(3:75)

(a) Find the difference equation to approximate the velocity of the drum as a function of depth using an implicit Euler integrator. Choose the integration step T ¼ 1 ft. (b) Find the approximate velocity vA(n) at depths of 0, 1000, 2000, 3000, 4000, 5000, and 6000 ft. (c) Compare the results from part (b) to the true velocities v(nT ) at depths of 0, 1000, 2000, 3000, 4000, 5000, and 6000 ft. (a) Dividing both sides of Equation 3.75 by Wv=g gives dv g 1 gc þ (FB W) ¼ u dy W v W

(3:76)

where the input u ¼ u(y) ¼ 1, y 0. Comparing Equations 3.71 and 3.76, it follows that the nonlinear function N(v) is N(v) ¼

g 1 (FB W) W v

(3:77)

gc W

(3:78)

and the constant K is expressible as K¼

According to Equation 3.74, the implicit equation for vA(n þ 1) is vA (n þ 1) þ T

g 1 gc ¼ vA (n) T(1) (FB W) W vA (n þ 1) W

(3:79)

Substituting the values g ¼ 32.2, c ¼ 0.8, W ¼ 350, FB ¼ 275, and T ¼ 1 ft yields vA (n þ 1) 6:9

1 ¼ vA (n) 0:0736 vA (n þ 1)

(3:80)

(b) Multiplying Equation 3.80 by vA(n þ 1) and collecting terms give vA2 (n þ 1) þ [0:0736 vA (n)]vA (n þ 1) 6:9 ¼ 0

(3:81)

which can be solved using the quadratic formula. The result is

vA (n þ 1) ¼

[vA (n) 0:0736]

pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ [vA (n) 0:0736]2 þ 27:6 2

(3:82)

113

Elementary Numerical Integration

Hence, in this case, we are still able to update the state vA(n þ 1) explicitly in terms of the previous state vA(n). The ﬁrst two iterations are illustrated in the following. Starting from vA(0) ¼ v(0) ¼ 0, n ¼ 0:

n ¼ 1:

pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ [vA (0) 0:0736]2 þ 27:6 vA (1) ¼ 2 pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 0 0:0736 þ [0 0:0736]2 þ 27:6 ¼ 2 ¼ 2:5902 pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ [vA (1) 0:0736] [vA (1) 0:0736]2 þ 27:6 vA (2) ¼ 2 pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 2:5902 0:0736 þ [2:5902 0:0736]2 þ 27:6 ¼ 2 ¼ 4:1709 [vA (0) 0:0736]

Note that since the velocity is increasing, the negative root of Equation 3.82 was discarded. The M-ﬁle ‘‘Chap3__Ex5_2.m’’ generates the values of vA(n) for n ¼ 1–6000. The approximate velocities at depths yn ¼ nT (n ¼ 0, 1000, 2000, 3000, 4000, 5000, and 6000) are listed in Table 3.4. (c) An exact solution to Equation 3.75, v ¼ v(y), is not possible. However, it is possible to obtain an exact solution for depth y as a function of the velocity v, namely y¼

W v W FB W FB cv ln þ c2 g c W FB

(3:83)

We are interested in the depths corresponding to velocities up to the terminal velocity of 93.75 ft=s. Equation 3.83 can be evaluated for 0 v 93.75 and the results plotted with depth y along the abscissa and velocity v along the ordinate axis as in Figure 3.12. From an observation of Figure 3.12, the true velocities at the required depths, 0, 1000, 2000, 3000, 4000, 5000, and 6000 ft, agree with the approximate values in Table 3.4. The question in part (e) of Example 3.6 can now be answered. From Figure 3.12, the velocity of the drum at a depth of 1 mi (5280 ft) does exceed 60 mph (88 ft=s). In the majority of cases, difference equations resulting from the use of implicit numerical integrators can only be solved by iterative schemes for ﬁnding the roots of nonlinear algebraic equations. For example, consider an object falling in a viscous medium where the drag force is a nonlinear function of velocity TABLE 3.4 as shown in Figure 3.13. The continuous-time model describing the object’s velocity v(t) is given in Equation 3.87. Data Points from Implicit

Euler Integration (T ¼ 1 ft) of Continuous-Time Model in Equation 3.75 n 0 1000 2000 3000 4000 5000 6000

yn ¼ nT (ft)

vA(n) (ft=s)

0 1000 2000 3000 4000 5000 6000

0 74.3629 85.9310 90.3467 92.2281 93.0618 93.4373

m

dv ¼ W fD dt

(3:84)

dv W 1 ¼ f (v) dt m m

(3:85)

dv 1 ¼ g cvp dt m

(3:86)

dv ¼ g avp , dt

a¼

c m

(3:87)

A simulation diagram of the system is shown in Figure 3.14.

Simulation of Dynamic Systems with MATLAB® and Simulink®

114

Actual velocity v vs. depth y 100 90 80

v (ft/s)

70 60 50 40 30 20 10 0

FIGURE 3.12

0

1000

2000

3000 y (ft)

4000

5000

6000

Graph of points obtained from exact solution, Equation 3.83. Replacing the continuous-time integrator with an implicit Euler integrator and making all the signals discrete time lead to a discrete-time system with difference equation

fD

v

vA (n þ 1) ¼ vA (n) þ T fg a[vA (n þ 1)]p g

(3:88)

) vA (n þ 1) þ aT[vA (n þ 1)]p ¼ vA (n) þ Tg

(3:89)

W

Unless p is numerically equal to 1 or 2, a root-solving algorithm is required to solve Equation 3.89 for vA(n þ 1) once vA(n) has been determined. This process can dramatically increase the amount of computational overhead in comparison to what would be required for an explicit numerical integrator.

FIGURE 3.13 Object falling in a viscous medium with nonlinear drag force fd ¼ cv p.

3.5.3 DISCRETE-TIME STATE EQUATIONS Given the linear state equations x, u ) ¼ A) x þ Bu x_ ¼ f () + ) )

(3:90)

y ¼ g( x, u ) ¼ C ) x þ D) u ) )) )

(3:91)

for a continuous-time dynamic system, a discrete-time model approximation can be obtained in a straightforward manner. The approximation to the continuous-time state x(t) is )xA (nT) or simply )xA (n) for short. Difference equations for the discrete-time state )xA (n) using one of the numerical g

dv/dt

∫

ν

−α( ) p

FIGURE 3.14

Simulation diagram for a falling object modeled by dv=dt ¼ g av p.

115

Elementary Numerical Integration

integrators are obtained in exactly the same way as before. For example, using explicit Euler integration, the state derivative vector x_ is assumed constant over the integration interval. Thus, xA (n þ 1) ¼ x A (n) þ Tf [x A (n), u(n)]

(3:92)

¼ x A (n) þ T[Ax A (n) þ Bu(n)]

(3:93)

¼ (I þ TA)x A (n) þ TBu(n)

(3:94)

The discrete-time output is determined from y A (n) ¼ Cx A (n) þ Du(n)

(3:95)

An example involving the discrete-time state equations follows. Example 3.8 A circuit used in control systems is the RC lead-lag network shown in Figure 3.15. The differential equation relating the output v0(t) and input vi (t) is R1 C1 R2 C2 v€0 þ (R1 C1 þ R1 C2 þ R2 C2 )v_ 0 þ v0 ¼ R1 C1 R2 C2 v€i þ (R1 C1 þ R2 C2 )v_ i þ vi

(3:96)

(a) Represent the circuit in state variable form. (b) Find the discrete-time state equations for approximating the circuit dynamics based on the use of explicit Euler integration. (c) The capacitor voltages are initially zero and the input is a step vi (t) ¼ 1 V, t 0. Approximate the step response using explicit Euler integration with step size T ¼ 0.001 s. The circuit parameter values are R1 ¼ 10,000 V, R2 ¼ 5,000 V, C1 ¼ 7.5 106 F, and C2 ¼ 2.5 106 F. (d) An alternate form of the state equations is given by dvC1 1 1 1 1 1 þ vC2 þ vi ¼ vC1 dt C1 R1 R2 R2 C1 R2 C1

(3:97)

dvC2 1 1 1 vC vC þ vi ¼ dt R2 C2 1 R2 C2 2 R2 C2

(3:98)

Find the matrices A, B, C, and D in the state variable model with the states equal to the capacitor voltages. (e) Repeat part (c) using the new state equations. Compare the results in parts (c) and (e).

C1 + – νC1 +

+ R1 R2

νi (t) νC2 –

FIGURE 3.15

A lead-lag network.

+ –

ν0(t)

C2 –

Simulation of Dynamic Systems with MATLAB® and Simulink®

116

(a) Dividing through by the lead coefﬁcient term R1, C1, R2, and C2 and introducing new constants a1, a2, b0, b1, and b2 give v€0 þ a1 v_ 0 þ a0 v0 ¼ b2 v€i þ b1 v_ i þ b0 vi

(3:99)

where a0 ¼ b0 ¼

1 , R1 C1 R2 C2

1 , R1 C1 R2 C2

a1 ¼ b1 ¼

R1 C1 þ R1 C2 þ R2 C2 R1 C1 R2 C2

R1 C1 þ R2 C2 , R1 C1 R2 C2

(3:100)

b2 ¼ 1

(3:101)

Constructing the simulation diagram for the system starts with the following two equations, which are equivalent to Equation 3.99 (see Section 2.4): €z þ a1 z_ þ a0 z ¼ vi

(3:102)

z v0 ¼ b0 z þ b1 z_ þ b2 €

(3:103)

Solving for €z in Equation 3.102 and substituting the result in Equation 3.103 yield _ v0 ¼ b0 z þ b1 z_ þ b2 [vi a0 z a1 z]

(3:104)

¼ (b0 a0 b2 )z þ (b1 a1 b2 )z_ þ b2 vi

(3:105)

The simulation diagram follows directly from Equations 3.102 and 3.105. It is presented in Figure 3.16. Choosing the outputs of the integrators in Figure 3.16 as the states results in x_ 1 ¼ x2

(3:106)

x_ 2 ¼ a0 x1 a1 x2 þ vi

(3:107)

v0 ¼ (b0 a0 b2 )x1 þ (b1 a1 b2 )x2 þ b2 vi

(3:108)

From Equations 3.106 through 3.108, the matrices A, B, C, and D in the linear state equations x_ ¼ Ax þ Bu, y ¼ Cx þ Du are A¼

0 a0

1 , a1

B¼

0 , 1

C ¼ ½ b0 a0 b2

b1 a1 b2 ,

D ¼ [b2 ]

(3:109)

b2 b1 − a1b2 νi

.. z

∫

. z x2

∫

z x1

−a1 −a0

FIGURE 3.16

Simulation diagram for circuit in Figure 3.15.

b0 − a0b2

ν0

117

Elementary Numerical Integration In terms of the electrical parameters 2

3 1 5 , R1 C1 þ R1 C2 þ R2 C2 R1 C1 R2 C2

0 1 A¼4 R1 C1 R2 C2

B¼

" # 0

1 , C¼ 0 , R2 C1 1

D ¼ [1]

(3:110)

(b) From Equations 3.94 and 3.95, the discrete-time state equations are 2

1 x A (n þ 1) ¼ 4 T R1 C1 R2 C2

3 " # T 0 5 R1 C1 þ R1 C2 þ R2 C2 x A (n) þ vi (n) 1T T R1 C1 R2 C2

(3:111)

1 x (n) þ vi (n) yA,1 (n) ¼ v0 (n) 0 R2 C1 A

(3:112)

(c) Equation 3.111 is solved recursively in ‘‘Chap3_Ex5_3.m’’ for the state x A (n), which is used in Equation 3.112 to ﬁnd the discrete-time step response v0(n), n ¼ 0, 1, 2,. . . . The ﬁrst 25 discrete points and every 10th point after that until steady state are plotted in the top window in Figure 3.17. (d) Solving Equations 3.97 and 3.98 for the state derivatives v_ C1 and v_ C2 leads to "

v_ C1 v_ C2

#

3 2 1 3 1 1 1 1 " # þ 7 6 C R v 6 R2 C1 7 R2 R2 C1 7 C1 1 1 6 7 ¼6 þ6 7 4 1 5vi 4 1 1 5 vC2 R2 C2 R2 C2 R2 C2 2

(3:113)

v0(t) vs. t 1 v0 (V)

0.95 0.9

States: x1, x2 from simulation diagram

0.85 0.8 0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

0.3

0.35

0.4

0.45

0.5

v0(t) vs. t 1

v0 (V)

0.95 0.9

States: vC1, vC2

0.85 0.8 0

0.05

0.1

0.15

0.2

0.25 t (s)

FIGURE 3.17

Discrete-time step response of a circuit using explicit Euler integration.

Simulation of Dynamic Systems with MATLAB® and Simulink®

118

From the circuit, the output equation is v0 ¼ vi vC1

"

¼ ½ 1 0

vC 1 vC2

(3:114)

# þ [1]vi

(3:115)

The matrices A, B, C, and D follow directly from Equations 3.113 and 3.115. (e) The new state equations are discretized based on the use of explicit Euler integration and solved recursively in ‘‘Chap3_Ex5_3.m.’’ The result is shown in the bottom window of Figure 3.17. The two step responses are identical. The second choice of the state variables, namely, the capacitor voltages, is more intuitive than the state deﬁnition based on the simulation diagram in Figure 3.16. The output vector could be modiﬁed to include additional outputs y2 ¼ vC1 and y3 ¼ vC2 making y ¼ [v0 vC1 vC2 ]T to allow visualizing the capacitor voltages (see Exercise 3.21). A recursive solution to Equation 3.111 requires the initial discrete-time state vector x A (0) ¼ [x1,A (0) x2,A (0)]T ¼ [x1 (0) x2 (0)]T . Since the states x1 and x2 are not physical quantities, their initial values must be calculated from knowledge of the initial capacitor voltages vC1 (0) and vC2(0).

3.5.4 DISCRETE-TIME STATE SYSTEM MATRICES If either of the two implicit numerical integrators is used instead of the explicit Euler integrator, Equation 3.92 is replaced with one of the following two equations: Implicit Euler: x A (n þ 1) ¼ x A (n) þ Tf [x A (n þ 1), u(n þ 1)] Trapezoidal: x A (n þ 1) ¼ x A (n) þ

T {f [x A (n), u(n)] þ f [x A (n þ 1), u(n þ 1)]} 2

(3:116) (3:117)

If the continuous-time system is linear, Equations 3.116 and 3.117 can be solved explicitly for xA(n þ 1) in terms of xA(n) and u(n þ 1). For the implicit Euler integrator, x A (n þ 1) ¼ x A (n) þ T[Ax A (n þ 1) þ Bu(n þ 1)]

(3:118)

Solving for xA(n þ 1) gives x A (n þ 1) ¼ (I þ TA)1 [x A (n) þ TBu(n þ 1)]

(3:119)

The state xA(n) is updated recursively without the need to solve an implicit equation for x A(n þ 1); however, the computations are more extensive than with explicit Euler integration because of the requirement to invert the matrix I TA. Using trapezoidal integration to update the state, T u (n) þ A)xA (n þ 1) þ B) u (n þ 1)] )xA (n þ 1) ¼ )xA (n) þ 2 [A)xA (n) þ B)

(3:120)

Solving Equation 3.120 for x A(n þ 1) gives x A (n þ 1) ¼

1 I TA 2

1

1 1 1 1 I TA TB[u(n) þ u(n þ 1)] I þ TA x A (n) þ 2 2 2

(3:121)

119

Elementary Numerical Integration

In summary, the use of the explicit Euler integrator to approximate the continuous-time system x_ ¼ Ax þ Bu resulted in a discrete-time state variable model of the form x A (n þ 1) ¼ Gx A (n) þ Hu(n)

(3:122)

y A (n þ 1) ¼ Cx A (n) þ Du(n)

(3:123)

A similar result occurred for the two implicit numerical integrators, with the exception of u(n þ 1) appearing on the right-hand side of Equation 3.122 in place of u(n) with implicit Euler integration. Both u(n) and u(n þ 1) are present on the right-hand side in the case of trapezoidal integration. The matrices G and H are the discrete-time counterparts to A and B, the system and input matrices for the continuous-time case. For a stable discrete-time system with state equations given by Equations 3.122 and 3.123, the steady-state response to a constant input u(n) ¼ u0, n ¼ 0, 1, 2, . . . is obtained from Equation 3.122 by setting xA(n) ¼ xA(n þ 1) ¼ xA(1) resulting in x A (1) ¼ Gx A (1) þ Hu0 ¼ (I G)1 Hu0

(3:124) (3:125)

The general solution of the scalar version of Equation 3.122 was given in Section 1.4. A similar approach using recursion works when the state and inputs are vectors and the coefﬁcients of each are matrices. The result is (Ogata 1995) x A (n) ¼ F(n)x A (0) þ

n1 X

F(n k 1)Hu(k)

(3:126)

k¼0

y A (n) ¼ CF(n)x A (0) þ C

n1 X

F(n k 1)Hu(k) þ Du(n)

(3:127)

k¼0

where the matrix F(n) is called the discrete-time state transition matrix. It is expressed in terms of the discrete-time system matrix G according to F(n) ¼ Gn

(3:128)

From Equations 3.94, 3.119, and 3.121, the discrete-time state transition matrices for the three numerical integrators already considered are Explicit Euler: F(n) ¼ (I þ TA)n

(3:129)

Implicit Euler: F(n) ¼ [(I TA)1 ]n " 1 #n 1 1 Trapezoidal: F(n) ¼ I TA I þ TA 2 2

(3:130) (3:131)

EXERCISES 3.13 Show that an approximate solution of the ﬁrst-order continuous-time model dx ¼ f (x, u) dt based on replacing the derivative dx=dt with the ﬁnite difference [x(n þ 1) x(n)]=T is equivalent to using forward (explicit) Euler integration.

120

Simulation of Dynamic Systems with MATLAB® and Simulink®

3.14 In Example 3.6, ﬁnd the largest step size T for which Maxjv(nT) vA (nT)j 0:1 Start with T ¼ 0.025 s and keep incrementing by 0.025 s until the condition is no longer satisﬁed. 3.15 Rework Example 3.6 using forward Euler integration. Choose the integration step size as T ¼ 0.5 s, the same value used for trapezoidal integration. Prepare a similar table of results for the approximate and exact solutions. 3.16 The position of the sinking drum in Example 3.6 is related to its velocity by ðt

y(t) ¼ y(0) þ v(t 0 )dt 0 0

Using trapezoidal integration and a step size T ¼ 2 s, ﬁnd the approximate solution vA(n) for 100 s and feed this discrete-time signal to another trapezoidal integrator to generate yA(n), the approximation to the actual position of the drum. 3.17 Consider the case of a liquid discharged from a tank at a rate proportional to the square root of the level in the tank. The continuous-time model is A

3.18

3.19 3.20

3.21

dH þ aH 1=2 ¼ F1 dt

where H ¼ H(t) is the continuous-time tank level, F1 ¼ F1(t) is the ﬂow in, and a is a constant dependent on the physical characteristics of the tank. (a) Use implicit Euler integration to ﬁnd a difference equation involving the discrete-time signals HA(n) and F1(n þ 1) where HA(n) H(nT ) and F1(n) ¼ F1(nT ). Write the equation in implicit form with HA(n þ 1) on both sides. (b) Show that the implicit equation can be solved explicitly for HA(n þ 1) in terms of HA(n) and F1(n þ 1) by making the substitution x ¼ [HA(n þ 1)]1=2 and solving the resulting quadratic equation in x. Suppose a ¼ 0.5 and p ¼ 1.2 in the example of the object falling in a viscous medium. The object is initially at rest. (a) Find the approximate velocity of the object after 5 s. Use an explicit Euler integrator with an appropriate step size. (b) Repeat part (a) using an implicit Euler integrator. Hint: Use a root-solving routine like the single point iteration or bisection method to solve the implicit equation. Verify the solution for x A ¼ (n þ 1) in Equation 3.121, which gives the updated state in the approximate solution of x_ ¼ Ax þ Bu by trapezoidal integration. Find the discrete-time state equations for the circuit in Example 3.8 using (a) Implicit Euler integration (b) Trapezoidal integration In the lead-lag circuit of Example 3.8, the outputs are y1 ¼ v0, y2 ¼ vC1 , and y3 ¼ vC2 . (a) Choose the states as the capacitor voltages vC1 and vC2 . Find expressions for the matrices A, B, C, and D in the state equations in terms of the electrical parameters R1, R2, C1, and C2. (b) Find the difference equations based on trapezoidal integration with step size T for approximating the continuous-time system outputs to input vi(t).

121

Elementary Numerical Integration

(c) The capacitor voltages are both initially zero, and the input is a step voltage of 12 V applied at t ¼ 0. Solve the difference equations recursively, and plot the discrete-time outputs in the output vector yA(n) ¼ [ y1, A(n)y2, A(n)y3, A(n)]T. (d) The initial capacitor voltages are vC1 (0) ¼ 1 V vC2 (0) ¼ 0 V, and the input vi(t) ¼ 0 V, t 0. Solve the difference equations recursively and plot the discrete-time outputs in the output vector y A (n) ¼ [ y1,A (n)y2, A (n)y3, A (n)]T . 3.22 For the circuit in Example 3.8 described by Equations 3.97 and 3.98 (a) Use the technique presented in Section 2.3 for converting two ﬁrst-order differential equations into a single second-order differential equation to eliminate vC2 (t) from the two equations and obtain €vC1 þ a1 v_ C1 þ a0 vC1 ¼ b2€vi þ b1 v_ i þ b0 vi Express the coefﬁcients a1, a0, b2, b1, and b0 in terms of the electrical parameters R1, R2, C1, and C2. (b) The circuit output is v0(t). Find the matrices A, B, C, and D in the continuous-time state equation model. Express your answers in terms of the circuit parameters R1, R2, C1, and C2. (c) Find the matrices G and H in the discrete-time state equations resulting from the use of explicit Euler integration to approximate the continuous-time response of the circuit. (d) The input vi(t) ¼ 1 V, t 0. Find and plot the discrete-time response v0(n), n ¼ 0, 1, 2, . . . based on explicit Euler integration with step size T ¼ 0.001 s and compare your answer to the results shown in Figure 3.17. 3.23 The dynamic interaction of rabbit and fox populations in a forest is under investigation. The predator–prey ecosystem is illustrated in Figure E3.23:

hR(t) hF (t)

Rabbit and fox ecosystem

R(t) F(t)

FIGURE E3.23

R(t) is the population of rabbits after ‘‘t’’ weeks F(t) is the population of foxes after ‘‘t’’ weeks hR(t) is the rate of rabbit hunting (rabbits=week) hF (t) is the rate of fox hunting (foxes=week) The mathematical model consists of the following coupled differential equations: dR ¼ aR bF hR dt dF ¼ cF þ dR hF dt a, b are constant parameters deﬁning the growth rate of rabbits c, d are constant parameters deﬁning the growth rate of foxes (a) Find the equilibrium point (Re, Fe) when hR (t) ¼ hR , t 0 and hF (t) ¼ hF , t 0. Express your answers for Re and Fe in terms of the system parameters a, b, c, and d hF . and constant hunting rates hR ,

Simulation of Dynamic Systems with MATLAB® and Simulink®

122

(b) Baseline values of the system parameters are given as follows: a ¼ 0:04 c ¼ 0:1

rabbits=week , rabbit foxes=week , fox

b ¼ 0:2

rabbits=week , fox

d ¼ 0:0075

foxes=week rabbit

Foxes are endangered and hunting foxes is forbidden. Rabbits are hunted at a constant rate, and after a long period of time, the fox population stabilizes at 750. Find the constant rate of rabbit hunting. Find the rabbit population at the same time. R(t) and the input vector u be deﬁned as (c) Let the state be deﬁned as x(t) ¼ F(t) h (t) . Find the matrices A and B in the state equation x_ ¼ Ax þ Bu. u(t) ¼ R hF (t) (d) Suppose neither rabbits nor foxes are hunted. Using explicit Euler integration with step size T ¼ 1 week, ﬁnd the 2 2 matrix G such that

R(n þ 1) R(n) ¼G , F(n þ 1) F(n)

n ¼ 0, 1, 2, 3, . . .

(e) Find the 2 2 transition matrix F(n) in the general solution

R(n) R(0) ¼ F(n) , F(n) F(0)

n ¼ 0, 1, 2, 3, . . .

(f) The initial populations of rabbits and foxes are R(0) ¼ 10,000 and F(0) ¼ 1,000. Use the general solution to ﬁnd R(10) and F(10).

3.6 IMPROVEMENTS TO EULER INTEGRATION Euler integration is popular in large measure due to its simplicity. A graphical interpretation of either explicit or implicit Euler integration is straightforward. A discussion of error characteristics for Euler integrators is deferred until a later chapter. However, it is apparent that serious errors can propagate as the discrete-time variable ‘‘n’’ increases with Euler integration as a result of the underlying assumption that the state derivative remains constant for an entire integration step. For systems in which one or more of the state variables experience frequent ﬂuctuations (relative to the integration step size), this assumption is unjustiﬁed.

3.6.1 IMPROVED EULER METHOD The inherent weakness of Euler integration can be overcome in ways other than by simply reducing the integration step size, which may not always be practical. An improved way of determining the new state xA(n þ 1) with explicit Euler integration is illustrated in Figure 3.18. Keep in mind that the current state xA(n) is generally not on the solution curve x(t) as is shown in the ﬁgure. With explicit Euler integration, advancing the state xA(n) is equivalent to projecting line segment L1, whose slope is f [xA(n), u(n)], until it reaches the end of the interval at (n þ 1)T. The updated state is shown as ^xA (n þ 1). From there, another forward Euler integration step would proceed along the line segment L2 whose slope is f [^xA (n þ 1), u(n þ 1)].

123

Elementary Numerical Integration x [(n + 1)T ] . x = f (x, u) Slope of L1 = f [xA(n), (n)]

xA(n + 1)

Slope of L2 = f [xˆA(n + 1), u(n + 1)] Slope of L = 1 (Slope of L1 + Slope of L2) 2

L

L2 xˆ A(n + 1)

x(t)

xA(n)

L1

nT

FIGURE 3.18

(n + 1)T

t

Illustration of improved Euler method.

Recognizing that L1 may not be the most judicious direction to move along for approximating the continuous-time state x[(n þ 1)T ], the question to be asked is ‘‘Is there a better choice for determining the path from xA(n) to xA(n þ 1)?’’ The line segment L starting from xA(n) with slope equal to the average of the slopes of L1 and L2 appears to be a more prudent choice. The rationale for choosing the new direction along L is that the average of the slopes of L1 and L2 is more likely to reﬂect the direction of the chord from xA(n) to x[(n þ 1)T ] than the slope of line L1 does. Alternatively, Euler integration is predicated on the assumption that the derivative function f(x, u) is constant, which is true only when the solution x(t) is a linear function of t. It makes sense to base the constant on evaluations of f (x, u) at more than one point. In summary, a new method for computing xA(n þ 1) consists of the following: 1. Prediction of the new state using forward Euler integration, that is, moving from xA(n) to ^xA (n þ 1) along the line segment with slope L1. ^xA (n þ 1) ¼ xA (n) þ Tf [xA (n), u(n)]

(3:132)

2. Computing the derivative function f [^xA (n þ 1), u(n þ 1)] at ^xA (n þ 1), that is, the slope of line segment L2. 3. Improving the predicted value ^xA (n þ 1), that is, moving from xA(n) along a line segment whose slope is the average of the slopes of line segments L1 and L2 to the new updated state xA(n þ 1). xA (n þ 1) ¼ xA (n) þ

T { f [xA (n), u(n)] þ f [^xA (n þ 1), u(n þ 1)]} 2

(3:133)

The numerical integrator based on Equations 3.132 and 3.133 is called improved Euler integration, also known as Heun’s method. When the state is a vector and the system model is linear, that is, x_ ¼ f (x, u) ¼ Ax þ Bu

(3:134)

Simulation of Dynamic Systems with MATLAB® and Simulink®

124

the predicted state using forward Euler integration is given by Equation 3.94 of the previous section as ^x A (n þ 1) ¼ (I þ TA)x A (n) þ TBu(n)

(3:135)

The improved state estimate is computed from x A (n þ 1) ¼ x A (n) þ

T {f [x A (n), u(n)] þ f [^x A (n þ 1), u(n þ 1)]} 2

(3:136)

Substituting Equation 3.135 into Equation 3.136 results in 1 1 1 x A (n þ 1) ¼ I þ TA þ (TA)2 x A (n) þ T(I þ TA)Bu(n) þ TBu(n þ 1) 2 2 2

(3:137)

The discrete-time system matrix using improved Euler integration is therefore 1 G ¼ I þ TA þ (TA)2 2

(3:138)

and the improved Euler discrete-time state transition matrix is from Equation 3.128

1 f(n) ¼ G ¼ I þ TA þ (TA)2 2

n

n

(3:139)

The difference in transition matrices between explicit Euler given in Equation 3.129 and improved 1 Euler is the additional term (TA)2 in Equation 3.139. 2 The following example demonstrates the improved accuracy with improved Euler integration compared with ordinary Euler integration (explicit or implicit). Example 3.9 Consider the autonomous second-order system €x þ v2 x ¼ 0

(3:140)

Choosing state variables x1(t) ¼ x(t) and x2 (t) ¼ x_ (t) leads to the state equations x_ 1 ¼ f1 (x1 , x2 ) ¼ x2

(3:141)

x_ 2 ¼ f2 (x1 , x2 ) ¼ v x1 2

(3:142)

The initial conditions are x1(0) ¼ x(0) ¼ x0 and x2 (0) ¼ x_ (0) ¼ x_ 0 . (a) (b) (c) (d)

Find the system matrix A. Find the discrete-time state transition matrices for explicit and improved Euler integration. Find the general solution of the discrete-time state equations using both Euler integrators. Find the transient response using explicit and improved Euler integrators when v ¼ 1 rad=s, x0 ¼ 1 ft, x_ 0 ¼ 0 ft=s, and T ¼ 0.25 s. Plot the results. (e) Find the exact solution for the transient response of the continuous-time system and compare it with the approximate solutions in part (d).

125

Elementary Numerical Integration (a) From Equations 3.141 and 3.142, the system matrix is A¼

0 v2

1 0

(3:143)

(b) The discrete-time state transition matrices are Explicit Euler: F(n) ¼ (I þ TA)n " #n 1 T ¼ v2 T 1 n 1 Improved Euler: F(n) ¼ I þ TA þ (TA)2 2 3n 2 1 2 T 1 (vT) 7 6 2 7 ¼6 5 4 1 2 2 v T 1 (vT) 2

(3:144) (3:145) (3:146)

(3:147)

(c) General solutions for the discrete-time states for each integrator are 1 x(0) ¼ Explicit Euler: )xA (n) ¼ F(n)) v2 T 2

1 2 6 1 2 (vT) x(0) ¼ 4 Improved Euler: )xA (n) ¼ F(n)) v2 T

T 1

n

x0 x_ 0

3n T 7 x0 5 1 x_ 0 1 (vT)2 2

(3:148)

(3:149)

(d) The transient responses of the discrete-time states x1,A(n) and x2,A(n) when v ¼ 1 rad=s, x0 ¼ 1 ft, x_ 0 ¼ 0 ft=s, and T ¼ 0.25 s are plotted in Figures 3.19 and 3.20 for the explicit and improved Euler integrators. (e) The exact solution for the continuous-time states of the undamped second-order system in Equation 3.140 is given in the following and plotted in Figures 3.19 and 3.20. x1 (t) ¼ x0 cos vt,

x2 (t) ¼ vx0 sin vt

(3:150)

Note the considerable improvement in accuracy obtained with the improved Euler integrator. The discrete-time state )xA (n) ¼ [x1,A (n) x2,A (n)]T based on explicit Euler integration is a poor approximation to the continuous-time state x(t), to say the least. This is not surprising in light of the fact that the state derivatives x_ 1 and x_ 2 vary signiﬁcantly over the interval T in violation of the basic assumption underlying explicit Euler integration. (See graph of x2 ¼ x_ 1 in Figure 3.19.) In Chapter 8, we will learn that explicit Euler integration of an undamped second-order system is never stable and should not be used. However, lightly damped second-order systems, that is, those with high natural frequencies, require smaller integration steps for accurate results. The controlling parameter for dynamic accuracy is vT, the product of natural frequency and the integration time step.

3.6.2 MODIFIED EULER INTEGRATION In general, forward Euler integration does not result in the ‘‘best’’ direction for advancing the state from x A (n) to x A (n þ 1) (see Figure 3.18). As the name suggests, improved Euler integration

Simulation of Dynamic Systems with MATLAB® and Simulink®

126

x1,A(n), n = 0, 1, 2, ..., 50

4

x1(t), 0 ≤ t ≤ 2π

x1

2 0 −2 0

1

2

3

4

5

6

7

8

9

10

11

12

6 7 t (s)

8

9

10

11

12

t (s) x2, A(n), n = 0, 1, 2, ..., 50

4

x2(t), 0 ≤ t ≤ 2π

x2

2 0 −2 0

1

2

3

4

5

FIGURE 3.19 Continuous-time solution and approximate solution using explicit Euler integration (T ¼ 0.25 s) to second-order system €x þ v2 x ¼ 0, v ¼ 1 rad=s.

x1,A(n), n = 0, 1, 2, ..., 50

4

x1(t), 0 ≤ t ≤ 2π x1

2 0 −2 0

1

2

3

4

5

6 7 t (s)

8

9

10

11

12

6 7 t (s)

8

9

10

11

12

x2,A(n), n = 0, 1, 2, ..., 50

4

x2(t), 0 ≤ t ≤ 2π

x2

2 0 −2 0

1

2

3

4

5

FIGURE 3.20 Continuous-time solution and approximate solution using improved Euler integration (T ¼ 0.25 s) to second-order system €x þ v2 x ¼ 0, v ¼ 1 rad=s.

127

Elementary Numerical Integration x[(n + 1)T]

Slope of L1 = f [xA(n), u(n)] 1 ), u(n + – 1 )] Slope of L2 = f [xA(n + – 2 2 Slope of L = slope of L2

xA(n + 1) L

. x = f (x, u)

L2 x(t)

xA(n)

1) xA(n + – 2

L1

nT

(n + –1 )T

(n + 1)T

t

2

FIGURE 3.21

Illustration of the modiﬁed Euler method.

represents an improvement although it comes with a penalty of requiring twice as many state derivative function evaluations compared with explicit Euler integration for the identical step size. Another method for ﬁnding a better direction (compared with explicit Euler integration) to proceed from the current state x A (n) is portrayed in Figure 3.21. It is called the midpoint or modiﬁed Euler method because the line segment L, which determines the new approximate state, is based on a state derivative calculation at the midpoint of the interval. A forward Euler step is taken along line segment L1 ending up at the point [(n þ 1=2)T, x A (n þ 1=2)]. A new direction is calculated, namely, f [x A (n þ 1=2), u(n þ 1=2)], which represents the slope of line L2. Finally, the updated state xA(n þ 1) is obtained by starting from the current state x A(n) and moving in the direction of line segment L, which is parallel to line segment L2, until the end of the interval. A discrete-time state equation can be obtained for the modiﬁed Euler integration solution of x_ ¼ Ax þ Bu in the same way it was obtained for the improved Euler integrator. First, the state x A (n þ 1=2) is calculated from 1 T xA n þ (3:151) ¼ x A (n) þ f [x A (n), u(n)] 2 2 The updated state x A(n þ 1) is based on the derivative function f (x, u) evaluated at the point [(n þ 1=2)T, x A (n þ 1=2)]. The updated state is therefore 1 1 (3:152) x A (n þ 1) ¼ x A (n) þ Tf x A n þ , u n þ 2 2 From Equations 3.151, 3.152, and f (x, u) ¼ Ax þ Bu, the discrete-time state equation is 1 1 1 x A (n þ 1) ¼ I þ (TA) þ (TA)2 x A (n) þ T 2 ABu(n) þ TBu n þ 2 2 2

(3:153)

and the discrete-time state transition matrix using the modiﬁed Euler method is

1 F(n) ¼ I þ (TA) þ (TA)2 2

n (3:154)

Simulation of Dynamic Systems with MATLAB® and Simulink®

128

Hence, the state transition matrices with improved Euler integration, Equation 3.139, and modiﬁed Euler integration, Equation 3.154, are identical. The modiﬁed Euler integrator requires input sampling at twice the normal frequency of 1=T due to the presence of the term u(n þ 1=2) in Equation 3.153. Trapezoidal, improved, and modiﬁed Euler integrators are roughly comparable in accuracy and are superior to the explicit and implicit Euler integrators. The state transition matrices for improved and modiﬁed Euler integration are only slightly more involved than the state transition matrix for forward Euler integration, the difference being the additional term 1=2(TA)2 . The added computations necessary to include the squared term depend on the dimension of the square matrix A, which in turn is related to the size of the state vector. The discrete-time transition matrices for the explicit integrators (forward Euler, improved Euler, and modiﬁed Euler) bear a striking similarity to the transition matrix for the continuous-time state equations. The state transition matrix F(t) for the system x_ ¼ Ax þ Bu was introduced in Equation 2.129. It was expressed in terms of an inﬁnite series of matrices, that is, F(t) ¼ I þ (tA) þ

1 1 (tA)2 þ (tA)3 þ 2! 3!

(3:155)

At the end of a single integration step, the exact solution to x_ ¼ Ax is 1 1 2 3 x(T) ¼ F(T)x(0) ¼ I þ (TA) þ (TA) þ (TA) þ x(0) 2! 3!

(3:156)

With improved or modiﬁed Euler integration, the discrete-time state vector approximation at the same time is 1 2 x A (1) ¼ F(1)x A (0) ¼ I þ TA þ (TA) x(0) (3:157) 2 The difference or error in the discrete-time state approximation is therefore 1 1 x A (1) x(T) ¼ (TA)3 þ (TA)4 þ x(0) 3! 4!

(3:158)

The importance of choosing T small is evident from Equation 3.158. Example 3.10 In Section 2.6, a second-order system with system matrix A and transition matrix F(t) was given. They are repeated as follows: A¼

0 2

1 , 2

F(t) ¼

2et e2t 2et þ 2e2t

et e2t et þ 2e2t

(3:159)

The initial state is x(0) ¼ [x1(0) x2(0)]T. Modiﬁed Euler integration is to be used to compute x A (1) ¼ [x1,A (1) x2,A (1)]T . (a) Find the continuous-time state transition matrix at t ¼ T, that is, F(t)jt ¼T. (b) Find the discrete-time state transition matrix at n ¼ 1, that is, F(n)jn ¼1. For parts (c) and (d), the initial state x(0) ¼ [1 1]T and the step size T ¼ 0.25 s. (c) Find F(t)jt ¼1 and x(T) (d) Find F(n)jn ¼1 and x A (1).

129

Elementary Numerical Integration (a) From Equation 3.159, F(t)jt¼T ¼

2eT e2T 2eT þ 2e2T

eT e2T eT þ 2e2T

(3:160)

(b) From Equation 3.154, 1 F(n)jn¼1 ¼ I þ TA þ (TA)2 2 " #!2 " # 0 1 0 1 1 T ¼IþT þ 2 2 3 2 3 3 2 3 2 T 1 T 1 T 7 6 2 7 ¼6 4 7 25 T( 2 þ 3T) 1 3T þ T 2 (c)

F(t)jt¼0:25 ¼

2 (d)

6 F(n)jn¼1 ¼ 4

(3:161) (3:162)

(3:163)

0:9511 0:1723 2e0:25 e2(0:25) e(0:25) e2(0:25) ¼ 0:3445 0:4343 2e0:25 þ 2e2(0:25) e0:25 þ 2e2(0:25) x1 (0:25) ¼ F(t)jt¼0:25 x(0) x2 (0:25) 0:9511 0:1723 1 1:1234 ¼ ¼ (3:164) 0:3445 0:4343 1 0:0898

1 (0:25)2 0:25[2 þ 3(0:25)]

3 3 0:25 1 (0:25) 0:9375 0:1563 7 2 5¼ 0:3125 0:4688 7 1 3(0:25) þ (0:25)2 2

x1,A (1) ¼ F(n)jn¼1 x A (0) x2,A (1) 0:9375 0:1563 1 1:0938 ¼ ¼ 0:3125 0:4688 1 0:1563

(3:165)

The discrete-time state transition matrix F(n) for n ¼ 1 and the continuous-time state transition matrix F(t) at t ¼ T differ signiﬁcantly. The discrepancy is attributable to the integration step size T, which must be reduced to make [x1,A(1) x2,A(1)]T closer to the exact solution [x1(0.25) x1(0.25)]T and assure substantial agreement of subsequent vectors [x1,A(n) x2,A(n)]T and [x1(nT) x2(nT)]T, n ¼ 2, 3, 4,. . . . Table 3.5 shows the effect of reducing the step size T on the discrete-time state transition matrix and state vector. As expected, the difference between the discrete- and continuous-time quantities diminishes as the step size is reduced. The next example looks at the transient and steady-state responses of a second-order system using modiﬁed Euler integration.

Example 3.11 The input to the second-order system in Figure 3.22 is a unit step u(t) ¼ 1, t 0. System parameters are z ¼ 0.5, vn ¼ 0.4 rad=s, and K ¼ 2. Both initial conditions are zero. (a) Write state equations for the system if x1 ¼ y and x2 ¼ dy=dt and the output y1 ¼ y. (b) Find the discrete-time system matrix G based on the use of modiﬁed Euler integration to approximate the solution of the continuous-time state equations. Leave your answers in terms of the system parameters z, vn, and K and integration step size T.

Simulation of Dynamic Systems with MATLAB® and Simulink®

130

TABLE 3.5 Effect of Reduced Step Size on the Continuous-Time and Discrete-Time State Transition Matrices and State Vectors T

0.5 0.05 0.01

F(t)jt ¼T 0:9511 0:1723 0:3445 0:4343 0:9976 0:4664 0:0928 0:8584 0:9999 0:0099 0:0197 0:9703

(c) (d) (e) (f) (g)

x(T ) 1:1233 0:0898 1:0440 0:7657 1:0098 0:9506

F(n)jn ¼1 0:9375 0:1563 0:3125 0:4688 0:9975 0:0462 0:0925 0:8588 0:9999 0:0098 0:0197 0:9703

d2 y(t) + zζω d y(t)+ω 2 y(t) = Kω 2 u(t) n n n dt dt 2

u(t)

FIGURE 3.22

x A (n) 1:0938 0:1563 1:0438 0:7662 1:0097 0:9506

y(t)

A second-order system with a unit step input.

Find the continuous-time response for x1(t). Find the steady state x(1). Choose the integration step T ¼ 0.5 s and ﬁnd the discrete-time system matrix G. Find the steady-state vector xA(1). Compare the results from parts (d) and (f). Find the discrete-time signal x1,A(n) and compare it with x1(t).

(a) The state equations for this second-order system are easily found from a simulation diagram using cascaded integrators with outputs dy=dt and y. The result is dx1 ¼ x2 dt dx2 ¼ Kv2n u v2n x1 2zvn x2 dt

(3:166) (3:167)

Since y1 ¼ y ¼ x1, the matrices A, B, C, and D in the state equations are A¼

0 v2n

1 , 2zvn

B¼

0 , Kv2n

C ¼ ½1

0 ,

D ¼ [0]

(3:168)

(b) From Equation 3.153, the discrete-time system matrix is 1 G ¼ I þ (TA) þ (TA)2 2 " # " #2 1 0 1 1 2 0 þ T ¼IþT 2 v2n 2zvn v2n 2zvn 3 2 1 2 1 T) T(1 zv T) (v n n 7 6 2 7 ¼6 5 4 1 2 2 2 vn T(1 zvn T ) 1 2zvn T þ (vn T) (4z 1) 2

(3:169) (3:170)

(3:171)

131

Elementary Numerical Integration (c) The unit step response is (see Equation 2.23) zvn x1 (t) ¼ K 1 ezvn t cos vd t þ sin vd t , vd

t0

(3:172)

The damped natural frequency vd is computed from its deﬁnition vd ¼

pﬃﬃﬃ qﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 3 rad=s 1 z2 v n ¼ 1 0:52 0:4 ¼ 5

Substituting the system parameter values into Equation 2.23 and simplifying lead to pﬃﬃﬃ pﬃﬃﬃ pﬃﬃﬃ 3 3 3 x1 (t) ¼ 2 1 et=5 cos tþ sin t , 5 3 5

t0

(3:173)

(d) The continuous-time state vector at steady state x(1) is obtained from x_ (1) ¼ Ax(1) þ Bu(1) ¼ 0

(3:174)

1

x(1) ¼ A Bu(1) where

(3:175)

0 1 0 ¼ v2n 2zvn (0:4)2 2(0:5)(0:4) 0:16 0 0 0 ¼ ¼ B¼ 2 Kv2n 2(0:4) 0:32 2 0 1 1 0 [1] ¼ ) x(1) ¼ 0:32 0 0:16 0:4 A¼

0

1

¼

1 0:4

(e) The discrete-time system matrix is computed from Equation 3.171 as 3 1 1 [0:4(0:5)]2 0:5[1 0:5(0:4)(0:5)] 7 6 2 G¼4 5 1 (0:4)2 0:5[1 0:5(0:4)(0:5)] 1 2(0:5)(0:4)(0:5) þ [0:4(0:5)]2 [4(0:5)2 1] 2 0:980 0:45 ¼ 0:072 0:80 2

(f) The discrete-time state is updated using Equation 3.153. 1 1 x A (n þ 1) ¼ Gx A (n) þ T 2 ABu(n) þ TBu n þ 2 2 " " # 0 0:980 0:45 1 x A (n) þ (0:5)2 ¼ 2 0:16 0:072 0:80 " # 0 þ (0:5) [1] 0:32 " # " # 0:980 0:45 0:040 x A (n þ 1) ¼ x A (n) þ [1] 0:072 0:80 0:144

(3:176) 1 0:4

#"

0 0:32

# [1]

Note that u(n) and u(n þ 1=2) in Equation 3.176 are both equal to the 1 1 vector [1].

(3:177)

(3:178)

Simulation of Dynamic Systems with MATLAB® and Simulink®

132 2.4 2.1 1.8

x1 (ft)

1.5

Modified Euler integration (T = 0.5 s)

1.2 0.9 0.6

x1,A(n), n = 0, 1, 2, 3, ..., 55 x1(t), 0 ≤ t ≤ 27.5

0.3 0

FIGURE 3.23

0

3

6

9

12

15 t (s)

18

21

24

27

Continuous- and discrete-time step responses.

The discrete-time state vector at steady state xA(1) is obtained by substituting xA(n þ 1) ¼ xA(n) ¼ xA(1) in the previous equation.

) x A (1) ¼

0:980 I 0:072

0:45 0:80

1

2 0:040 [1] ¼ 0 0:144

in agreement with the continuous-time state vector at steady state x(1). (g) The difference equation for xA(n) in Equation 3.178 is solved recursively in the MATLAB® script ﬁle ‘‘Chap3_Ex6_3.m.’’ The continuous-time state variable x1(t) and the discrete-time state variable x1,A(n) are plotted in Figure 3.23. A sample of the results for x1,A(n) along with the exact solution for x1(t) are compiled in Table 3.6. Our last example is that of a nonlinear second-order system. The equations developed in this and previous sections for linear systems are not applicable; however, the implementation of numerical integration is nonetheless straightforward. A state variable model of the nonlinear system is required. The discrete-time state is updated using the state derivative functions in accordance with the desired numerical integration routine.

TABLE 3.6 Summary of Results for x1(t) and x1, A(n) n

x1,A(n)

tn

x1(t1)

N

x1, A(n)

tn

x1(tn)

0 5 10 15 20 25

0 0.6904 1.7046 2.2447 2.2979 0.1434

0 2.5 5 7.5 10 12.5

0 0.6806 1.6989 2.2487 2.3062 2.1492

30 35 40 45 50 55

2.0038 1.9509 1.9604 1.9869 2.0042 2.0080

15 17.5 20 22.5 25 27.5

2.0046 1.9487 1.9580 1.9859 2.0043 2.0086

133

Elementary Numerical Integration

Example 3.12 A simple pendulum is shown in Figure 3.24. The mass of the rod is negligible compared to the mass m of the sphere. Linear damping at the ﬁxed end is assumed. The angular position of the rod u(t) satisﬁes the nonlinear differential equation J€u þ cu_ þ mgr sin u ¼ 0

(3:179)

_ (a) Find the nonlinear state equations when x1 ¼ u and x1 ¼ u. (b) Find the difference equations for updating the discrete-time state components x1,A(n) and x2,A(n) when explicit Euler integration is used. Suppose the system parameters are m ¼ 0.25 slugs, r ¼ 0.75 ft, and c ¼ 0.1 ft lb per rad=s. The moment of inertia J ¼ mr 2 ¼ 0.1406 ft lb s2. Find a suitable value for T and solve the discrete-time state equations recursively under the following conditions: _ ¼ 0 rad=s. Graph x1,A(n) and x2,A(n). (c) u(0) ¼ p=6 rad, u(0) _ ¼ 0:5 rad=s. Graph x1,A(n) and x2,A(n). (d) u(0) ¼ 0 rad, u(0) (a) x_ 1 ¼ u_ ¼ x2

(3:180)

1 _ x_ 2 ¼ €u ¼ [mgr sin u cu] J

(3:181)

1 ¼ (mgr sin x1 cx2 ) J

(3:182)

The continuous-time state equations are x_ 1 ¼ f1 (x1 , x2 ) ¼ x2 x_ 2 ¼ f2 (x1 , x2 ) ¼

1 (mgr sin x1 cx2 ) J

(3:183) (3:184)

(b) Using explicit Euler integration, the difference equations for updating the discrete-time state are x1,A (n þ 1) ¼ x1,A (n) þ Tf1 [x1,A (n), x2,A (n)]

(3:185)

) x1,A (n þ 1) ¼ x1,A (n) þ Tx2,A (n)

(3:186)

x2,A (n þ 1) ¼ x2,A (n) þ Tf2 [x1,A (n), x2,A (n)]

(3:187)

T ) x2,A (n þ 1) ¼ x2,A (n) [mgr sin x1,A (n) þ cx2,A (n)] J θ r

m

FIGURE 3.24 A simple nonlinear pendulum with damping.

(3:188)

(c) Choosing T ¼ 0.0025 s, a recursive solution of Equations 3.186 and 3.188 is easily obtained. The initial state is x1,A(0) ¼ x1(0) ¼ p=6 rad and x2,A(0) ¼ x2(0) ¼ 0 rad=s. To make it easier to visualize the discrete nature of the response, graphs of x1,A(n) and x2,A(n) are shown for n ¼ 0, 20, 40, . . . , 4000 in Figure 3.25 corresponding to approximations of each state at times tn ¼ 0, 0.05, 0.1, . . . , 10 s. As expected, the pendulum returns to its equilibrium position. (d) Simulation results for x1,A(0) ¼ 0 rad and x2,A(0) ¼ 0.5 rad=s are shown in Figure 3.26.

Simulation of Dynamic Systems with MATLAB® and Simulink®

134

x1, A(n), rad

0.5

x1, A(0) = x(0) = π/6 rad

0.25 0 −0.25 −0.5 0

1

2

3

4

5 t (s)

6

7

8

9

10

8

9

10

x2, A(n), rad/s

1 x2, A(0) = dx(0)/dt = 0 rad/s

2 0 −2 0

FIGURE 3.25

1

2

3

4

5 t (s)

6

7

Nonlinear pendulum simulation with x1(0) ¼ p=6 rad and x2(0) ¼ 0 rad=s.

x1, A(n), rad

0.08 x1, A(0) = x (0) = 0 rad

0.04 0 −0.04 −0.08 0

1

2

3

4

5 t (s)

6

7

8

9

10

9

10

x2, A(n), rad/s

0.5 x2, A(0) = dx(0)/dt = 0.5 rad/s

0.25 0 −0.25 −0.5 0

FIGURE 3.26

1

2

3

4

5 t (s)

6

7

8

Nonlinear pendulum simulation with x1(0) ¼ 0 rad and x2(0) ¼ 0.5 rad=s.

Exact solutions for the state components are not easily obtained owing to the nonlinearity in Equation 3.179. A ‘‘quasi exact’’ solution could be found by choosing an exceedingly small value of T and plotting the results on the same graph for comparison with the discrete-time approximations shown in Figures 3.25 and 3.26. It is left as an exercise to show that the discrete-time and ‘‘quasi exact’’ responses are in basic agreement. Looking at the graphs in Figures 3.25 and 3.26, we might be inclined to believe that the integration step size T ¼ 0.0025 s is a ‘‘one size ﬁts all’’ value for simulating the pendulum dynamics. However, Figure 3.27 will quickly dispel this thinking. The results shown

135

Elementary Numerical Integration

x1, A(n), rad

2 x1,A(0) = x(0) = π/6 rad

1 0 −1 −2

c = 0 ft lb/rad/s 0

x2, A(n), rad/s

10

2

4

6

8

10 t (s)

12

14

16

18

20

10 t (s)

12

14

16

18

20

x2,A(0) = dx(0)/dt = 0 rad/s

5 0 −5 c = 0 ft lb/rad/s −10

FIGURE 3.27

0

2

4

6

8

Undamped pendulum simulation with x1(0) ¼ p=6 rad and x2(0) ¼ 0 rad=s.

in Figure 3.27 correspond to an undamped pendulum (c ¼ 0) with the same initial conditions as in part (c) and the same step size of 0.0025 s. Every 20th point of the discrete-time state responses is plotted. Clearly, explicit Euler integration using a step size of T ¼ 0.0025 s is not advisable since the discrete-time state responses bear no resemblance whatsoever to the real (continuous-time) system responses. A valuable lesson of this example is the need to exercise caution when choosing the integration step size for numerical integration. If we are not careful, the integrators may be ‘‘unstable’’ under certain conditions. This point is revisited in detail in Chapter 8.

EXERCISES 3.24 A mass is suspended from a stationary support by a spring as shown in Figure E3.24. The mass is displaced from its equilibrium position 1 ft and released with zero velocity. The continuous-time model of the system is m€x þ kx ¼ 0.

k

x m

FIGURE E3.24

Simulation of Dynamic Systems with MATLAB® and Simulink®

136

(a) Find the matrix A in the state equations x_ ¼ Ax for the continuous-time model. (b) Find the matrix G in the discrete-time state equations xA(n þ 1) ¼ GxA(n) resulting from the use of improved Euler integration to approximate the response of the continuous-time system. (c) The system parameters are k ¼ 4 lb=ft and m ¼ 1 slug. Fill in the following table:

N 0 1 2 3 4 5 6 7 8 9 10

xA(n) T ¼ 0.05 s

x(nT )

n

xA(n) T ¼ 001 s

x(nT )

0 5 10 15 20 25 30 35 40 45 50

3.25 By trial and error, determine an acceptable value for the step size T in simulating the nonlinear pendulum response in Example 3.12 using implicit Euler integration. The initial conditions are x1(0) ¼ p=6 rad and x2(0) ¼ 0.5 rad=s. Plot the discrete-time state x1, A(n), n ¼ 0, 1, 2, . . . , nf where nfT ¼ 10 s for each value of T. 3.26 Repeat Exercise 3.25 using trapezoidal integration instead of implicit Euler. 3.27 Choose a very small time step, for example, T ¼ 0.0001 s, in Example 3.12 to obtain the ‘‘quasi exact’’ solution and plot the results on the same graph with the discrete-time responses in Figures 3.25 and 3.26. Comment on the results. 3.28 The nonlinear pendulum model in Example 3.12 is often approximated by J€ u þ cu_ þ mgru ¼ 0 when the angular displacement u is small, that is, the small angle approximation u ¼ sin u is used resulting in the linear differential equation model above. Compare the results of simulating the linear and nonlinear models using modiﬁed Euler integration. The initial _ angle u(0) ¼ 58 and the initial angular velocity u(0) ¼ 08=s. 3.29 A logistic population growth model dP ¼ cP(Pm P) dt is to be simulated in order to approximate the population P(t) for a period of time. (a) Find the difference equation for PA(n) intended to approximate P(t) based on the use of the following numerical integrators: (i) Explicit Euler (T ¼ 0.25 year) (ii) Trapezoidal (T ¼ 0.5 year) (iii) Improved Euler (T ¼ 0.5 year)

137

Elementary Numerical Integration

(b) Fill in the following table with the simulated populations based on the three numerical integrators and the exact solution. Note that c ¼ 1.25 109, Pm ¼ 25 million, and P(0) ¼ 5 million. The exact solution is given by P(t) ¼

t (Years) Explicit Euler Trapezoidal Improved Euler Exact

Pm P(0) , P(0) þ [Pm P(0)]ecPm t

0

50

100

t0

150

200

250

5.0000 5.0000 5.0000 5.0000

3.30 The tank in Figure E3.30 has a brine solution ﬂowing into it. The solution is stirred well to ensure that the concentration of salt in the tank is uniform. c1, F1 H c, Q

A

c, F0

FIGURE E3.30

c1 is the brine concentration (lb=gal) F1 is the brine ﬂow (gal=min) c is the salt concentration in tank (lb=gal) Q is the quantity of salt in tank (lb) H is the liquid level in tank (ft) V is the volume of liquid in tank (gal) F0 is the ﬂow rate from tank (gal=min) The mathematical model consists of the following equations: dQ ¼ c1 F1 cF0 dt c A

Q , V ¼ AH V

dH þ F0 ¼ F1 , dt

K F0 ¼ aH 1=2

The system baseline parameter values are A ¼ 25 ft2 and a ¼ 0.75 gal=min per ft1=2. Note: 1 ft3 of water is roughly 8.3 gal.

138

Simulation of Dynamic Systems with MATLAB® and Simulink®

(a) Draw a simulation diagram of the system. (b) Choose the state variables as x1 ¼ Q and x2 ¼ H and the outputs y1 ¼ c, y2 ¼ Q, and y3 ¼ V. Write the state equations in the form x_ 1 ¼ f1 (x1 , x2 , c1 , F1 ), y1 ¼ g1 (x1 , x2 , c1 , F1 ) x_ 2 ¼ f2 (x1 , x2 , c1 , F1 ) y2 ¼ g2 (x1 , x2 , c1 , F1 ) y3 ¼ g3 (x1 , x2 , c1 , F1 ) (c) Find expressions for the steady-state values of the states x1(1) and x2(1) and the outputs y1(1), y2(1), and y3(1) assuming c1 and F1 are constant. (d) The tank is initially ﬁlled with 100 gal of water (no salt). Brine starts ﬂowing in to the tank at a rate of 2 gal=min. The salt concentration of the brine is 0.25 lb=gal. Both the ﬂow rate and salt concentration of the brine ﬂow remain constant. Using explicit Euler and improved Euler integration, ﬁnd the discrete-time state equations. x A (n þ 1) ¼ f [(x A (n), u(n)] yA (n) ¼ g[x A (n), u(n)] which are used to obtain an approximate solution for the continuous-time states and outputs. (e) Solve the discrete-time state equations recursively for the discrete-time states and x1, A(n) and x2, A(n) and outputs y1, A(n), y2, A(n), and y3, A(n). Graph the transient responses. Comment on the values of T used for each type of numerical integrator. (f) Compare the steady-state results obtained in part (e) with the predicted values from part (c). Comment on the results.

3.7 CASE STUDY: VERTICAL ASCENT OF A DIVER As a diver submerges, pressure increases in direct proportion to the depth. This pressure is caused by the combined weight of the surrounding water and the atmosphere above and is called ambient pressure. At a depth of 70 ft, ambient pressure is equal to more than three atmospheres (three times the atmospheric pressure at sea level). In order to overcome this pressure and ﬁll his lungs with vital air, the diver must breathe air supplied to him at the ambient pressure. The air is a mixture of approximately 20% vital oxygen and 80% inert nitrogen. The oxygen component of the air is used by the body, and waste carbon dioxide is exhaled. Under normal atmospheric conditions, the nitrogen component of the mixture has no effect. But under pressure, it dissolves in the bloodstream and in tissues and remains there after the diver begins to ascend. If the diver ascends too quickly, the nitrogen expands and equalizes with the decreasing ambient pressure. Nitrogen bubbles form in the bloodstream and the tissues, leading to an extremely painful condition known as decompression sickness (DCS), more commonly known as the ‘‘bends,’’ which can cause paralysis and even death. The focus of this study is an investigation of the types of cable forces that can be used to bring a deep-sea diver safely to the surface. The mathematical model governing the diver’s ascent consists of differential equations relating the forces acting on the diver and the dynamics of the diver’s internal body pressure (McClamroch 1980). The following notation is used: h ¼ h(t) is the depth of diver below sea level, ft h_ ¼ (d=dt)h(t) is the velocity of diver, ft=s € h ¼ (d2=dt 2)h(t) is the acceleration of diver, ft=s2

139

Elementary Numerical Integration

p ¼ p(t) is the internal body pressure of diver, relative to atmospheric pressure at sea level, lb=ft2 p_ ¼ (d=dt)p(t) is the rate of change of diver’s internal body pressure, lb=ft2 per s Dp ¼ Dp(t) is the difference between body pressure and local underwater pressure, lb=ft2 fc ¼ fc(t) is the external cable force on diver, lb fd ¼ fd(t) is the drag force on diver, lb fB is the buoyant force on diver, lb m is the mass of diver, slugs W is the weight of diver and gear at sea level, lb V is the volume of diver and gear, ft3 K is the body tissue constant of diver, s1 m is the drag coefﬁcient of diver under water, lb s=ft g is the weight density of water (62.4 lb=ft3) g is the gravitational constant (32.2 ft=s2) The forces acting on the diver are a cable force fc, a drag force fd, a buoyant force fB, and the diver’s weight W. From Newton’s second law with h and all forces measured positive in the downward direction, m€ h ¼ W fB þ f d f c

(3:189)

fd ¼ mh_

(3:190)

The drag force is modeled by

The buoyant force is equal to the weight of water displaced by the diver and gear fB ¼ gV

(3:191)

Combining Equations 3.189, 3.190, and 3.191 gives W€ h þ mh_ ¼ (W gV) fc g

(3:192)

The right-hand side of Equation 3.192 is the difference between the diver’s effective weight in the water (W gV ) and the cable force fc. Denoting the net cable force by fn ¼ (W gV) fc

(3:193)

leads to the second-order differential equation W€ h þ mh_ ¼ fn g

(3:194)

The rate of change of the diver’s internal body pressure is assumed proportional to the difference between the local underwater (ambient) pressure and the diver’s internal body pressure. That is, p_ ¼ K(gh p)

(3:195)

We are interested in h, the diver’s depth below the surface, and Dp, the difference between the internal body pressure of the diver and the ambient underwater pressure. The dynamic system under investigation is portrayed in Figure 3.28.

Simulation of Dynamic Systems with MATLAB® and Simulink®

140

fn

FIGURE 3.28

h

Diver

Δp

Dynamic system with input fn and outputs h and Dp.

The third-order linear dynamic system can be modeled in state variable form. The state variables are chosen as _ x2 ¼ h,

x1 ¼ h,

x3 ¼ p

(3:196)

Solving for the state derivatives x_ 1 ¼ h_ ¼ x2

(3:197)

mg _ g h þ fn W W mg g ¼ x2 þ f n W W

x_ 2 ¼ € h¼

(3:198) (3:199)

x_ 3 ¼ p_ ¼ Kgx1 Kx3 2 3 2 0 1 x_ 1 6 7 6 mg 7 6 )6 4 x_ 2 5 ¼ 4 0 W x_ 3 Kg 0

0

32

3

2

(3:200)

3

0 x1 76 7 6 g 7 6 7 6 7 0 7 54 x2 5 þ 4 W 5[ fn ] x3 K 0

(3:201)

The outputs are expressed in terms of the states as y1 ¼ h ¼ x 1

(3:202)

y2 ¼ P gh ¼ x3 gx1 " )

y1

#

" ¼

y2

1

0

g

0

2

(3:203)

3

# x1 0 6 7 6 x2 7 4 5 1 x3

(3:204)

The state equation matrices A, B, C, and D are given by 2

0

6 A¼6 4 0 Kg

3 1 0 7 mg 0 7 5, W 0 K

2

3 0 6g7 7 B¼6 4 W 5, 0

" C¼

1

0

0

g

0

1

# ,

D¼

" # 0 0

(3:205)

In order to obtain a numerical solution to the state equations, the initial conditions, that is, the initial state x(0), must be known. Assuming the diver is initially in equilibrium with his or her surroundings leads to _ h(0) ¼ x2 (0) ¼ 0

(3:206)

_ p(0) ¼ K[gh(0) p(0)]

(3:207)

¼ K[gx1 (0) x3 (0)]

(3:208)

141

Elementary Numerical Integration

Setting p_ equal to zero in Equation 3.208 gives x3 (0) ¼ gx1 (0)

(3:209)

Initial depth x1(0) is arbitrary; however, to be in equilibrium, the diver’s effective weight in the water W gV must be counterbalanced by the initial cable force fc(0). fc (0) ¼ W gV

(3:210)

Note that the initial net force to maintain the diver in equilibrium is fn (0) ¼ (W gV) fc (0) ¼ 0

(3:211)

A simulation of the diver’s ascent subject to a constant cable force in excess of fc(0) in Equation (3.210) is needed. The discrete-time state equation is x A (n þ 1) ¼ Gx A (n) þ Hu(n)

(3:212)

where G and H depend on the choice of numerical integrator. Using trapezoidal integration for now and leaving the other discrete-time integrators for the exercise problems, the discrete-time state is updated according to Equation 3.121 x A (n þ 1) ¼

1 I þ TA 2

1 1 1 1 1 I þ TA x A (n) þ I TA TB[ u(n) þ u(n þ 1)] 2 2 2

(3:213)

With a constant cable force fc ¼ fc , t 0, the input fn is likewise constant, that is, fn ¼ fn ¼ (W gV)fc ,

t0

(3:214)

The second term in Equation 3.213 can be simpliﬁed, that is, 1 1 1 1 1 1 TB[ u(n) þ u(n þ 1)] ¼ TB[ fn þ fn ] I TA I TA 2 2 2 2 1 1 ¼ T I TA Bfn 2

(3:215)

(3:216)

Hence, for the special case where the input u(n) is constant for all n, the discrete-time matrices G and H in Equation 3.212 using trapezoidal integration are

1 1 1 I þ TA G ¼ I TA 2 2 1 1 H ¼ T I ¼ TA B 2

(3:217)

(3:218)

Baseline numerical values for the system parameters are K ¼ 0.2, m ¼ 6.5, W ¼ 300, V ¼ 3, and the step size T ¼ 0.25 s. Evaluating matrices A and B, 2 3 2 3 0 1 0 0 A¼4 0 0:6977 0 5, B ¼ 4 0:1073 5 12:48 0 0:2 0

Simulation of Dynamic Systems with MATLAB® and Simulink®

142

The discrete-time matrices G and H are obtained from Equations 3.217 and 3.218. 2

3 2 3 0 0:0031 0 5, H ¼ 4 0:0247 5 0:0047 0:9512

1 0:2299 G¼4 0 0:8396 3:0439 0:3500

The discrete-time state equation, Equation 3.212, is 2

1 0:2299 x A (n þ 1) ¼ 4 0 0:8396 3:0439 0:3500

3 2 3 0 0:0031 0 5x A (n) þ 4 0:0247 5fn 0:9512 0:0047

(3:219)

Before simulating the diver’s ascent to the surface, we can make the cable force equal to its equilibrium value in Equation 3.210 and observe whether the system remains in equilibrium. Setting fc ¼ W gV ¼ 112.8 lb makes the net force fn ¼ 0. Additionally, we must remember to make x3(0) ¼ gx1(0) where x1(0) is the arbitrary initial depth. Figure 3.29 shows the results of solving Equation 3.219 under these conditions with the diver starting at 500 ft below the surface. As expected, the system remains in an equilibrium state. Suppose the cable force is increased by 10% above its equilibrium value to 1.1(W gV) ¼ 1.1 (112.8) ¼ 124.08 lb. The MATLAB script ﬁle ‘‘Chap3_CaseStudy.m’’ generates a recursive solution to the discrete-time system difference equations in Equation 3.219. The results are plotted in Figure 3.30 for a duration of time sufﬁcient to bring the diver to the surface. The integration step size T could be varied an order of magnitude in either direction and the results compared with those in Figure 3.30 to determine if the current value T ¼ 0.25 s needs to be adjusted. Since the system dynamics are linear, analytical solutions for the continuous-time state variables in Equation 3.201 are easily determined and given in Equations 3.220 through 3.222.

Discrete-time state variables for diver at equilibrium

x1 (ft)

600 x1(n), n = 0, 1, 2, ... x1(t)

400 200 0

0

1

2

3

4

5

6

7

8

9

10

4

5

6

7

8

9

10

4

5 t (s)

6

7

8

9

10

x2 (ft/s)

10 x2(n), n = 0, 1, 2, ... x2(t)

7.5 5 2.5 0

x3 (Ib/sq ft)

4

×104

1

2

3

3 x3(n), n = 0, 1, 2, ... x3(t)

2 1 0

0

1

2

3

FIGURE 3.29 System at equilibrium: x1(0) ¼ 500 ft, x2(0) ¼ 0 ft=s, x3(0) ¼ gx1(0) ¼ 3120 lb=ft2, fc ¼ W gV ¼ 112.8 lb.

143

Elementary Numerical Integration

x1 (ft)

600 x1(n), n = 0, 25, 50, ... x1(t)

400 200 0

0

50

100

150

200

250

300

x2 (ft/s)

0 x2(n), n = 0, 25, 50, ... x2(t)

−0.5 −1 −1.5 −2

x3 (Ib/sq ft)

4

50

×104

100

150

200

250

300

x3(n), n = 0, 25, 50, ... x3(t)

3 2 1 0

0

50

100

150

200

250

300

t (s)

FIGURE 3.30

State variables for diver’s ascent: fc ¼ 1.1 (W gV).

The derivation is left as an exercise problem at the end of this section. gfn 1 eat t x1 (t) ¼ h(0) þ aW a gfn (1 eat ) aW

gfn K(1 eat ) a(1 eKt ) x3 (t) ¼ g h(0) þ tþ aW a(a K) K(a K)

x2 (t) ¼

(3:220) (3:221) (3:222)

where the constant a ¼ mg=W. The analytical solutions for the states are plotted in Figure 3.30 along with the discrete-time states. There is close agreement between the numerical (discrete time) and analytical solutions for each of the state variables. Notice that after about 6 s, the diver is surfacing at a constant velocity, and both depth and internal body pressure are decreasing linearly with time. Equation 3.220 can be used to estimate the time required for the diver to surface. If the initial depth is great enough, at the time the diver surfaces, the exponential term will have died out. Consequently, the time to surface ts can be estimated from 0 ¼ h(0) þ ) ts ¼ ¼

gfn 1 ts aW a

(3:223)

W mh(0) W mh(0) ¼ mg fn mg (W gV) fc 300 6:5(500) ¼ 289:6 6:5(32:2) 0:1(112:8)

in agreement with the graphs of x1, A(n) and x1(t) shown in Figure 3.30.

(3:224)

Simulation of Dynamic Systems with MATLAB® and Simulink®

144

We have yet to look at the differential pressure Dp ¼ p gh, the second component of the output vector y2 in Equation 3.203. The discrete-time output y A (n) is a linear combination of the discretetime state x A(n) and input u(n), that is, y A (n) ¼ Cx A (n) þ Du(n)

(3:225)

The second component of yA(n) reduces to y2, A (n) ¼ C2,1 x1, A (n) þ C2,2 x2, A (n) þ C2,3 x3, A (n)

(3:226)

since the direct transmission matrix D is zero. Substituting the components of C in Equation 3.205 into Equation 3.226 gives y2, A (n) ¼ gx1, A (n) þ x3, A (n)

3.7.1 MAXIMUM CABLE FORCE

FOR

(3:227)

SAFE ASCENT

Suppose a safe ascent implies that the differential pressure Dp is never to exceed a value denoted by Dpmax. The maximum cable force for a safe ascent ( fc)max can be obtained in one of two ways. 3.7.1.1 Trial and Error The constant cable force can be initialized to a value slightly more than the equilibrium force Weff ¼ W gV and the diver’s ascent simulated. If the maximum differential pressure during the ascent is less than Dpmax, the ascent is simulated again with a larger cable force. The reverse is true if the maximum differential pressure exceeds Dpmax. The process is repeated until the cable force producing a maximum differential pressure of Dpmax (within some tolerance) is obtained. Figure 3.31 shows the result of simulating several ascents to ﬁnd ( fc)max for the case when Dpmax ¼ 4 psi. The discrete-time differential pressure responses are labeled and graphed as if they were continuous time in nature; however, the points along each plot were obtained by recursive solution of difference equations. Note the dramatic increase in ascent time as the cable force approaches the equilibrium value of 112.8 lb. 4.5

fc = 125 lb

Δpmax = 4 psi

Differential pressure Δp(t), (psi)

4 3.5

fc = 123 lb

3

fc = 121 lb

2.5

fc = 119 lb

2 1.5

fc = 117 lb

1

fc = 115 lb

0.5 0

FIGURE 3.31

0

250

500

750 t (s)

1000

1250

1500

Differential pressure during ascent of a diver for different cable forces.

145

Elementary Numerical Integration

3.7.1.2 Analytical Solution A second approach to ﬁnding the maximum cable force for a safe ascent is based on analytical solutions for the state variables x1(t) and x3(t). From Equations 3.220 and 3.222, the steady-state responses are gfn 1 t x1 (t)ss ¼ h(0) þ aW a

gfn K a tþ x3 (t)ss ¼ g h(0) þ a(a K) K(a K) aW

(3:228) (3:229)

where fn is the constant net force applied during ascent of the diver. The differential pressure at steady state is Dpss ¼ x3 (t)ss gx1 (t)ss

(3:230)

Substituting Equations 3.228 and 3.229 into Equation 3.230 and simplifying the expression result in Dpss ¼

gfn mK

(3:231)

( The cable force ( fc )max responsible for Dpss ¼ Dpmax is obtained from Dpmax ¼

gfn g½(W gV) (fc )max ¼ mK mK

) (fc )max ¼ (W gV) þ

(3:232)

mKDpmax g

¼ [300 62:4(3)] þ ¼ 124:8 lb

6:5(0:2)(4 144) 62:4 (3:233)

in agreement with the response shown in Figure 3.31.

3.7.2 DIVER ASCENT

WITH

DECOMPRESSION STOPS

Ordinarily, a deep-sea diver ascending from several 100 ft or more down makes several decompression stops to allow the nitrogen gas to be released in a slow and controlled manner. His internal pressure is given time to equalize with the ambient pressure at different depths. A typical cable force for accomplishing this is shown in Figure 3.32. Alternating the cable force between a value larger than the diver’s effective weight, that is, (1 þ b)Weff, b > 0, and the diver’s effective weight Weff results in the diver remaining at certain depths for a ﬁxed period of time before continuing the ascent to the surface. To illustrate, suppose the diver is initially at a depth of 500 ft and is to be brought to the ocean surface in stages allowing for decompression. The difference in ambient water pressure and his internal pressure is not to exceed 4 psi. Figure 3.33 shows the results of a simulation for the same diver as before brought up by a periodic cable force of 124 lb for L ¼ 100 s followed by a value of 112.8 lb for 200 s and then repeated. Once again, the discrete-time signals are plotted as if they were continuous time.

Simulation of Dynamic Systems with MATLAB® and Simulink®

146 fc(t) (1 + β)Weff Weff

L

0

P+L

t 2P

Cable force proﬁle for raising a diver with decompression stops.

fc(t), Ibs

FIGURE 3.32

P

124

130 120 110 100

112.8 L = 100 s, P = 300 s 0

100

200

300

400

500

600

0

100

200

300

400

500

600

200

300

400

500

600

h(t), ft

600 400 200

Δp(t), psi

0

Δpmax = 4 psi

4 2 0

0

100

t (s)

FIGURE 3.33

Diver ascent with stops for decompression.

Referring to Figure 3.31 or Equation 3.233, it follows that a constant cable force of 124 lb for the entire ascent would bring the diver to the surface with a differential pressure never exceeding the safe limit of 4 psi. The ascent would be considerably faster than the 691.75 s shown in Figure 3.33. However, the proﬁle of Dp(t) shown in Figure 3.33 is a safer alternative than the exponential rise shown in Figure 3.31. It may appear from Figure 3.33 that the diver’s depth becomes constant when the cable force is switched from fc ¼ 124 lb to fc ¼ Weff ¼ 112.8 lb. Realistically, the diver cannot come to an abrupt stop when the cable force changes in step fashion. A close-up look at the net cable force fn(t) in Equation 3.193 and the diver’s velocity during a portion of the ascent is shown in Figure 3.34. It is clear from observing the velocity that the diver continues moving toward the surface for a short period of time immediately following the change in cable force from 124 to 112.8 lb (or equivalently the net force changing from 11.2 to 0 lb). The explanation of decompression and the plots shown in Figure 3.33 oversimplify the problem. Onset of the ‘‘bends’’ is caused by an excess of dissolved nitrogen in the blood to the point where it cannot be disposed of in a normal manner. The amount of nitrogen that dissolves in the blood is related to the time a diver remains at a given depth. That is, it takes longer to absorb a dangerous amount of nitrogen at a shallow depth compared to a depth further down from the surface. Reference tables provide empirical data relating required decompression times with duration of time spent at a given depth (Reseck 1990). A ﬁnal observation about the diver model is relevant. The coupling between the second-order differential equation for h in Equation 3.192 and the ﬁrst-order differential equation for p in

147

Elementary Numerical Integration

0 −1

dh/dt

−2 −3 −4 −5 −6 −7 −8 −9 −10 −11

fn(t)

−12

FIGURE 3.34

100

150

200 t (s)

250

300

Net cable force fn(t) in lbs and diver velocity dh=dt in ft=s with decompression stops.

Equation 3.195 is one way, that is, the diver’s internal pressure p does not affect the depth h, and a second-order state model is suitable if the pressure is not of interest. On the other hand, the depth h inﬂuences the diver’s internal pressure p, and hence the ﬁrst-order differential Equation (3.195) cannot be solved independently of the second-order differential Equation (3.192).

EXERCISES 3.31 A simple study can be conducted to ﬁnd the ‘‘best’’ value for T, the integration step size. Since a graph of the analytical solutions for the continuous-time state variables and the discrete-time state approximation are in close agreement (Figure 3.30) when T ¼ 0.25 s, we would like to know if a larger value of T can be used without sacriﬁcing signiﬁcant accuracy. With this in mind, for T ¼ 0.5, 1, 2, 4, . . . . (a) Find the system and input matrices G and H of the discrete-time system using trapezoidal integration. (b) Solve the resulting discrete-time state equations for the discrete-time state vector x A (n) ¼ [x1, A (n), x2, A (n), x3, A (n)]T and plot the results on the same graph as the continuous- time solution, similar to Figure 3.30. Stop when a noticeable difference between x A(n) and x(nT) occurs. 3.32 Using the baseline conditions for the system parameters unless stated otherwise, (a) Find the cable force ( fc)max to bring up divers (plus gear) weighing 200, 250, 300, 350, and 400 lb while not exceeding a maximum differential pressure DPmax ¼ 4 psi. Enter the results in the following table. Prepare a graph of ( fc)max vs. W. Comment on the results. (b) In part (a), record the time required for the diver to surface ts and enter in the following table. Plot a graph of ts vs. W. W (lb)

200

250

300

350

400

( fc)max ts (s)

(c) Suppose the volume V of the diver and gear vary with the diver’s weight according to V ¼ 1 þ (W=150). Repeat parts (a) and (b).

Simulation of Dynamic Systems with MATLAB® and Simulink®

148

3.33 For the velocity during diver with baseline conditions, ﬁnd the ‘‘best’’ step size T for simulating the diver’s ascent from 250 ft using (i) Explicit Euler integration (ii) Improved Euler integration (iii) Modiﬁed Euler integration Specify your criterion for determining the ‘‘best’’ step size. 3.34 Derive the analytical solutions for the continuous-time states given in Equation 3.220 through 3.222. Hint: It may be necessary to defer this problem until after reading Section 4.2 on the Laplace transform. 3.35 Using the baseline conditions given for the diver, simulate the response using explicit Euler integration when the constant cable force is 15% below the equilibrium value. Prepare plots of the continuous-time and discrete-time states for a duration of 100 s. 3.36 It is suggested that a sinusoidal cable force fc (t) ¼ F þ A sin(2pt=p) be more effective in bringing the diver to the surface safely, that is, Dp(t) Dpmax, t 0, and in less time compared to a constant force. Using the baseline system parameters, choose a numerical integration method to approximate the system dynamics with the suggested type of cable force, that is, experiment with different values of F, A, and P, and comment on the validity of the claim about using the sinusoidal cable force. 3.37 Suppose the diver with baseline condition parameter values is initially at a depth of 750 ft at equilibrium conditions. (a) The cable force bringing the diver to the surface is as shown in Figure 3.32 with b ¼ 0.1 and P ¼ 300 s. Vary the duty cycle 100 (L=P) from 20% to 100% in increments of 20%, and simulate the diver’s ascent using a numerical integrator with appropriate step size. Fill in the following table and plot the results. Duty Cycle (%)

Time to Surface (s)

Maximum Differential Pressure (psi)

20 40 60 80 100

(b) Repeat part (a) with the duty cycle ﬁxed at 50% and vary the parameter b as shown in the table and ﬁll in the table. b

Time to Surface (s)

Maximum Differential Pressure (psi)

0.03 0.06 0.09 0.12 0.15

3.38 For a diver with system parameters W ¼ 300, K ¼ 0.2, m ¼ 6.5, and V ¼ 3, (a) Plot the inverse relationship in Equation 3.233, that is, Dpmax vs. ( fc)max. (b) Simulate several diver ascents from different initial depths using constant cable forces and compare the simulated maximum differential pressure with the values from the graph.

Elementary Numerical Integration

149

3.39 A 250 lb diver with gear weighing another 100 lb is 400 ft below the surface in equilibrium with his surroundings. A winch cable begins bringing him to the surface using a constant force. (a) Using the analytical solution for the state variables, ﬁnd the required force needed for the diver to be ascending at a constant rate of 1.5 ft=s (h_ ¼ 1:5 ft=s) when he reaches the surface. The remaining parameter values are K ¼ 0.25, m ¼ 5, and V ¼ 3.25. (b) Simulate the diver ascent using the force determined in part (a) to verify the result. Use Euler integration with step size T ¼ 0.1 s. (c) Plot the state variables for the simulation in part (b). 3.40 A diver initially in equilibrium at a depth of 150 ft is ascending to the surface under the inﬂuence of a constant cable force equal to 10% greater than the equilibrium force. The cable snaps when the diver is 50 ft from the surface. Simulate the diver’s depth, velocity, and differential pressure for 120 s. Use any of the numerical integrators presented. System parameters are W ¼ 325, K ¼ 0.23, m ¼ 4.8, and V ¼ 3.15.

This page intentionally left blank

4

Linear Systems Analysis

4.1 INTRODUCTION Chapter 2 introduced ﬁrst- and second-order linear time-invariant (LTI) systems in a very superﬁcial way. A general form for the family of step responses, in the absence of input derivative terms, was presented for both types of systems. Alternate representations of LTI systems, namely, simulation diagrams and state-space models, were also discussed. Chapters 1 and 3 outlined methods for transforming continuous-time differential equation models into discrete-time system models comprising difference equations. In doing so, the grounds were laid for the foundation of continuous-time system simulation. A natural question that arises is ‘‘How accurate is the simulation?’’ In the case of continuous-time systems with LTI models, it helps to have a solid grasp of how LTI systems respond to elementary inputs such as a step, polynomials, exponentials, and periodic functions. The analytical solutions serve as a benchmark in comparing different simulation (discrete-time system) models. This chapter begins with a review of the Laplace transformation and its use in ﬁnding the free and forced response of continuous-time LTI system models. The counterpart of the Laplace transform for discrete-time systems is the z-transform, and it is covered in the later sections along with examples of how it facilitates the process of ﬁnding the response of discrete-time LTI systems. Time and frequency domain characteristics of continuous- and discrete-time LTI system models are discussed. Mappings from the s-plane to the z-plane corresponding to speciﬁc numerical integrators are introduced as a quick way of obtaining discrete-time model approximations of continuous-time systems.

4.2 LAPLACE TRANSFORM The Laplace transform, as the name implies, is a transformation of functions between two domains. The independent variables in the two domains are commonly denoted ‘‘t’’ and ‘‘s’’ as shown in Figure 4.1, and the domains are referred to as the time domain (or t-domain) and s-domain, respectively. A class of functions f(t) deﬁned for t 0 in the time domain are transformed into functions F(s) in the s-domain according to 1 ð

F(s) ¼

f (t)est dt

(4:1)

0

Equation 4.1 is the deﬁnition of the one-sided Laplace transform of a function f(t). The deﬁnition of f(t) for t < 0 is irrelevant since the interval of integration in Equation 4.1 is 0 to 1. It is valid for functions f(t), which are said to be of exponential order, that is, functions that are bounded by increasing exponentials as t ! 1, assuring the convergence of the integral in Equation 4.1. This includes all real-world signals as well as certain functions for which limt!1 f(t) ¼ 1. The notation L{f (t)} is interpreted as the Laplace transform of f(t), that is, the function of ‘‘s’’ resulting from evaluating the integral in Equation 4.1. The function f(t) and its Laplace transform

151

Simulation of Dynamic Systems with MATLAB® and Simulink®

152

F(s) =

{ f(t)}

f(t)

F(s) −1

f(t) =

{F(s)}

t-domain

s-domain

FIGURE 4.1 The Laplace transform L{f (t)} ¼ F(s) and its inverse f (t) ¼ L1 {F(s)}.

F(s) are referred to as a Laplace transform pair using the symbol , with the function f(t) on one side and its transform F(s) on the other side. To illustrate, consider the unit step function û(t) that equals 1 for t 0 and zero for t < 0.

^ ¼ L{^ U(s) u(t)} ¼

1 ð

st

^ u(t)e 0

1 ð

dt ¼

1e 0

st

est

1 1 1 dt ¼ ¼0 ¼ s 0 s s

(4:2)

The contribution from the upper limit, es(1) in Equation 4.2, is zero provided s > 0. More speciﬁcally, Re(s) > 0 because s is a complex variable s ¼ s þ jv. Therefore, 1 L{^ u(t)} ¼ , Re(s) > 0 s

(4:3)

indicating the integral in Equation 4.2 converges so long as the complex variable s is located in the right half of the complex plane. Note that the constant function u(t) ¼ 1, 1 < t < 1 is identical to û(t) for t 0 and consequently has the same Laplace transform. Henceforth, we shall omit reference to the region of convergence for the integral in Equation 4.1 and simply be concerned with the result. The region of convergence is only of interest when we perform the inverse Laplace transformation using an integration formula to transform F(s) into f(t). Returning to the example of the unit step function, the Laplace transform pair is ^u(t) , TABLE 4.1 Table of Laplace Transform Pairs for Elementary Continuous-Time Signals f(t) u(t) ¼ ^ e at tn cos vt sin vt

0, 1,

t > > > < 2(t 1), f (t) ¼ 3, > > > > t þ 7, > > : 0,

9 > > > > 1 t < 2> > = 2t > > 4 t < 7> > > ; 7t t > > < 2t þ 5, u1 (t) ¼ > 1, > > : 0,

0t 0). For simplicity, assume the poles p1, p2, . . . , pn2 are distinct. The partial fraction expansion is N(s) c1 c2 cn2 d1 s þ d2 þ þ þ þ ¼ s pn2 as2 þ bs þ c D(s) s p1 s p2

Y(s) ¼

(4:96)

The constants c1, c2, c3, . . . , cn2 are obtained as before (Case I). The constants d1 and d2 are obtained by recombining the terms on the right-hand side of Equation 4.96 and then equating the coefﬁcients of powers of s in the numerator with the coefﬁcients of like powers of s in the original form of the numerator N(s). The inverse Laplace transform of the last term in Equation 4.96 is L1

d1 s þ d2 d1a þ d2 at d cos bt ¼ e sin bt 1 s2 þ as þ b b

(4:97)

sþ1 sþ1 ¼ s4 þ 5s3 þ 11s2 þ 15s s(s þ 3)(s2 þ 2s þ 5)

(4:98)

c1 c2 d1 s þ d2 þ þ s s þ 3 s2 þ 2s þ 5

(4:99)

To illustrate, consider Y(s) ¼ ¼

From the quadratic formula, the roots of s2 þ 2s þ 5 are 1 j2. Thus, a ¼ 1 and b ¼ 2. The constants c1 and c2 are calculated from

sþ1

¼ 1 2 (s þ 3)(s þ 2s þ 5) s¼0 15 s¼0

sþ1 sþ1 1

c2 ¼ (s þ 3) ¼ ¼ s(s þ 3)(s2 þ 2s þ 5) s¼3 s(s2 þ 2s þ 5) s¼3 12 c1 ¼ s

sþ1 s(s þ 3)(s2 þ 2s þ 5)

¼

(4:100) (4:101)

Combining terms in Equation 4.99 over a common denominator and equating the numerator to s þ 1, the numerator in Equation 4.98 gives 1 1 (s þ 3)(s2 þ 2s þ 5) þ s(s2 þ 2s þ 5) þ (d1 s þ d2 )s(s þ 3) 15 12 1 1 1 1 11 5 )sþ1¼ þ þ d1 s3 þ þ þ 3d1 þ d2 s2 þ þ þ 3d2 s þ 1 15 12 3 6 15 12 sþ1¼

(4:102) (4:103)

Equating coefﬁcients of like powers of s on both sides of Equation 4.103, 1 1 1 1 3 þ þ d1 ) d1 ¼ ¼ 15 12 15 12 20 1 1 1 1 1 3 1 ¼ s2 : 0 ¼ þ þ 3d1 þ d2 ) d2 ¼ 3d1 ¼ 3 3 6 3 6 2 20 20 11 5 1 11 5 1 s1 : 1 ¼ þ þ 3d2 ) d2 ¼ 1 ¼ 15 12 3 15 12 20

s3 : 0 ¼

s0 : 1 ¼ 1 Note, only two of the ﬁrst three equations are needed to solve for d1 and d2, and the remaining two equations serve as a check. Solving for c1 and c2 directly in Equations 4.100 and 4.101 eliminates

Simulation of Dynamic Systems with MATLAB® and Simulink®

166

the need to solve four simultaneous equations for the unknown constants c1, c2, d1, and d2. Substituting the values for c1, c2, d1, and d2 into Equation 4.99 yields 1=15 1=12 (3=20)s 1=20 þ þ s sþ3 s2 þ 2s þ 5 1 1 1 1 1 3s þ 1 ¼ þ 15 s 12 s þ 3 20 s2 þ 2s þ 5

Y(s) ¼

(4:104) (4:105)

The last term is inverted using Equation 4.97 with d1 ¼ 3, d2 ¼ 1, a ¼ 1, and b ¼ 2. Y(t) ¼ ¼

1 1 1 3(1) þ 1 þ e3t et 3 cos 2t þ sin 2t 15 12 20 2

(4:106)

1 1 1 þ e3t et (3 cos 2t sin 2t) 15 12 20

(4:107)

The second method for inverse Laplace transforming terms like the one in Equation 4.97 is based on decomposing it into two terms that can be readily inverted. Starting with an expression containing a quadratic in the denominator with complex roots, the ﬁrst step is to complete the square as illustrated in the following equations: d 1 s þ d2 þ as þ b d 1 s þ d2 ¼ 2 (s þ as þ a2 =4) þ (b a2 =4) d 1 s þ d2 a2 2 v ¼b ¼ 4 (s þ a=2)2 þ v2

F(s) ¼

s2

(4:108) (4:109) (4:110)

After completing the square in the denominator, Equation 4.110 is expressed as the sum of two terms that are the Laplace transforms of shifted trigonometric functions. d1 [(s þ a=2) a=2] þ d2 (s þ a=2)2 þ v2 (s þ a=2) d2 (a=2)d1 v þ ¼ d1 2 2 v (s þ a=2) þ v (s þ a=2)2 þ v2

F(s) ¼

From Table 4.1 and the shifting property P2, f (t) ¼ L1 {F(s)} is d2 (a=2)d1 (a=2)t (a=2)t e f (t) ¼ d1 e cos vt þ sin vt v Returning to the previous example, 1 3s þ 1 1 d 1 s þ d2 ¼ 20 s2 þ 2s þ 5 20 s2 þ as þ b

(4:111) (4:112)

(4:113)

(4:114)

making d1 ¼ 3, d2 ¼ 1, a ¼ 2, b ¼ 5, and v2 ¼ b a2=4 ¼ 4. Substituting the values for d1, d2, a, b, and v into Equation 4.113 leads to the inverse Laplace transform,

1 d2 (a=2)d1 (a=2)t 1 e d1 e(a=2)t cos vt þ sin vt ¼ (3et cos 2t et sin 2t) (4:115) v 20 20 in agreement with the result shown in Equation 4.107.

167

Linear Systems Analysis

Rather than having to remember L

1

d 1 s þ d2 2 s þ as þ b

¼ d1 e

(a=2)t

d2 (a=2)d1 (a=2)t e cos vt þ sin vt v

(4:116)

the inverse Laplace transform in the last example can be obtained directly by completing the square, that is, 1 3s þ 1 F(s) ¼ 20 s2 þ 2s þ 5

1 3[(s þ 1) 1] þ 1 ¼ 20 (s þ 1)2 þ 22 1 3(s þ 1) 2 ¼ 20 (s þ 1)2 þ 22 1 (s þ 1) 2 3 ¼ 20 (s þ 1)2 þ 22 (s þ 1)2 þ 22

(4:117)

(4:118)

(4:119)

(4:120)

Inverse Laplace transformation of F(s) gives the same f(t) in Equation 4.115.

EXERCISES 4.1 Find the Laplace transforms of the functions f(t) given below. Note that û(t t0) is the unit step function delayed t0 units of time. (b) t^ u(t 1) (c) (t 1)^u(t) (d) 2[^u(t Ð 1) ^u(t 4)] (a) t2 sin 2t t (e) (d=dt)(tet) (f) sin(2t þ p=4) (g) Ð(1 3t)e3t (h) e3t 0 sin 2t cos 2tdt t 2 2t 2t (j) te sin 3t (k) 0 te cos 3(t t)dt (i) sin t 4.2 Find the inverse Laplace transforms of the functions F(s) given in the following: 1 1 sþ1 sþ1 (b) (a) 2 (d) 2 (c) (s 1) (s þ 2)(s þ 3) (s þ 2)2 þ 9 s(s 4)3 es e3s sþ1 2s þ 1 s (f) 2 (g) 2 (e) (h) 2 s(s þ 1) s þ1 (s þ 2s þ 5)(s2 þ 5s þ 6) (s þ s þ 1)2 4.3 Find the Laplace transform of the functions f(t) in Figure E4.3a and b. In Figure E4.3b, the function is parabolic over the intervals 0 t < 2 and 4 t < 6 and passes through the points (0, 0), (1, 3), (2, 4) and (4, 4), (5, 3), (6, 0). f(t)

f (t)

5

5

4

4

3

3

2

2

1 0

0 (a)

FIGURE E4.3

1 1

2

3

4

5

6

t

0

0 (b)

1

2

3

4

5

6

t

Simulation of Dynamic Systems with MATLAB® and Simulink®

168

4.4 Graph the function f(t) deﬁned by f (t) ¼ t^ u(t) þ (t 1)^ u(t 1) 2t^u(t 2) þ ^u(t 3) and ﬁnd its Laplace transform. 4.5 Find the Laplace transform of the periodic function f(t) shown in Figure E4.5: f(t) f(t) = f (t – 2), 0 ≤ t < ∞ 3 2 1 0

0

1

2

3

4

5

6

7

8

t

FIGURE E4.5

4.3 TRANSFER FUNCTION Before we introduce the transfer function, the concept of an impulse function is presented because of its relevance to the response of LTI systems.

4.3.1 IMPULSE FUNCTION An impulse function at t ¼ t0, denoted d(t t0), is deﬁned by its property of sifting the value of a function f(t) at t0 inside an integral, that is, 1 ð

d(t t0 )f (t)dt ¼ f (t0 ),

1 < t0 < 1

(4:121)

1

f *g The impulse function d(t t0) is equal to zero wherever t 6¼ t0 and is not ﬁnite at t ¼ t0. No such function exists in a physical sense; however, it can be used to approximate real signals x(t), which occur over a very short duration D and satisfy the condition t0 ð þD

x(t)dt ¼ 1

(4:122)

t0

as illustrated in Figure 4.6. x(t)

Unit impulse function lim

δ(t − t0)

Δ 0

Area = 1

t t0 + Δ

t

t0

FIGURE 4.6 The unit impulse function d(t t0) as a limit of a real function x(t).

t

169

Linear Systems Analysis

From Equation 4.121, the Laplace transform of d(t t0) is given by 1 ð

d(t t0 )est dt ¼ est0 ,

t0 > 0

(4:123)

0

When t0 ¼ 0, Equation 4.123 with lower limit 0 reduces to L{d(t)} ¼ 1

4.3.2 RELATIONSHIP

BETWEEN

UNIT STEP FUNCTION

AND

(4:124)

UNIT IMPULSE FUNCTION

The unit step function û(t) that equals 1 for t > 0 and 0 for t > 0 is discontinuous at t ¼ 0. Although it cannot be implemented in a physical sense, it serves as an approximation to actual signals, which switch from one level to another in a very short period of time. The ﬁrst derivative of a unit step function is zero everywhere except at the origin where it fails to exist as a result of the discontinuity. The unit impulse function d(t) is likewise zero for all values of t except t ¼ 0 where it is inﬁnite. The unit impulse function d(t) can be thought of as the derivative of the unit step function û(t). This provides a framework for analyzing systems with discontinuous inputs that result when input derivatives are present in the mathematical model (Ogata 1998). To illustrate, consider the ﬁrstorder system differential equation model dy du þ 2y ¼ þu dt dt

(4:125)

where the input u ¼ û(t) and the system is initially at rest, that is, y(0) ¼ 0. Note that the initial time is taken as 0 to indicate the initial state value prior to application of the step input at t ¼ 0. Substituting û(t) for u in Equation 4.125 and replacing (d=dt)û(t) with d(t), dy d þ 2y ¼ ^ u(t) þ ^u(t) ¼ d(t) þ ^u(t) dt dt

(4:126)

We learned in Chapter 2 that differential equations, where the highest order derivatives of the input and output are identical, possess a direct path between the input and output. We should therefore expect the output y(t) in Equation 4.125 to be discontinuous at t ¼ 0, that is, y(0þ) 6¼ y(0) when the input is a unit step û(t). The impulse function on the right-hand side of Equation 4.126 is inﬁnite at t ¼ 0 accounting for the jump in y(t) over the inﬁnitesimal time period from t ¼ 0 to t ¼ 0þ. It is possible to demonstrate this behavior without actually solving Equation 4.126 for y(t). Solving for dy=dt in Equation 4.126, dy ¼ d(t)^u(t) 2y dt

(4:127)

Integrating both sides of Equation 4.127 from 0 to t, ðt [d(l) þ ^ u(l) 2y(l)]dl

y(t) ¼ 0

(4:128)

Simulation of Dynamic Systems with MATLAB® and Simulink®

170

Decomposing the integral in Equation 4.128 into two separate integrals, ðt

0ðþ

[d(l) þ ^ u(l) 2y(l)]dl þ

y(t) ¼ 0

[d(l) þ ^u(l) 2y(l)]dl

(4:129)

0þ

The ﬁrst integral simpliﬁes because û(t) and y(t) are both ﬁnite at t ¼ 0. The second integral simpliﬁes by virtue of d(t) ¼ 0 and û(t) ¼ 1 for t 0þ. Equation 4.129 becomes 0ðþ

y(t) ¼

ðt d(l)dl þ

0

[1 2y(l)]dl

(4:130)

0þ

From the sifting property of the impulse function, Equation 4.121, the ﬁrst term on the right-hand side of Equation 4.130 is 1. Evaluating y(t) at t ¼ 0þ,

y(0þ ) ¼ 1 þ

0ðþ

[1 2y(l)]dl ¼ 1

(4:131)

0þ

proving that y(t) is discontinuous at t ¼ 0 since y(0) ¼ 0. For functions that are discontinuous at the origin, the initial conditions in the differentiation property of Laplace transforms (P6) apply at t ¼ 0. Hence, for n ¼ 1 dy ¼ sY(s) y(0 ) L dt

(4:132)

Returning to Equation 4.126, Laplace transformation of both sides yields sY(s) y(0 ) þ 2Y(s) ¼ 1 þ

1 s

(4:133)

sþ1 y(0 ) sþ1 1 1 1 þ ¼ ¼ þ ) Y(s) ¼ s(s þ 2) s þ 2 s(s þ 2) 2 s s þ 2

(4:134)

1 ) Y(t) ¼ (1 þ e2t ), t 0þ 2

(4:135)

Substituting t ¼ 0þ in Equation 4.135 gives y(0þ) ¼ 1 in agreement with Equation 4.131. The initial condition y(0þ) can be obtained by applying the initial value property of Laplace transforms that states P9: y(0þ ) ¼ limþ y(t) ¼ lim sY(s) t!0

s!1

(4:136)

In this example, sþ1 y(0 ) ¼ lim sY(s) ¼ lim s ¼1 s!1 s!1 s(s þ 2) þ

(4:137)

171

Linear Systems Analysis

4.3.3 IMPULSE RESPONSE The response of LTI systems to an impulse forcing function is of great interest. We shall see why momentarily, but ﬁrst an example is presented illustrating the process of ﬁnding the response of a simple system to an ‘‘impulse-like’’ input and comparing it with the true impulse response of the system. Example 4.8 A spring-mass-damper system is struck by a hammer resulting in a force f(t) like the one shown in Figure 4.7. (a) Find and graph the response x(t) for T ¼ 1, 0.5, 0.1, 0.01 s. (b) Find and graph the impulse response. (a) The differential equation model of the system is m€x þ c_x þ kx ¼ f ) €x þ 2_x þ 4x ¼

1 ^(t T)] [^ u(t) u T

(4:138)

Laplace transforming Equation 4.138 with zero initial conditions, 1 1 eTs s T s 1 1 eTs X(s) ¼ 2 T s(s þ 2s þ 4)

(s2 þ 2s þ 4)X(s) ¼

(4:139) (4:140)

Inverse Laplace transformation of Equation 4.140 eventually results in x(t) ¼

pﬃﬃﬃﬃﬃ pﬃﬃﬃﬃﬃ 1 1 1 et cos 3t þ pﬃﬃﬃ sin 3t 4T 3

pﬃﬃﬃ pﬃﬃﬃ 1 1 ^(t T) 1 e(tT) cos 3(t T) þ pﬃﬃﬃ sin 3(t T) u 4T 3

(4:141)

which is simply a linear combination of the step response and a delayed version of the step response. Graphs of Equation 4.141 for T ¼ 1, 0.5, 0.1, 0.01 s are generated in the M-ﬁle ‘‘Chap4_Ex3_1.m’’ and shown in Figure 4.8.

f(t) c=2

k=4

1 T

x m=1 f(t)

FIGURE 4.7 Mechanical system with pulse input f(t).

0

T

t

Simulation of Dynamic Systems with MATLAB® and Simulink®

172

Pulse response for different pulse widths and impulse response 0.3

T = 0.1 s T = 0.5 s

0.25 0.2

T=1 s

x(t)

0.15 0.1 0.05 T = 0.01 s 0 − 0.05

Impulse response 0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

t (s)

FIGURE 4.8 Pulse response of mechanical system for T ¼ 1, 0.5, 0.1, 0.01 s and the impulse response. (b) The true impulse response is obtained by Laplace transforming €x þ 2_x þ 4x ¼ d(t)

(4:142)

) (s2 þ 2s þ 4)X(s) ¼ 1

(4:143)

Solving for X(s) followed by inverse Laplace transformation results in pﬃﬃﬃﬃﬃ 1 ximpulse response (t) ¼ pﬃﬃﬃ et sin 3t, 3

t0

(4:144)

It is graphed in Figure 4.8 and appears identical to the response x(t) when the pulse width T ¼ 0.01 s. Hence, the impulse response provides an accurate approximation of how the mechanical system responds to inputs of short (relative to the time constants of the system’s natural modes) duration. In Section 4.4.2, a mathematical model of a second-order system with input u(t) and output y(t) was introduced as an example of how Laplace transforms can be used to solve for the system response. The second-order LTI system shown in Figure 4.9 is referred to as a single input–single output (SISO) system. The mathematical model is given by d2 d d2 d y(t) þ a1 y(t)a0 y(t) ¼ b2 2 u(t) þ b1 u(t) þ b0 u(t) 2 dt dt dt dt

(4:145)

Laplace transforming Equation 4.145, with zero initial conditions for the input, output, and their derivatives, leads to Y(s) ¼

u(t)

2 b2 s þ b1 s þ b0 U(s) s2 þ a1 s þ a0

Linear time-invariant second-order system

FIGURE 4.9 Second-order system with input u(t) and output y(t).

(4:146)

y(t)

173

Linear Systems Analysis

The ratio of Y(s) to U(s), when all initial conditions are identically zero, is called the transfer function of the system. Denoting it by H(s), H(s) ¼

Y(s) ¼ U(s)

2 b2 s þ b1 s þ b0 s2 þ a1 s þ a0

(4:147)

Consider an nth-order LTI system with transfer function expressible as the ratio of two polynomials in proper fraction form, that is, the denominator polynomial is higher order than the numerator polynomial as in H(s) ¼

bm sm þ bm1 sm1 þ þ b1 s þ b0 sn þ an1 sn1 þ þ a1 s þ a0

(n > m)

(4:148)

The transfer function in Equation 4.148 is an alternative to the differential equation model representation of the system dynamics. It offers a convenient way of determining the forced response of an LTI system. From Equation 4.147, Y(s) is equal to the product of the system transfer function H(s) and the Laplace transform of the input, Y(s) ¼ H(s)U(s)

(4:149)

and the response is obtained by inverse Laplace transformation y(t) ¼ L1{Y(s)}. The following examples illustrate the use of the transfer function to obtain the forced response of an LTI system.

Example 4.9 A ﬁrst-order system is governed by the differential equation dy þ 2y ¼ u, y(0) ¼ 0 dt

(4:150)

(a) Find H(s), the transfer function of the system. (b) Find y(t), the response when u(t) is (i) sin 3t, t 0 and (ii) û(t). (a) From Equation 4.148 with n ¼ 1, m ¼ 0, b0 ¼ 1, and a0 ¼ 2 H(s) ¼

b0 1 ¼ s þ a0 s þ 2

(4:151)

(b) For u(t) ¼ sin 3t, U(s) ¼ 3=(s2 þ 9) and Equation 4.149 becomes 1 3 Y(s) ¼ H(s)U(s) ¼ s þ 2 s2 þ 9 3 1 s2 ¼ 2 13 s þ 2 s þ 9 3 1 s 2 3 ¼ þ 13 s þ 2 s2 þ 9 3 s2 þ 9 3 2 e2t cos 3t þ sin 3t , t 0 y(t) ¼ L1 {Y(s)} ¼ 13 3

(4:152) (4:153) (4:154) (4:155)

Simulation of Dynamic Systems with MATLAB® and Simulink®

174

For u(t) ¼ û(t), U(s) ¼ 1=s and Equation 4.149 reduces to Y(s) ¼ H(s)U(s) ¼

1 1 1 1 1 ¼ sþ2 s 2 s sþ2

1 y(t) ¼ L1 {Y(s)} ¼ (1 e2t ), 2

(4:156)

t0

(4:157)

Example 4.10 For the system with transfer function, H(s) ¼

s2 þ 3s þ 1 (s þ 1)(s þ 3)(s þ 5)

(4:158)

(a) Find the differential equation model of the system. (b) Find the forced response to the input u(t) ¼ t, t 0. (a) The differential equation of the system is obtained from H(s) as follows: H(s) ¼

Y(s) s2 þ 3s þ 1 s2 þ 3s þ 1 ¼ ¼ 3 U(s) (s þ 1)(s þ 3)(s þ 5) s þ 9s2 þ 23s þ 15

(4:159)

) (s3 þ 9s2 þ 23s þ 15)Y(s) ¼ (s2 þ 3s þ 1)U(s)

(4:160)

) s3 Y(s) þ 9s2 Y(s) þ 23sY(s) þ 15Y(s) ¼ s2 U(s) þ 3sU(s) þ U(s)

(4:161)

Performing the inverse Laplace transformation of the individual terms with all initial conditions zero results in the differential equation d3 d2 d d2 d y(t) þ 9 y(t) þ 23 u(t) þ 3 u(t) þ u(t) y(t) þ 15y(t) ¼ 3 2 2 dt dt dt dt dt

(4:162)

(b) Substituting U(s) ¼ 1=s2 in Equation 4.149 gives Y(s) ¼

s3

s2 þ 3s þ 1 1 þ 9s2 þ 23s þ 15 s2

(4:163)

The MATLAB statements n ¼ [1 3 1]; d ¼ [1 9 23 15 0 0]; [R,P] ¼ residue(n,d) result in the residues and poles of the partial fraction expansion leading to the following expansion for Y(s), Y(s) ¼

1 1 22 1 1 1 1 1 11 1 þ þ 15 s2 225 s 8 sþ1 36 s þ 3 200 s þ 5

(4:164)

and the forced response is obtained by inverse Laplace transformation of Y(s), y(t) ¼

1 22 1 t 1 11 5t tþ e e3t þ e , 15 225 8 36 200

t0

(4:165)

175

Linear Systems Analysis u(t) = δ(t) U(s) = 1

FIGURE 4.10

y(t) = yimpulse response(t)

H(s)

Y(s) = H(s) . 1

Linear time-invariant system with unit impulse input.

4.3.4 RELATIONSHIP

BETWEEN IMPULSE

RESPONSE

AND

TRANSFER FUNCTION

The impulse response function and the transfer function of an LTI system are related. Suppose the input to an LTI system is a unit impulse function as illustrated in Figure 4.10. Since Y(s) ¼ H(s)U(s) ¼ H(s) 1 ¼ H(s), it follows that yimpulse response (t) ¼ L1 {H(s)} ¼ h(t)

(4:166)

In other words, the impulse response of an LTI system is simply the inverse Laplace transform of the system transfer function. It is denoted h(t) and referred to as the impulse response function. The impulse response function serves as alternative way of describing the dynamics of an LTI system. It can be used to ﬁnd the forced response to an arbitrary input by ﬁrst ﬁnding the transfer function H(s) ¼ L{h(t)} and then proceeding in a similar manner to Example 4.10. Alternatively, the forced response of an LTI system can be obtained directly from ðt

1

y(t) ¼ L {H(s)U(s)} ¼ h(t t)u(t)dt

(4:167)

0

that is, by convolution of the impulse response function h(t) and the input u(t). To illustrate, the unit step response of the third-order system in Example 4.10 is obtained using the convolution integral in Equation 4.167. s2 þ 3s þ 1 1 1 2 11 ¼ þ H(s) ¼ (s þ 1)(s þ 3)(s þ 5) 8 sþ1 sþ3 sþ5

(4:168)

1 h(t) ¼ L1 {H(s)} ¼ (et 2e3t þ 11e5t ) 8

(4:169)

ðt

ðt y(t) ¼ h(t)u(t t)dt ¼ 0

0

1 ¼ 8 ¼

1 (et 2e3t þ 11e5t ) 1dt 8

(4:170)

2 3t 11 5t t t e þ e e 3 5 0

(4:171)

1 1 t 1 11 þ e þ e3t e5t , 15 8 12 40

t0

(4:172)

The initial condition y(0) ¼ 0 and from Equation 4.172, y(0þ) ¼ 0 as well. The response y(t) is therefore continuous at t ¼ 0 despite the discontinuity in the step input. In other words, a direct coupling from the input to the output does not exist. We should expect this result by observing that the third-order differential equation in Equation 4.162 does not contain a term on the right-hand side involving the third derivative of the input. If we express the system model in state variable form, the 1 1 direct coupling matrix D would be zero.

Simulation of Dynamic Systems with MATLAB® and Simulink®

176 u b0 − a0b3

b1 − a1b3

∫

x1

−a0

FIGURE 4.11

∫

−a1

b3

b2 − a2b3

x2

∫

x3

y

−a2

Simulation diagram of third-order system in observer canonical form.

A simulation diagram for an LTI system offers a convenient way of deﬁning the states and revealing whether a direct path (no integrators) exists from the input to the output. Figure 4.11 shows a simulation diagram for the third-order system d3 d2 d d3 d2 d y(t) þ a2 2 y(t) þ a1 y(t) þ a0 y(t) ¼ b3 3 u(t) þ b2 2 u(t) þ b1 u(t) þ b0 u(t) (4:173) 3 dt dt dt dt dt dt in what is known as observer canonical form (Ogata 1998). This form clearly shows the direct path from the input u to the output y when b3 6¼ 0. For the case when b3 ¼ 0, the state x3 is equal to the output y and a direct path exists from u to x_ 3 . For a unit step input, the following is true if b3 ¼ 0: y(0þ ) ¼ y(0 ),

y_ (0þ ) ¼ y_ (0 ) þ (b2 a2 b3 )u(0þ ) ¼ y_ (0 ) þ b2

(4:174)

Consider the third-order system with transfer function given in Equation 4.159 and modeled by the differential equation in Equation 4.162. Comparing Equations 4.162 and 4.173 implies a2 ¼ 9, a1 ¼ 23, and a0 ¼ 15 and b3 ¼ 0, b2 ¼ 1, b1 ¼ 3, and b0 ¼ 1. Assuming zero initial conditions, the ﬁrst derivative jumps from y_ (0 ) ¼ 0 to y_ (0þ ) ¼ y_ (0 ) þ b2 ¼ 1 at t ¼ 0. Differentiating the solution for the unit step response y(t) in Equation 4.172 gives dy 1 ¼ (5et 10e3t þ 55e5t ) dt 40

(4:175)

dy þ 1 (0 ) ¼ (5 10 þ 55) ¼ 1 dt 40

(4:176)

At t ¼ 0þ,

The system transfer function provides a convenient way of ﬁnding the forced response of an SISO LTI system. However, ﬁnding the transfer function can be a challenge when the mathematical model of the system consists of coupled algebraic and differential equations as opposed to a single nth-order differential equation relating the system input and output. Fortunately, the Laplace transform can be used to reduce the problem of ﬁnding the transfer function into one of an algebraic nature. The alternative, namely, eliminating dependent signals and their derivatives in the time domain, is far more cumbersome.

177

Linear Systems Analysis C2 v R

ei

FIGURE 4.12

C1

R

v0

Circuit with input ei and output v0.

For example, consider the bridged-T network shown in Figure 4.12. The node voltage method for analyzing the circuit results in the following equations: ei v dv v v0 ¼ C1 þ R R dt C2

d v v0 ¼0 (ei v0 ) þ R dt

(4:177) (4:178)

Rearranging Equations 4.177 and 4.178 with node voltage terms on one side and the input terms on the other gives dv þ 2v v0 ¼ ei dt

(4:179)

dv0 dei þ v0 v ¼ RC2 dt dt

(4:180)

RC1 RC2

The node voltage v must be eliminated from Equations 4.179 and 4.180 to arrive at a second-order differential equation involving ei and v0. Laplace transforming both equations with initial conditions set to zero and collecting terms produces the algebraic system of equations (RC1 s þ 2)V(s) V0 (s) ¼ Ei (s) V(s) þ (RC2 s þ 1)V0 (s) ¼ RC2 sEi (s)

(4:181)

Using Cramer’s rule, the solution for V0(s) is

RC1 s þ 2 Ei (s)

1 RC2 sEi (s)

R2 C1 C2 s2 þ 2RC2 s þ 1

¼ Ei (s) V0 (s) ¼

2

1 R C1 C2 s2 þ R(C1 þ 2C2 )s þ 1

RC1 s þ 2

1 RC2 s þ 1

(4:182)

The transfer function is V0 (s) R2 C1 C2 s2 þ 2RC2 s þ 1 ¼ 2 Ei (s) R C1 C2 s2 þ R(C1 þ 2C2 )s þ 1

(4:183)

Inverse Laplace transformation of Equation 4.183 leads to the differential equation R2 C1 C2

d2 v 0 dv0 d2 e i dei 2 þ v þ 2RC2 þ ei þ R(C þ 2C ) ¼ R C C 1 2 0 1 2 2 dt dt dt dt

(4:184)

Simulation of Dynamic Systems with MATLAB® and Simulink®

178

4.3.5 SYSTEMS WITH MULTIPLE INPUTS

AND

OUTPUTS

In general, linear systems (and nonlinear systems) have more than a single input and output. Those systems and their models are designated multiple input–multiple output, abbreviated as MIMO. The transfer function concept still applies. Suppose, for example, an LTI system such as an electric circuit is driven by independent voltage sources e1(t) and e2(t), and signals iR(t), vC(t), and vload(t) appearing at various points in the circuit are deﬁned as outputs. A total of six transfer functions exist, one from each of two inputs to each of three outputs. We can write IR (s) ¼ G1,1 (s)E1 (s) þ G1,2 (s)E2 (s)

(4:185)

VC (s) ¼ G2,1 (s)E1 (s) þ G2,2 (s)E2 (s)

(4:186)

Vload (s) ¼ G3,1 (s)E1 (s) þ G3,2 (s)E2 (s)

(4:187)

where

IR (s)

IR (s)

, G1,2 (s) ¼ G1,1 (s) ¼ E1 (s) E2 (s)¼0 E2 (s) E1 (s)¼0

VC (s)

VC (s)

G2,1 (s) ¼ , G (s) ¼ 2,2 E1 (s) E2 (s)¼0 E2 (s) E1 (s)¼0

Vload (s)

Vload (s)

, G3,2 (s) ¼ G3,1 (s) ¼ E1 (s) E2 (s)¼0 E2 (s) E1 (s)¼0

(4:188)

(4:189)

(4:190)

The notation Gij(s) denotes the transfer function from the jth input to the ith output. Equations 4.185 through 4.187 are a consequence of the principle of superposition that applies to linear systems. Superposition implies that the response of a system to multiple inputs applied simultaneously is equivalent to the sum of the system responses to the individual inputs applied one at a time. An MIMO system and a method for ﬁnding its transfer functions are the focus of the following example. Example 4.11 The amount of solute (drug or metabolite) introduced to or produced in the human body is often assumed to be stored in different compartments of the body. A separate equation for each compartment relates the rate of solute removal to the amount or concentration of the solute in the compartment. The solute can either be transported to another compartment or eliminated from the body by metabolism or excretion. Consider the linear compartment model described in Riggs (1970) for describing the quantities of iodine in humans. The state variables are x1: x2: x3: x4:

Amount of Amount of Amount of Amount of

inorganic iodine in the thyroid gland organic iodine in the thyroid gland hormonal iodine in the extrathyroidal tissue iodine in the inorganic iodide compartment

and the inputs are q3: Rate of entry of exogenous iodide q4: Rate of entry of exogenous hormonal iodine

179

Linear Systems Analysis k12 x2

x1 k21

q4

FIGURE 4.13

k23

k14

k41

k34

x4

q3

x3

ku

kf

Urine

Feces

Compartmental model for iodine distribution in a human.

The model equations are summarized by the diagram illustrated in Figure 4.13, where k12, k13, k21, k24, k31, k43, ku, and kf are the rate constants governing the transfer of iodine between the compartments and its excretion from the body. The outputs are y1 ¼ x1 þ x2 þ x3 þ x4, total iodine in the body y2 ¼ kfx3 þ kux4, rate of iodine excretion from the body (a) Write the state equations for the system and ﬁnd the matrices A, B, C, and D. (b) Draw a block diagram of the system, and label the Laplace transforms of the states x1, x2, x3, and x4 and outputs y1 and y2. (c) Find the transfer function Y2(s)=Q4(s). (d) Baseline values of the system parameters are k12 ¼ 0:8=day,

k21 ¼ 0:005=day, k23 ¼ 0:01=day, and

k14 ¼ 0:15=day,

k41 ¼ 0:5=day, kf ¼ 0:02=day,

and

k34 ¼ 0:3=day ku ¼ 1:2=day

Find the steady-state iodine levels in each compartment in response to a daily intake of iodine, q4 ¼ 150 mg=day. Assume q3 ¼ 0 mg=day. (e) Find and graph the step response of x2(t) if the daily intake of iodine drops from 150 (where it has been for a long time) to 50 mg=day. (a) From Figure 4.13, the state equations are x_ 1 ¼ (k12 þ k14 )x1 þ k21 x2 þ k41 x4 x_ 2 ¼ k12 x1 (k21 þ k23 )x2 x_ 3 ¼ k23 x2 (k34 þ kf )x3 þ q3 x_ 4 ¼ k14 x1 þ k34 x3 (k14 þ ku )x4 þ q4 ) y1 ¼ x1 þ x2 þ x3 þ x4 y2 ¼ kf x3 þ ku x4

9 > > > > = > > > > ;

(4:191)

(4:192)

Simulation of Dynamic Systems with MATLAB® and Simulink®

180

The matrices A, B, C, and D in x_ ¼ Ax þ Bu and y ¼ Cx þ Du where u ¼ [q3 q4]T are 2 6 6 A¼6 4

3

(k12 þ k14 )

k21

0

k41

k12

(k21 þ k23 )

0

0

0

k23

(k34 þ kf )

0

k14

0

k34

(k41 þ ku )

C¼

1 1 0 0

1 kf

1 , ku

D¼

0 0

7 7 7, 5

0 0

2

0 0

3

60 07 7 6 B¼6 7 41 05

(4:193)

0 1 (4:194)

(b) The block diagram is obtained by Laplace transforming the state Equations 4.193 and 4.194, then solving for X1(s), X2(s), X3(s), and X4(s) in the respective equations. Introducing the notation k1 ¼ k12 þ k14, k2 ¼ k21 þ k23, k3 ¼ k34 þ kf, and k4 ¼ k41 þ ku yields 1 [k21 X2 (s) þ k41 X4 (s)] s þ k1 k12 X1 (s) X2 (s) ¼ s þ k2 1 [k23 X2 (s) þ Q3 (s)] X3 (s) ¼ s þ k3 1 [k14 X1 (s) þ k34 X3 (s) þ Q4 (s)] X4 (s) ¼ s þ k4

X1 (s) ¼

(4:195) (4:196) (4:197) (4:198)

The block diagram follows immediately from Equations 4.195 through 4.198 and Equation 4.192. It is shown in Figure 4.14. (c) The transfer function Y2(s)=Q4(s) can be obtained by graphical methods from the block diagram or directly from the model equations. The latter approach is illustrated. Laplace transforming the second output equation in Equation 4.192 followed by division of each term by Q4(s), Y2 (s) ¼ kf X3 (s) þ ku X4 (s) )

Q3(s)

1 s + k3

(4:199)

Y2 (s) X3 (s) X4 (s) ¼ kf þ ku Q4 (s) Q4 (s) Q4 (s)

(4:200)

X3(s)

k23 k34 Y2(s)

kf Y1(s)

ku Q4(s)

X4(s) 1 s + k4

k41

X1(s) 1 s + k1

k12 X2(s) s + k2

k21 k14

FIGURE 4.14

Block diagram of system modeled by Equations 4.195 through 4.198 and 4.192.

181

Linear Systems Analysis

Setting Q3(s) ¼ 0 in Equation 4.197 and solving Equations 4.195 through 4.198 for X3(s) and X4(s),

s þ k1 k21 0 k41

k12 s þ k2 0 0

0 0

k23

0

k 0 Q4 (s) s þ k4

14

X3 (s) ¼

s þ k1 k21 0 k41

k12 s þ k2 0 0

0

k23 s þ k3

0

k 0 k34 s þ k4

14

(4:201)

s þ k1 k21 0 0

k12 s þ k2 0 0

0

k23 s þ k3

0

k 0 k34 Q4 (s)

14

X4 (s) ¼

s þ k1 k21 0 k41

k12 s þ k2 0 0

0

k23 s þ k3

0

k 0 k34 s þ k4

14

(4:202)

Evaluation of the determinants in Equations 4.201 and 4.202 is a tedious process left as an exercise problem. The results are as follows:

a0 Q4 (s) s4 þ a3 s3 þ a2 s2 þ a1 s þ a0

X3 (s) ¼

(4:203)

X4 (s) ¼

s3 þ b2 s2 þ b1 s þ b0 Q4 (s) s4 þ a3 s3 þ a2 s2 þ a1 s þ a0

a0 ¼ k12 k23 k41 , b0 ¼ k1 k2 k3 k12 k21 k3 b1 ¼ k1 k2 þ k1 k3 þ k2 k3 k12 k21 , b2 ¼ k1 þ k2 þ k3

(4:204)

(4:205) 9 > > > =

a0 ¼ k1 k2 k3 k4 k14 k41 k2 k3 k12 k21 k3 k4 k12 k23 k34 k41

a1 ¼ k1 k2 k3 þ k1 k2 k4 þ k1 k3 k4 þ k2 k3 k4 k12 k21 (k3 þ k4 ) k14 k41 (k2 þ k3 ) > a2 ¼ k1 k2 þ k1 k3 þ k1 k4 þ k2 k3 þ k2 k4 þ k3 k4 k12 k21 k14 k41 > > ; a3 ¼ k1 þ k2 þ k3 þ k4

(4:206)

Combining Equations 4.200, 4.203, and 4.204 produces the desired transfer function, Y2 (s) kf a0 þ ku (s3 þ b2 s2 þ b1 s þ b0 ) ¼ Q4 (s) s4 þ a3 s3 þ a2 s2 þ a1 s þ a0

(4:207)

(d) The steady-state iodine levels in each compartment are obtained from the state equations x_ ¼ Ax þ Bu with x_ ¼ 0. 1

xss ¼ A Buss

(q3 )ss where uss ¼ (q4 )ss

0 ¼ 150 mg=day

(4:208)

Simulation of Dynamic Systems with MATLAB® and Simulink®

182

For the given values of the rate constants, 3 2 0 0:5 1 0 6 0 0 7 7 60 7 6 0:32 0 5 41 0:3 1:7 0

2

0:95 0:005 6 0:8 0:015 6 xss ¼ 6 4 0 0:01 0:15 0

3 2 3 89:6 0 6 7 07 6 4780:9 7 7 0 ¼6 7 7 4 149:4 5 0 5 150 122:5 1

(4:209)

(e) Using the same method we employed to ﬁnd X3(s)=Q4(s) and X4(s)=Q4(s), the transfer function X2(s)=Q4(s) is X2 (s) g1 s þ g0 ¼ Q4 (s) s4 þ a3 s3 þ a2 s2 þ a1 s þ a0 g0 ¼ k12 k41 k3 ,

(4:210)

g1 ¼ k12 k41

(4:211)

Working backward from the transfer function X2(s)=Q4(s), the differential equation relating x2(t) and q4(t) is :::: : x2 þ a3 €x2 þ a2€x2 þ a1 x_ 2 þ a0 x2 ¼ g1 q_ 4 þ g0 q4 (4:212) Once the initial conditions are established, Equation 4.212 can be solved to ﬁnd the complete step response. Let us assume the input q4(t) has been constant at 150 mg=day long enough for the system to reach the steady-state levels given in Equation 4.209. It is possible to redeﬁne t ¼ 0 as the instant when q4(t) switches from 150 to 50 mg=day. Figure 4.15 shows the input dropping from q4(0) ¼ 150 mg=day to q4(0þ) ¼ 50 mg=day. With the system at steady-state at t ¼ 0, the initial conditions are x2(0) ¼ 4780.9 mg, : x_ 2 (0 ) ¼ €x2 (0 ) ¼ €x2 (0 ) ¼ 0. Laplace transforming Equation 4.212, s4 X2 (s) s3 x2 (0 ) þ a3 [s3 X2 (s) s2 x2 (0 )] þ a2 [s2 X2 (s) sx2 (0 )] þ a1 [sX2 (s) x2 (0 )] þ a0 X2 (s) ¼ g1 [sQ4 (s) q4 (0 )] þ g0 Q4 (s)

(4:213)

Solving for X2(s), X2 (s) ¼

s4

þ a3

s3

g1 s þ g0 x2 (0 )(s3 þ a3 s2 þ a2 s þ a1 ) g1 q4 (0 ) Q4 (s) þ 2 þ a2 s þ a1 s þ a0 s4 þ a3 s3 þ a2 s2 þ a1 s þ a0

(4:214)

where Q4 (s) ¼ L{q4 (t)} ¼

q4 (0þ ) s

(4:215)

M-ﬁle ‘‘Chap3_Ex3_4.m’’ uses the ‘‘residue’’ function to evaluate the partial fraction expansion of each term on the right-hand side of Equation 4.214. The ﬁnal expression for X2(s) is of the form X2 (s) ¼

5 X i¼1

ci s pi

(4:216)

q4(t) 150 μg/day

50 μg/day 0

FIGURE 4.15

Step change in input q4(t).

t

183

Linear Systems Analysis

where the system poles are p1 ¼ 1.7901, p2 ¼ 0.8621, p3 ¼ 0.3248, and p4 ¼ 0.0080 and the input pole p5 ¼ 0. The residues are c1 ¼ 13.6, c2 ¼ 59.1, c3 ¼ 2.4, c4 ¼ 3230.4, and c5 ¼ 1593.6. The partial fraction expansion of X2(s) is 13:6 59:1 2:4 3230:4 1593:6 þ þ þ s þ 1:7901 s þ 0:8621 s þ 0:3248 s þ 0:0080 s

(4:217)

x2 (t) ¼ 13:6e1:7901t 59:1e0:8621t þ 2:4e0:3248t þ 3230:4e0:0080t þ 1593:6

(4:218)

X2 (s) ¼ Inverting X2(s) gives

Note that a convenient check of x2(t) in Equation 4.218 is x2 (0 ) ¼ 13:6 59:1 þ 2:4 þ 3230:4 þ 1593:6 ¼ 4780:9 which agrees with the initial condition. The step response is shown in Figure 4.16. The natural modes of the system are e1.7901t, e0.8621t, e0.3248t, and e0.0080t and the dominant time constant tdominant ¼ 1=0.008 ¼ 125 days. It takes approximately 5 tdominant ¼ 625 days for x2 to attain the new steady-state value of 1593.6 mg. There is another property of Laplace transforms that is particularly useful when it comes to ﬁnding the steady-state response of a system. Known as the Final Value Theorem, it relates the steady state or ﬁnal value of a signal to its Laplace transform, that is, P10: Given Y(s) ¼ L{y(t)}, if a ﬁnal value y(1) exists, it is given by y(1) ¼ lim y(t) ¼ lim sY(s) t!1

(4:219)

s!0

For a system with transfer function G(s), the steady-state response to a step input of magnitude U0 is y(1) ¼ lim sY(s) ¼ lim sG(s)U(s) ¼ lim sG(s) s!0

s!0

s!0

U0 ¼ G(0)U0 s

5000 4500

x2(t), mg

4000 3500 3000 2500 2000 1500

FIGURE 4.16

0

100

200

300 t (days)

400

500

600

Step response for x2(t) following step change in q4(t) from 150 to 50 mg=day.

(4:220)

Simulation of Dynamic Systems with MATLAB® and Simulink®

184

G(0) is referred to as the steady-state gain of the system. The ﬁnal value property makes it possible to determine the ﬁnal value y(1) from Y(s) without having to ﬁnd y(t). This is particularly useful when trying to ﬁnd the steady-state response of a system to a constant input. The input must be constant long enough to allow the transient response to vanish. Practically speaking, this is roughly four to ﬁve times the largest effective time constant of the system.

In Example 4.11, the transfer function Y1(s)=Q4(s) can be expressed as Y1 (s) X1 (s) þ X2 (s) þ X3 (s) þ X4 (s) ¼ Q4 (s) Q4 (s) ¼

X1 (s) X2 (s) X3 (s) X4 (s) þ þ þ Q4 (s) Q4 (s) Q4 (s) Q4 (s)

(4:221) (4:222)

where the last three terms on the right-hand side are obtained from Equations 4.210, 4.203, and 4.204. The remaining term is left as an exercise. The result is X1 (s) d2 s 2 þ d1 s þ d 0 ¼ 4 Q4 (s) s þ a3 s3 þ a2 s2 þ a1 s þ a0 d0 ¼ k41 k2 k3,

d1 ¼ k41 (k2 þ k3 ),

d2 ¼ k41

(4:223) (4:224)

making the transfer function G(s) ¼

Y1 (s) s3 þ (b2 þ d2 )s2 þ (b1 þ g1 þ d1 )s þ a0 þ b0 þ g0 þ d0 ¼ s 4 þ a 3 s 3 þ a2 s 2 þ a 1 s þ a0 Q4 (s)

(4:225)

The ﬁnal value y1(1) ¼ x1(1) þ x2(1) þ x3(1) þ x4(1) when q4(t) ¼ 150, t 0 (same initial input in Example 4.11) is

a 0 þ b0 þ g 0 þ d 0 150 y1 (1) ¼ G(0) 150 ¼ a0 0:004 þ 0:00328 þ 0:128 þ 0:0024 ¼ 150 ¼ 5142:4 mg 0:004016

(4:226)

in agreement with the sum of the components of xss in Equation 4.209. A word of caution when applying the ﬁnal value property. A function y(t) could theoretically grow without bound, that is, limt!1y(t) ¼ 1 or have an undamped oscillatory component, and the ﬁnal value property will nevertheless produce a ﬁnite value. Clearly, the result does not represent a ﬁnal or steady-state value. We shall investigate the conditions that produce theoretical unbounded outputs of a linear system in a future section.

4.3.6 TRANSFORMATION

FROM

STATE VARIABLE MODEL

TO

TRANSFER FUNCTION

The state-space representation offers several advantages over the input–output transfer function method of describing the dynamics of a linear system. For one, it is a more complete representation since the states provide useful information about the internal behavior of the system. Properties of linear systems such as observability and controllability as well as system identiﬁcation and state feedback are topics normally covered in modern control theory, which rely on state-space models.

185

Linear Systems Analysis

However, there are times when the transfer function of an SISO system (or transfer functions if the system is MIMO) is required for a system modeled in state variable form. Consider an MIMO system with inputs u1, u2, . . . , ur and outputs y1, y2, . . . , ym modeled in state space by x_ ¼ Ax þ Bu

(4:227)

y ¼ Cx þ Du

(4:228)

where x is the n-dimensional state vector [x1 x2 . . . xn]T and the matrices A, B, C, and D are appropriately dimensioned. Laplace transformation of Equation 4.227 with x(0) ¼ 0 gives sX(s) ¼ AX(s) þ BU(s)

(4:229)

) X(s) ¼ (sI A)1 BU(s)

(4:230)

Laplace transforming y ¼ Cx þ Du and substituting X(s) from Equation 4.230 gives Y(s) ¼ [C(sI A)1 B þ D]U(s)

(4:231)

¼ G(s)U(s)

(4:232)

where G(s), known as the transfer matrix, is a matrix of transfer functions from each of the r inputs to each of the m outputs, that is, Gij (s) ¼

Yi (s) , i ¼ 1, 2, . . . , m, Uj (s)

j ¼ 1, 2, . . . , r

(4:233)

To illustrate, let us revisit the state variable model for iodine storage in Example 4.11 where the matrices A, B, C, and D are given in Equations 4.193 and 4.194. There are two inputs u1(t) ¼ q3(t) and u2(t) ¼ q4(t), and outputs y1(t) and y2(t) are deﬁned in Equation 4.192. One of the four transfer functions, namely, Y1(s)=Q4(s), is given in Equation 4.225. Using the baseline parameter values in Example 4.11 results in Y1 (s) s3 þ 1:785s2 þ 0:88655s þ 0:13768 ¼ 4 Q4 (s) s þ 2:985s3 þ 2:42855s2 þ 0:52054s þ 0:004016

(4:234)

The matrix F(s) ¼ (sI A)1 in Equation 4.231 is computed according to 0

2

0:95

6 B B 6 0:8 6 F(s) ¼ (sI A)1 ¼ B sI B 6 0 @ 4

0:005

0

0:015

0

0:01

0:32

0

0:3

0:15 2

s þ 0:95

6 6 0:8 ¼6 6 0 4

0:15

0:5

311

7C 0 7C 7C C 0 7 5A

1:7

0:005

0

0:5

s þ 0:015

0

0

0:01

s þ 0:32

0

0

0:3

s þ 1:7

(4:235)

31 7 7 7 7 5

(4:236)

Simulation of Dynamic Systems with MATLAB® and Simulink®

186

F(s) is the Laplace transform of the continuous-time system transition matrix F(t), used to obtain the state response in the time domain. Inverting (sI A) results in 2

f11 (s) f12 (s) f13 (s)

6 6 f21 (s) f22 (s) f23 (s) F(s) ¼ 6 6 f (s) f (s) f (s) 4 31 32 33 f41 (s) f42 (s) f43 (s)

f14 (s)

3

7 f24 (s) 7 7 f34 (s) 7 5

(4:237)

f44 (s)

where 1 [(s þ 0:015)(s þ 0:32)(s þ 1:7)] D(s) 1 f12 (s) ¼ [0:003(s þ 1:2)] D(s) 1 [0:15(s þ 0:015)] f13 (s) ¼ D(s) 1 [0:5(s þ 0:015)(s þ 0:32)] f14 (s) ¼ D(s) 1 [0:8(s þ 0:32)(s þ 1:7)] f21 (s) ¼ D(s) 1 3 [s þ 2:97s2 þ 2:388s þ 0:4928] f22 (s) ¼ D(s) 1 [0:12] f23 (s) ¼ D(s) 1 [0:4(s þ 0:32)] f24 (s) ¼ D(s) 1 [0:008(s þ 1:7)] f31 (s) ¼ D(s) 1 [0:01(s2 þ 2:65s þ 0:865)] f32 (s) ¼ D(s) 1 3 [s þ 2:665s2 þ 1:57575s þ 0:0163] f33 (s) ¼ D(s) 1 [0:004] f34 (s) ¼ D(s) f11 (s) ¼

¼ A k x0 þ

k1 X

Aki1 Bui , k ¼ 0, 1, 2, 3, . . .

(4:238) (4:239) (4:240) (4:241) (4:242) (4:243) (4:244) (4:245) (4:246) (4:247) (4:248) (4:249) (4:250)

i¼0

1 ¼ [0:00375(s þ 0:824)] D(s) 1 [0:3(s2 þ 0:965s þ 0:01025)] f43 (s) ¼ D(s) 1 3 [s þ 1:285s2 þ 0:31905s þ 0:00328] f44 (s) ¼ D(s)

f42 (s) ¼

D(s) ¼ jsI Aj ¼ s4 þ 2:985s3 þ 2:42855s2 þ 0:52054s þ 0:004016

(4:251) (4:252) (4:253) (4:254)

187

Linear Systems Analysis

Finally, the transfer function matrix G(s) in Equation 4.232 is given by G(s) ¼ CF(s)B þ D " ¼ " ¼

1

1

1

0

0

kf

2

f (s) #6 11 1 6 f21 (s) 6 ku 6 4 f31 (s) f41 (s)

f12 (s) f13 (s) f22 (s) f23 (s) f32 (s) f33 (s) f42 (s) f43 (s)

f14 (s)

32

0 76 f24 (s) 76 0 76 6 f34 (s) 7 54 1 0 f44 (s)

0

(4:255)

3

7 " 0 07 7þ 7 0 05 1

0 0

f13 (s) þ f23 (s) þ f33 (s) þ f43 (s) f14 (s) þ f24 (s) þ f34 (s) þ f44 (s) kf f33 (s) þ ku f43 (s)

# (4:256)

#

kf f34 (s) þ ku f44 (s)

(4:257)

The component G12(s) in Equation 4.257 is the transfer function Y1(s)=Q4(s) previously obtained in Equation 4.234. The reader can verify that the two are identical.

EXERCISES 4.6 4.7

Show that the step response of a system whose impulse response function h(t) ¼ 3e2t þ 5d(t) is discontinuous at t ¼ 0. The differential equation of an LTI system is d3 y d2 y dy d3 u þ 15y ¼ 2 þ 5 þ 11 þu dt 3 dt 2 dt dt 3 Find the transfer function H(s) ¼ Y(s)=U(s) of the system. Find the impulse response function h(t) for the system. Find the step response when the initial conditions at t ¼ 0 are identically zero. Find y(1) using the ﬁnal value property, and check your answer with the result obtained in part (c) as t ! 1. (e) Find y(0þ) using the initial value property and check your answer with the result obtained in part (c) as t ! 0þ. (f) Find the step response by convolution and compare your answer to the step response found in part (c). (g) Draw a simulation diagram for the system in observer canonical form. (h) Represent the system in state variable form x_ ¼ Ax þ Bu, y ¼ Cx þ Du. (i) Find the 1 1 transfer function G(s) ¼ Y(s)=U(s) using Equation 4.255. Repeat Exercise 4.7 when the system differential equation is dy þ 5y ¼ 10u (a) dt (a) (b) (c) (d)

4.8

(b)

d2 y dy þ 5 þ 6y ¼ u 2 dt dt

d3 y d2 y dy þ 5 þ 11 þ 15y ¼ u dt 3 dt 2 dt 4.9 Use convolution to ﬁnd the response of the systems with transfer functions sþ3 1 sþ1 , (b) H(s) ¼ 2 , (c) H(s) ¼ 2 (a) H(s) ¼ 2 s þ 2s þ 1 s þ 3s þ 2 s þ 2s þ 2 to the following inputs: (i) u(t) ¼ û(t), (ii) u(t) ¼ û(t) û(t 2), and (iii) u(t) ¼ tû(t). 4.10 The circuit in Figure E4.10 is governed by the differential equation (c)

d2 v 0 1 dv0 1 1 dig þ þ v0 ¼ dt 2 RC dt LC C dt

Simulation of Dynamic Systems with MATLAB® and Simulink®

188

L = 25 mH

R

ig

C = 25 nF

ν0

FIGURE E4.10

Find the impulse response function and plot the results when (a) R ¼ 400 V, (b) R ¼ 500 V, and (c) R ¼ 625 V. 4.11 Repeat Example 4.10 with H(s) ¼ 1=[(s þ 1)(s þ 3)(s þ 5)]. 4.12 Find the transfer function of the bridged-T circuit in Figure 4.12 using equations in the time domain only to ﬁnd the differential equation of the circuit. 4.13 For the system of interacting tanks shown in Figure E4.13: Fi,1(t)

Fi,2(t)

H1(t) R12

A11 F12(t) =

A22

H1(t) − H2(t) R12

H2(t) F2(t) =

1 H (t) R2 2

FIGURE E4.13

H2 (s) H1 (s) H1 (s) F2 (s) , , , Fi,1 (s) Fi,2 (s) Fi,1 (s) Fi,2 (s) (b) Find the differential equation relating H1(t) and Fi,2(t). 4.14 The unit step response of a system is (a) Find the transfer functions

y(t) ¼ 1 þ e2t ( cos 3t þ 4 sin 3t)

4.15

4.16 4.17

4.18

(a) Find the transfer function of the system. (b) Find the impulse response of the system. (c) Find the differential equation of the system. In Example 4.11, ﬁnd x3(1) and x4(1) when q4(t) ¼ 150 mg=day, t 0 and q3(t) ¼ 0, t 0 using the ﬁnal value property and the expressions for X3(s) and X4(s) in Equations 4.203 and 4.204. Compare your answer with the results in Equation 4.209. In Example 4.11, ﬁnd X1(s)=Q4(s) and compare your answer with the expression in Equation 4.223. In Example 4.11, (a) Find the transfer functions Y1(s)=Q3(s), Y2(s)=Q3(s) in a form similar to Equation 4.225. (b) Find the step responses for y1(t) and y2(t) to inputs q4(t) ¼ 50 mg=day, t 0 and q3(t) ¼ 0, t 0. Assume the initial state is xss in Equation 4.209. In Example 4.11, verify that the transfer function Y2(s)=Q4(s) in Equation 4.207 is the same as G22(s) in Equation 4.257.

189

Linear Systems Analysis

4.4 STABILITY OF LINEAR TIME INVARIANT CONTINUOUS-TIME SYSTEMS In order for a physical system to operate as intended, it must be capable of generating output(s) in a stable fashion. Regulation of a process temperature is unsatisfactory if the heat source cycles continuously between extremes, that is, off or operating at maximum output, unless it is designed to operate that way like a room thermostat. A control system for maintaining a ﬁxed amount of material in a storage tank in the presence of a ﬂuctuating input may not be performing as intended if the regulating valve in the input line continually cycles between its limits. Each is a real-world example of a control system operating in an unstable manner. The starting point of an investigation concerning the stability of a system is its mathematical model. The discussion is conﬁned to LTI systems. Excluding nonlinear systems may appear to signiﬁcantly limit the range of systems considered. However, nonlinear systems can be linearized about speciﬁc operating points and stability analyses performed with respect to each operating point. The subject of linearization is treated in Chapter 7. Consider the second-order system model from the previous section, d2 d d2 d y(t) þ a y(t) ¼ b u(t) þ b1 u(t) þ b0 u(t) y(t) þ a 1 0 2 dt 2 dt 2 dt dt

(4:258)

Applying the differentiation property of the Laplace transform and collecting terms, the Laplace transform of the system output is

_ ) þ b1 u(0 ) b2 u(0 )s þ b2 u(0 y(0 )s þ y_ (0 ) þ a1 y(0 ) þ Y(s) ¼ H(s)U(s) s 2 þ a1 s þ a0 s 2 þ a1 s þ a 0

(4:259)

where H(s) is the transfer function H(s) ¼

Y(s) b2 s2 þ b1 s þ b0 ¼ 2 s þ a1 s þ a 0 U(s)

(4:260)

For zero input, Y(s) reduces to the Laplace transform of the free response, that is, Yfree (s) ¼

y(0)s þ y_ (0) þ a1 y(0) s 2 þ a1 s þ a0

(4:261)

Note that in the absence of an input, the ‘‘’’ superscript on the initial conditions is no longer necessary. The free response yfree (t) ¼ L1 {Yfree (s)} depends on the roots of the equation s2 þ a1s þ a0 ¼ 0. Denoting the roots as p1 and p2, yfree(t) assumes one of the forms in 8 pt p2 t 1 > < c1 e þ c2 e , yfree (t) ¼ est [c1 cos vt þ c2 sin vt], > : (c1 þ c2 t)ept ,

p1 , p2 real and distinct p1 , p2 complex p1 ¼ p 2 ¼ p

(4:262)

Constants c1 and c2 depend on the initial conditions y(0) and y_ (0). The constants s, v, p1, p2, and p depend on the values of a0 and a1, which are related to the physical parameters of the system. For example, a0 and a1 depend on M, B, and K in a mechanical system or R, L, and C for an electrical circuit. The free response in Equation 4.262 is also referred to as the natural response of the system. It consists of a linear combination of the system’s natural modes.

Simulation of Dynamic Systems with MATLAB® and Simulink®

190

4.4.1 CHARACTERISTIC POLYNOMIAL The denominator of the transfer function H(s) in Equation 4.260 is D(s) ¼ s2 þ a1 s þ a0 ¼ (s p1 )(s p2 )

(4:263)

It is called the characteristic polynomial of the system and D(s) ¼ 0 is the characteristic equation. The roots of the characteristic polynomial are referred to as the poles of the system transfer function, and from Equations 4.260 and 4.263, H(p1) ¼ H(p2) ¼ 1. The stability of the system is related to the free response, speciﬁcally the limit L ¼ limt!1yfree(t) when one or both initial conditions are nonzero. The following possibilities exist: 1. 2. 3. 4.

L ¼ 0. L ¼ constant 6¼ 0. L fails to exist because the free response oscillates with constant amplitude. L fails to exist because the magnitude of the free response approaches inﬁnity.

The system is said to be asymptotically stable in the ﬁrst case, marginally stable in the second and third cases, and unstable in the last case. Since the poles p1 and p2 dictate the behavior of the free response, they also determine the nature of the system’s stability. As a result, we can infer that the stability of the second-order linear system in Equation 4.258 is an inherent system property, that is, it depends on the values of the system parameters and not on the system inputs. The previous statement is entirely general and not restricted to the second-order system under consideration. The different possibilities for the poles of H(s) in Equation 4.260 are illustrated in Figure 4.17. Im

Im

Re (a)

(b)

(c) Im

Re

Re (d)

(e) Im

Im

Re (f )

Im

Re (g)

Im

Re (h)

Im

Re

FIGURE 4.17

Re

Re

Im

(i)

Im

Im

Re (j)

Re (k)

Possible locations for transfer function poles of a second-order system.

191

Linear Systems Analysis

In (a), (b), (c), (d), and (e), the poles p1 and p2 are real and distinct. From Equation 4.262, the free response is the linear combination of natural modes ep1 t and ep2 t . Since 8 0, > < pt lim e ¼ 1, t!1 > : 1,

p0

the two natural modes decay to zero in (a), and the limit L ¼ 0. Therefore, (a) corresponds to an asymptotically stable system. In (b), one of the natural modes grows monotonically over time and L fails to exist. Hence, (b) represents an unstable system. A similar analysis of the remaining cases (c) through (k) leads to the results shown in Table 4.2. In summary, the second-order system with transfer function in Equation 4.260 is asymptotically stable provided the two poles are located entirely in the left half of the complex plane. The system is unstable if one or both of its poles lie in the right half of the complex plane or if it has a double pole at the origin. Lastly, it is marginally stable if there is a single pole at the origin and the other pole is negative or there exists a pair of purely imaginary poles located on the imaginary axis. The Routh– Hurwitz stability condition is a simple test for the presence of right-half-plane poles of the transfer function for an nth order LTI system (Dorf and Bishop 2005). An alternate deﬁnition of asymptotic stability is based on the system’s forced response. It states that for a system to be asymptotically stable, its response to any bounded input must remain bounded over time. The same conclusions with respect to the pole locations of an asymptotically stable system shown in Table 4.2 apply to this alternate deﬁnition as well. Systems that are not asymptotically stable according to this deﬁnition, that is, bounded input– bounded output (BIBO), are classiﬁed as marginally stable or unstable. In the case of a marginally stable system, the forced response to a bounded input may or may not be bounded depending on the input. Consider case (d) in Figure 4.17 where one of the poles is s ¼ 0 and the other is located along the negative real axis. In particular, suppose the second pole is s ¼ 2 and the second-order system transfer function is H(s) ¼

sþ3 s(s þ 2)

(4:265)

TABLE 4.2 Poles, Natural Modes, and Stability for a Second-Order System Poles (a) p1 < 0, p2 < 0 (b) p1 < 0, p2 > 0 (c) p1 > 0, p2 > 0 (d) p1 < 0, p2 ¼ 0 (e) p1 ¼ 0, p2 > 0 (f) p1 ¼ p2 ¼ p < 0 (g) p1 ¼ p2 ¼ p ¼ 0 (h) p1 ¼ p2 ¼ p > 0 (i) p1, p2 ¼ s jv (s < 0) (j) p1, p2 ¼ jv (k) p1, p2 ¼ s jv (s > 0)

Natural Modes p1 t

p2 t

e ,e e p1 t , e p2 t e p1 t , e p2 t e p1 t , 1 1, e p2 t e pt , te pt 1, t e pt , te pt est cos vt, est sin vt cos vt, sin vt est cos vt, est sin vt

System Stability Asymptotically stable Unstable Unstable Marginally stable Unstable Asymptotically stable Unstable Unstable Asymptotically stable Marginally stable Unstable

Simulation of Dynamic Systems with MATLAB® and Simulink®

192

The forced response to input u1(t) ¼ sin t, t 0 is obtained as follows: Y1 (s) ¼ H(s)U1 (s) ¼

sþ3 1 1:5 0:1 1:4s 0:2 ¼ s(s þ 2) s2 þ 1 s s þ 2 s2 þ 1 s2 þ 1

y1 (t) ¼ 1:5 0:1e2t 1:4 cos t 0:2 sin t,

t0

(4:266) (4:267)

The forced response to input u2(t) ¼ 1, t 0 is obtained in similar fashion. Y2 (s) ¼ H(s)U2 (s) ¼

sþ3 1:5 0:25 0:25 ¼ 2 þ s(s þ 2)s s s sþ2

y2 (t) ¼ 1:5t 0:25 þ 0:25e2t , t 0

(4:268) (4:269)

In both instances, the input is a bounded function of time. The output y1(t) remains bounded while the system response y2(t) is unbounded as a result of the ﬁrst term. Careful examination of the system transfer function in Equation 4.265 reveals that the only bounded inputs capable of producing an unbounded output are those whose Laplace transform contains a pure ‘‘s’’ term in the denominator. In other words, the input must either be a constant or a sum of bounded time functions containing a constant. The forced response of an unstable system to a bounded input is always unbounded due to the presence of an unstable natural mode (see Table 4.2) which appears in the response. For example, the forced response of a second-order system with a double pole at s ¼ 0 (case [g] in Figure 4.17) to any bounded input contains the unstable mode ‘‘t’’ and is always unbounded. A higher order LTI system is unstable if the transfer function contains one or more right-halfplane poles, the same as for a second-order system. It is not surprising since the characteristic polynomial of an nth-order system can always be factored into a number of linear and quadratic factors with real coefﬁcients. Using partial fraction expansion, the transfer function with factored denominator can be decomposed into a sum of ﬁrst- and second-order systems. For example, consider the ﬁfth-order system with transfer function given by H(s) ¼

Y(s) 7s4 þ 19s3 þ 45s2 þ 62s þ 52 ¼ 5 U(s) s þ 5s4 þ 12s3 þ 26s2 þ 32s þ 24

(4:270)

With the help of the MATLAB ‘‘residue’’ function, H(s) ¼

s2

s sþ1 5 þ 2 þ þ 4 s þ 2s þ 2 s þ 3

(4:271)

and the output Y(s) ¼ H(s)U(s) of the ﬁfth-order system can be expressed as Y(s) ¼

s sþ1 5 U(s) U(s) þ 2 U(s) þ s2 þ 4 s þ 2s þ 2 sþ3

(4:272)

The system is marginally stable as a result of the complex poles at s ¼ j2 located on the imaginary axis. The remaining poles at s ¼ 1 j and s ¼ 3 are associated with stable natural modes. The step response of the system with transfer function in Equation 4.270 remains bounded. However, the bounded inputs u(t) ¼ sin 2t or u(t) ¼ cos 2t result in an (s2 þ 4)2 term in the denominator of Y(s) and t sin 2t or t cos 2t terms in the output y(t). Hence, a bounded step response is necessary but not a sufﬁcient condition for asymptotic stability of LTI systems.

193

Linear Systems Analysis

For MIMO systems, the number of transfer functions can grow quickly. However, since stability is an intrinsic property of the system, that is, independent of the system inputs, it is not necessary to investigate each and every transfer function to determine if the system is stable. We shall soon see that the denominator polynomial of each transfer function is identical and, therefore, must be the characteristic polynomial of the system, D(s). The transfer function matrix G(s) of an MIMO system is the matrix whose ijth element is the transfer function Yi(s)=Uj(s). From the previous section, G(s) ¼ C(sI A)1 B þ D ¼ CF(s)B þ D

(4:273)

where A is the n n coefﬁcient matrix B, C, and D are the other matrices in the state variable model description The inverse of sI A is F(s), which can be expressed in terms of the adjoint of matrix sI A and its determinant according to F(s) ¼ (sI A)1 ¼

1 Adj(sI A) jsI Aj

(4:274)

It follows from Equations 4.273 and 4.274 that every component transfer function of G(s) has the same denominator, that is, the nth-order polynomial jsI Aj ¼ sn þ an1 sn1 þ an2 sn2 þ þ a1 s þ a0

(4:275)

Hence, the stability of a linear system described by the state variable model x_ ¼ Ax þ Bu, y ¼ Cx þ Du depends solely on the coefﬁcient matrix A. Furthermore, it is immaterial whether the system is SISO with one transfer function or MIMO with several transfer functions; the coefﬁcient matrix A is all we need to determine whether the system is asymptotically stable, marginally stable, or unstable. This is consistent with the earlier statement that the stability of the second-order system modeled by the differential equation in Equation 4.258 depends strictly on the constants a0 and a1. After all, the 2 2 coefﬁcient matrix A, while not unique, is determined entirely by a0 and a1. One choice for the states is x1 ¼ y and x2 ¼ y_ that leads to 0 1 A¼ (4:276) a0 a1 The characteristic polynomial in Equation 4.263 and the nth-order polynomial in Equation 4.275 with n ¼ 2 are identical, that is, D(s) ¼ s2 þ a1 s þ a0 ¼ jsI Aj

(4:277)

A compartment model for iodine storage in humans was presented in Example 4.11. The M-ﬁle ‘‘Chap4_iodine.m’’ computes the coefﬁcient matrix 2 3 0:95 0:005 0 0:5 6 0:8 0:015 0 0 7 6 7 A¼6 7 4 0 0:01 0:32 0 5 0:15 0 0:3 1:7 The characteristic polynomial was given as D(s) ¼ s4 þ 2:985s3 þ 2:42855s2 þ 0:52054s þ 0:004016

(4:278)

Simulation of Dynamic Systems with MATLAB® and Simulink®

194

It is left as an exercise (Exercise 4.21) to show that expansion of the determinant jsI Aj produces the characteristic polynomial given in Equation 4.278. The characteristic roots (poles of the system transfer functions) can be obtained by ﬁnding the roots of D(s) ¼ 0 in Equation 4.278 or equivalently the roots of D(s) ¼ jsI Aj ¼ 0

(4:279)

that are also referred to as the eigenvalues of matrix A. The MATLAB functions ‘‘roots(1 2.985 2.43855 0.52054 0.004016)’’ and ‘‘eig(A)’’ both return the characteristic roots 1.7901, 0.8621, 0.3248, and 0.0080. Since all the characteristic roots are in the left half of the complex plane, the system is asymptotically stable.

4.4.2 FEEDBACK CONTROL SYSTEM Real-world processes are nonlinear and may possess one or more equilibrium states. Linear models used to approximate the dynamics in the neighborhood of the equilibrium points are for the most part stable. However, control systems designed to improve some aspect of the system’s performance may in fact produce the opposite effect. An example is presented of a stable open-loop system under closed-loop control, which can produce unstable modes in the natural response if the control system parameters are chosen incorrectly. Figure 4.18 shows a simpliﬁed block diagram of a feedback control system for controlling the heading or yaw angle of a small ship. The open-loop system consists of the power converter (motor and gears that control the ship’s rudder) modeled by a ﬁrst-order lag with gain KP ¼ 108 (rudder)=V and time constant tp ¼ 0.2 s. The ship’s yaw dynamics include a gain KS ¼ 0.58 (heading)=s=8 (rudder) and time constant tS ¼ 7.5 s resulting in a sluggish response to changes in rudder position. A feedback closed-loop control system is implemented to improve the response. ucom(s) and u(s) are Laplace transforms of the commanded and actual ship headings, respectively. E(s) is the Laplace transform of the error signal input to the controller. The closed-loop system transfer function u(s)=ucom(s) is obtained by eliminating E(s) and U(s) from the following three equations: E(s) ¼ ucom (s) u(s) sþ1 U(s) ¼ KC E(s) s þ 10 0:5 10 U(s) u(s) ¼ s(7:5s þ 1) (0:2s þ 1)

θcom(s) deg (heading)

E(s) –

KC s + 1 s + 10 Controller and power amplifier

U(s) Volts

KP (τp s + 1)

(4:281) (4:282)

KS

R(s)

s (τS s + 1)

deg (rudder) Power converter Ship yaw dynamics and rudder Open-loop system

FIGURE 4.18

(4:280)

Block diagram of control system for ship heading.

θ(s) deg (heading)

195

Linear Systems Analysis

The result is u(s) 5KC (s þ 1) ¼ ucom (s) 1:5s4 þ 22:7s3 þ 78s2 þ 5(KC þ 2)s þ 5KC

(4:283)

The characteristic polynomial is D(s) ¼ 1:5s4 þ 22:7s3 þ 78s2 þ 5(KC þ 2)s þ 5KC

(4:284)

For every value of controller gain KC, there are four closed-loop system poles, which are the solutions to the characteristic equation, D(s) ¼ 0. Root-locus (Dorf and Bishop 2005) is a graphical design method used by control system engineers to plot the poles as the gain parameter KC varies from 0 to 1. There are four branches or loci, each containing one of the poles. The M-ﬁle ‘‘Chap4_ feedback_yaw.m’’ produces a root-locus plot shown in Figure 4.19a. When the gain KC ¼ 10, D(s) has two linear factors with real poles at s ¼ 3.922 and s ¼ 10.525 and a quadratic factor with a pair of complex poles located at 0.343 j0.831 (see Figure 4.19b). The quadratic factor damping ratio, natural frequency, damped natural frequency, and effective time constant are shown in Table 4.3. 20 1

15

0.75

−0.343 + j0.831

0.5

Kcrit

5

Imaginary axis

Imaginary axis

10

0 −5

0.25 0 −0.25 −0.5

−10

−0.75 −15

−0.343−j0.831

−1

−20 −30

−25

−20

(a)

FIGURE 4.19

−15 −10 −5 Real axis

0

5

10

(b)

−1.25 −1 −0.75−0.5 −0.25 0 0.25 0.5 0.75 1 1.25 Real axis

(a) Root-locus plot. (b) Zoom in near complex poles where KC ¼ 10.

TABLE 4.3 Closed-Loop System Properties (KC ¼ 10) Characteristic polynomial Poles Factory Damping ratio Natural frequency Damped natural frequency Time constants

D(s) ¼ 1:5s4 þ 22:7s3 þ 78s2 þ 60s þ 50 p1 ¼ 10:525, p2 ¼ 3:922, p3 , p4 ¼ 0:343 j0:831 s2 þ 0:686s þ 0:808, s þ 10:53, s þ 3:92 z ¼ 0.382 vn ¼ 0.899 rad=s vd ¼ 0.831 rad=s 1 1 1 ¼ 0:095 s, t2 ¼ ¼ 0:255 s, t ¼ ¼ 2:914 s t1 ¼¼ p1 p2 zvn

Simulation of Dynamic Systems with MATLAB® and Simulink®

196

The natural response of the closed-loop system (KC ¼ 10) is given by unat (t) ¼ c1 et=0:095 þ c2 et=0:255 þ et=2:914 [c3 cos (0:831t) þ c4 sin (0:831t)]

(4:285)

The closed-loop system response, when KC ¼ 10, is faster than the open-loop system as evidenced by the reduction in dominant time constant from 7.5 to 2.914 s. Suppose the ship is maintaining a heading of 08 (with the rudder angle at 08) when it becomes necessary to increase the heading by 58. In the open-loop system, a pulse input to the power converter and rudder subsystem is selected to produce the new desired heading. A pulse is speciﬁed rather than a step input because the rudder angle must return to zero once the new heading is achieved. What would happen if a step input were applied? For a pulse input of magnitude A and duration T, u(t) ¼ A Au(t T),

t0

(4:286)

the ship’s heading is from Equation 4.282

0:5 uopen-loop (s) ¼ s(7:5s þ 1)

10 A(1 eTs ) (0:2s þ 1) s

(4:287)

The inverse Laplace transform, uopen-loop (t) ¼ L1 {uopen-loop (s)}, is obtained by partial fraction expansion of Equation 4.287 without the 1 eTs followed by the shifting property P3 introduced in Section 4.4.2. It is left as an exercise to ﬁnd uopen-loop(t) and show that the ﬁnal value, that is, new heading, is uopen-loop (1) ¼ KP KS AT ¼ 5AT

(4:288)

The closed-loop system response with KC ¼ 10 to a command heading of 58 is obtained from Equation 4.283 as uclosed-loop (s) ¼

1:5s4

50(s þ 1) 5 3 2 þ 22:7s þ 78s þ 60s þ 50 s

(4:289)

Using the MATLAB ‘‘residue’’ function to ﬁnd the residues (partial fraction expansion coefﬁcients) and poles of uclosed-loop(s) in Equation 4.289 results in R1 ¼ 0:2188, p1 ¼ 10:5254,

R2 ¼ 1:3934,

R3 , R4 ¼ 3:0873 j0:6270,

p2 ¼ 3:9215,

R5 ¼ 5

p3 , p4 ¼ 0:3432 j0:8305, p5 ¼ 0

enabling uclosed-loop(s) to be expressed as the sum 5 X Ri uclosed-loop (s) ¼ s pi i¼1

(4:290)

Invert Laplace transforming Equation 4.290 gives the time domain response uclosed-loop (t) ¼

5 X i¼1

Ri epi t ,

t0

(4:291)

197

Linear Systems Analysis

The third and fourth terms involve complex coefﬁcients and complex exponentials, R3 ep3 t þ R4 ep4 t ¼ (3:087 j0:627)e(0:343þj0:831)t þ (3:087 þ j0:627)e(0:343j0:831)t

(4:292)

It is inadvisable to express the real-valued closed-loop response uclosed-loop(t) in terms of complex exponentials with complex coefﬁcients. However, computing and plotting the response using MATLAB to evaluate the terms in Equation 4.292 produce real numbers because R3 ep3 t þ R4 ep4 t is real-valued for all values of t. In fact, it is easily shown that uclosed-loop(t) reduces to the real expression uclosed-loop (t) ¼ 0:2188 e10:5254t þ 1:3934 e3:9215t e0:3432t [6:175 cos (0:8305t) 1:254 sin (0:8305t)] þ 5,

t0

(4:293)

The open-loop response with A ¼ 0.1, T ¼ 10 s and closed-loop response with KC ¼ 10 are plotted in Figure 4.20. Figure 4.19a shows that the quadratic factor poles migrate to the right-half plane producing a pair of unstable modes when the gain KC is larger than the critical gain Kcrit. An approximation of Kcrit is possible by varying KC in Equation 4.284 until the MATLAB ‘‘roots’’ function indicates the presence of a pair of imaginary poles located on the imaginary axis. After several attempts at locating the critical gain, the approximate result is KC ¼ 166.19, and the poles of the marginally stable closed-loop system are located at approximately 14.0705, 0.000011 j6.086566, 1.0627. Increasing KC further produces an unstable system. Figure 4.21 shows the heading response for the closed-loop system with KC ¼ 166.19. Note the sustained oscillations in the marginally stable system. An unstable response corresponding to KC ¼ 175 is also shown in Figure 4.21. The increasing magnitude of oscillations in the unstable system results from a pair of complex poles in the right-half plane at 0.0601 j6.2285. Applying the ﬁnal value property to the closed-loop transfer function in Equation 4.283 gives uss ¼ lim s s!0

5KC (s þ 1) ucom ¼ ucom s 1:5s4 þ 22:7s3 þ 78s2 þ 5(KC þ 2)s þ 5KC

(4:294)

Equation 4.294 holds as long as the control system is asymptotically stable, that is, KC < Kcrit. 8 7 6

Closed-loop, KC = 10

θ(t) (deg)

5 4

Open-loop, A = 0.1, T = 10

3 2 1 0 −1

FIGURE 4.20

0

5

10

15

20 t (s)

25

30

Ship heading response with open- and closed-loop control.

35

40

Simulation of Dynamic Systems with MATLAB® and Simulink®

198

10

θ(t) (deg)

8 6 4 2 0

KC = 166.19

KC = 175

−2 0

FIGURE 4.21

0.5

1

1.5

2 t (s)

2.5

3

3.5

4

Heading response for marginally stable and unstable closed-loop system.

The previous example illustrates the concept of stability for an LTI system. The results are predicated on the system response being conﬁned to a range of values for which the linear model is an accurate representation of the actual system’s dynamics. Furthermore, limitations on power consumption, component displacements, velocities, etc., must also be satisﬁed. For example, the design of the ship heading control system using the proportional controller with gain KC ¼ 10 could result in an unrealizable rudder response. A strong argument for simulation is that it allows us to check and monitor such assumptions.

EXERCISES 4.19 For the systems governed by the following differential equations: (a) y_ ¼ u (an integrator) (b) €y ¼ u (a double integrator) (c) y_ þ 2y ¼ u (d) y_ 2y ¼ u (e) €y þ 1:5_y þ 0:5y ¼ u (f) €y þ 4y ¼ u €y þ 4€y þ 6€y þ 5_y þ 2y ¼ u (g) €y 9y ¼ u (h) € €y þ 2:5€y_ þ 2€y þ 2:5_y þ y ¼ u (i) € determine whether the system is asymptotically stable, marginally stable, or unstable, and ﬁnd the natural response, that is, a linear combination of the natural modes. 4.20 Find the characteristic polynomial and characteristic roots of the system with state equations 0 0 1 (a) x_ ¼ xþ u, y ¼ [ 1 0 ]x 1 2 3 2 3 2 3 0 0 0 0 1 u 1 0 x1 (b) x_ ¼ 4 0 1 0 5x þ 4 1 0 5 1 , y ¼ u2 0 1 x2 0 1 2 1 2 2 3 20 4 8 (c) x_ ¼ 4 40 8 20 5x, y ¼ [ 1 0 1 ]x 60 12 26

199

Linear Systems Analysis

4.21 Show that jsI Aj ¼ s4 þ 2.985s3 þ 2.42855s2 þ 0.52054s þ0.004016 when A is the coefﬁcient matrix given by 2

0:95 6 0:8 6 A¼6 4 0

0:005 0:015 0:01 0

0:15

0 0

3 0:5 0 7 7 7 0 5

0:32 0:3 1:7

4.22 Derive the expression for the closed-loop transfer function u(s)=ucom(s) in Equation 4.283. 4.23 Starting with the Laplace transform uopen-loop(s) of the open-loop system

KP uopen-loop (s) ¼ s(tP s þ 1)

KS U(s) (tS s þ 1)

(a) Find uopen-loop(t) in response to the pulse input given in Equation 4.286. Leave your answer in terms of the KP, KS, tP, tS and the pulse parameters A and T. (b) Verify Equation 4.288 for the ﬁnal value uopen-loop(1). (c) Verify the open-loop pulse response shown in Figure 4.20. (d) Find and plot the open-loop step response (i) As the limit as T ! 1 of the open-loop pulse response. (ii) By inverse Laplace transformation of uopen-loop(s) when U(s) ¼ A=s. 4.24 In the ship heading example, the input to the ship yaw dynamics in Figure 4.18 is R(s), the rudder angle in degree. (a) Find the transfer function R(s)=ucom(s). (b) Find and plot a graph of r(t) for the case where ucom(t) ¼ 58, t 0 and KC ¼ 10. Comment on the results. (c) For the same command input ucom(t) ¼ 58, t 0 as in part (b), ﬁnd the maximum controller gain KC for which the rudder deﬂection never exceeds 308. Plot r(t) and u(t) for a time sufﬁcient for the system to reach steady state. 4.25 For the closed-loop system to control the ship’s heading (a) Find the fourth-order differential equation relating the output u(t) and input ucom(t). (b) Find a suitable choice for matrices A, B, C, and D in the state variable form x_ ¼ Ax þ Bu, y ¼ Cx where u ¼ ucom and y ¼ u. Leave your answers in terms of the system parameters KC, KP, KS, tP, and tS. Hint: Draw a simulation diagram. (c) Choose the same values for KP, KS, tP, and tS as in the example. Find the characteristic polynomial D(s) as a function of KC by evaluating jsI Aj. (d) Prepare a table with two columns. The ﬁrst column contains values of KC ¼ 1, 5, 10, 25, 50, 75, . . . , 200 V=deg heading, and the second column lists the four closed-loop system poles. (e) Use the MATLAB M-ﬁle ‘‘Chap4_ feedback_yaw.m’’ or write your own to ﬁnd the value(s) of KC that results in an underdamped quadratic factor of D(s) with damping ratio equal to 0.5. 4.26 The water current speed vW(t) inﬂuences the angle of the ship’s rudder and is considered a load variable or disturbance. The open-loop system is redrawn to reﬂect the disturbance input in Figure E4.26:

Simulation of Dynamic Systems with MATLAB® and Simulink®

200

VW (s)

U(s)

Volts

Knots

KL

Open-loop system

KP (τP s + 1)

R (s) deg (rudder)

Power converter and rudder

KS S(τS s + 1)

θ(s) deg (heading)

Ship yaw dynamics

FIGURE E4.26

The load gain KL can be assumed constant if the angle between the ship’s rudder and the water current direction is relatively constant.

u(s)

u(s)

(a) Find the closed-loop transfer functions and ucom (s) VW (s)¼0 VW (s) ucom(s) ¼0 where "

# " #

u(s)

u(s)

u(s) ¼ ucom (s) þ VW (s) ucom (s) VW (s)¼0 VW (s) ucom(s)¼0 (b) Find u(t) when ucom(t) ¼ 0, t 0 and vW(t) ¼ 2 kn, t 0. Assume the parameter values KP, KS, tP, and tS are the same as in the example. The controller gain KC ¼ 7.5 V=deg heading and the load gain KL ¼ 0.58 rudder=kn. 4.27 A ship with parameters KP, KS, tP, and tS given in the text is traveling in its intended direction, due North as shown in Figure E4.27. The ship cruising speed is 20 kn. The ocean current suddenly switches from zero to ﬁve knots in an east-to-west direction. Find the ship’s heading u(t) with the control system gain KC ¼ 5 V=deg heading. N νship νcurrent

θ

νship

FIGURE E4.27

Hint: Find the new command heading to keep the ship traveling due north.

4.5 FREQUENCY RESPONSE OF LTI CONTINUOUS-TIME SYSTEMS The response of LTI continuous-time systems to sinusoidal inputs is of interest because it provides an alternative to time domain methods based on the impulse response function to characterize the system’s dynamics. A nonperiodic signal f(t) can be resolved into sinusoidal functions over a continuum of frequencies according to Jackson (1991) 1 f (t) ¼ 2p

1 ð

F(jv)e jvt dv 1

(4:295)

201

Linear Systems Analysis

where the sinusoidal functions are the complex exponentials e jvt ¼ cos vt þ j sin vt

(1 < v < 1)

(4:296)

and the function F(jv) is given by 1 ð

F(jv) ¼

f (t)ejvt dt

(4:297)

1

The complex-valued function F( jv) is called the Fourier integral or Fourier transform of the signal f(t). Entire books have been written on the Fourier transform and its applications (Papoulis 1962; Bracewell 1986) while other books in the area of signals and systems (Kailath 1980; Jackson 1991; Kraniauskas 1992) include considerable coverage of the topic. F(jv) is a function that assumes complex values over the frequency range (1, 1). In polar form, F(jv) is written as F( jv) ¼ A( jv)e jf( jv) ,

A( jv) ¼ jF( jv)j and

f( jv) ¼ Arg[F( jv)]

(4:298)

where the magnitude A(jv) is called the Fourier spectrum of f(t). In rectangular form, F( jv) ¼ R( jv) þ jX( jv), R( jv) ¼ Re{F( jv)},

X( jv) ¼ Im{F( jv)}

(4:299)

If f(t) is causal, that is, f(t) ¼ 0, t < 0, it can be expressed as a continuum of the real sinusoidal functions cos vt or sin vt (Papoulis 1962) 2 f (t) ¼ p

1 ð

2 R( jv) cos vt dv ¼ p

0

1 ð

X( jv) sin vt dv,

t>0

(4:300)

0

implying that R( jv) and X( jv) are not independent. Suppose an LTI system with transfer function H(s) is subjected to an input u(t) with Fourier transform U( jv). By a convolution property similar to the one for Laplace transforms, the Fourier transform of the output y(t) is given by Y( jv) ¼ H( jv)U( jv)

(4:301)

where H( jv) is the system transfer function with s replaced by jv. H( jv) is called the frequency response function of the system. It follows from Equation 4.295 y(t) ¼

1 2p

1 ð

H( jv)U( jv)e jvt dv

(4:302)

1

and, therefore, each input component (1=2p)U ( jv)e jvt in the continuum of frequencies from 1 to 1 is scaled by H( jv) and integrated over (1, 1) to form the output y(t). If the input u(t) ¼ U0 cos v0t, its Fourier transform is (Jackson 1991) U( jv) ¼ U0 p[d(v þ v0 ) þ d(v þ v0 )]

(4:303)

Simulation of Dynamic Systems with MATLAB® and Simulink®

202

and Equation 4.302 reduces to (see Exercise 4.28) y(t) ¼ U0 jH(jv0 )j cos {v0 t þ Arg[H(jv0 )]}

(4:304)

The amplitude of the output is equal to the amplitude of the input multiplied by the magnitude of the frequency response function evaluated at v0. The phase angle (with respect to the input) equals the argument of the frequency response function at v0. Equation 4.304 is an essential property of linear systems and the foundation of AC steady-state analysis of electric circuits. Equation 4.304, valid for stable LTI systems, applies only in the steady state, that is, after the system’s natural response has vanished. In the case of nonlinear systems, the steady-state output in response to a sinusoidal input with frequency v0 contains sinusoids at harmonic frequencies 2v0, 3v0, 4v0, . . . along with a sinusoidal component at the fundamental frequency v0. Example 4.12 illustrates the property in Equation 4.304 for a simple ﬁrst-order system. Example 4.12 For the ﬁrst-order system in Figure 4.22, (a) Find the transient and steady-state responses to the input u(t) ¼ A sin v0t. Leave your answer in terms of the system parameters K and t and input parameters A and v0. (b) Find the frequency response function of the system. (c) A ¼ 1, v0 ¼ 2 rad=s, K ¼ 3, and t ¼ 0.5 s. Plot u(t) and y(t) on the same graph. (d) Find the time lag between the input and output at steady state, and verify the result from the graphs of u(t) and y(t). (a) For input u(t) ¼ A sin v0t, Y(s) is given by Y(s) ¼

K K Av0 KAv0 1 ¼ U(s) ¼ t ts þ 1 ts þ 1 s2 þ v20 (s þ 1=t)(s2 þ v20 )

(4:305)

Performing a partial fraction expansion of the last term in Equation 4.305 and simplifying, KAv0 t 1 ts þ Y(s) ¼ 1 þ (v0 t)2 s þ 1=t s2 þ v20 s2 þ v20

(4:306)

The inverse Laplace transform of Y(s) is y(t) ¼

KAv0 1 [tet=t þ sin v0 t t cos v0 t] v0 1 þ (v0 t)2

(4:307)

Using the trigonometric relationship A cos v0 t þ B sin v0 t ¼ C sin (v0 t þ w)

(4:308)

where C ¼ (A2 þ B2 )1=2 ,

U(s)

FIGURE 4.22

First-order system (K > 0).

w ¼ tan1 (A=B)

K τs + 1

(4:309)

Y(s)

203

Linear Systems Analysis the sin v0t and cos v0t terms in Equation 4.307 may be combined into a single term, that is, y(t) ¼ KA

v0 t 1 et=t þ sin (v0 t þ w) 2 1 þ (v0 t) [1 þ (v0 t)]1=2

(4:310)

where w ¼ tan1 (v0 t)

(4:311)

From Equation 4.310, the transient and steady-state responses are KAv0 t t=t e 1 þ (v0 t)2

(4:312)

KA sin (v0 t þ w) [1 þ (v0 t)2 ]1=2

(4:313)

ytr (t) ¼ yss (t) ¼

(b) The frequency response function is H( jv) ¼ H(s)js¼jv ¼

K

¼ ts þ 1 s¼jv

K 1 þ jvt

(4:314) (4:315)

From Equation 4.314, the magnitude and phase angle of H( jv) are

K

1 þ jvt

K ¼ [1 þ (vt)2 ]1=2

jH( jv)j ¼

(4:316) (K > 0)

ArgH( jv) ¼ tan1 (vt)

(4:317) (4:318)

(c) Substituting the given values for A, K, t, and v ¼ v0 gives ytr (t) ¼

(3)(1)(2)(0:5) t=t e ¼ 1:5e2t 1 þ [(2)(0:5)]2

(3)(1) sin {2t tan1 [(2)(0:5)]} {1 þ [(2)(0:5)]2 }1=2 pﬃﬃﬃ p ¼ 1:5 2 sin 2t 4

yss (t) ¼

(4:319)

(4:320) (4:321)

pﬃﬃﬃ The input u(t) ¼ sin 2t and output y(t) ¼ 1.5e2t þ 1.5 2 sin(2t p=4) are shown in Figure 4.23. The transient response dies out in approximately 5t ¼ 5(0.5) ¼ 2.5 s. (d) Figure 4.24 is a close-up of Figure 4.23 near the peaks of u(t) and y(t). The lag time T is estimated as T 4.31 3.92 ¼ 0.39 s in agreement with the exact value v0 T ¼ w ) T ¼

w p=4 p ¼ ¼ ¼ 0:393 s v0 2 8

(4:322)

Simulation of Dynamic Systems with MATLAB® and Simulink®

204

Sinusoidal response of first-order system, H(s) = K/(τs + 1) 2.5 2 1.5 1 0.5 0 u(t) = sin 2t

−0.5 −1 −1.5 −2

y(t) = 1.5e−2t + 1.5√2sin(2t – π/2)

−2.5 0

FIGURE 4.23

1

2

3

4 t (s)

5

6

7

8

Graph of input u(t) and output y(t).

Close-up showing output lag time T 2.2 2 1.8

Output y(t)

1.6 1.4 1.2 1 0.8 0.6 0.4

T

Input u(t)

0.2 0 3.6 3.7 3.8 3.9 4 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 t (s)

FIGURE 4.24

Close-up of input and response near peaks.

This example illustrates how the steady-state sinusoidal response of an LTI system can be obtained considerably faster using the frequency response function compared to methods that determine the complete response. Graphical tools exist for conveying the magnitude and phase properties of an LTI continuoustime system with transfer function H(s). The simplest one consists of graphs of jH( jv)j and Arg H ( jv) vs. v. The graphs are typically plotted over a frequency range of interest. Control systems engineers and analog ﬁlter designers prefer a variation of the frequency response plots in which 20 logjH( jv)j, the magnitude measured in decibels (db), is plotted vs. v on a logarithmic scale. The result (along with the phase plot) is called a Bode diagram or Bode plot.

205

Linear Systems Analysis

|H(jω)|, db

0 −50 −100 −150 100

101

102 ω (rad/s)

103

104

101

102 ω (rad/s)

103

104

Arg [H(jω)], deg

0 −100 −200 −300 100

FIGURE 4.25

Bode plot for third-order Butterworth low-pass ﬁlter (vb ¼ 100 rad=s).

To illustrate, consider a system with transfer function H(s) ¼

(s þ vb

v3b þ vb s þ v2b )

)(s2

(4:323)

which describes a third-order low-pass Butterworth ﬁlter designed to pass frequencies in the band 0 (DC) to vb and reject all others. The M-ﬁle ‘‘Chap4_Fig5_4.m’’ includes statements to evaluate the magnitude and phase of H(s) when vb ¼ 100 rad=s for frequencies between 100 and 104 rad=s. The Bode plot is shown in Figure 4.25. The control system toolbox, a complementary suite of utilities designed for use with the MATLAB environment, includes a function ‘‘bode’’ for drawing the Bode plot of an LTI system. The control system toolbox is covered later in Section 4.4.10. The magnitude measured in db (sometimes referred to as the gain) is close to zero, and, hence, the magnitude is close to 1 over a considerable portion of the interval 0 v vb. At v ¼ vb,

jH(jvb )j ¼

v3b 1 1

¼ ¼ pﬃﬃﬃ 2 2 (s þ vb )(s þ vb s þ vb ) s¼jvb j1 þ jj 2

1 ) 20 log jH(jvb )j ¼ 20 log pﬃﬃﬃ 3 db 2

(4:324)

(4:325)

The gain is 3 db at v ¼ vb and starts falling off from vb at approximately 60 db for every 10-fold increase in frequency (decade) (see Figure 4.25). The frequency response function of a system dictates the extent to which sinusoidal inputs at speciﬁc frequencies are passed or rejected by the system, and coupled with the fact that input time signals can be resolved into sinusoids over a continuum of frequencies, explains why linear systems are often called linear ﬁlters.

Simulation of Dynamic Systems with MATLAB® and Simulink®

206

R(s)

FIGURE 4.26

Open-loop system

GD(s)

D(s)

GC(s)

−

U(s)

GP(s)

Y(s)

A feedback control system with command and disturbance inputs.

The individual components in a linear feedback control system such as sensors, controllers, and power converters are examples of continuous-time ﬁlters, which transmit the range of frequencies in the input according to their frequency response function. Control system design based on frequency response relies on assumptions related to the frequency content of the command inputs and the uncontrollable inputs, referred to as load variables or disturbances. A simple unity feedback control system is shown in Figure 4.26. R(s) and D(s) are the reference (command) and disturbance inputs. The open-loop system model is Y(s) ¼ GP (s)[U(s) þ GD (s)D(s)]

(4:326)

The control system output Y(s) can be written as Y(s) ¼ TR (s)R(s) þ TD (s)D(s)

(4:327)

where TR (s) ¼

GC (s)GP (s) , 1 þ GC (s)GP (s)

TD (s) ¼

GD (s)GP (s) 1 þ GC (s)GP (s)

(4:328)

It frequently happens that the command input r(t) is a slow varying signal compared to the disturbance input d(t). Assuming GP(s) and GD(s) are ﬁxed, proper design entails selecting a controller transfer function GC(s) to simultaneously make jTR( jv)j close to 1 at the lower frequencies contained in r(t) and jTD( jv)j close to zero for the frequencies present in d(t). Suppose the command input is band-limited from 0 to 0.25 Hz (1.57 rad=s) and the disturbance frequencies start at roughly 10 Hz (62.8 rad=s) and the open-loop system transfer functions are GP (s) ¼

K 1 ¼ s2 þ 2zvn s þ v2n s2 þ 2:25s þ 0:5625 GD (s) ¼ KD ¼ 40

(4:329) (4:330)

The controller is of the proportional plus integral (P-I) type, GC (s) ¼ KC þ

K1 2 ¼5þ s s

(4:331)

Bode plots of TR( jv) and TD( jv) are generated in ‘‘Chap4_Fig5_6.m’’ and shown in Figure 4.27. The frequency content of the command input r(t) is conﬁned primarily to frequencies below 1.57 rad=s. The output will track the input closely since the gain 20 log jTR( jv)j is roughly 0 db,

207

Linear Systems Analysis

Gain (db)

20 0

|TD( jω)|

|TR( jω)|

−20 −40 −60

Phase angle (deg)

10−2

10−1

101

102

101

102

100 Arg [TD( jω)] 0

Arg (TR( jω))

−100 −200 10−2

FIGURE 4.27

100 ω (rad/s)

10−1

100 ω (rad/s)

Bode plot for closed-loop frequency response functions TR( jv) and TD( jv).

corresponding to a magnitude of 1 from DC (v ¼ 0) to approximately 1 rad=s. The phase angle Arg [TR( jv)] is close to 08 from v ¼ 0 to v 0.5 rad=s and is 36.18 at v ¼ 1.57 rad=s. Conversely, the gain 20 log jTD( jv)j ¼ 40 db, which is equivalent to a magnitude of 0.01 at approximately 62 rad=s. The control system effectively ﬁlters out the disturbances by attenuating all frequencies above 62.8 rad=s. The steady-state error, ess ¼ y(1) r(1), is zero when r(t) or d(t) is constant. This can be demonstrated by showing that the DC gains TR( j0) ¼ 1 and TD(j0) ¼ 0, a direct consequence of the open-loop gain GC(0)GP(0) ¼ 1. The inﬁnite open-loop gain results from the presence of the integrator in GC(s). While zero steady-state error is a desirable condition, we must still be mindful of the location of the control system’s characteristic roots since it determines the transient response. The transfer functions of real-world components and complete systems possess Bode plots in which the gain ‘‘rolls off’’ at high frequencies. Properly designed closed-loop control systems track low-frequency command inputs reasonably well. Further increases in frequency require excessive power be delivered to control system components, thus limiting the system’s ability to track higher frequency command inputs. Any component or system with transfer function G(s) given by the ratio of polynomials in proper fraction form, that is, numerator polynomial, is lower order than denominator will satisfy lim

v!currency

jG( jv)j ¼ 0 ) lim 20 log jG( jv)j ¼ 1 v!1

(4:332)

A common measure of the frequency where ‘‘roll off’’ begins is vb and the interval (0, vb) is called the bandwidth of the system. The frequency vb satisﬁes jG(jvb )j ¼

1 jG(j0)j ) 20 log jG(jvb )j ¼ 20 log jG(j0)j 3 db 21=2

(4:333)

Consequently, vb is the (lowest) frequency at which the gain (magnitude function measured in db) is 3 db below the DC gain of the system.

Simulation of Dynamic Systems with MATLAB® and Simulink®

208

Consider the ﬁrst-order system in Figure 4.22 with magnitude function jH( jv)j given in Equation 4.316. The frequency vb is obtained from K 1 1 ¼ 1=2 jH(j0)j ¼ 1=2 K 1=2 2 2 [1 þ (vb t ) ] 2 2 ) 1 þ (vb t) ¼ 2 1 ) vb ¼ t

jH(jvb )j ¼

(4:334) (4:335) (4:336)

Equation 4.336 is important because it relates vb, a frequency domain parameter to the time constant t, which characterizes the system’s transient response in the time domain. Furthermore, being inversely proportional to the system, time constant tells us that the bandwidth frequency vb is a measure of the speed of response of the ﬁrst-order system. Hence, ﬁrst-order systems like the one in Figure 4.22 with a fast natural mode (t small) exhibit larger bandwidths. For a second-order system with transfer function G(s) ¼

Kv2n s2 þ 2zvn s þ v2n

(4:337)

increasing the natural frequency vn (with z constant) decreases the transient response time regardless of whether the system is underdamped, overdamped, or critically damped (see expressions for step response in Section 2.3). It is left as an exercise to show that the bandwidth frequency vb for the system with transfer function in Equation 4.337 is proportional to vn. Speciﬁcally, h i1=2 vn , (K ¼ 1) (4:338) vb ¼ 1 2z2 þ (2 4z2 þ 4z4 )1=2 and, therefore, vb is a measure of the speed of response for a second-order system as well. A Bode plot for three second-order systems, all with vn ¼ 1 rad=s and damping ratios of z ¼ 0.25, 1, 2, is shown in Figure 4.28. Also shown is an enlargement of the plots for the purpose of Bode plots of three second-order systems ζ = 0.25 ζ=2

−20

|G( jω)| (db)

|G( jω)| (db)

0

Close-up of Bode plots

ζ=1 −0 −60 −80 −2 10

100 ω (rad/s)

102

ζ=1

−3 −5

ζ=2 100 ω (rad/s)

ζ=2

Arg [G( jω)] (deg)

Arg [G( jω)] (deg)

0

0 ζ = 0.25

ζ=1 −100 −150 10−2

FIGURE 4.28

ζ = 0.25

10–1

0 −50

5

100 ω (rad/s)

102

ζ=1 −50

ζ = 0.25

ζ=2

−100

−150 10–1

100 ω (rad/s)

Bode plots for second-order systems (vn ¼ 1 rad=s) with z ¼ 0.25, 1, 2.

209

Linear Systems Analysis

estimating the corresponding bandwidths. The calculated values of vb from Equation 4.338 are 1.4845 rad=s (z ¼ 0.25), 0.6436 rad=s (z ¼ 1), and 0.2666 rad=s (z ¼ 2) in agreement with the values estimated from Figure 4.28. Figure 4.28 shows a peak in the gain (and magnitude function) for the underdamped system indicating the presence of a resonant frequency. The resonant frequency is vr ¼ 0.935 rad=s with jG( jvr)j ¼ 2.0656 (6.3 db). Not all underdamped second-order systems exhibit resonance (see Exercise 4.32). The Bode plots and bandwidth calculations are handled in the MATLAB script ﬁle ‘‘Chap4_Fig5_7.m.’’ The step responses of the three second-order systems are shown in Figure 4.29. The rise time is deﬁned as tr ¼ t0.9 t0.1, where t0.1 and t0.9 are the times required for the step response to reach 10% and 90% of its ﬁnal value, respectively. The rise time is another measure of the system’s speed of response. The times t0.1 and t0.9 and the approximate rise times are shown on the zoomed-in plots of the step responses. As expected, the lightly damped system (z ¼ 0.25) with the greatest bandwidth responds the quickest (shortest rise time) while the overdamped system (z ¼ 2) with the smallest bandwidth is the most sluggish and least responsive. The step responses are generated in the M-ﬁle ‘‘Chap4_Fig5_8.m.’’ LTI systems modeled by transfer functions where the order of the numerator and that of the denominator polynomials are equal, that is, a direct connection exists from the input to the output, exhibit ﬁnite gain at frequencies approaching inﬁnity. That is,

n

an s þ an1 sn1 þ þ a1 s þ a0

an

¼ lim jH( jv)j ¼ lim

n v!1 v!1 bn s þ bn1 sn1 þ þ b1 s þ b0

bn s¼jv

(4:339)

Since a real system cannot respond in a way suggested by Equation 4.339, the transfer function H(s) with equal order polynomials in the numerator and denominator, or equivalently the same number of ﬁnite zeros and poles, is an ideal approximation that breaks down above a certain frequency. Nonetheless, it is a useful approximation to the transfer function of a system that readily passes

0.9

1 ζ = 0.25

0.5 0

0.1 0

5

10

15

20

0

ζ=1

1.6

2

4

5

tr = 3.32 s

0

5

10

15

0

20

1

2

3

0.9

0.5

y(t)

y(t)

1.2

0.1

1

FIGURE 4.29

0.8

0.9

0.5

0

0.4

y(t)

y(t)

1

0

tr = 1.25 s

y(t)

y(t)

1.5

ζ=2

tr = 8.24 s 0.1

0

5

10 t (s)

15

20

0 1 2 3 4 5 6 7 8 9 10 t (s)

Step responses and rise times for three second-order systems.

Simulation of Dynamic Systems with MATLAB® and Simulink®

210

vc(t) C e0(t)

+

+ R

_

vR(t) _

FIGURE 4.30

Circuit with high-pass ﬁlter transfer function.

high-frequency components present in its input(s), as in the case of a high-pass ﬁlter. Of course, when the high-frequency signals represent unwanted noise, which is invariably present in control systems, the closed-loop transfer function should be designed to attenuate the noise (see Exercise 4.34). The simple RC circuit in Figure 4.30 with the voltage vR(t) as output is an example of a high-pass ﬁlter. The transfer function is H(s) ¼

VR (s) RCs ¼ E0 (s) RCs þ 1

(4:340)

At high frequencies (v 1=RC), the magnitude jH(j1)j 1 (0 db). Note that the capacitor behaves like a short circuit at high frequencies.

4.5.1 STABILITY

OF

LINEAR FEEDBACK CONTROL SYSTEMS BASED ON FREQUENCY RESPONSE

Linear control systems are a class of LTI systems, and the basic premises of stability presented in the previous section are applicable. The following is a brief introduction to stability, as it applies to simple feedback control systems from the viewpoint of frequency response. For a more detailed discussion of the subject, the reader is encouraged to refer to any of the texts in linear feedback control systems listed in the References. Figure 4.31 is a block diagram of a servo control system with transfer functions for the controller, actuator, plant, and sensor=transmitter. Insight into the stability of the system can be ascertained by tracking the response to the error signal e(t) ¼ L1 {E(s)} as it propagates around the loop. Suppose the loop is broken immediately following the transmitter and a test signal e(t) ¼ sin vt is inserted at the controller input. Each component along the open-loop path processes a sinusoidal input and delivers a sinusoidal output (both at radian frequency v) to the next component. Magnitude and phase shift of the individual sinusoids are determined by the frequency response functions of each component at radian frequency v.

E(s) GC (s)

R(s)

UC(s)

GA (s)

UA(s)

GP(s)

– Command input

Controller

Actuator UT (s)

Plant

GT (s) Transmitter

FIGURE 4.31

Block diagram of representative linear feedback control system.

Y(s) Output

211

Linear Systems Analysis

The closed-loop control system is unstable if uT (t) ¼ L1 {UT (s)} is ever in phase with e(t) and its amplitude is greater than one. When this occurs, the error signal propagates around the loop and increases in magnitude while doing so. Conversely, when e(t) and uT(t) are in phase and juT(t)j ¼ juT(t)j < 1, a stable system results. Finally, a marginally stable system exists when e(t) and uT(t) are in phase and juT(t)j ¼ juT(t)j ¼ 1. Since the negative sign in uT(t) is equivalent to 1808 phase shift, uT(t) will be in phase with e(t) whenever uT(t) lags e(t) by 1808, that is, there is a combined total of 1808 phase lag in the open-loop system. The frequency at which this occurs is called the phase crossover frequency vcp. Hence, for a closed-loop, negative feedback control system to be marginally stable (or unstable), there must exist at least one frequency where the open-loop phase lag is equal to 1808. The open-loop transfer function is GOL (s) ¼ GC (s)GA (s)GP (s)GT (s)

(4:341)

For this example, assume the dynamics of each component are described by GC (s) ¼ KC ,

GA (s) ¼

KA , tA s þ 1

GP (s) ¼

KP , s(tP s þ 1)

GT (s) ¼

KT tT s þ 1

(4:342)

where KC ¼ 0.25, KA ¼ 2, tA ¼ 0.25, KP ¼ 8, tP ¼ 4, KT ¼ 0.1, and tT ¼ 0.003. The open-loop transfer function becomes KA KP KT tA s þ 1 s(tP s þ 1) tT s þ 1 2 8 0 ¼ (0:25) 0:25s þ 1 s(4s þ 1) 0:003s þ 1 0:4 ¼ s(0:25s þ 1)(4s þ 1)(0:003s þ 1)

GOL (s) ¼ KC

(4:343) (4:344) (4:345)

A Bode plot of the open-loop transfer function is shown in Figure 4.32. Bode plot of open-loop transfer function (KC = 0.25)

Gain (db)

100 0 −100 −200 10−2

ωcg = 0.271 rad/s 10−1

100

101

102

103

102

103

Phase (deg)

0 −100 −200 −300 −400 10−2

ωcp = 0.994 rad/s 10−1

100

101 ω (rad/s)

FIGURE 4.32

Bode plot of GOL(s) for stable system (KC ¼ 0.25).

Simulation of Dynamic Systems with MATLAB® and Simulink®

212

Inspection of Equation 4.345 reveals the open-loop phase varies from 908 at v ¼ 0 to 3608 at v ! 1 indicating the possibility of a marginally stable or unstable system. The phase crossover frequency vcp was determined by trial and error to be approximately 0.9936 rad=s. As a check, Arg[GOL (j0:9936)] 180

(4:346)

The magnitude function evaluated at vcp 0.9936 rad=s is jGOL (jvcp )j ¼ GOL (j0:9936)j ¼ 0:0953(20:4 db)

(4:347)

The system is stable since the magnitude function is less than one, or equivalently the gain is less than 0 db, at the phase crossover frequency. The gain of 20.4 db is a measure of stability. Control engineers would say the ‘‘gain margin’’ is 20.4 db. Another indicator of stability, the ‘‘phase margin,’’ is the difference between the open-loop phase lag and 1808 at the frequency where the gain is 0 db. This frequency, called the gain crossover frequency vcg, is approximately 0.271 rad=s for the stable system in Figure 4.32. Since Arg [GOL(jvcg)] ¼ Arg[GOL(j0.271)] ¼ 141.28, the phase margin is equal to 142.1 (180) ¼ 37.98. Higher phase margins imply a greater measure of relative stability. Increasing the controller gain KC generally makes the system more responsive. Consider raising the gain KC by an amount sufﬁcient to make the system marginally stable, that is, jGOL(jvcp)j ¼ 1 ) 20 log jGOL( jvcp)j ¼ 0 db. From Equation 4.347, it follows that if we multiply the current gain KC ¼ 0.25 by 1=jGOL(jvcp)j ¼ 1=0.0953, the new open-loop gain will be equal to 0 db at vcp (which remains unchanged at 0.9936 rad=s). The Bode plot of the open-loop system transfer function when KC ¼ 0.25(1=0.0953) ¼ 2.62 is shown in Figure 4.33. The gain crossover frequency is identical to the phase crossover frequency, and the two stability margins have been reduced to zero. The control system is marginally stable, and there will be persistent oscillations at the crossover frequency 0.9936 rad=s in the natural response of the system.

Bode plot of open-loop transfer function (KC = 2.62)

Gain (db)

100 0 −100 ωcg = 0.994 rad/s −200 10−2

10−1

100

101

102

103

102

103

Phase (deg)

0 −100 −200 −300 −400 10−2

ωcp = 0.994 rad/s 10−1

100

101 ω (rad/s)

FIGURE 4.33

Bode plot of GOL(s) for marginally stable system.

213

Linear Systems Analysis

The closed-loop transfer function is GCL (s) ¼

GC (s)GA (s)GP (s) 1 þ GC (s)GA (s)GP (s)GT (s)

(4:348)

and the closed-loop system poles are the roots of 1 þ GC (s)GA (s)GP (s)GT (s) ¼ 1 þ (2:6224)

2 8 0:1 ¼0 0:25s þ 1 s(4s þ 1) 0:003s þ 1

(4:349)

) (0:25s þ 1)s(4s þ 1)(0:003s þ 1) þ (2:6224)(2)(8)(0:1) ¼ 0

(4:350)

) 0:003s4 þ 1:01275s3 þ 4:253s2 þ s þ 4:1958 ¼ 0

(4:351)

Solving the characteristic equation above produces the four closed-loop system poles, s1 ¼ 333:3,

s2 ¼ 4:25, s3 ¼ j0:9936, s4 ¼ j0:9936

demonstrating the marginal stability (poles on the imaginary axis) of the system as well as the frequency of sustained oscillations, namely, vcp ¼ 0.9936 rad=s. Further increase in controller gain KC produces an unstable system resulting in negative stability margins (gain and phase) as well as closed-loop system poles in the right-half plane. Superior performance requires a different type of controller, that is, one which provides sufﬁcient phase lead in the vicinity of the gain crossover frequency for adequate stability and possibly phase lag at lower frequencies to improve steady-state response. Indeed, this is the essence of synthesizing controllers for feedback control systems using frequency response methods. Simulation is an indispensable tool for verifying control system design.

EXERCISES 4.28 Use Equations 4.302 and 4.303 to derive Equation 4.304. 4.29 The Fourier spectrum jF( jv)j of a signal f(t) can be used to ﬁnd the energy in the signal in the frequency spectrum (v1, v2) according to v ð2

jF( jv)j2 dv

Ef (v1 , v2 ) ¼ v1

0, t 1. Hence, the region of convergence is outside the Unit Circle, jzj ¼ 1. A closed form for U(z) is preferable to the inﬁnite series and often easy to recognize when uk is a simple expression.

Example 4.14 (a) Find the z-transform of the discrete-time signal uk resulting from sampling the continuoustime function u(t) ¼ eat, t 0 every T s. (b) Suppose u(t) and uk are as shown in Figure 4.35. Find U(z). (a) Sampling a continuous-time signal u(t) every T s results in a discrete-time signal uk where uk ¼ u(t)jt ¼kT ¼ u(kT ), k ¼ 0, 1, 2, 3,. . . . Hence, from the deﬁnition of the z-transform and uk ¼ eakT, k ¼ 0, 1, 2, . . . , U(z) ¼

1 X

eakT zk ¼

k¼0

1 X

(eaT z1 )k ¼

k¼0

1 z ¼ , jzj > eaT 1 eakT z1 z eaT

Note the dependence of U(z) on the sampling interval T. uˆ k

1 ……. 0

FIGURE 4.34

1

2

The discrete-time unit step.

3

4

5

6

…….

k

(4:355)

217

Linear Systems Analysis

u0

1

u(t) = e−at, t ≥ 0 a=1

u1

0.8

u2

0.6

uk = e−akT, k = 0, 1, 2, 3, ...

u3 0.4

T = 0.25 s

0.2 0

k

0 1 2 3 4 .............................. 0

1

2

3

4

5

6

t (s)

FIGURE 4.35

Uniform sampling of a continuous-time exponential function.

(b) For a ¼ 1, T ¼ 0.25, U(z) ¼

z , z e0:25

jzj > e0:25

(4:356)

The next example looks at a discrete-time signal, which occurs frequently in the analysis of linear discrete-time systems, namely, the geometric sequence. Example 4.15 Find the z-transform of the discrete-time signal uk ¼ a k ,

k ¼ 0, 1, 2, 3, . . .

(4:357)

Once again, our starting point is the deﬁnition of the z-transform in Equation 4.352. U(z) ¼

1 X k¼0

ak zk ¼

1 X

(az1 )k ¼

k¼0

1 z ¼ , 1 az1 z a

jzj > jaj

(4:358)

The result is easily checked by long division, that is, if the denominator in Equation 4.358 is divided into the numerator, the result is z ¼ 1 þ az1 þ a2 z2 þ a3 z3 þ þ ak zk þ za

(4:359)

From the deﬁnition of U(z) as an inﬁnite series, U(z) ¼

1 X k¼0

uk zk ¼ u0 þ u1 z1 þ u2 z2 þ u3 z3 þ þ uk zk þ

(4:360)

Simulation of Dynamic Systems with MATLAB® and Simulink®

218

Comparing Equation 4.359 and Equation 4.360, it follows that u0 ¼ 1, u1 ¼ a, u2 ¼ a2, u3 ¼ a3, . . . , and, therefore, uk ¼ ak, k ¼ 0, 1, 2, 3,. . . . The long division method provides a quick check on U(z) for a discrete-time signal uk, k ¼ 0, 1, 2, 3,. . . . Typically, the ﬁrst several coefﬁcients in the inﬁnite series expression for U(z) are compared to the corresponding values of the discrete-time signal uk with an equivalence necessary (but not sufﬁcient) for U(z) ¼ z{uk}. Depending on the numerical value of the constant ‘‘a,’’ the discrete-time signal uk in Equation 4.357 can asymptotically approach zero in magnitude (jaj < 1), remain constant in magnitude (jaj ¼ 1), or increase in magnitude without bound (jaj > 1). All six cases are shown in Figure 4.36. Note that when a ¼ 1, the discrete-time unit step (Figure 4.34) results and Equation 4.358 reduces to Equation 4.354. The exponential sequence in Example 4.14 is also a geometric sequence. This is evident by expressing it in a slightly different way, that is, uk ¼ eakT ¼ (eaT )k ¼ (b)k ,

where b ¼ eaT

k ¼ 0, 1, 2, 3, . . .

(4:361)

The sequences resulting from uniform sampling of continuous-time sine and cosine functions are fundamental discrete-time signals with z-transforms that follow directly from the basic deﬁnition. The results are sin kvT ,

cos kvT ,

( sin vT)z (2 cos vT)z þ 1

(4:362)

z(z cos vT) z2 (2 cos vT)z þ 1

(4:363)

z2

where the symbol , denotes a z-transform pair, that is, a discrete-time signal and its z-transform. The discrete-time signals in Equations 4.362 and 4.363 produce interesting results when the sampling occurs at certain frequencies as shown in Example 4.16.

1 0.5

1 a = −0.5

a = −2

0.5 0

0

1000 500 a = −1 0

−0.5

−500

−1

−0.5 0 2 4 6 8 10 k

0 2 4 6 8 10 k

0 2 4 6 8 10 k

2 1 0.75

a = 0.5

0.5 0.25

1.5

a=1

a=2

750 1

500

0.5

250

0

0 0 2 4 6 8 10 k

FIGURE 4.36

1000

0

0 2 4 6 8 10 k

0 2 4 6 8 10 k

Discrete-time signal uk ¼ ak, k ¼ 0, 1, 2, 3, . . . for a ¼ 0.5, 1, 2, 0.5, 1, 2.

219

Linear Systems Analysis

Example 4.16 Find the z-transform of the discrete-time signal obtained from sampling (a) x(t) ¼ sin 3t, t 0 when T ¼ p=6 s (b) x(t) ¼ sin 3t, t 0 when T ¼ p=3 s (c) x(t) ¼ cos vt, t 0 when T ¼ 2p=v s From Equations 4.362 and 4.363, (a)

xk ¼ sin 3kT ,

z2

( sin 3 p=6)z ( sin p=2)z z ¼ 2 ¼ 2 (2 cos 3 p=6)z þ 1 z (2 cos p=2)z þ 1 z þ 1

xk ¼ sin 3kT ,

(b)

( sin 3 p=3)z ( sin p)z ¼ ¼0 z2 (2 cos 3 p=3)z þ 1 z2 (2 cos p)z þ 1

z(z cos v 2p=v) z(z cos 2p) ¼ z2 (2 cos v 2p=v)z þ 1 z2 (2 cos 2p)z þ 1 z(z 1) z ¼ 2 ¼ z 2z þ 1 z 1

(4:364) (4:365)

cos kvT ,

(c)

(4:366)

Figure 4.37 shows the continuous-time signal x(t) ¼ sin 3t, t 0 and the discrete-time signals xk ¼ sin 3kT, k ¼ 0, 1, 2, 3, . . . resulting from sampling in parts (a) and (b). Note, in part (a), the frequency of sampling vs ¼ 2p=T ¼ 12 rad=s is four times the frequency of the signal x(t). The result given in Equation 4.364 is easily veriﬁed by long division of z2 þ 1 into z giving the inﬁnite series z z1 z3 þ z5 z7 þ z9 z11 þ z2 þ 1 8 k ¼ 0, 2, 4, 6, . . . < 0, 0, ¼ ) uk ¼ 1, k ¼ 1, 5, 9, . . . : (1)(kþ3)=2 , 1, k ¼ 3, 7, 11, . . .

U(z) ¼

(4:367) k ¼ 0, 2, 4, 6, . . . k ¼ 1, 3, 5, 7, . . .

x(t) = sin 3t, t ≥ 0 and xk = x (kT), k = 0, 1, 2, 3,... T = π/6 s 1

x(t) xk

0.5 0 0

1

2

3

4

5

6

7

8

9

k

10 11

−0.5 −1 0

1

2

3

4

5

6

x(t) = sin 3t, t ≥ 0 and xk = x (kT), k = 0, 1, 2, 3,... T = π/3 s 1

x(t) xk

0.5 0

0

1

0

1

2

3

4

k

5

−0.5 −1

FIGURE 4.37

2

3 t (s)

4

5

Uniform sampling of x(t) ¼ sin 3t (T ¼ p=6 s and T ¼ p=3 s).

6

(4:368)

Simulation of Dynamic Systems with MATLAB® and Simulink®

220

x(t) = cos ωt, t ≥ 0 and xk = x(kT), k = 0, 1, 2, 3,... T = 2π/ω s x(t) xk

1

0.5

0 0

1

2

3

4

k

5

−0.5

−1 t (s)

FIGURE 4.38

Uniform sampling of cos vt (T ¼ 2p=v s).

At the slower sampling frequency of 6 rad=s in part (b), the discrete-time signal is identically zero for all k. In part (c), the cosine function is sampled once per cycle resulting in the discrete-time unit step function shown in Figure 4.38. Table 4.4 is a brief listing of elementary continuous-time functions and their Laplace transforms along with the discrete-time signals resulting from uniform sampling of the continuous-time signals and the corresponding z-transforms (Jacquot 1981).

TABLE 4.4 Table of Laplace and z-Transforms f(t), t 0

F(s) ¼ L{f (t)}

1

1 s

1

z z1

T

1 s2

KT

Tz (z 1)2

eat

1 sþa

eakT

z z eaT

teat

1 (s þ a)2

kTeakT

TeaT z (z eaT )2

sin vt

v s2 þ v2

sin kvT

( sin vT)z z2 2( cos vT)z þ 1

s þ v2

cos kvT

cos vt

s2

fk ¼ f(kT ), k ¼ 0, 1, 2, . . .

eat sin vt

v (s þ a)2 þ v2

eakT sin kvT

eat cos vt

sþa (s þ a)2 þ v2

eakT cos kvT

F(z) ¼ z{fk }

z2

z2 ( cos vT)z 2( cos vT)z þ 1

z2

(eaT sin vT)z 2(eaT cos vT)z þ e2at

z2

z2 (eaT cos vT)z 2(eaT cos vT)z þ e2aT

221

Linear Systems Analysis

4.6.1 DISCRETE-TIME IMPULSE FUNCTION We now introduce a discrete-time function, which plays a prominent role in analyzing the behavior of linear discrete-time systems. The unit strength discrete-time impulse occurring at discrete-time k ¼ 0 is deﬁned by dk ¼

k¼0 k ¼ 1, 2, 3, . . .

1, 0,

(4:369)

Delaying the discrete-time impulse by n units of discrete-time produces 1, k ¼ n dkn ¼ 0, k ¼ 0, 1, 2, . . . , n 1, n þ 1, . . .

(4:370)

It follows directly from the deﬁnition of the z-transform that z{dk } ¼ 1

and

z{dkn } ¼ zn

(4:371)

An arbitrary discrete-time signal fk, k ¼ 0, 1, 2, . . . can be expressed as a weighted sum of unit discrete-time impulses, that is, fk ¼

1 X

fi dki ¼ f0 dk þ f1 dk1 þ f2 dk2 þ f3 dk3 þ

k ¼ 0, 1, 2, 3, . . .

(4:372)

i¼0

The output of a linear discrete-time system subject to a unit discrete-time impulse is termed the unit impulse response. Just like in the case of continuous-time systems, the discrete-time impulse response reﬂects the natural dynamics of the system. This will be demonstrated after the z-domain transfer function is introduced. Example 4.17 Represent the discrete-time signal uk, k ¼ 0, 1, 2, 3, . . . shown in Figure 4.39 in terms of discretetime impulses and ﬁnd U(z). 8 k ¼ 0, 1, 2, 6, 7, . . . < 0, uk ¼ 1, (4:373) k ¼ 3, 5 : 2, k¼4 From Equation 4.372, uk ¼ 1 dk3 þ 2 dk4 þ 1 dk5 U(z) ¼ z{uk } ¼ z{dk3 þ 2dk4 þ dk5 } ¼ z3 þ 2z4 þ z5 ¼

(4:374) z2 þ 2z þ 1 z5

uk 2 1 ……. 0

FIGURE 4.39

1

2

3

4

5

6

7 …….

Graph of discrete-time signal uk, k ¼ 0, 1, 2, 3,. . . .

k

(4:375)

Simulation of Dynamic Systems with MATLAB® and Simulink®

222

Note in Equation 4.375 we employed the linearity property of z-transforms, that is, z{dk3 þ 2dk4 þ dk5 } ¼ z{dk3 } þ 2z{dk4 } þ z{dk5 }

(4:376)

In the general case, zz{auk þ byk } ¼

1 X

(auk þ byk )zk ¼ a

k¼0

1 X

uk zk þ b

k¼0

1 X

ykzk ¼ aU(z) þ bY(z)

(4:377)

k¼0

Other useful properties (analogous to those of the Laplace transform) of the z-transform are included in Table 4.5. The ‘‘delay’’ property is especially important. Suppose a discrete-time signal uk for which uk ¼ 0 when k < 0 is delayed n units of discrete-time. The delayed signal, denoted ukn, is expressed in terms of uk in Table 4.5. The case where n ¼ 1 and 2 along with the general case is illustrated in Figure 4.40a through d. The unit-delay operator, as the name suggests, delays its input by one unit of discrete-time. The symbol for a unit-delay operator is a block with z1 inside. If the input to a unit-delay operator is the discrete-time signal uk shown in Figure 4.40a, the output would be uk1 in Figure 4.40b. A pair of unit-delay operators in series is shown in Figure 4.41. The outputs xk and yk are related to the input uk by

xk ¼ uk1

8 0, > > > < u0 , ¼ > u1 , > > : ...

k¼0 k¼1 k¼2 ...

(4:378)

TABLE 4.5 Useful Properties of the z-Transform Description Linearity Delay (right shifting)

Summation

Discrete-Time Signal uk ¼ axk þ byk Given uk, k ¼ 0, 1, 2, 3, . . . , where uk ¼ 0 for k < 0 8 0, k ¼ 0, 1, 2, . . . , n 1 > > > > > < u0 , k ¼ n ukn ¼ u1 , k ¼ n þ 1 > > > > u , k ¼nþ2 > : 2 etc: k P ui yk ¼ i¼0

Multiplication by geometric sequence

yk ¼ akuk

Multiplication by k property

yk ¼ kuk

Initial value property

fk ¼

1 P

Final value property

fk ¼

U(z) ¼ aX(z) þ bY(z) z{ukn} ¼ znU(z)

z U(z) z1 z Y(z) ¼ U a Y(z) ¼

Y(z) ¼ z k ¼ 0, 1, 2, 3, . . .

f0 ¼ lim F(z)

fi dki ,

k ¼ 0, 1, 2, 3, . . .

f1 ¼ lim (z 1)F(z)

i¼0

jzj!1

jzj!1

zn ^ F(z) 1 n1 X ^ ¼ fk zk where F(z) F(z) ¼

Periodic signal

d U(z) dz

fi dki ,

i¼0 1 P

Property

fk ¼ fkþn ,

k ¼ 0, 1, 2, 3, . . .

zn

k¼0

223

Linear Systems Analysis uk

uk−1 z{uk–1} = z–1U(z)

z{uk} = U(z) ……. −2 −1 0 (a)

1

2

3

4

……. k

5 …….

−2 −1 0 (b)

uk−2

1

2

3

4

5 …….

k

uk−n z{uk−2} = z−2U(z) z{uk−n} = z−nU(z) …

−2 −1 0 (c)

FIGURE 4.40

1

2

3

4

5

6

7

−2 −1 0 (d)

1

2

3

4

5 …. n n+1 n+2 n+3 n+4

k

Illustration of the delay property in Table 4.5.

uk

FIGURE 4.41

k

z−1

xk

z−1

yk

Unit-delay operators in series.

yk ¼ xk1 ¼ uk2

8 0, > > > < u0 , ¼ > u , > > : 1 ...

k ¼ 0, 1 k¼2 k¼3 ...

(4:379)

In a later section when we introduce simulation diagrams for discrete-time systems, it will be apparent that the unit delay is the counterpart to a continuous-time integrator in the simulation diagram of continuous-time systems.

Several examples illustrating the properties in Table 4.5. Example 4.18 A unit alternating sequence (a ¼ 1 in Figure 4.36) is the input to a summer as shown in Figure 4.42. (a) Find the output yk, k ¼ 0, 1, 2, 3,. . . . (b) Find Y(z).

uk = (−1)k, k = 0, 1, 2, 3, ...

FIGURE 4.42

k

∑

A summer with a unit alternating sequence input.

yk = ∑ ui i=0

Simulation of Dynamic Systems with MATLAB® and Simulink®

224

(a) Referring to the graphs of the geometric sequence in Figure 4.36 for the case when a ¼ 1, it is apparent that the output of the summer is 1, k ¼ 0, 2, 4, . . . yk ¼ (4:380) 0, k ¼ 1, 3, 5, . . . (b) From the deﬁnition of the z-transform as an inﬁnite series in z1, Y(z) ¼ 1 þ 1 z2 þ 1 z4 þ 1 z6 þ 2

2 2

(4:381)

2 3

¼ 1 þ (z ) þ (z ) þ (z ) þ 1 ¼ 1 (z2 ) z2 ¼ 2 z 1

(4:382) (4:383) (4:384)

Alternatively, from the summation property in Table 4.5 and knowing z{ak} ¼ z=(z a), z z z z2 Y(z) ¼ U(z) ¼ ¼ 2 z 1 z1 z1 zþ1

(4:385)

Example 4.19 Find the z-transform of the discrete-time signal resulting from sampling the output of a half-wave rectiﬁer whose input is the continuous-time function sin v0t. Sampling starts at t ¼ 0 at a frequency of 8v0, where v0 ¼ 2p rad=s. The output of the half-wave rectiﬁer is ( sin v0 t, kp=v0 t (k þ 1)p=v0 v(t) ¼ 0, (k þ 1)p=v0 t (k þ 2)p=v0

for k ¼ 0, 2, 4, . . . for k ¼ 1, 3, 5, . . .

(4:386)

Both v(t) and vk ¼ v(kT ), k ¼ 0, 1, 2, 3, . . . are shown in Figure 4.43. The discrete-time signal vk is periodic, and the period is n ¼ 8, that is, vkþ8 ¼ vk, k ¼ 0, 1, 2, 3,. . . .

v(t) vk

v(t) = sin 2πt, k/2 ≤ t ≤ (k + 1)/2, n = 0, 2, 4, ... elsewhere

0, 1 0.8

T = 1/8 s

0.6 0.4 0.2 0 0 0

FIGURE 4.43

1

2 0.25

3

4 0.5

5

6 0.75

7

8 1

9 10 11 12 13 14 15 16 17 1.25 t (s)

1.5

1.75

k

2

Sampling the continuous-time output of a half-wave rectiﬁer with input sin 2pt.

225

Linear Systems Analysis The z-transform of the ﬁrst cycle of vk is ^ ¼ V(z)

7 X

vk zk ¼

k¼0

¼ 0 þ sin

3 X

sin (2pkT)zk þ

k¼0

p 4

7 X

0 zk ¼

p

z2 þ sin

2 pﬃﬃﬃ pﬃﬃﬃ 2 1 2 3 z þ z2 þ z ¼0þ 2 2

sin

K¼0

k¼4

z1 þ sin

3 X

3p 3 z 4

kp k z 4

(4:387)

(4:388)

(4:389)

Applying the property in Table 4.5 for periodic signals gives V(z) ¼

pﬃﬃﬃ pﬃﬃﬃ 2 1 2 3 z þ z2 þ z 2 2 pﬃﬃﬃ pﬃﬃﬃ z5 2 2 2 ¼ 8 z þzþ z 1 2 2

zn ^ z8 V(z) ¼ 8 n z 1 z 1

(4:390) (4:391)

pﬃﬃﬃ pﬃﬃﬃ Long division of z8 1 into ( 2=2)z7 þ z6 þ ( 2=2)z5 will generate a power series in z1 with coefﬁcients corresponding to the sampled values shown in Figure 4.43.

4.6.2 INVERSE z-TRANSFORM The analysis of discrete-time system dynamics requires the capability of inverting a z-transform F(z) to ﬁnd the discrete-time signal fk,, k ¼ 0, 1, 2, 3,. . . . It is similar to the way in which the inverse Laplace transform was obtained, that is, by exploiting the basic properties of the z-transform, referring to tables of z-transform pairs, partial fraction expansion, and using one additional method not applicable to continuous-time systems, namely, long division. A simple example of ﬁnding the inverse z-transform based on some of the methods outlined above follows. Example 4.20 Find the inverse z-transform of F(z) ¼

zþ1 z(z þ 2)

(4:392)

(a) Using properties of the z-transform along with the lookup table of z-transform pairs. (b) By the method of long division. (a)

zþ1 zþ1 ¼ z1 z(z þ 2) zþ2 z z þ z2 ¼ z1 zþ2 zþ2

F(z) ¼

(4:393) (4:394)

From Table 4.4, the term (z=(z þ 2)) is the z-transform of the discrete-time signal gk ¼ (2)k, k ¼ 0, 1, 2, 3,. . . . From the delay property in Table 4.5, fk is the sum of gk delayed one unit of time and gk delayed two units of discrete-time. Denoting the delayed signals by ~ gk,1 and ~ gk,2 , we can write fk ¼ ~gk,1 þ ~gk,2

k ¼ 0, 1, 2, 3, . . .

(4:395)

Simulation of Dynamic Systems with MATLAB® and Simulink®

226 where

~gk,1 ¼ ~gk,2 ¼

0, (2)k1 ,

k¼0 k ¼ 1, 2, 3, . . .

(4:396)

0, (2)k2 ,

k ¼ 0, 1 k ¼ 2, 3, 4, . . .

(4:397)

Combining Equations 4.395 and 4.396, the inverse z-transform is 8 k¼0 < 0, fk ¼ 1, k¼1 : (2)k1 þ (2)k2 , k ¼ 2, 3, 4, . . .

(4:398)

Simplifying the expression in Equation 4.398 when k ¼ 2, 3, 4, . . . gives 8 < 0, fk ¼ 1, : ( 2)k2 ,

k¼0 k¼1 k ¼ 2, 3, 4, . . .

(4:399)

(b) Long division of the denominator in Equation 4.392 into the numerator results in an inﬁnite series. The ﬁrst few terms are zþ1 ¼ z1 z2 þ 2z3 4z4 þ 8z5 z2 þ 2z

(4:400)

Looking at Equation 4.400, it is possible to recognize a pattern in the coefﬁcients starting with the z2 term. This pattern results in the expression in the third line of the general solution in Equation 4.399. The reader should verify that Equations 4.399 and 4.400 generate identical values for fk, k ¼ 0, 1, 2, 3, . . . as they must.

4.6.3 PARTIAL FRACTION EXPANSION Causal signals, that is, discrete-time signals fk that are identically zero for negative values of discrete-time k, possess z-transforms of the form F(z) ¼

N(z) b0 zn þ b1 zn1 þ þ bm znm ¼ n (n m) D(z) z þ a1 zn1 þ þ an1 z þ an

(4:401)

The partial fraction expansion of F(z) depends on the nature of the roots of D(z). Equation 4.401 is rewritten with the denominator D(z) in factored form, F(z) ¼

b0 zn þ b1 zn1 þ þ bm znm (n m) (z p1 )(z p2 ) (z pn )

(4:402)

where p1, p2, . . . , pn are the poles of F(z). Three cases are considered for ﬁnding the inverse z-transform of F(z) by partial fractions. Case I: Poles of F(z) are real and distinct When the poles p1, p2, . . . , pn are real and unequal, F(z) in partial fraction form is F(z) ¼ c0 þ c1

z z z þ c2 þ þ cn z p1 z p2 z pn

(4:403)

227

Linear Systems Analysis

The constant c0 is easily determined by substituting z ¼ 0 in Equations 4.402 and 4.403. ( c0 ¼ F(z)jz¼0 ¼ F(0) ¼

0, bn , (p1 )(p2 ) (pn )

n>m n¼m

(4:404)

The remaining coefﬁcients c1, c2, . . . , cn are obtained from (Cadzow 1973) ci ¼

z pi F(z)

, z z¼pi

i ¼ 1, 2, 3, . . . , n

(4:405)

From the z-transform pairs dk , 1, ak , z=(z a) and the linearity property of the z-transform, the inverse z-transform of F(z) in Equation 4.403 is fk ¼ c0 dk þ c1 pk1 þ c2 pk2 þ þ cn pkn ,

k ¼ 0, 1, 2, 3, . . .

(4:406)

Example 4.21 Find the discrete-time signal with z-transform given by F(z) ¼

z2 þ z þ 1 z2 4

(4:407)

Factoring the denominator leads to the partial fraction expansion z2 þ z þ 1 z2 þ z þ 1 z z þ c ¼ ¼ c þ c 0 1 2 z2 4 (z 2)(z þ 2) z2 zþ2

(4:408)

where

z2 þ z þ 1

1 :¼ (z 2)(z þ 2) z¼0 4

z2 z2 þ z þ 1

7 c1 ¼ F(z)

¼

¼8 z z(z þ 2) z¼2 z¼2

2

zþ2 z þ z þ 1

3 ¼ ¼ c2 ¼ F(z)

z z(z 2) z¼2 8 z¼2 1 7 z 3 z þ ) F(z) ¼ þ 4 8 z2 8 zþ2 c0 ¼ F(0) ¼

1 7 3 ) fk ¼ dk þ (2)k þ (2)k , 4 8 8

k ¼ 0, 1, 2, 3, . . .

(4:409) (4:410) (4:411) (4:412) (4:413)

It is left as an exercise to show that the ﬁrst several values of fk, k ¼ 0, 1, 2, 3, . . . are in agreement with the values obtained by long division of z2 4 into z2 þ z þ 1. If the denominator D(z) in Equation 4.401 has a factor zp, the inverse z-transform of zp F(z) should be determined ﬁrst, followed by use of the delay property to obtain the ﬁnal result. To illustrate, suppose F(z) is given by F(z) ¼

z2 þ z þ 1 z3 (z2 4)

(4:414)

Simulation of Dynamic Systems with MATLAB® and Simulink®

228 We start by inverting z3 F(z),

z3 F(z) ¼

z2 þ z þ 1 z2 4

(4:415)

From Example 4.21, we know z

1

z2 þ z þ 1 z2 4

1 7 3 ¼ dk þ (2)k þ (2)k 4 8 8

(4:416)

Hence, the inverse z-transform of F(z) in Equation 4.414 is the discrete-time signal in Equation 4.416 delayed three units of discrete-time, that is,

fk ¼

8 < 0,

k ¼ 0, 1, 2,

1 7 3 : dk3 þ (2)k3 þ (2)k3 , 4 8 8

k ¼ 3, 4, 5, . . .

(4:417)

Case II: Repeated real poles of F(z) Suppose the pole p1 has multiplicity m1. The partial fraction expansion contains the m1 terms c1

z z p1

þ þ cm1 1

z z p1

m1 1

þ cm1

z z p1

m1 (4:418)

associated with the factor (z p1)m1 in the denominator of F(z). Simultaneous equations are developed for the constants c1 , c2 , . . . , cm1 1 . An illustrative example follows. Example 4.22 Find fk, k ¼ 0, 1, 2, 3, . . . when F(z) ¼

2z2 þ z (z 1)3 (z þ 1)

(4:419)

The partial fraction expansion of F(z) is F(z) ¼

z z 2 z 3 2z2 þ z z c þ c þ c þ c ¼ c 0 1 2 3 4 z1 z1 z1 zþ1 (z 1)3 (z þ 1)

(4:420)

The constants c0 and c4 are obtained as they would in Case I, that is, c0 ¼ F(0) ¼ 0

zþ1 2z þ 1

1 ¼ ¼ F(z)

c4 ¼ z (z 1)3 z¼1 8 z¼1

(4:421) (4:422)

The coefﬁcient of the highest order term is evaluated directly from c3 ¼

z1 3

F(z)

z

¼ z¼1

2z þ 1

3 ¼ z2 (z þ 1) z¼1 2

(4:423)

229

Linear Systems Analysis Substituting the values for c0, c3, and c4 into Equation 4.420 yields F(z) ¼

z z 2 3 z 3 1 z 2z2 þ z þ þ ¼ c þ c 1 2 z1 z1 2 z1 8 zþ1 (z 1)3 (z þ 1)

(4:424)

Combining the terms on the right-hand side of Equation 4.424 into a single term with common denominator (z 1)3(z þ 1) and then equating the numerators give 3 1 2z2 þ z ¼ c1 z(z 1)2 (z þ 1) þ c2 z2 (z 1)(z þ 1) þ z3 (z þ 1) þ z(z 1)3 2 8

(4:425)

Expanding the right-hand side of Equation 4.425 and equating coefﬁcients of like powers of z on both sides lead to 8 3 1 > > z4 : 0 ¼ c1 þ c2 þ þ > > 2 8 > > > > > 3 3 > 3 > < z : 0 ¼ c1 þ 2 8 > 3 > > z2 : 2 ¼ c1 c2 þ > > > 8 > > > > 1 > : z: 1 ¼ c1 8

(4:426)

Selecting two of the above equations for simultaneous solution results in c1 ¼ 9=8 and c2 ¼ 11=4. Substituting the known values for c1 and c2 in Equation 4.424 gives F(z) ¼

9 z 11 z 2 3 z 3 1 z þ þ 8 z1 4 z1 2 z1 8 zþ1

(4:427)

Inverting F(z) is accomplished using Table 4.6 (Cadzow 1973) fk ¼

9 11 3 (k þ 1)(k þ 2) 1 (k þ 1) þ þ (1)k , 8 4 2 2 8

k ¼ 0, 1, 2, 3, . . .

TABLE 4.6 Table for Inverting z-Transforms of the Form [z=(z a)]n, n ¼ 1, 2, 3, . . . F(z) z (z a) 2 z (z a) 3 z (z a) 4 z (z a) 5 z (z a)

fk, k ¼ 0, 1, 2, 3, . . . k

a

(k þ 1)ak (k þ 1)(k þ 2) k a 2 (k þ 1)(k þ 2)(k þ 3) k a 3 (k þ 1)(k þ 2)(k þ 3)(k þ 4) k a 4

(4:428)

Simulation of Dynamic Systems with MATLAB® and Simulink®

230

Evaluating the ﬁrst several values of fk gives f0 ¼

9 11 3 1 þ þ ¼ 0, 8 4 2 8

f3 ¼

9 44 60 1 9 55 90 1 9 66 126 1 þ ¼ 5, f4 ¼ þ þ ¼ 10, f5 ¼ þ ¼ 16 8 4 4 8 8 4 4 8 8 4 4 8

f1 ¼

9 22 18 1 þ ¼ 0, 8 4 4 8

f2 ¼

9 33 36 1 þ þ ¼2 8 4 4 8

Checking the above by long division conﬁrms the numerical values above. 2z2 þ 5z3 þ 10z4 þ 16z5 z4 2z3 þ 0z2 þ 2z 1j2z2 þ z þ 4z1

2z2

5z þ 0

4z1

þ 2z2

5z 10

þ 0z1

þ 10z2

5z3

10

4z1

8z2

þ 5z3

10

20z1 0z1

þ 20z3 10z4

16z1 8z2

15z3 þ 10z4

2z2 4z þ 0

Case III: Complex poles of F(z) When F(z) possesses complex poles, the partial fraction expansion is dictated by the last two z-transform pairs in Table 4.4. An example serves to illustrate the procedure. F(z) ¼

z2 þ z (z 1)(z2 3z þ 9)

(4:429)

The ﬁrst step is to decompose F(z) in two parts, z Az2 þ Bz þ C (z2 3z þ 9) z1

(4:430)

z1 z2 þ z z þ 1

2

¼ ¼ z (z 1)(z2 3z þ 9) z¼1 z2 3z þ 9 z¼1 7

(4:431)

F(z) ¼ The constant C is evaluated from C¼

Constants A and B are obtained by combining the terms in Equation 4.430 into a single term with common denominator (z 1) (z2 3z þ 9) and then equating the numerator to z2 þ z the numerator in Equation 4.429. The resulting expression for F(z) is (2=7)z2 þ (11=7)z 2 z þ z2 3z þ 9 7 z1 2 1 2z 11z 2 z ¼ þ 2 7 z 3z þ 9 7 z1

F(z) ¼

(4:432) (4:433)

The quadratic factor in the denominator of Equation 4.433 implies that inverting F(z) will require a linear combination of eakT sin kvT and eakT cos kvT (see Table 4.4). Comparing the standard form of the denominator in the last row of Table 4.4 and the quadratic denominator in Equation 4.433, z2 2(eaT cos vT)z þ e2aT ¼ z2 3z þ 9

(4:434)

231

Linear Systems Analysis Equating like powers of z and solving for eaT and vT, e2aT ¼ 9 ) eaT ¼ 3

(4:435)

2(eaT cos vT) ¼ 3 ) cos (vT) ¼

1 p ) vT ¼ 2 3

(4:436)

The quadratic numerator in F(z) in Equation 4.433 must be expressed as a linear combination of the standard numerator forms in the last two rows of Table 4.4, that is, 2z2 11z ¼ c1 (eaT sin vT)z þ c2 [z2 (eaT cos vT)z] Solving for c1 and c2 in Equation 4.437 leads to c1 ¼ 16 form where Table 4.4 can be used to ﬁnd fk. F(z) ¼

(4:437)

pﬃﬃﬃﬃﬃﬃﬃﬃ 3=9, c2 ¼ 2: F(z) is now written in a

1 c1 (eaT sin vT)z c2 [z2 (eaT cos vT)z] 2 z þ þ 2 aT 2aT 2 aT 2aT cos vT)z þ e cos vT)z þ e 7 z 2(e z 2(e 7 z1

1 2 f (k) [c1 eakT sin kvT þ c2 eaT cos kvT] þ , k ¼ 0, 1, 2, 3, . . . 7 7 pﬃﬃﬃ 1 16 3 k kp kp 2 (3) sin þ 2(3)k cos þ , k ¼ 0, 1, 2, 3, . . . ¼ 9 7 3 3 7

(4:438)

(4:439)

(4:440)

By observation of F(z) in Equation 4.429, it follows that f0 ¼ 0 and f1 ¼ 1. The reader can readily verify these values from Equation 4.440 with k ¼ 0, 1. An alternative approach when F(z) contains complex poles is to proceed the same way as in Case 1 where all the poles were real and distinct. The key is appropriate conversion between rectangular and polar representations of the complex roots of F(z) and the complex coefﬁcients arising from partial fraction expansion. Suppose F(z) is of the form F(z) ¼

N(z) N(z) ¼ D(z) (z p1 )(z p2 )

(4:441)

where the complex poles expressed in polar form are p1 ¼ Re ju, p2 ¼ Reju. Expanding F(z) as we did in Case 1 (real and distinct poles), F(z) ¼ A1

z z p1

þ A2

z z p2

(4:442)

where A1 ¼

(z p1 ) N(z) N(p1 ) ¼ z (z p1 )(z p2 ) z¼p1 p1 (p1 p2 )

(4:443)

and A2 is the conjugate of A1. In polar form, A1 ¼ Ce jf, A2 ¼ Cejf Equation 4.442 becomes F(z) ¼ Ce jf

z z jf þ Ce z Re ju z Reju

(4:444)

Simulation of Dynamic Systems with MATLAB® and Simulink®

232

The inverse z-transform of F(z) in Equation 4.444 is fk ¼ Ce jf (R e ju )k þ Cejf (Reju )k

(4:445)

¼ CRk [e jf (e ju )k þ ejf (eju )k ]

(4:446)

¼ 2CRk

e j(kuþf) þ ej(kuþf) 2

¼ 2CRk cos (ku þ f),

(4:447)

k ¼ 0, 1, 2, . . .

(4:448)

Thus, F(z) in Equation 4.441 can be inverted simply by ﬁnding polar coordinates of the poles p1, p2, and complex coefﬁcients A1, A2.

Example 4.23 Find the inverse z-transform of F(z) ¼ z2 z z2 0:6z þ 0:25: Factoring the denominator to ﬁnd the poles p1 and p2, F(z) ¼

z2 z z2 z ¼ , z2 0:6z þ 0:25 (z p1 )(z p2 )

p1,2 ¼ 0:3 j0:4

(4:449)

Converting the complex poles to polar form gives p1,2 ¼ 0:3 j0:4 ¼ Re ju

(4:450)

where R ¼ [(0:3)2 þ (0:4)2 ]1=2 ¼ 0:5 4 ¼ 0:9273 rad u ¼ tan1 3 From Equation 4.443, the constant A1 in the partial fraction expansion of F(z) is A1 ¼

N(p1 ) p21 p1 p1 1 ¼ ¼ p1 (p1 p2 ) p1 (p1 p2 ) p1 p2

¼

0:3 þ j0:4 1 0:3 þ j0:4 (0:3 j0:4)

¼

1 7 þj 2 8

(4:451)

Converting A1 polar form,

pﬃﬃﬃﬃﬃﬃ

1 65 7

C ¼ jA1 j ¼

þ j

¼ 8 2 8 1 7 7 f ¼ Arg(A1 ) ¼ Arg þj ¼ tan1 ¼ 1:0517 rad 2 8 4

(4:452) (4:453)

233

Linear Systems Analysis From Equation 4.448, the discrete-time signal fk is pﬃﬃﬃﬃﬃﬃ 65 (0:5)k cos (0:9273k þ 1:0517), 8

k ¼ 0, 1, 2, . . .

(4:454)

¼ 2:0156(0:5)k cos (0:9273k þ 1:0517),

k ¼ 0, 1, 2, . . .

(4:455)

fk ¼ 2

The reader should check that the ﬁrst several values of fk obtained from Equation 4.455 agree with the numerical values obtained by long division of the denominator z2 0.6z þ 0.25 of F(z) into the numerator z2 z.

EXERCISES 4.36 Find the z-transforms of the following causal sequences fk, k ¼ 0, 1, 2, 3,. . . . Use long division to check the ﬁrst two nonzero values of fk. (b) k2(1)k (c) dk þ (0.5)k (d) sin kp (e) (1)k cos(2kp=3) (a) kak 0, k ¼ 0, 2, 4, 6, . . . 0, k ¼ 0, 1, 2, 3, . . . (h) fk ¼ (f) (k þ 1)dk1 (g) fk ¼ 1, k ¼ 0, 1, 3, 5, . . . k, k ¼ 4, 5, 6, . . . 8 1, k¼0 > > < k ¼ 0, 1, 3, 5, 7, . . . (i) fk ¼ 0, > 1 > : (2)k=2 , k ¼ 2, 4, 6, . . . 2 4.37 Find the inverse z-transform of the expressions below. Use long division to check the ﬁrst two nonzero values of fk. (a)

zþa zþb

(b)

z2 þ 1 1)

(e)

z3 þ z (z2 1)2

(f)

z2 þ 1 z3 þ z2

(g)

(i)

z4 z4 1

(j)

z2 þ 1 z2 þ 2

(k)

z2 (z2

(c)

z2 (z 3)3 z2

zþ2 zþ4

(d)

(h)

z2 þ 1 (z þ 1)2 z2

z(z 2) z þ (3=4)

zþ1 z(z2 þ z þ 2)

4.38 Find the z-transforms of the discrete-time signals resulting from uniform sampling of the continuous-time functions below. All functions are zero for t < 0. (a) 1 þ 2t (b) te2t (c) eat ebt (d) t2 sin 2t (e) e2t cos t (f) 1=2t 4.39 (a) Find the z-transforms U(z) and F(z) of the discrete-time signals pictured in Figure E4.39. uk 1

fk …….

0 1 2 3 4 5 6 …….

1 k

…….

0 −1

1 2 3 4 5 6 7

k

…….

FIGURE E4.39

(b) Express the signal uk in Figure E4.39 as uk ¼ a þ b(1)k, k ¼ 0, 1, 2, 3, . . . and determine a and b. Use the linearity property and the z-transforms of the unit step and unit alternating sequence, that is, z{ûk} ¼ z=(z 1) and z{(1)k} ¼ z=(z þ 1), to ﬁnd U(z).

Simulation of Dynamic Systems with MATLAB® and Simulink®

234

4.40 Graph the discrete-time signals fk, k ¼ 0, 1, 2, 3, . . . below and ﬁnd F(z). 1 k k k P P P P (a) fk ¼ dki (b) fk ¼ 1 (c) fk ¼ i (d) fk ¼ (1)i i¼0

i¼0

i¼0

i¼0

4.41 Use the two methods discussed for inverting z-transforms with complex poles to ﬁnd the discrete-time signal fk, k ¼ 0, 1, 2, . . . with z-transform F(z) ¼

3z2 þ z (z 1)(z2 þ 2z þ 2)

4.42 Write a MATLAB function to invert F(z) ¼

b3 z3 þ b2 z2 þ b1 z þ b0 (z p1 )(z2 þ a1 z þ a0 )

where the quadratic term z2 þ a1z þ a0 ¼ (z p2)(z p3), p2, p3 ¼ a jb. The inverse z-transform is given by fk ¼ F0dk þ A1(p1)k þ 2CRk cos(ku þ f),

k ¼ 0, 1, 2, 3,. . . .

The function input parameters are p1, a1, a0, b3, b2, b1, and b0 and the outputs are A1, C, R, u, f, and F0. The function declaration line is [A1, C, R, theta, phi, F0] ¼ invert(p1,a1,a0,b3,b2,b1,b0) Check the function by running it for (i) F(z) ¼

3z2 þ z (z 1)(z2 þ 2z þ 2)

(ii) F(z) ¼

2z3 þ z2 þ 4z þ 5 (z 3)(z2 þ 2z þ 4)

and comparing the ﬁrst several values of fk , k ¼ 0, 1, 2, . . . with the values obtained by long division of the cubic denominator into the quadratic numerator.

4.7 z-DOMAIN TRANSFER FUNCTION We have seen how the transfer function of a linear continuous-time system is used to ﬁnd the system’s response to elementary inputs. Stability and frequency response characteristics of the system can be inferred from the transfer function as well. A discrete-time system transfer function does the same for linear discrete-time systems. We begin with the nth-order, linear, constant coefﬁcient difference equation yk þ a1 yk1 þ þ an ykn ¼ b0 uk1 þ þ bm ukm ,

nm

(4:456)

z-Transforming both sides and applying the linearity property gives z{yk } þ a1 z{yk1 } þ þ an z{ykn } ¼ b0 z{uk } þ b1 z{uk1 } þ þ bm z{ukm }

(4:457)

Assuming the input is applied at k ¼ 0 and the initial values y1, y2, . . . , yn are zero, we can use the delay property in Table 4.5 in the previous section to arrive at Y(z) þ a1 z1 Y(z) þ þ an zn Y(z) ¼ b0 U(z) þ b1 z1 U(z) þ þ bm zm U(z)

(4:458)

235

Linear Systems Analysis

The z-domain transfer function is deﬁned as the ratio of Y(z) to U(z). Thus, H(z) ¼ ¼

Y(z) b0 þ b1 z1 þ þ bmzm ¼ , U(z) 1 þ a1 z1 þ þ an1 znþ1 þ an zn b0 zn þ b1 zn1 þ þ bm znm , zn þ a1 zn1 þ þ an1 z þ an

nm

nm

(4:459)

(4:460)

Depending on the application, one of the two forms given in Equations 4.459 and 4.460 for the transfer function, also called the pulse transfer function, is usually preferable. A good example to illustrate how to ﬁnd the z-domain transfer function of a discrete-time system is an Euler integrator. Recall from Section 3.3 that the difference equation for approximating a continuous-time integrator using explicit Euler integration is xA (n þ 1) ¼ xA (n) þ Tu(n), n ¼ 0, 1, 2, . . .

(4:461)

where u(n) and xA(n) are the discrete-time input and outputs and xA(0) ¼ 0. Employing the notation of this chapter, the difference equation is written xk xk1 ¼ Tuk1 ,

k ¼ 1, 2, 3, . . .

(4:462)

where uk ¼ u(kT ), k ¼ 0, 1, 2, . . . are sampled values of the input signal and xk, k ¼ 0, 1, 2, . . . is the discrete-time output intended to approximate the continuous-time integrator output x(t) at the end of each integration step. The initial condition is x0 ¼ x(0) ¼ 0 and the ﬁrst computed value is x1. z-transforming Equation 4.462, z{xk } z{xk1 } ¼ Tz{uk1 }

(4:463)

Since xk and uk are both zero for k < 0, the delay property in Table 4.5 applies. X(z) z1 X(z) ¼ Tz1 U(z) H(z) ¼

X(z) Tz1 T ¼ ¼ 1 U(z) 1 z z1

(4:464) (4:465)

Example 4.24 The input to a continuous-time integrator is u(t) ¼ sin pt. (a) Approximate the output x(t) using Euler integration with step size T ¼ 0.1 s. (b) Find the exact solution x(t) and plot on the same graph with xk. (a) Solving for X(z) in Equation 4.465 and looking up U(z) ¼ z{uk} ¼ z{sin kvT} from Table 4.4 give

T ( sin vT)z

z 1 z2 2( cos vT)z þ 1 T¼0:1,v¼p 0:1 ( sin 0:1p)z ¼ z 1 z2 2( cos 0:1p)z þ 1

X(z) ¼ H(z)U(z) ¼

(4:466) (4:467)

Simulation of Dynamic Systems with MATLAB® and Simulink®

236

Explicit Euler integration of u(t) = sin πt x(t), 0 ≤ t ≤ 2 xk, k = 0, 1, 2, ... , 20

0.6 0.5

T = 0.1 s 0.4 x(t) = (1/π)(1–cos πt)

0.3 0.2 0.1 0

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 k 0

FIGURE 4.44

0.2

0.4

0.6

0.8

1 t (s)

1.2

1.4

1.6

1.8

2

Continuous- and discrete-time (explicit Euler) integrator outputs.

Using the method of partial fraction expansion presented in Section 4.4.6, the inverse z-transform of X(z) is (details are left as an exercise) xk ¼ 0:05

sin 0:1p (1 cos 0:1kp) sin 0:1kp , 1 cos 0:1p

k ¼ 0, 1, 2, 3, . . .

(4:468)

(b) The continuous-time integrator output is obtained by integration of the input u(t), ðt ðt 1 x(t) ¼ u(l)dl ¼ sin pl dl ¼ (1 cos pt) p 0

(4:469)

0

The discrete-time signal xk and the continuous-time integrator output x(t) are plotted in Figure 4.44 for one cycle of the input.

4.7.1 NONZERO INITIAL CONDITIONS Using the z-transform to solve a difference equation with nonzero initial conditions requires additional terms to account for the nonzero values. Suppose yk is a discrete-time signal for which y1 6¼ 0 like the one shown in Figure 4.45. Also shown is yk1. yk

yk−1 y0

y0 y−1

y−1 …….

……. −2 −1

FIGURE 4.45

0

1

2

3

4

5

k

−2 −1

Discrete-time signals yk and yk1(y1 6¼ 0).

0

1

2

3

4

5

6

k

237

Linear Systems Analysis

z{yk1} is obtained from the basic deﬁnition of the z-transform, that is, z{yk1 } ¼

1 X

yk1 zk ¼ y1 þ y0 z1 þ y1 z2 þ y2 z3 þ

(4:470)

k¼0

¼ y1 þ z1 [y0 þ y1 z1 þ y2 z2 þ ]

(4:471)

¼ y1 þ z1 Y(z)

(4:472)

Consider the ﬁrst-order difference equation yk ¼ buk þ ayk1 ,

k ¼ 0, 1, 2, 3, . . .

(4:473)

with input uk applied at k ¼ 0 and nonzero initial condition y1. It will be shown later that Equation 4.473 is the difference equation of a low-pass digital ﬁlter. z-transforming Equation 4.473 and using the result in Equation 4.472 give Y(z) ¼ bU(z) þ a[y1 þ z1 Y(z)] Multiplying Equation 4.474 by z and solving for Y(z) give bz z U(z) þ ay1 Y(z) ¼ za za

(4:474)

(4:475)

The ﬁrst term on the right-hand side of Equation 4.475 is H(z) U(z). The additional term results from the nonzero initial condition. A similar procedure is employed for higher order difference equations with several nonzero initial conditions. Example 4.25 For the discrete-time system described by Equation 4.473, (a) Find the response to a unit step when the initial condition y1 6¼ 0. (b) Find the response to a unit alternating input when y1 6¼ 0. (c) For a ¼ 0.9 and b ¼ 0.1, graph the responses in parts (a) and (b) when y1 ¼ 2. (a) uk ¼ 1, k ¼ 0, 1, 2, 3, . . . , and U(z) ¼ z=(z 1). z bz z þ ay1 za z1 za z b h z z i ¼ a þ ay1 1a z1 za za

Y(z) ¼

yk ¼

b (1 akþ1 ) þ y1 akþ1 , 1a

k ¼ 0, 1, 2, . . .

(4:476) (4:477) (4:478)

(b) uk ¼ (1)k, k ¼ 0, 1, 2, 3, . . . , and U(z) ¼ z=(z þ 1). z bz z Y(z) ¼ þ ay1 za zþ1 za z b z z þa þ ay1 ¼ 1þa zþ1 za za

(4:479) (4:480)

Simulation of Dynamic Systems with MATLAB® and Simulink®

238

Unit step and unit alternating responses of yk = βuk + αyk−1 with y−1 = 2 2 1.8

a = 0.9, b = 1 – a = 0.1

1.6 1.4

yk , for uk = 1, k = 0, 1, 2, ... and y−1 = 2

1.2 1 0.8 yk, for uk = (−1)k, k = 0, 1, 2, ... and y−1 = 2

0.6 0.4 0.2 0 0

10

20

30

40

50

k

FIGURE 4.46

Responses of discrete-time system with nonzero initial condition.

yk ¼

b [( 1)k þ akþ1 ] þ y1akþ1 , 1þa

k ¼ 0, 1, 2, . . .

(4:481)

Note that the solutions in Equations 4.478 and 4.481 reduce to the given initial condition y1 for k ¼ 1. (c) Graphs of yk, k ¼ 1, 0, 1, 2, . . . in Equations 4.478 and 4.481 are shown in Figure 4.46. Note how the system passes the low-frequency unit step and effectively blocks the higher frequency unit alternating sequence once the transient component ak þ 1 dies out. Setting b ¼ 1 a, the normalized unit step and unit alternating steady-state responses are (yk )ss ¼ 1 (yk )ss ¼

for uk ¼ 1, k ¼ 0, 1, 2, 3, . . .

1a 1 0:9 1 (1)k ¼ (1)k ¼ (1)k for uk ¼ (1)k , k ¼ 0, 1, 2, 3, . . . 1þa 1 0:9 19

(4:482) (4:483)

4.7.2 APPROXIMATING CONTINUOUS-TIME SYSTEM TRANSFER FUNCTIONS It is common practice to start with a block diagram representation of a continuous-time system and transform it to a block diagram of a discrete-time system with comparable dynamics. The discretetime signals are intended to approximate the corresponding signals in the continuous-time system at discrete points in time. To illustrate, suppose we have a need to approximate the behavior of a second-order system H(s) ¼

Y(s) Kv2n ¼ 2 U(s) s þ 2zvn s þ v2n

(4:484)

A simulation diagram is shown in Figure 4.47. The continuous-time integrator blocks with transfer function H1(s) ¼ 1=s are replaced by discretetime (numerical) integrators with z-domain transfer functions H1(z), and the signals become discrete-time in nature (see Figure 4.48).

239

Linear Systems Analysis u

.. y

Kωn2

. y x2

HI(s)= 1s

y x1

HI(s) = 1s

−2ζωn

−ωn2

FIGURE 4.47

Simulation diagram for second-order system in Equation 4.484.

uk U(z)

.. yk

Kωn2

HI(z)

. yk x2,k

HI(z)

yk x1,k

Y(z)

−2ζωn

–ωn2

FIGURE 4.48

Discrete-time system with numerical integrator z-domain transfer functions.

Block diagram reduction or any other suitable method, for example, Mason’s Gain Formula (Dorf and Bishop 2005), using signal ﬂow graphs or solution of simultaneous equations results in the pulse transfer function of the discrete-time system given in Equation 4.485. H(z) ¼

Y(z) Kv2n HI2 (z) ¼ 2 2 U(z) vn HI (z) þ 2zvn H1 (z) þ 1

(4:485)

Choosing HI(z) as the z-domain transfer function for an explicit Euler integrator (see Equation 4.465) gives H(z) ¼

Y(z) Kv2n (T=(z 1))2 ¼ 2 U(z) vn (T=(z 1))2 þ 2zvn (T=(z 1)) þ 1

(4:486)

Simplifying the above expression yields H(z) ¼

Y(z) K(vn T)2 ¼ 2 U(z) z 2(1 zvn T)z þ 1 2zvn T þ (vn T)2

(4:487)

The difference equation for the discrete-time system is obtained directly from the z-domain transfer function expressed in terms of negative power of z. Y(z) K(vn T)2 z2 ¼ 1 U(z) 1 2(1 zvn T)z þ [1 2zvn T þ (vn T)2 ]z2

(4:488)

) Y(z) 2(1 zvn T)z1 Y(z) þ [1 2zvn T þ (vn T)2 ]z2 Y(z) ¼ K(vn T)2 z2 U(z)

(4:489)

) Yk2 (1 zvn T)yk 1 þ [1 2zvn T þ (vn T)2 ]yk2 ¼ K(vn T)2 uk2

(4:490)

Simulation of Dynamic Systems with MATLAB® and Simulink®

240

y0 = y(0) . y−1 = y(0)−Ty(0) −T k = −1

FIGURE 4.49

. y(0) 1 0 k=0

T k=1

t

Initial conditions y0, y1 obtained from y(0) and y_ (0).

Assuming the initial conditions are y1 and y0, the discrete-time variable k in Equation 4.490 assumes the values k ¼ 1, 2, 3,. . . . The ﬁrst computed value is y1. Initial conditions in the discrete-time system model are based on the initial conditions for the continuous-time system, y(0) and y_ (0). Figure 4.49 illustrates a derivation for y1 using backward extrapolation from the point y(0) along the line with slope y_ (0). Note the dependence on T in the result for y1. A similar approach is used to extrapolate y1 when the initial conditions are y0 and y1. The ﬁrst computed value is y2. What is the starting value for k in Equation 4.490? Example 4.26 Consider a second-order system with parameters K ¼ 1, vn ¼ 2 rad=s, and z ¼ 0.5. (a) Using explicit Euler integration with step size T ¼ 0.025 s, ﬁnd a difference equation that can be solved recursively to approximate the unit step response of the continuous-time system. (b) Find the analytical solution for the step response of the continuous-time system. (c) Plot the continuous- and discrete-time responses on the same graph.

(a) A recursive solution for yk, k ¼ 1, 2, 3, . . . is obtained from Equation 4.490 as follows. yk ¼ 2(1 zvn T)yk1 [1 2zvn T þ (vn T)2 ]yk2 þ K(vn T)2 uk2 , k ¼ 1, 2, 3, . . . ) yk ¼ 1:95yk1 0:9525yk2 þ 0:0025uk2 , k ¼ 1, 2, 3, . . .

(4:491) (4:492)

(b) The continuous-time step response can be obtained from the transfer function of the secondorder system by inverse Laplace transformation of Y(s) ¼ H(s)U(s). Alternatively, we can use Equation 2.23 or 2.24 for the step response of an underdamped second-order system. Adopting the latter approach, qﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ zvn y(t) ¼ K 1 ezvn t cos vd t þ sin vd t , t 0 vd ¼ 1 z2 vn vd pﬃﬃﬃﬃﬃ pﬃﬃﬃﬃﬃ 1 t cos 3t þ pﬃﬃﬃ sin 3t ) y(t) ¼ 1 e 3

(4:493) (4:494)

(c) Graphs of the solution to Equations 4.492 (every other point) and 4.494 are plotted in Figure 4.50, and selected values are presented in Table 4.7 for comparison (see MATLAB M-ﬁle ‘‘Chap4_Ex7_3.m’’). From the numerical values in Table 4.7, it appears that the discrete- and continuous-time transient responses are in agreement to one place after the decimal point. Greater accuracy requires we reduce the step size or consider a more accurate numerical integrator like the ones discussed in Chapter 3.

241

Linear Systems Analysis 1.2 1.1 1 0.9 0.8 0.7 0.6 0.5

Explicit Euler integration, T = 0.025 s

0.4 0.3 0.2

yk, k = 0, 2, 4, 6, ..., 200

0.1

y(t), 0 ≤ t ≤ 5

0

0

0.5

1

1.5

2

2.5 t (s)

3

3.5

4

4.5

5

FIGURE 4.50 Continuous- and discrete-time (Euler integration) second-order system step responses (K ¼ 1, vn ¼ 2 rad=s, z ¼ 0.5).

TABLE 4.7 Continuous- and Discrete-Time (Euler Integration) Responses yk

tk

y(tk)

0 01170 0.3643 0.6425 0.8845 1.0562 1.1506 1.1787 1.1605 1.1174 1.0677

0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.25 2.5

0 0.1044 0.3403 0.6105 0.8494 1.0234 1.1244 1.1616 1.1531 1.1184 1.0746

K 0 10 20 30 40 50 60 70 80 90 100

A general approach to deriving the z-domain transfer function H(z) for a discrete-time system intended to approximate a linear continuous-time system with transfer function H(s) is now given. Starting with a simulation diagram of the continuous-time system, each integrator block with transfer function HI(s) ¼ 1=s is replaced by a discrete-time transfer function block HI(z) corresponding to a speciﬁc numerical integrator. For example, replacing HI(s) by HI(z) for explicit Euler integration, 1 s

HI (z) ¼

T )s z1

1 z1 ¼ HI (z) T

(4:495)

Simulation of Dynamic Systems with MATLAB® and Simulink®

242

Hence, when explicit Euler integration is used to approximate the continuous-time integrators in an LTI system with transfer function H(s), the z-domain transfer function of the discrete-time system is obtained by replacing s in H(s) with (z 1)=T. That is, H(z) ¼ H(s)js

(4:496)

(z1)=T

For the continuous-time second-order system of Equation 4.484, H(z) ¼

Kv2n

2 2 s þ 2zvn s þ vn s

¼ (z1)=T

Kv2n ((z 1)=T) þ 2zvn ((z 1)=T) þ v2n 2

(4:497)

Simplifying Equation 4.497 results in Equation 4.487.

Example 4.27 Use trapezoidal integration in place of explicit Euler to approximate the unit step response of the second-order system in Example 4.26. Approximating a continuous-time integrator with input u(t) and output y(t) using trapezoidal integration results in (see Equation 3.40) T yk ¼ yk1 þ [uk1 þ uk ] 2

(4:498)

z-transforming Equation 4.498, Y(z) z1 Y(z) ¼

T 1 [z U(z) þ U(z)] 2

(4:499)

and solving for HI(z) give Y(z) T 1 þ z1 ¼ U(z) 2 1 z1 T zþ1 ¼ 2 z1

HI (z) ¼

(4:500)

(4:501)

The z-domain transfer function of the discrete-time system is therefore H(z) ¼ H(s)js

1 HI (z)

¼

Kv2n

s2 þ 2zvn s þ v2n s

(4:502) (2=T)((z1)=(zþ1))

Replacing s by (2=T)((z 1)=(z þ 1)) in Equation 4.502 and simplifying result in H(z) ¼

K(vn T)2 (z2 þ 2z þ 1) [4(1 þ zvn T) þ (vn T) ]z2 þ 2[(vn T)2 4]z þ 4(1 zvn T) þ (vn T)2 2

(4:503)

Multiplying the numerator and denominator of H(z) in Equation 4.503 by z2 leads to the difference equation of the discrete-time system, [4(1 þ zvn T) þ (vn T)2 ]yk þ 2[(vn T)2 4]yk1 þ [4(1 zvn T) þ (vn T)2 yk2 ¼ K(vn T)2 (uk þ 2uk1 þ uk2 )

(4:504)

243

Linear Systems Analysis Substituting the given values for K, z, and vn gives yk ¼

1 [7:995yk1 3:9025yk2 þ 0:0025(uk þ 2uk1 þ uk2 )], 4:1025

k ¼ 1, 2, 3, . . .

(4:505)

where uk ¼ 1, k ¼ 0, 1, 2, 3, . . . (zero otherwise) and y1 ¼ y0 ¼ 0. The unit step responses of the continuous- and discrete-time system approximation in Equation 4.505 are calculated in the M-ﬁle ‘‘Chap4_Ex7_4.m.’’ The results are graphed in Figure 4.51 and tabulated in Table 4.8. As expected, the trapezoidal integrator is more accurate than the explicit Euler.

1.2 1.1 1 0.9 0.8 0.7 0.6 0.5 0.4

Trapezoidal integration, T = 0.025 s

0.3 yk, k = 0, 2, 4, 6, ..., 200 y(t), 0 ≤ t ≤ 5

0.2 0.1 0

0

0.5

1

2

1.5

2.5 t (s)

3

4

3.5

4.5

5

FIGURE 4.51 Continuous- and discrete-time (trapezoidal integration) second-order system step responses (K ¼ 1, vn ¼ 2 rad=s, z ¼ 0.5).

TABLE 4.8 Continuous- and Discrete-Time (Trapezoidal Integration) Responses K 0 10 20 30 40 50 60 70 80 90 100

yk

tk

y(tk)

0 0.1090 0.3468 0.6169 0.8546 1.0268 1.1261 1.1620 1.1526 1.11175 1.0736

0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.25 2.5

0 0.1044 0.3403 0.6105 0.8494 1.0234 1.1244 1.1616 1.1531 1.1184 1.0746

Simulation of Dynamic Systems with MATLAB® and Simulink®

244

4.7.3 SIMULATION DIAGRAMS

AND

STATE VARIABLES

When a discrete-time system is modeled by one or more difference equations, a simulation diagram represents a more visual description of the system’s dynamics. Furthermore, a simulation diagram leads directly to an equivalent discrete-time state-space model, in much the same way a continuous-time state variable model was developed from a simulation diagram of the continuous-time system. As in the continuous-time case, the simulation diagram and state-space models of a discrete-time system are not unique. The dynamic block in a simulation diagram representation of a continuous-time system is the integrator or 1=s block. In a discrete-time system, delaying yk for one time step results in yk1. If y1 ¼ 0, the delay property states z{yk1} ¼ z1z{yk}. For a discrete-time system, the unit-delay block is the counterpart to the integrator block. Figure 4.52 shows several common ways of representing a unit-delay block. A block diagram implementation of the nth-order difference Equation 4.456 is shown in Figure 4.53. The block diagram shown in Figure 4.53 contains n þ m unit delays to implement the nth-order discrete-time system governed by the difference equation in Equation 4.456. Only block diagrams with the minimum number of n delays are classiﬁed as simulation diagrams. A simulation diagram serves as a convenient way of identifying the discrete-time states in much the same way continuoustime simulation diagrams were used to deﬁne the continuous-time states. The discrete-time states x1,k, x2,k, . . . , xn,k are chosen as the outputs of the n unit delays. As in the case of continuous-time systems, the simulation diagram and, hence, the states are not unique. When the past input terms uk1, uk2, . . . , ukm are not present in Equation 4.456, the constants b1 ¼ b2 ¼ ¼ bm ¼ 0 and the block diagram in Figure 4.53 reduces to a simulation diagram.

uk

FIGURE 4.52

Unit delay

uk−1

uk

uk−1

T

uk

uk−1

z−1

Graphical representation of the delay property.

uk

z−1

b0

uk−1

b1

z−1

uk−2

b2

z−1

.....

uk−m

bm

yk z−1

z−1

−a1

z−1

−a2

.....

. . . . .

FIGURE 4.53

Block diagram for nth-order discrete-time system in Equation 4.456.

−an

245

Linear Systems Analysis

When one or more past input terms appear in the difference equation, a simulation diagram can be constructed by starting with the z-domain transfer function in Equation 4.459 expressed as Y(z) Y(z) W(z) ¼ U(z) W(z) U(z)

(4:506)

W(z) 1 ¼ U(z) 1 þ a1 z1 þ a2 z2 þ þ an zn

(4:507)

Y(z) ¼ b0 þ b1 z1 þ þ bm zm W(z)

(4:508)

where

Difference equations corresponding to Equations 4.507 and 4.508 are wk ¼ uk a1 wk1 a2 wk2 an wkn

(4:509)

yk ¼ b0 wk þ b1 wk1 þ þ bm wkm

(4:510)

Implementation of Equations 4.509 and 4.510 results in the simulation diagram shown in Figure 4.54. Discrete-time state equations relate the state vector at time k þ 1 to the discrete-time state vector and input vector at time k. In the single input case with the states as shown in Figure 4.54, the result is 8 x1,kþ1 ¼ x2,k > > > x ¼ x3,k > < 2,kþ1 .. (4:511) . > > > x ¼ x > n,k : n1,kþ1 xn,kþ1 ¼ wk ¼ an x1,k a2 xn1,k a1 xn,k þ uk

b0 b1 b2

. . . .

yk

bm uk

wk

wk−1 z−1 x n,k

z−1

wk−2 xn−1,k

z−1

wk−m xn−m+1,k

z−1

wk−n x1,k

−a1 −a2 . . . .

−am

. . . . −an

FIGURE 4.54

Simulation diagram for nth-order system showing states x1,k, x2,k, . . . , xn,k.

Simulation of Dynamic Systems with MATLAB® and Simulink®

246

The output yk is expressed in terms of the state and input according to yk ¼ bm xnmþ1,k þ þ b2 xn1,k þ b1 xn,k þ b0 wk

(4:512)

¼ bm xnmþ1,k þ þ b2 xn1,k þ b1 xn,k þ b0 [uk an x1,k a2 xn1,k a1 xn,k ] (4:513) 8 an b0 x1,k an1 b0 x2,k a1 b0 xn,k þ b0 uk , m ¼ 0 > > > < a b x a b x a b x n 0 1,k n1 0 2,k mþ1 0 nm,k yk ¼ > þ(b a b )x þ þ (b1 a1 b0 )xn,k þ b0 uk , m ¼ 1, . . . , n 1 m m 0 nmþ1,k > > : (bn an b0 )x1,k þ (bn1 an1 b0 )xn1,k þ þ (b1 a1 b0 )xn,k þ b0 uk , m ¼ n (4:514) In the general case of a linear discrete-time system with r inputs and p outputs, the discrete-time state equations are of the form x kþ1 ¼ Ax k þ Bu k , y k ¼ Cx k þ Du k

(4:515)

where the system matrix A is n n, the input matrix B is n r, the output matrix C is p n, and the direct coupling matrix D is p r. For the discrete-time system described by Equations 4.511 and 4.514, the system matrix A and input matrix B are 2

0 6 0 6 . . A¼6 6 . 4 0 an

.. .

1 0 .. .

0 1 .. .

0 an1

0 an2

0 0 .. . 0 a2

3 2 3 0 0 607 0 7 6.7 .. 7 6.7 . 7 7, B ¼ 6 . 7 5 405 1 a1 1

(4:516)

and the output matrix C and direct transmission matrix D are 8 [ an b0 an1 b0 a1 b0 ], > < C ¼ [ an b0 an1 b0 amþ1 b0 bm am b0 > : [bn an b0 bn1 an1 b0 b1 a1 b0 ],

m¼0

b1 a1 b0 ],

m ¼ 1, . . . , n 1 m¼n (4:517)

D ¼ [b0 ]

(4:518)

The simulation diagram is redrawn for the case where m ¼ n in Figure 4.55. To illustrate the use of the state equations, consider the discrete-time approximation to a secondorder continuous-time system using trapezoidal integration. From Equation 4.504, the difference equation is yk þ a1 yk1 þ a2 yk2 ¼ b0 uk þ b1 uk1 þ b2 uk2 a1 ¼ b0 ¼

2[(vn T)2 4] , 4(1 þ zvn T) þ (vn T)2

K(vn T)2 , 4(1 þ zvn T) þ (vn T)2

b1

a2 ¼

4(1 zvn T) þ (vn T)2 4(1 þ zvn T) þ (vn T)2

2K(vn T)2 , 4(1 þ zvn T) þ (vn T)2

The simulation diagram is shown in Figure 4.56.

(m ¼ n ¼ 2)

b2 ¼

(4:519) (4:520)

K(vn T)2 (4:521) 4(1 þ zvn T) þ (vn T)2

247

Linear Systems Analysis b0 b1 − a1b0 b2 − a2b0 xn,k+1

uk

z−1

xn,k

z−1

xn–1,k

z−1

x1,k

yk

bn − anb0

–a1 –a2 −an

FIGURE 4.55

Simulation diagram for nth-order discrete-time system in Equation 4.456 (m ¼ n).

b0 b1 − a1b0 uk

z−1

x2,k

z−1

x1,k

yk

b2 − a2b0

−a1 −a2

FIGURE 4.56

Simulation diagram for trapezoidal integration of second-order system.

The state equations follow directly from Figure 4.56.

x 1 , k þ 1 ¼ x2 , k x2 , k þ 1 ¼ a2 x1,k a1 x2,k þ uk

(4:522)

yk ¼ (b2 a2 b0 )x1,k þ (b1 a1 b0 )x2,k þ b0 uk

(4:523)

and the matrices A, B, C, and D in Equation 4.515 are

0 A¼ a2

1 a1

2

0 2 ¼ 4 4(1 zvn T) þ (vn T) 4(1 þ zvn T) þ (vn T)2

3 1 2 5, 2[(vn T) 4 2 4(1 þ zvn T) þ (vn T)

B¼

0 1 (4:524)

C ¼ [ b 2 a2 b0

2 vn T [ zvn T 4(1 þ zvn T) þ (vn T)2 K(vn T)2 D ¼ [b0 ] ¼ 4(1 þ zvn T) þ (vn T)2

b1 a1 b0 ] ¼ 8K

2 þ zvn T ]

(4:525)

(4:526)

Using the same second-order system parameter values as in Examples 4.26 and 4.27, recursive solution of Equations 4.522 and 4.523 produces identical results to those shown in Figure 4.51 and Table 4.8 (see M-ﬁle ‘‘Chap4_trapezoidal_state.m’’).

Simulation of Dynamic Systems with MATLAB® and Simulink®

248 2

yk, k = 0, 10, 20, ..., 800

1.6

y(t), 0 ≤ t ≤ 20

1.2 0.8 0.4 0

K = 1, ωn = 1 rad/s, ζ = 0.1

T = 0.025 s 0

2

4

6

8

10

12

14

16

18

20

t (s)

(a) 1 0.8

yk, k = 0, 10, 20, ..., 800

0.6

y(t), 0 ≤ t ≤ 20

0.4 T = 0.025 s

0.2 0

0

2

4

K = 1, ωn = 1 rad/s, ζ = 2.5

6

8

FIGURE 4.57

10

12

14

16

18

20

t (s)

(b)

Trapezoidal integration of (a) light and (b) heavily damped second-order systems.

Discrete-time approximations to the step responses of two additional continuous-time secondorder systems, one with light damping (K ¼ 1, z ¼ 0.1, vn ¼ 1 rad=s) and the other heavily damped (K ¼ 1, z ¼ 2.5, vn ¼ 1 rad=s) are shown in Figure 4.57. Results are based on recursive solution of the state equations for trapezoidal integration (see M-ﬁle ‘‘Chap4_Fig7_14.m’’). Agreement between the exact and approximate solutions for both systems appears to be acceptable. More detailed comparisons require numerical outputs from the continuous- and discrete-time systems.

4.7.4 SOLUTION

OF

LINEAR DISCRETE-TIME STATE EQUATIONS

A general solution to the discrete-time state equations gives the state xk for any value of discretetime k without resorting to a recursive (sequential) solution. Solving for the ﬁrst several values of xk in Equation 4.515 leads to the observation xk ¼ Ak x0 þ Ak1 Bu0 þ Ak2 Bu1 þ þ ABuk2 þ Buk1 , ¼ Ak x0 þ

k1 X

Aki1 Bui ,

k ¼ 0, 1, 2, 3, . . .

k ¼ 0, 1, 2, 3, . . .

(4:527) (4:528)

i¼0

Equation 4.528 for the state xk is substituted in Equation 4.515 to obtain the general solution for the output yk, k ¼ 0, 1, 2, 3,. . . . The result is

y k ¼ CA x 0 þ C k

k1 X i¼0

! ki1

A

Bu i

þ Du k ,

k ¼ 0, 1, 2, 3, . . .

(4:529)

249

Linear Systems Analysis

The discrete-time state transition matrix Fk is deﬁned as Fk ¼ A k ,

k ¼ 0, 1, 2, 3, . . .

(4:530)

Solutions for xk and yk, in terms of Fk, are x k ¼ F k x0 þ

k1 X

Fki1 Bui ,

k ¼ 0, 1, 2, 3, . . .

(4:531)

i¼0

yk ¼ CFk x0 þ C

k1 X

(Fki1 Bui ) þ Duk ,

k ¼ 0, 1, 2, 3, . . .

(4:532)

i¼0

Observe that an unforced system (uk ¼ 0, k ¼ 0, 1, 2, 3, . . . ) transitions from its initial state x0 to a new state xk at time k according to xk ¼ Fkx0. The discrete-time state equations and solutions are analogous to the results for continuous-time systems. An expression for evaluating the discrete-time transition matrix can be obtained by z-transforming the ﬁrst equation in Equation 4.515 resulting in z{xkþ1 } ¼ z{Axk þ Buk } ¼ AX(z) þ BU(z)

(4:533)

It is left as an exercise to show that z{xkþ1 } ¼ z[X(z) x0 ]

(4:534)

Combining Equations 4.533 and 4.534 gives z[X(z) x0 ] ¼ AX(z) þ BU(z)

(4:535)

(zI A)X(z) ¼ zx0 þ BU(z)

(4:536)

X(z) ¼ (zI A)1 [zx0 þ BU(z)]

(4:537)

xk ¼ z1 {(zI A)1 (zx0 )} þ z1 {(zI A)1 BU(z)}

(4:538)

Comparison of Equations 4.531 and 4.538 with uk ¼ 0, k ¼ 0, 1, 2, . . . implies Fk ¼ z1 {F(z)} ¼ z1 {z(zI A)1 }

(4:539)

An example using the discrete-time state equations follows. Example 4.28 The yearly increase in a monetary fund is a weighted sum of the increases over the prior 2 years plus an end-of-year (EOY) deposit. The fund starts with an initial amount P0. (a) Write the difference equation for yk, k ¼ 0, 1, 2, 3, . . . the fund balance at the end of the kth year. Let uk, k ¼ 0, 1, 2, 3, . . . be the EOY deposit in the fund. The weights are a (previous year increase) and b (increase 2 years ago). (b) Draw a simulation diagram and convert the difference equation to state variable form.

Simulation of Dynamic Systems with MATLAB® and Simulink®

250

y−1

−3 −2

FIGURE 4.58

−2 −1

y1

y0

−1 0

0 1

k

3

2 3

1 2

EOY

4

Relationship between discrete-time variable k and end of year.

(c) Given a ¼ 0.5, b ¼ 0.25, and P0 ¼ $100, and all EOY deposits are zero, ﬁnd the components of the discrete-time state transition matrix needed to solve for yk, k ¼ 0, 1, 2, 3,. . . . (d) Find and plot the fund balance yk, k ¼ 0, 1, 2, 3,. . . . (a) The time line in Figure 4.58 shows the relationship between the discrete-time variable k and the EOY marker. Note that the initial fund amount is y1. The difference equation for yk, k ¼ 0, 1, 2, 3, . . . is yk yk1 ¼ a(yk1 yk2 ) þ b(yk2 yk3 ) þ uk ,

k ¼ 0, 1, 2, 3, . . .

(4:540)

The initial conditions are y1 ¼ P0, y2 ¼ y3 ¼ 0. Rewriting Equation 4.540 in the standard from introduced in Equation 4.456 yk þ a1 yk1 þ a2 yk2 þ a3 yk3 ¼ b0 uk ,

k ¼ 0, 1, 2, 3, . . .

(4:541)

where a1 ¼ (1 þ a), a2 ¼ a b, a3 ¼ b, and b0 ¼ 1. (b) Referring to Figure 4.53 or 4.54 with n ¼ 3, m ¼ 0, and b0 ¼ 1, the simulation diagram reduces to Figure 4.59. The state equations follow from the simulation diagram. 8 < x1 , k þ 1 ¼ x2 , k x , k þ 1 ¼ x3 , k : 2 x3 , k þ 1 ¼ a3 x1 , k a2 x2 , k a1 x3 , k þ uk 2

0 A¼4 0 a3 C ¼ [ a3

yk ¼ a3 x1 ,k a2 x2 ,k a1 x3 ,k þ uk 3 2 3 0 1 0 1 0 5 4 ¼ 0 0 1 5, 0 1 b b a 1 þ a a2 a1 a2

a1 ] ¼ [ b

b a 1 þ a ],

(4:542) (4:543) 2 3 0 B ¼ 405 1

(4:544)

D ¼ [1]

(4:545) yk

uk

z−1

x3,k

z−1

x2,k

z−1

−a1 −a2 −a3

FIGURE 4.59

Simulation diagram for monetary fund example.

x1,k

251

Linear Systems Analysis (c) a1 ¼ (1 þ a) ¼ (1 þ 0.5) ¼ 1.5, a2 ¼ a b ¼ 0.5 0.25 ¼ 0.25, a3 ¼ b ¼ 0.25 2

1

0 0

2

3

0

1

0

3

7 7 6 6 0 1 7 1 07 5 54 0 a3 a2 a1 0 0 1 3 3 2 2 z 1 0 z 1 0 7 7 6 6 6 ¼6 z 1 7 z 1 7 5 5¼4 0 40 a3 a2 z þ a1 0:25 0:25 z 1:5

6 zI A ¼ z6 40

(4:546)

(4:547)

F(z) ¼ z(zI A)1

(4:548)

Inverting (zI A) followed by multiplication by z results in 2 F(z) ¼

z3

1:5z2

6 z 6 þ 0:25z þ 0:25 4

z2 1:5z þ 0:25

z 1:5

0:25

z(z 1:5)

0:25z

1

3

7 z7 5

(4:549)

0:25(z þ 1) z2

From Equation 4.532, with uk ¼ 0, k ¼ 0, 1, 2, . . . the solution for yk is yk ¼ CFk x0

(4:550)

where the initial state 2

y3

3

2

0

3

7 6 7 6 7 6 7 x0 ¼ 6 4 y2 5 ¼ 4 0 5 y1

P0

The transition matrix Fk is obtained by inverse z-transforming F(z) in Equation 4.549. The last column of Fk is all that is necessary to determine yk as a result of the zeros in the ﬁrst and second rows of x0. The last column of Fk comprises (Fk )1, 3 ¼ z1 {F1, 1 (z)} ¼ z1 (Fk )2, 3 ¼ z1 {F2, 1 (z)} ¼ z1 (Fk )3, 3 ¼ z1 {F3, 1 (z)} ¼ z1

z 3 2 z 1:5z þ 0:25z þ 0:25 z2 3 2 z 1:5z þ 0:25z þ 0:25 z3 z3 1:5z2 þ 0:25z þ 0:25

(4:551)

(4:552)

(4:553)

The roots of z3 1.5z2 þ 0.25z þ 0.25 ¼ 0 are p1 ¼ 1, p2 ¼ 0.8090, p3 ¼ 0.3090. (Fk)1,3, (Fk)2,3, (Fk)3,3 are linear combinations of the geometric sequences (p1)k, p2k, (p3)k, that is, (Fk )1,3 ¼ A1 (p1 )k þ A2 (p2 )k þ A3 (p3 )k

(4:554)

(Fk )2,3 ¼ B1 (p1 )k þ B2 (p2 )k þ B3 (p3 )k

(4:555)

(Fk )3,3 ¼ C1 (p1 )k þ C2 (p2 )k þ C3 (p3 )k

(4:556)

Simulation of Dynamic Systems with MATLAB® and Simulink®

252

The partial fraction expansion coefﬁcients are evaluated in M-ﬁle ‘‘Chap4_Ex7_5.m.’’ The results are A1 ¼ 4,

A2 ¼ 4:6833,

A3 ¼ 0:6833

B1 ¼ 4,

B2 ¼ 3:7889,

B3 ¼ 0:2111

C1 ¼ 4,

C2 ¼ 3:065,

C3 ¼ 0:0652

(d) From Equations 4.545 and 4.550, the fund balance is 3 2 (Fk )1,3 7 6 7 yk ¼ [ a3 a2 a1 ]6 4 (Fk )2,3 5P0 (Fk )3,3 3 2 A1 (p1 )k þ A2 (p2 )k þ A3 (p3 )k 7 6 k k k 7 ¼ [b b a 1 þ a ]6 4 B1 (p1 ) þ B2 (p2 ) þ B3 (p3 ) 5P0

(4:557)

(4:558)

C1 (p1 )k þ C2 (p2 )k þ C3 (p3 )k ¼ {b[A1 (p1 )k þ A2 (p2 )k þ A3 (p3 )k ] þ (b a)[B1 (p1 )k þ B2 (p2 )k þ B3 (p3 )k ] þ (1 þ a)[C1 (p1 )k þ C2 (p2 )k þ C3 (p3 )k ]}P0

(4:559)

A graph of yk, k ¼ 3, 2, 1, 0, 1, 2, . . . is show in Figure 4.60. The limiting value, y1 ¼ $400 from the root p1 ¼ 1. Since the magnitude of roots p2 and p3 are less than 1, it follows from Equation 4.559 at steady state that the output y1 is given by y1 ¼ lim yk ¼ [bA1 þ (b a)B1 þ (1 þ a)C1 ]P0 k!1

¼ [(0:25)(4) þ (0:25 0:5)(4) þ (1 þ 0:5)(4)]100 ¼ 400

(4:560)

We will have a lot more to say about the location of these roots in the next section on stability. Fund value vs. time y∞ 400 350 300

yk , $

250

y2 y1

200 y0

150

y−1

100

yk , k = −3, −2, −1, 0, 1, 2, ...

50 0

y−3

y−2

−3 −2 −1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 k

FIGURE 4.60

Discrete-time system output in Example 4.28.

253

Linear Systems Analysis

The complete transition matrix is left as an exercise problem. However, a suitable check on the correctness of Fk is that it satisﬁes F0, where I is the n n identity matrix. This follows from Equation 4.530 with k ¼ 0 as well as Equation 4.531 with zero input and k ¼ 0. A quick glance at F(z) in Equation 4.549 should be enough to convince you that F(z) (Hint: only the diagonal terms of F(z) contain cubic polynomials in z in the numerator). Keep in mind that F0 ¼ I is necessary but not sufﬁcient for Fk to be correct.

4.7.5 WEIGHTING SEQUENCE (IMPULSE RESPONSE FUNCTION) A difference equation and a z-domain transfer function are but two of several different ways of characterizing a discrete-time system. A third approach is based on the system’s impulse response function, similar to the case of continuous-time systems. Recall from our discussion of linear continuous-time systems that the response to an arbitrary input u(t), t 0 is expressible in the form of a convolution integral, that is, ðt y(t) ¼ h(t)u(t t)dt

(4:561)

0

where h(t), t 0 is the impulse response function. It is related to the continuous-time system transfer function H(s) according to h(t) ¼ L1 {H(s)}. We now demonstrate the existence of a sequence, hk, k ¼ 0, 1, 2, 3, . . . which allows us to ﬁnd the forced response of a linear discrete-time system to an arbitrary input uk, k ¼ 0, 1, 2, 3, . . . similar to the convolution integral in Equation 4.561 for linear continuous-time systems. The only restriction is that the initial conditions prior to application of the input, namely, y1, y2, . . . , yn, are zero for an nth-order linear discrete-time system. Consider the ﬁrst-order system yk þ a1 yk1 ¼ b0 uk þ b1 uk1

(4:562)

where y1 ¼ 0 and the input uk ¼ 0, k < 0. Evaluating the ﬁrst several values of yk, k ¼ 0: k ¼ 1:

y0 ¼ b 0 u 0

(4:563)

y1 þ a1 y 0 ¼ b 0 u 1 þ b1 u0

(4:564)

y1 ¼ b0 u1 þ (b1 a1 b0 )u0 y 2 þ ¼ a1 y 1 ¼ b0 u 2 þ b 1 u 1

k ¼ 2:

y2 ¼ b0 u2 þ (b1 a1 b0 )u1 a1 (b1 a1 b0 )u0 k ¼ 3:

y3 þ a0 y 2 ¼ b 1 u 3 þ b0 u2

y3 ¼ b0 u3 þ (b1 a1 b0 )u2 a1 (b1 a1 b0 )u1 þ a21 (b1 a1 b0 )u0

(4:565) (4:566) (4:567) (4:568) (4:569)

By induction, a general solution for yk, k ¼ 0, 1, 2, 3, . . . is yk ¼

k X i¼0

hi uki ,

k ¼ 0, 1, 2, 3, . . .

(4:570)

Simulation of Dynamic Systems with MATLAB® and Simulink®

254

where hi ¼

i¼0 i ¼ 1, 2, 3, . . .

b0 , (b1 a1 b0 )(a1 )i1 ,

(4:571)

The discrete-time variable in Equation 4.571 is written as ‘‘i’’ instead of ‘‘k’’ to avoid confusion; however, it is helpful to think of the sequence as hk, k ¼ 0, 1, 2, 3,. . . . Equation 4.570 reveals that the current output yk is a linear combination of the current and past inputs, that is, writing out the terms in the sum yk ¼ h0 uk þ h1 uk1 þ h2 uk2 þ þ hk u0 ,

k ¼ 0, 1, 2, 3, . . .

(4:572)

The weights are in fact the numerical values of the sequence hk, k ¼ 0, 1, 2, 3, . . . with the current input uk weighted by h0, the previous input uk1 weighted by h1 up to the oldest input u0 with a weight of hk. The sequence hk, k ¼ 0, 1, 2, 3, . . . in Equations 4.570 and 4.572 is called the weighting sequence of the discrete-time system. The sum in Equation 4.570 is called the convolution sum, the counterpart to the convolution integral for continuous-time systems in Equation 4.561. The weighting sequence and convolution sum representation are not restricted to the simple ﬁrst-order discrete-time system in Equation 4.562. They are applicable to nth-order LTI discrete-time systems. Fortunately, a more efﬁcient technique for determining the weighting sequence than was previously illustrated exists. The method is deferred until after the following example. Example 4.29 The low-pass ﬁlter in Equation 4.473 is a ﬁrst-order discrete-time system. (a) Find the weighting sequence hk, k ¼ k ¼ 0, 1, 2, 3,. . . . (b) Graph the weighting sequence for a ¼ 0.9 and b ¼ 0.1. (c) Find the unit step response by convolution, and compare the result with the response in Equation 4.478 with y1 ¼ 0. (a) For the discrete-time system in Equation 4.473, a1 ¼ a, b0 ¼ b, and b1 ¼ 0. The weighting sequence given in Equation 4.571 reduces to hk ¼

b,

k¼0

(ab)(a)k1 ,

k ¼ 1, 2, 3, . . .

¼ b(a)k ,

k ¼ 0, 1, 2, 3, . . .

(4:573) (4:574)

(b) The weighting sequence with a ¼ 0.9 and b ¼ 0.1 is graphed in Figure 4.61. (c) From Equation 4.570 with uk ¼ 1, k ¼ 0, 1, 2, 3, . . . , the unit step response is yk ¼

k X

hi uki ¼

i¼0

¼b

k X i¼0

1 akþ1 1a

¼ 1 (0:9)kþ1 ,

hi ¼

k X

bai

(4:575)

i¼0

(4:576) k ¼ 0, 1, 2, 3, . . .

in agreement with the unit step response obtained from Equation 4.478 with y1 ¼ 0.

(4:577)

255

Linear Systems Analysis

hk = β(α)k, k = 0, 1, 2, 3, ...

0.1 0.09

yk = βuk + αyk−1, k = 0, 1, 2, 3, ...

0.08

(α = 0.9, β = 0.1)

hk

0.07 0.06 0.05 0.04 0.03 0.02 0.01 0

FIGURE 4.61

0

2

4

6

8 10 12 14 16 18 20 22 24 26 28 30 k

Weighting sequence hk, k ¼ 0, 1, 2, 3, . . . for ﬁrst-order system in Equation 4.473.

The memory and transient response of a stable linear discrete-time system are reﬂected in its weighting sequence. Loosely speaking, the memory in a discrete-time system depends on how far back past inputs affect the current output in a signiﬁcant way, that is, if the current output is predominantly inﬂuenced by only the last several inputs, then the system is said to exhibit a relatively short memory. Conversely, if distant inputs are inﬂuential in determining the current output, the system possesses a longer memory. From the convolution sum representation for the current output yk in Equation 4.572, it is readily apparent that the amount of memory in the system is directly related to how fast the weighting sequence approaches zero. (Discrete-time systems with weighting sequences that do not approach zero as k approaches inﬁnity are considered in the next section dealing with stability.) Transient and steady-state response will also be considered at the same time; however, it should be clear even now that a fast responding system, that is, one with a short transient response must have a weighting sequence that approaches zero quickly and is, therefore, characterized as a system with a short memory.

For the ﬁrst-order system considered in Example 4.29, the rate of decay to zero in the weighting sequence depends solely on the parameter a. Figure 4.62 shows the unit step responses of three ﬁrstorder systems with different values of a and b ¼ 1 a. One is a fast responding system (a ¼ 0.3), one with moderate speed (a ¼ 0.7), and the last one is seen to have a sluggish response (a ¼ 0.9). The response of an LTI discrete-time system to an impulse dk is quite signiﬁcant. From the convolution sum in Equation 4.570, the unit impulse response is (yk )impulse response ¼

k X

hi dki ¼ hk ,

k ¼ 0, 1, 2, 3, . . .

(4:578)

i0

In other words, the impulse response is identical to the weighting sequence. Furthermore, for a system with z-domain transfer function H(z), the z-transform of the impulse response is given by Yimpulse response (z) ¼ H(z)z{dk } ¼ H(z) 1 ¼ H(z)

(4:579)

Simulation of Dynamic Systems with MATLAB® and Simulink®

256

Weighting sequence hk = βαk, k = 0, 1, 2, 3, .... (β = 1−a)

0.8

hk

0.6 α = 0.3 (fast) α = 0.7 (moderate) α = 0.9 (slow)

0.4 0.2 0 0

5

10

20 k

15

Unit step response of yk = βuk + αyk−1, k = 0, 1, 2, 3, .... (β = 1− α)

yk

1

0.5

α = 0.3 (fast) α = 0.7 (moderate) α = 0.9 (slow)

0 0

5

10

20 k

15

FIGURE 4.62 Weighting sequences and unit step responses of three ﬁrst-order discrete-time systems governed by yk ¼ (1 a)uk þ ayk1, k ¼ 0, 1, 2,. . . .

Invert z-transforming Equation 4.579, (yk )impulse response ¼ hk ¼ z1 {H(z)}

(4:580)

Equation 4.580 tells us the impulse response of an LTI discrete-time system is equal to the inverse z-transform of the z-domain transfer function of the system. Henceforth, the impulse response sequence will be denoted hk, k ¼ 0, 1, 2,. . . . This most important property of discrete-time systems is illustrated in Figure 4.63. The z-domain transfer function of the ﬁrst-order system in Example 4.29 is H(z) ¼

U(z) Input 1. δk (Impulse) 2. uk (Arbitrary)

FIGURE 4.63

Y(z) bz ¼ U(z) z a

Linear discrete-time system hk = Z −1{H(z)}

(4:581)

Y(z) = H(z) U(z)

Output

1. yk = hk (Impulse response) 2. yk =

k

∑ hiuk−i (Convolution sum)

i=0

Relationship of impulse response to z-domain transfer function.

257

Linear Systems Analysis

hk ¼ z1 {H(z)}

bz ¼ z1 za ¼ bak , k ¼ 0, 1, 2, 3, . . .

(4:582) (4:583) (4:584)

The impulse response (weighting sequence) is therefore the same as in Equation 4.574. The impulse response is fundamental to the design of digital ﬁlters implemented by linear difference equations. The two major categories of such ﬁlters are FIR and IIR, which stand for ‘‘ﬁnite impulse response’’ and ‘‘inﬁnite impulse response,’’ respectively (Orfanidis 1996).

EXERCISES 4.43 Find the z-domain transfer function of the discrete-time system, which results from an approximation to a continuous-time integrator using (a) Implicit Euler integration (b) Improved Euler integration 4.44 Find the z-domain transfer function H(z) of the discrete-time system resulting from approximation of the ﬁrst-order system t_y(t) þ y(t) ¼ ku(t) using the following numerical integrators: (a) Explicit Euler (b) Implicit Euler (c) Trapezoidal 4.45 Let uk, k ¼ 0, 1, 2, 3, . . . be uniformly Ð t spaced samples of an input u(t) and yk, k ¼ 0, 1, 2, 3, . . . be an approximation to y(t) ¼ 0 u(t)dt based on trapezoidal integration. (a) Find a difference equation relating uk and yk. (b) Solve the difference equation recursively using an appropriate step size to approximate the area under (i) u(t) ¼ tet=2 p,ﬃﬃﬃﬃﬃﬃ 1 2 t 2 (ii) u(t) ¼ (1= 2p)et =2 , 0 t 5 4.46 Prove Equation 4.534 for the scalar case, that is, show that z{xkþ1} ¼ z[X(z) x0], where x0 is the value of xk at k ¼ 0. 4.47 In Example 4.28, ﬁnd the complete transition matrix and verify that F0 ¼ I. 4.48 In Example 4.28, (a) Find Y(z), the z-transform of the response, by z-transforming the difference equation of the system with appropriate initial conditions. (b) Find y1 by applying the ﬁnal value property (see Table 4.5). (c) Find y0 by applying the initial value property (see Table 4.5). (d) Find y k ¼ z 1{Y(z)}. 4.49 In Example 4.28, assume the initial conditions y3 ¼ y2 ¼ y1 ¼ 0. (a) Find H(z) ¼ Y(z)=U(z), the z-domain transfer function of the system. (b) The input is uk ¼ A0dk þ A1dk1 þ A2dk2 and y1 ¼ y2 ¼ y3 ¼ 0. Find A0, A1, A2 if the response is identical to the case when uk ¼ 0, k ¼ 0, 1, 2, . . . and y1 ¼ P0, y2 ¼ y3 ¼ 0. 4.50 The unit step response of a discrete-time system is yk ¼ 1 þ 3kþ1, k ¼ 0, 1, 2, 3,. . . . (a) Find the difference equation relating uk and yk. (b) Find the impulse response, hk, k ¼ 0, 1, 2, 3,. . . . 4.51 The discrete-time signal uk ¼ 1 þ k, k ¼ 0, 1, 2, 3, . . . is delayed one unit of discrete-time and then input to a discrete-time system with z-domain transfer function H(z) ¼ Y(z)=U(z) ¼ z2=(z þ 1)2. Find the output yk at k ¼ 3 and k ¼ 6.

Simulation of Dynamic Systems with MATLAB® and Simulink®

258

4.52 A discrete-time system with input uk and output yk is governed by the difference equation yk ¼ a1yk1 þ b1uk1 þ b0uk, k ¼ 0, 1, 2, 3, . . . (a) Find the z-domain transfer function of the system (b) Find the impulse response sequence hk, k ¼ 0, 1, 2, 3, . . . (i) By inverse z-transformation of H(z) (ii) By recursive solution of the difference equation with uk ¼ dk (c) Find the ﬁnal value of the unit step response in terms of a1, b0, and b1. (i) By letting k ! 1 in the unit step response (ii) By applying the ﬁnal value property (iii) By setting uk ¼ 1, k ¼ 0, 1, 2, 3, . . . and solving for y1 ¼ limk!1 yk ¼ limk!1 yk1 in the difference equation 4.53 Use the same approach for ﬁnding z{yk1} when y1 6¼ 0 resulting in Equation 4.472 to ﬁnd (a) z{yk2}, y1, y2 6¼ 0 (b) z{ykn}, y1, y2, . . . , yn 6¼ 0 4.54 A discrete-time system is described by yk þ a1yk1 þ a2yk2 ¼ 0, k ¼ 0, 1, 2, 3, . . . (a) Find Y(z) for the case when y1 ¼ 0 and y2 ¼ 0. (b) Find Y(z) for the case when the right-hand side is b0dk þ b1dk1 and y1 ¼ y2 ¼ 0. (c) Find expressions for the weights b0 and b1 in terms of a1, a2, y1, and y2, so that the response yk, k ¼ 0, 1, 2, 3, . . . is the same in parts (a) and (b). Comment on the implication of replacing initial conditions with impulse forcing functions. 4.55 A simulation diagram for an M-B-K mechanical system governed by the second-order differential equation M€y(t) þ B_y(t) þ Ky(t) ¼ f (t) is shown in Figure E4.55: 1 M

f

.. y

1 s

. y

1 s

y

−B −K

FIGURE E4.55

(a) Find a difference equation relating yk and fk based on the use of explicit Euler integration. Convert the difference equation to state variable form. (b) Find a difference equation relating yk and fk based on the use of implicit Euler integration. Convert the difference equation to state variable form. (c) Find a difference equation relating yk and fk based on the use of trapezoidal Euler integration. Convert the difference equation to state variable form. (d) Find a difference equation relating yk and fk based on the use of explicit Euler integration for the ﬁrst integrator (_y) and implicit Euler integration for the second integrator (y). Convert the difference equation to state variable form. (e) Approximate the unit step response of the system for parts (a) through (d) when M ¼ 1, B ¼ 2, and K ¼ 1, and compare each with the continuous-time response. 4.56 Consider the double integrator shown in Figure E4.56: u(t) T

FIGURE E4.56

uk

∫

∫

HI(z)

HI(z)

y(t)

yk

259

Linear Systems Analysis

(a) Write the differential equation relating y(t) and u(t). (b) Find the difference equation relating yk and uk if both numerical integrators are based on explicit Euler integration. (c) Find dy=dt and y(t) when the initial conditions are y(0) ¼ 0, y_ (0) ¼ 1 and the input u(t) ¼ 10 et=2, t 0. (d) Find the z-domain transfer function and impulse response of the discrete-time system. (e) Find the output yk, k ¼ 1, 2, 3, . . . when the integration step size T ¼ 0.1 s. (f) Plot the continuous- and discrete-time outputs on the same graph, and comment on the results. 4.57 A discrete-time system is described by yk þ a1 yk1 þ a2 yk2 ¼ 0, k ¼ 0, 1, 2, 3, . . .. (a) Find Y(z) for the case when y1 6¼ 0, y2 6¼ 0. (b) Find Y(z) for the case when the right-hand side is b0 dk þ b1 dk1 and y1 ¼ y2 ¼ 0. (c) Find expressions for the weights b0 and b1 in terms of a1 , a2 , y1 , y2 so that the response yk , k ¼ 0, 1, 2, 3, . . . is the same in Parts (a) and (b). Comment on the implication of replacing initial conditions with impulse forcing functions. 4.58 Show that the unit step response of a discrete-time system with z-domain transfer function H (z) is given by yk ¼ z

1

z H(z) , k ¼ 0, 1, 2, . . . z1

4.8 STABILITY OF LTI DISCRETE-TIME SYSTEMS One way of characterizing the stability of a discrete-time system is by the way it responds to a bounded input. When the response remains bounded, the system is said to exhibit BIBO stability. The implications of BIBO stability on the system’s z-domain transfer function, impulse response (weighting sequence), and natural response will be explored. Consider an nth-order LTI discrete-time system described by Equation 4.456 in the previous section. The z-domain transfer function is H(z) ¼

Y(z) b0 zn þ b1 zn1 þ þ bm znm ¼ n , U(z) z þ a1 zn1 þ þ an1 z þ an

nm

(4:585)

Suppose the poles of H(z) are real and distinct. Then Y(z) ¼ H(z)U(z) ¼

b0 zn þ b1 zn1 þ þ bm znm U(z) (z p1 )(z p2 ) (z pn )

(4:586)

In the case where the poles of U(z) are different from p1, p2, . . . pn, Y(z) ¼ A0 A1

z z z þ A2 þ þ An z p1 z p2 z pn

þ terms due poles of U(z)z1 {U(z)}

(4:587)

The response yk k ¼ 0, 1, 2, 3, . . . is therefore yk ¼ A0 dk þ A1 pk1 þ A2 pk2 þ þ An pkn þ terms generated from z1 {U(z)} terms generated from z1 {U(z)}

(4:588)

260

Simulation of Dynamic Systems with MATLAB® and Simulink®

The bracketed expression is the natural response, that is, a linear combination of the natural modes pk1 , pk2 , , pkn , while the terms arising from the inverse z-transformation of U(z) are similar in nature to the input and comprise the forced component of the overall response. Since the natural response is excited by the presence of an input, it must obviously be a bounded sequence for a BIBO stable system. The impulse response hk ¼ z1{H(z)} is also a linear combination of the system’s natural modes k k p1 , p2 , . . . , pkn , (plus in some cases, a weighted impulse at the origin). Imagine a discrete-time system with impulse response hk, k ¼ 0, 1, 2, . . . subject to a unit step input uk ¼ 1, k ¼ 0, 1, 2,. . . . Using the convolution sum form of the output,

X

X

X k k k

hi uki ¼

hi < jyk j ¼

jhi j,

i¼0

i¼0

i¼0

k ¼ 0, 1, 2, . . .

(4:589)

From Equation 4.589, the step response at discrete-time k remains ﬁnite provided the sum of the ﬁrst k þ 1 values of the magnitude of the impulse response satisﬁes k X

jhi j < 1, k ¼ 0, 1, 2, 3, . . .

(4:590)

i¼0

It follows that the entire response yk, k ¼ 0, 1, 2, 3, . . . is bounded whenever the impulse response sequence satisﬁes 1 X

jhk j < 1

(4:591)

k¼0

While Equation 4.591 was derived for the case where the input is a unit step, it applies to any bounded input. Equation 4.591 is a necessary and sufﬁcient condition for the output of an LTI discrete-time system to remain bounded in response to any bounded input. A consequence of Equation 4.591 is that the weighting sequence of a BIBO stable system must decay to zero as k ! 1. From Equation 4.588, an nth-order LTI discrete-time system with z-domain transfer function having real and distinct poles is BIBO stable when the poles satisfy 1 < pi < 1,

i ¼ 1, 2, 3, . . . , n

(4:592)

The expression for the output yk in Equation 4.588 assumed that the poles of H(z) were real and distinct. A real pole p with multiplicity m generates a weighted sum of the natural modes pk, kpk, . . . , km1pk in the output; however, Equation 4.592 still applies for BIBO stability. When a pair of complex poles of H(z) is present, yk contains trigonometric terms like Rk cos (ku þ w) where R is the magnitude of the complex poles. In order to include the possibility of complex poles of H(z), Equation 4.592 is appropriately expressed as jpi j < 1,

i ¼ 1, 2, . . . , n

(4:593)

Consequently, a sufﬁcient condition for BIBO stability of LTI discrete-time systems is that all of its z-domain transfer function poles have a magnitude less than 1, that is, all poles are located inside the Unit Circle in the complex plane. In Example 4.30, we look at a second-order system with real and distinct poles subject to a bounded input. The effect of moving one of the poles is investigated. Following that, we consider the ramiﬁcations of various locations of the z-domain transfer function’s poles in the complex plane.

261

Linear Systems Analysis

Example 4.30 A discrete-time system is described by the difference equation yk þ a1 yk1 þ a2 yk2 ¼ b0 uk ,

k ¼ 0, 1, 2, 3, . . .

(4:594)

Initial conditions y1 ¼ y2 ¼ 0. The input sequence is given by uk ¼ 1 þ (0:1)k ,

k ¼ 0, 1, 2, 3, . . .

(4:595)

Find the z-domain transfer function H(z) and its poles, the impulse response hk, k ¼ 0, 1, 2, 3, . . . , the total response yk, k ¼ 0, 1, 2, 3, . . . , and the natural and forced components of the total response, and comment on stability for the following cases: (a) a1 ¼ 0,

a2 ¼ 0:25,

b0 ¼ 1

(b) a1 ¼ 0:5, a2 ¼ 0:5, b0 ¼ 1 (c) a1 ¼ 1:5, a2 ¼ 1,

b0 ¼ 1

(a) z-transforming the difference equation yk 0.25yk2 ¼ uk, k ¼ 0, 1, 2, 3, . . . yields H(z) ¼

Y(z) z2 z2 ¼ ¼ 2 U(z) z 0:25 (z 0:5)(z þ 0:5)

(4:596)

with poles p1 ¼ 0.5, p2 ¼ 0.5. The impulse response is obtained from

z2 (z þ 0:5)(z 0:5)

0:5z 0:5z ¼ z1 þ z þ 0:5 z 0:5

hk ¼ z1 {H(z)} ¼ z1

¼ 0:5[(0:5)k þ (0:5)k ], ¼ (0:5)kþ1 [(1)k þ 1], ¼ (0:5)k ,

(4:597)

(4:598)

k ¼ 0, 1, 2, 3, . . . k ¼ 0, 1, 2, 3, . . .

k ¼ 0, 2, 4, 6, . . .

(4:599) (4:600) (4:601)

The complete response yk, k ¼ 0, 1, 2, . . . is determined by inverse z-transformation of Y(z) ¼

h z z2 z i þ (z2 0:25) z 1 z 0:1

(4:602)

z3 (2z 1:1) (z þ 0:5)(z 0:5)(z 1)(z 0:1) 7 z 1 z 4 z 1 z þ þ ¼ 12 z þ 0:5 8 z 0:5 3 z1 24 z 0:1

¼

) yk ¼

7 1 4 1 (0:5)k þ (0:5)k þ (0:1)k , 12 8 3 24

k ¼ 0, 1, 2, 3, . . .

(4:603) (4:604) (4:605)

Simulation of Dynamic Systems with MATLAB® and Simulink®

262

From Equation 4.605, the natural (free) response and forced response are (yk )natural ¼

7 1 ( 0:5)k þ (0:5)k , 12 8

(yk )forced ¼

4 1 (0:1)k , 3 24

k ¼ 0, 1, 2, . . .

k ¼ 0, 1, 2, . . .

(4:606) (4:607)

The system is stable as evidenced by the natural response decaying to zero as k ! 1. This was expected since the two poles of H(z) are located between 1 and þ1. Can you show that Equation 4.591 is satisﬁed as well? Note the similarity between the natural response in Equation 4.606 and the impulse response in Equation 4.599. (b) The difference equation becomes yk 0.5yk1 0.5yk2 ¼ uk, k ¼ 0, 1, 2, 3,. . . . The results for this system are obtained in an analogous fashion to part (a). H(z) ¼

z2

z2 z2 ¼ 0:5z 0:5 (z þ 0:5)(z 1) hk ¼

yk ¼

1 [(0:5)k þ 2], 3

(p1 ¼ 0:5, p2 ¼ 1)

k ¼ 0, 1, 2, 3, . . .

7 44 2 1 ( 0:5)k þ þ k (0:1)k , 18 27 3 54 (yk )nat ¼

k ¼ 0, 1, 2, 3, . . .

(4:608) (4:609) (4:610)

7 44 ( 0:5)k þ , 18 27

k ¼ 0, 1, 2, 3, . . .

(4:611)

2 1 k (0:1)k , 3 54

k ¼ 0, 1, 2, 3, . . .

(4:612)

(yk )forced ¼

The forced response also contains a constant component resulting from the pole of U(z) at z ¼ 1. This constant is combined with the constant in the natural response, and the sum of 44=27 is shown entirely in the natural response in Equation 4.611. The second pole of H(z), namely, p2 ¼ 1, does not satisfy Equation 4.592, and the system is not BIBO stable. In this case, a bounded input produced an unbounded output. The impulse response in Equation 4.609 does not asymptotically decay to zero. (c) The difference equation is yk 1.5yk1 yk2 ¼ uk, k ¼ 0, 1, 2, 3,. . . . H(z) ¼

z2 z2 ¼ , z2 1:5z 1 (z þ 0:5)(z 2) 1 4 hk ¼ (0:5)k þ (2)k , 5 5

yk ¼

(p1 ¼ 0:5, p2 ¼ 2)

k ¼ 0, 1, 2, 3, . . .

7 232 k 2 1 (0:5)k þ (2) (0:1)k , 30 95 3 114 (yk )natural ¼

7 232 k (0:5)k þ (2) , 30 95

2 1 (0:1)k , (yk )forced ¼ 3 114

k ¼ 0, 1, 2, 3, . . .

k ¼ 0, 1, 2, 3, . . .

k ¼ 0, 1, 2, 3, . . .

(4:613) (4:614) (4:615) (4:616) (4:617)

Once again, the system is unstable. The natural response and, by implication, the impulse response are unbounded as k ! 1. The real poles of an nth-order LTI discrete-time system transfer function are located on the real axis in the complex plane. Figure 4.64 shows real poles located at (from right to left) 1.25, 1, 0.75, 0.5, 1, and 1.5 along the real axis.

263

Linear Systems Analysis Im Unit Circle Re

FIGURE 4.64

The Unit Circle and various locations of real and complex poles.

Pole of H(z), p > 1

Pole of H(z), p = 1

10 8

1 0.8

1.5 1k

6 (1.25)k

4

0.4 0.5

0

2

4

6

8

10

0

0.2 0

Pole of H(z), –1 p < 0

2

4

6

8

10

0 4 8 12 16 20 Pole of H(z), p < –1

100

(−1)k

0.75

0

Pole of H(z), p = –1

1

75

1

50

0.5 0.25

0

(−0.5)k

−0.25

−25

−1

−0.5 0

2

4

6

8

k

(−1.5)k

25

0

0

FIGURE 4.65

(0.75)k

0.6

1

2 0

Pole of H(z), 0 < p < 1

2

10

0

2

4

6

8

10

k

−50

0

2

4

6

8

10

k

Natural modes corresponding to real poles of H(z).

There are six distinct regions for location of real poles along the real axis, each with a different type of natural mode. According to Equation 4.592, only the poles at 0.75 and 0.5 located inside the Unit Circle correspond to stable natural modes. The impulse response hk, k ¼ 0, 1, 2, . . . approaches zero as k ! 1 in both cases. When the poles are located on the Unit Circle at þ1 and 1, the impulse response sequence remains ﬁnite as k ! 1; however, a linear discrete-time system with a pole at either location is not BIBO stable. The remaining two cases correspond to real poles located outside the Unit Circle, either in the region p > 1 or p < 1. The natural response of an LTI discrete-time system with poles located in either region is unbounded, and, hence, the system is not BIBO stable. Figure 4.65 illustrates the natural modes corresponding to each of the real poles.

4.8.1 COMPLEX POLES OF H(Z) Three pairs of complex poles are also shown in Figure 4.64. The z-domain transfer function H(z) possesses a pair of complex poles if there is a quadratic factor in its denominator with complex roots. Figure 4.66 illustrates the case where H(z) has complex poles at z ¼ a jb. The transformation to polar form z ¼ re ju is shown as well.

Simulation of Dynamic Systems with MATLAB® and Simulink®

264

Im × a + jb

r

r = (a2 + b2)1/2

θ −θ

Re

θ = tan−1(b/a)

r × a – jb

FIGURE 4.66

Complex poles of discrete-time system transfer function H(z).

In terms of polar coordinates, the quadratic factor is Q(z) ¼ (z re ju )(z reju ) ¼ z2 (2r cos u)z þ r2

(4:618)

Consider a second-order discrete-time system with z-domain transfer function H(z) ¼

z2

Az2 þ Bz (2r cos u)z þ r2

(4:619)

For reasons that will soon become apparent, H(z) is expressed as H(z) ¼

c1 (r sin u)z þ c2 [z2 (r cos u)z] z2 (2r cos u)z þ r2

(4:620)

where c1 and c2 are obtained by equating like powers of z in the numerators of Equations 4.619 and 4.620. The result is c1 ¼

Ar cos u þ B , r sin u

c2 ¼ A

(4:621)

H(z) in Equation 4.620 is expressed as H(z) ¼ c1

(r sin u)z z2 (r cos u)z þ c 2 2 z2 (2r cos u)z þ r2 z (2r cos u)z þ r 2

(4:622)

Referring to Table 4.4 with eaT ¼ r and vT ¼ u suggests the impulse response hk ¼ z1{H(z)} is hk ¼ c1 r k sin ku þ c2 r k cos ku ¼ r k (c1 sin ku þ c2 cos ku),

k ¼ 0, 1, 2, 3, . . .

(4:623)

There are three cases to consider, which are illustrated in Figure 4.64. The three cases correspond to the region inside the Unit Circle (r < 1), all points on the Unit Circle (r ¼ 1), and the exterior of the Unit Circle (r > 1). It follows from Equation 4.623 that the impulse response satisﬁes the necessary condition for BIBO stability in Equation 4.591 only in the ﬁrst case, r < 1, that is, when the poles are located inside the Unit Circle. The natural response, being of similar form to the impulse response, decays to zero as k ! 1. Hence, the system is BIBO stable. When the poles are either on the Unit Circle or outside, Equation 4.591 is not satisﬁed, and the system is therefore not BIBO stable. The natural response consists of sustained oscillations when r ¼ 1 and oscillations of increasing magnitude when r > 1.

265

Linear Systems Analysis

Example 4.31 A second-order discrete-time system has a z-domain transfer function given by H(z) ¼

z2 þ 3z Q(z)

(4:624)

where Q(z) is a quadratic with complex roots located in the three different regions like the ones shown in Figure 4.64. Suppose the roots are pﬃﬃﬃ (a) 0.25 j0.5 (b) 0:5(1 j 3) (c) 1 j (a) Find the z-domain transfer function H(z) for each case. (b) Find the impulse response hk, k ¼ 0, 1, 2, 3, . . . for each case. (c) Graph the impulse response for each case. (a) (i) (a ¼ 0.25, b ¼ 0.5). The polar coordinates of the transfer function poles are r ¼ [(0:25)2 þ (0:5)2 ]1=2 ¼ 0:5990,

u ¼ tan1

0:5 ¼ 2:0344 rad 0:25

Q(z) ¼ z2 (2r cos u)z þ r2 ¼ z2 [2(0:5990) cos (2:0344)]z þ (0:5990)2 ¼ z2 þ 0:5z þ 0:3125 ) H(z) ¼

z2 þ 3z z2 þ 3z ¼ 2 Q(z) z þ 0:5z þ 0:3125

pﬃﬃﬃ z2 þ 3z (ii) (a ¼ 0:5, b ¼ 0:5 3) ) r ¼ 1, u ¼ 1:0472 rad, H(z) ¼ 2 z zþ1 (iii) (a ¼ 1, b ¼ 1) ) r ¼

pﬃﬃﬃ 2,

u¼

p z2 þ 3z rad, H(z) ¼ 2 4 z 2z þ 2

(4:625) (4:626) (4:627)

(b) (i) c1 ¼

Ar cos u þ B 1(0:5990) cos (2:0344) þ 3 ¼ ¼ 5:5, c2 ¼ A ¼ 1 r sin u 0:5990 sin (2:0344)

The constants c1 and c2 for (ii) and (iii) are determined in similar fashion. From Equation 4.623, the impulse responses are (i) hk ¼ (0:5990)k [5:5 sin (2:0344k) þ cos (2:0344k)],

k ¼ 0, 1, 2, 3,

(ii) hk ¼ 4:0415 sin (1:0472k) þ cos (1:0472k), k ¼ 0, 1, 2, 3, pﬃﬃﬃk kp kp þ cos , k ¼ 0, 1, 2, 3, (iii) hk ¼ ( 2 ) 4 sin 4 4

(4:628) (4:629) (4:630)

(c) Graphs of the impulse responses in Equations 4.628 through 4.630 are shown in Figure 4.67. The discrete-time system with poles located inside the Unit Circle is BIBO stable. The impulse response given in Equation 4.628 satisﬁes the necessary and sufﬁcient condition for BIBO stability in Equation 4.591. Poles of the transfer functions in Equations 4.626 and 4.627 are situated on the Unit Circle and outside it, respectively. Neither system is BIBO stable.

Simulation of Dynamic Systems with MATLAB® and Simulink®

266

hk

2

Poles of H(z) at z = −0.25 ± j0.5

0

−2

0

1

2

hk

5

3

4

5

6

7

8

9

10

7

8

9

10

7

8

9

10

Poles of H(z) at z = 0.5 ± j0.5√3

0

−5 0

1

2

3

4

5

6

150 hk

100

Poles of H(z) at z = 1 ± j

50 0 −50

FIGURE 4.67

0

1

2

3

4

5 k

6

Impulse responses for discrete-time systems with different complex poles of H(z).

Consider a system with a pair of complex poles of H(z) on the Unit Circle at e ju. Its response to the bounded input uk ¼ sin ku, k ¼ 0, 1, 2, 3, . . . is obtained from N(z) sin u z (z e ju )(z eju ) z2 (2 cos u)z þ 1

(4:631)

¼

N(z) sin u z (z e ju )(z eju ) (z e ju )(z eju )

(4:632)

¼

sin u zN(z) (z e ju )2 (z eju )2

(4:633)

Y(z) ¼ H(z)U(z) ¼

It is left as an exercise to show that yk contains a linear combination of the terms, cos ku, sin ku, k cos ku, and k sin ku. Consequently, the response is unbounded, and the system is not BIBO stable. When a real pole of H(z) is located on the Unit Circle at z ¼ 1 or z ¼ þ1, and the input is uk ¼ (1)k, k ¼ 0, 1, 2, 3, or the unit step uk ¼ 1, k ¼ 0, 1, 2, 3, . . . , respectively, the response is unbounded due to the presence of (z þ 1)2 or (z 1)2 in the denominator of the output Y(z). The ﬁrst case results in the term k(1)k (multiplied by a constant) appearing in the output. In the second case, yk contains a term proportional to k(1)k ¼ k (see Example 4.30, part [b]). We conclude this section with a simulation of the continuous-time control system in Figure 4.68.

R(s)

E(s) –

KP +

KI s

GC (s)

FIGURE 4.68

U(s)

Kωn2 s2+2ζωn s+ωn2 G(s)

P–I control of a second-order continuous-time process.

Y(s)

267

Linear Systems Analysis

The analog P–I (Proportional–Integral) controller GC(s) is approximated by a discrete-time controller with transfer function GC(z) based on the use of trapezoidal integration. It was shown in Section 4.4.7 that the z-domain transfer function of a trapezoidal integrator is T zþ1 HI (z) ¼ 2 z1

(4:634)

And, therefore, GC(z) is obtained by replacing s with 1=HI(z), that is, GC (z) ¼ KP þ

KI

s s

¼ (2=T)((z1)=(zþ1))

(2KP þ KI T)z 2KP þ KI T 2(z 1)

(4:635)

Several discrete-time approximations to the second-order system in Figure 4.68 were developed in Section 4.4.7. Explicit Euler approximation resulted in G(z) ¼

Y(z) K(vn T)2 ¼ 2 U(z) z 2(1 zvn T)z þ 1 2zvn T þ (vn T)2

(4:636)

The block diagram of the discrete-time system intended to simulate the continuous-time control system is shown in Figure 4.69. The closed-loop transfer function is H(z) ¼

Y(z) GC (z)G(z) ¼ R(z) 1 þ GC (z)G(z)

(4:637)

and the poles of H(z) are the roots of the characteristic equation D(z) ¼ 1 þ GC (z)G(z) ¼ 0

(4:638)

Substituting Equations 4.635 and 4.636 into Equation 4.638 yields D(z) ¼ z3 þ a1 z2 þ a2 z þ a3 ¼ 0

(4:639)

9 a1 ¼ 3 þ 2zvn T = a2 ¼ 3 4zvn T þ (vn T)2 [1 þ K(Kp þ 0:5K1 T)] ; a3 ¼ 12zvn T þ (vn T)2 [1 þ K(Kp þ 0:5K1 T)]

(4:640)

where

Table 4.9 summarizes the results for different combinations of continuous-time second-order systems, controllers, and integration step size. The continuous-time system and discrete-time poles are shown in Figure 4.70. All three continuous-time control systems are stable since the poles are located in the left-half plane. The discrete-time systems for simulating them, however, are not all BIBO stable. In fact, the discretetime systems in Rows 2 and 3 in Table 4.9 possess a pair of complex poles located on the Unit Circle and outside it, respectively.

E(z)

R(z) –

FIGURE 4.69

GC (z)

Block diagram of discrete-time system.

U(z)

G(z)

Y(z)

Simulation of Dynamic Systems with MATLAB® and Simulink®

268

TABLE 4.9 Continuous- and Discrete-Time Control System Poles System Parameters and Integration Step Size

Mag of H(z) Complex Poles

Poles of H(s)

Poles of H(z)

K ¼ 1, vn ¼ 10, z ¼ 1:0 KP ¼ 0:5, KI ¼ 2 T ¼ 0:05

9:1616 j5:9448 1:6768

0:5398 j0:3201 0:9205

0:628

K ¼ 1, vn ¼ 5, z ¼ 0:5124 KP ¼ 1, KI ¼ 3 T ¼ 0:075

1:7133 j6:4225 1:6975

0:8674 j0:4979 0.8808

1.000

K ¼ 1, vn ¼ 20, z ¼ 0:15 KP ¼ 1, KI ¼ 3 T ¼ 0:025

2:2436 j28:0745 1:5128

0:9436 j0:7085 0:9629

1:180

Imaginary axis

H(s) poles, row 1

H(s) poles, row 2

5

5

20

0

0

0

−5

−5

− 20

−10

0 −5 Real axis

5

−10

Imaginary axis

H(z) poles, row 1

0 −5 Real axis

5

−10

H(z) poles, row 2 1

1

0

0

0

−1

−1

−1

0 1 Real axis

−1

0 1 Real axis

0 −5 Real axis

5

H(z) poles, row 3

1

−1

FIGURE 4.70

H(s) poles, row 3

−1

0 1 Real axis

Continuous- and discrete-time system poles for rows 1, 2, 3 in Table 4.9.

It is important to keep in mind that while the discrete-time system approximation in Row 1 of Table 4.9 is stable, its accuracy in approximating the continuous-time system response to various inputs is another matter. Suppose the input to the control system in Figure 4.68 is r(t), t 0 and the output is y(t), t 0. If the discrete-time system response to rk ¼ r(kT), k ¼ 0, 1, 2, . . . is yk, k ¼ 0, 1, 2, . . . , an accurate simulation requires that yk y(kT), k ¼ 0, 1, 2,. . . . The locations of the continuous- and discrete-time poles corresponding to Row 1 in Figure 4.70 imply that the natural responses consist of a monotonically decaying and damped oscillatory modes. The question still remains whether the time constants and damped natural frequencies are comparable. A thorough examination of this point is deferred to a later chapter; however, we can gain insight by looking at the step responses of each system.

269

Linear Systems Analysis 1 0.75 0.5 0

Continuous-time Discrete-time

T = 0.01 s

0.25 0

0.25

0.5

0.75

1

1.25

1.5

1.75

2

2.25

2.5

1 0.75 0.5 0

Continuous-time Discrete-time

T = 0.05 s

0.25 0

0.25

0.5

0.75

1

1.25

1.5

1.75

2

2.25

2.5

1 0.75 0.5 0

Continuous-time Discrete-time

T = 0.1 s

0.25 0

0.25

0.5

0.75

1

1.25 1.5 Time (s)

1.75

2

2.25

2.5

FIGURE 4.71 Unit step response of continuous-time system (Figure 4.68) and discrete-time system (Figure 4.69) with T ¼ 0.01, 0.05, 0.1 s.

Example 4.32 Find and graph the unit step response of the continuous-time system in Figure 4.68 (K ¼ 1, vn ¼ 10, z ¼ 1.0, KP ¼ 0.5, KI ¼ 2) and the discrete-time system shown in Figure 4.69 with integration step size T ¼ 0.01, 0.05, 0.1 s. The step responses are computed in M-ﬁle ‘‘Chap8_Ex8_3.m’’ and shown in Figure 4.71. The top graph is a plot of every fourth point of the discrete-time system step response. The discrete-time system is stable for all three values of integration step size T and the steadystate values are identical to the continuous-time steady-state value. However, the transient response of the discrete-time system when T ¼ 0.1 s varies considerably from the continuoustime system transient response.

EXERCISES 4.59 Find the poles of the z-domain transfer functions H(z) below, and comment on the stability of the corresponding discrete-time systems. z2 þ 2z 4z2 3z þ 1 (b) (c) 3 (a) z3 (3=2)z2 þ (3=4)z (1=8) 32z3 16z2 22z þ 1 4z 3z þ 1 z4 z 1 z3 þ 2z2 þ z (d) (e) (f) 16z4 28z3 þ 22z2 8z þ 1 4z4 þ 3z2 1 2z3 5z2 þ 6z 2 P1 4.60 Prove k¼0 jhk j < 1 is a sufﬁcient condition for BIBO stability of an LTI discrete-time system.

270

Simulation of Dynamic Systems with MATLAB® and Simulink®

4.61 A discrete-time system is described by the difference equation 4yk 3yk2 þ yk3 ¼ uk ,

k ¼ 0, 1, 2, 3, . . .

(y1 ¼ y2 ¼ y3 ¼ 0)

(a) Find the weighting sequence hP k, k ¼ 0, 1, 2, 3, . . . of the system. (b) Check whether the condition 1 k¼0 jhk j < 1 is satisﬁed. Is the system stable? (c) Find and graph the system response to the input uk ¼ 1 þ 2(1)k, k ¼ 0, 1, 2, 3,. . . . 4.62 Show the work required to establish Equations 4.608 through 4.610 in part (b) and Equations 4.613 through 4.615 in part (c) of Example 4.30. 4.63 Find the inverse z-transform of Y(z) ¼

( sin u zN(z)) in Equation 4.633. ((z e ju )2 (z eju )2 )

4.64 For a discrete-time system with z-domain transfer function given by H(z) ¼

Y(z) z2 þ z þ 1 ¼ 3 U(z) z 0:5z2 z þ 0:5

(a) Find the zeros and poles of H(z). (b) Find the impulse response sequence hk, k ¼ 0, 1, 2, 3, . . . . (c) Find the unit step response. (d) Find the forced response to uk ¼ (1)k, k ¼ 0, 1, 2, 3, . . . . 4.65 For the control system in Figure 4.68, (a) Find the transfer function HE(s) ¼ E(s)=R(s). (b) Use explicit Euler integration with integration step T to obtain HE(z), an approximation to the continuous-time transfer function HE(s). (c) Assume K ¼ 1, vn ¼ 10, z ¼ 1.0, KP ¼ 0.5, KI ¼ 2, and T ¼ 0.05, and ﬁnd the poles of HE(z). Compare your answer with the results shown in Table 4.9 for the same parameter values. (d) Find the difference equation relating ek and rk, k ¼ 0, 1, 2, 3, . . . . (e) Solve the difference equation when rk ¼ 1, k ¼ 0, 1, 2, 3, . . . . 4.66 For the control system in Figure 4.69 with baseline parameters speciﬁed in the last row of Table 4.9, ﬁnd the poles of H(z) and plot the magnitude of the most distant pole(s) from the origin when (a) z varies from 0 to 2 (b) T varies from 0.01 to 0.5 s (c) KP varies from 0.5 to 5 (d) vn varies from 5 to 50 rad=s 4.67 End-of-month deposits dk, k ¼ 0,1, 2, 3, . . . are placed in an investment account paying interest at a rate of i per month. The initial account balance is P0. The difference equation for Pk, the account balance after k months, is Pkþ1 ¼ (1 þ i)Pk þ dkþ1 ,

k ¼ 0, 1, 2, 3, . . .

(a) Find the z-domain transfer function H(z) ¼ P(z)=D(z) and its pole. Hint: Use the left shifting property, z{Pkþ1} ¼ zP(z) zP0. Comment on the stability of the discrete-time system. (b) Sketch Pk, k ¼ 0, 1, 2, 3, . . . when no deposits are made and i > 0. Repeat for i < 0.

271

Linear Systems Analysis

(c) Find the general solution for Pk, k ¼ 1, 2, 3, . . . when 0, k ¼ 0 (i) dk ¼ D, k ¼ 1, 2, 3, . . . 0, k ¼ 0, 2, 4, . . . (ii) dk ¼ D, k ¼ 1, 3, 5, . . . ( 0, k¼0 (iii) dk ¼ 2D, k ¼ 1, 3, 5, . . . D, k ¼ 2, 4, 6, . . . 4.68 Figure E4.68 shows the relationship between acceleration, velocity, and position of a particle moving along a straight line. A(s)

1 s

V(s)

t

v(t) = ∫ a(t΄) dt΄ 0

1 s

X(s)

t

x(t) = ∫ ν(t΄) dt΄ 0

FIGURE E4.68

(a) Write the differential equations relating v(t) and a(t), x(t) and v(t), and x(t) and a(t). (b) Use trapezoidal integration to approximate the three differential equations. That is, ﬁnd the difference equations relating vk and ak, xk and vk, and xk and ak. (c) Find the poles of the three transfer functions V(z)=A(z), X(z)=V(z), and X(z)=A(z). Comment on the stability of each. (d) Suppose the acceleration is given by 8 t, > < 1, a(t) ¼ > : 3 t, 0,

0t > : 12 0, k ¼ 13, 14, . . .

hk ¼

(4:700)

(4:701)

From Equation 4.693, the ﬁrst-order IIR low-pass digital ﬁlter impulse response is hk ¼ (1 a)ak ,

k ¼ 0, 1, 2, 3, . . .

(4:702)

Based on the convolution sum for the output of a discrete-time system, the FIR ﬁlter output depends solely on the past 12 inputs (not surprising) while the inﬁnite memory IIR ﬁlter output relies on the entire set of past inputs.

289

Linear Systems Analysis

Choosing a ¼ 0.99 places the pole of H(z) precariously close to the Unit Circle, the stability boundary in the z-plane. As a consequence, discrete-time input signals with poles near z ¼ 0.99, for example, a step input with pole at z ¼ 1, are readily passed. The transient response period is considerable since the natural mode ak ¼ 0.99k takes a long while to decay to zero. In Figure 4.86, if we arbitrarily assume the transient period to be 150 months [0.99150 ¼ 0.22], the estimated slope of the linear rise in lake temperature is computed as m2 ¼

(T^300 T^150 ) F 69:179 66:649 F ¼ ¼ 0:202 (300 150) months 1=12 year=month 12:5 year

(4:703)

which is close to the value obtained using the FIR smoothing ﬁlter.

EXERCISES 4.70 Repeat Example 4.33 using implicit Euler instead of explicit Euler integration for approximating the continuous-time system. 4.71 A second-order system with damping ratio z and natural frequency vn is simulated using trapezoidal integration. The DC gain of the system is unity. (a) Find the discrete-time frequency response function H(e jvT). Leave your answer in terms of z, vn, T, and v. (b) Draw a Bode plot of H(e jvT) when the continuous-time system poles are as shown in Figure E4.71. Assume vnT ¼ 0.1. Im j2

Im

Im j4

j1 Re

Re −1

−5

Re

−1 −j4

(a)

(b)

(c)

FIGURE E4.71

4.72 The electrical circuit shown in Figure E4.72 is that of a biquad ﬁlter, so named because the transfer function from the input to the output contains quadratic factors in the numerator and denominator. The differential equation of the circuit is C2 R + e1 −

R + C1

e0 −

FIGURE E4.72

a2€e0 þ a1 e_ 0 þ a0 e0 ¼ b2€e1 þ b1 e_ 1 þ b0 e1 where the constants a0, a1, a2 and b0, b1, b2 are related to R, C1, C2 by a0 ¼ 1,

a1 ¼ RC1 þ 2RC2 , a2 ¼ RC1 RC2 , b0 ¼ 1,

b1 ¼ 2RC2 ,

b2 ¼ RC1 RC2

Simulation of Dynamic Systems with MATLAB® and Simulink®

290

(a) Find the transfer function G(S) ¼ E0(S)=E1(S). (b) A discrete-time system approximation based on trapezoidal integration has a z-domain transfer function G(z) given by G(z) ¼

b 2 z 2 þ b 1 z þ b0 a 2 z 2 þ a 1 z þ a0

Show that b0 ¼ 4t1 t2 4t2 T þ T 2 ,

b1 ¼ 8t1 t2 þ 2T 2 ,

b2 ¼ 4t1 t2 þ 4t2 T þ T 2

a0 ¼ 4t1 t2 2(t1 þ 2t2 )T þ T 2 , a1 ¼ 8t1 t2 þ 2T 2 a2 ¼ 4t1 t2 þ 2(t1 þ 2t2 )T þ T 2 where t1 ¼ RC1 and t2 ¼ RC2 and T is the integration step size. (c) Draw a Bode plot for the discrete-time frequency response G(e jvT) when t1 ¼ 0.1 s, t2 ¼ 0.001 s, and T ¼ 2 104 s. (d) Fill in the following table. v, rad=s

jG( jv)j

jG(e jvT)j

Arg[G( jv)]

Arg[G(e jvT)]

0 5 100 5000

4.73 An analog signal r(t) is the command input to a digital control system, part of which is shown in Figure E4.73. The signal r(t) must be sampled and converted to a discrete-time signal for use by the digital controller. The command input consists of a signal component s(t) and a high-frequency (compared to the sampling rate 1=Ts) noise component n(t). An antialiasing ﬁlter is inserted before sampling to eliminate aliasing in ^rk the input to the controller. s(t)

r(t)

Antialiasing filter

ˆr(t)

Ts

ˆrk Digital controller

yk

n(t) = N sin ωt

Ts

Sensor

uk

y(t)

FIGURE E4.73

A fourth-order Butterworth low-pass ﬁlter is chosen. The transfer function is G(s) ¼

^ R(s) ¼ R(s)

v2n s2 þ 2 cos (pvn =8)s þ v2n

v2n s2 þ 2 cos (3pvn =8)s þ v2n

(a) The control system sampling rate is 1000 Hz. Find the Nyquist frequency vN. (b) Find vn, so that the magnitude of G( jv) is 60 db at the Nyquist frequency. Hint: Use trial and error guesses for vn along with Bode plots until the condition jG( jvN)j ¼ 60 db is approximately satisﬁed.

291

Linear Systems Analysis

(c) The signal and noise components of the command input r(t) are s(t) ¼ 1, t 0 and n(t) ¼ 5 103 sin(2 106t), t 0. Find the ﬁlter output ^r (t) at steady state. (d) Find G(z), the z-domain transfer function of the discrete-time system approximation to G(s) using explicit Euler integration. Leave your answer in terms of the integration step size T. (e) Comment on the choice of T necessary to simulate the ﬁlter response by recursive solution of the difference equation corresponding to G(z). 4.74 A method for approximating a continuous-time system with transfer function G(s) is illustrated in Figure E4.74. A continuous-time input u(t) is sampled every T s to produce the discrete-time input uk. A zero-order hold (ZOH) reconstructs a piecewise continuous approximation to u(t) denoted û(t), which is the input to the continuous-time system. The continuoustime output y(t) is sampled every T s resulting in the discrete-time output yk. The discrete-time system with input uk and output yk serves as an approximation to the continuous-time system with input u(t) and output y(t). The z-domain transfer function of the discrete-time system is (Jacquot) uk

t

k uk

yk

y(t)

u(t) ˆ

u(t)

t

T

G(s)

ZOH

t yk

G(z)

FIGURE E4.74

G(z) ¼

Y(z) ¼ U(z)

z1 G(s) z L1 z s

where z{L1[G(s)=s]} stands for the z-transform of the discrete-time signal resulting from sampling the continuous-time signal L1 [G(s)=s]. (a) Find the z-domain transfer function using the ZOH approximation method when the continuous-time system is ﬁrst order with transfer function G(s) ¼ 1=(ts þ 1). Leave your answer in terms of the time constant t and sampling period T. (b) Find the discrete-time frequency response function G(e jvT), and obtain expressions for the magnitude jG(e jvT)j and phase Arg[G(e jvT)]. (c) Plot the magnitude and phase of G(e jvT) when t ¼ 1 s and T ¼ 0.1 s. (d) Compare the continuous- and discrete-time unit step responses and comment on the results. (e) Find jG(e jvT)j and Arg[G(e jvT)] and compare with the values given in Table 4.10 where t ¼ 5 s and T ¼ 0.25 s. 4.75 Derive Equation 4.698 for the cutoff frequency of the ﬁrst-order low-pass digital ﬁlter with z-domain transfer function H(z) ¼ (1 a)z=(z a). 4.76 A notch ﬁlter is designed to attenuate input signals at one speciﬁc frequency called the notch frequency. The transfer function of a notch ﬁlter is G(s) ¼

s2 þ v2n (vn is notch frequency) s2 þ 2Bvn s þ v2n

Simulation of Dynamic Systems with MATLAB® and Simulink®

292

(a) Find G(z), the z-domain transfer function of a digital ﬁlter obtained by approximation of G(s) using trapezoidal integration. Leave your answer in terms of z, vn and the integration step size T. (b) The digital ﬁlter is to be used to ﬁlter out the monthly lake temperature ﬂuctuations in Example 4.35. The notch frequency is vn ¼ p=6 rad=month and the sampling period is T ¼ 1 month. On the same graph, plot jG(e jvT)j vs. v from zero to the Nyquist frequency for z ¼ 0.25, 0.5, 0.75. (c) Choose the value of z, which produces the largest attenuation at the notch frequency, and use the digital notch ﬁlter to ﬁlter out the monthly lake temperature ﬂuctuations in the dataset ‘‘Chap4_LakeTemp.mat.’’ Prepare a graph similar to the ones in Figures 4.84 and 4.86. 4.77 The design of a digital ﬁlter calls for the placement of a pair of poles and zeros as shown in Figure E4.77.

Unit Circle z1 rz φ

p1

rp θ

p2 z2

FIGURE E4.77

(a) Find the difference equation relating the ﬁlter’s input u(n) and output y(n). The ﬁlter coefﬁcients should be expressed in terms of rp, u, rz, and f. (b) Express the magnitude function jH(e jvT )j in terms of the parameters rp , u, rz , f and the sampling time T. (c) Plot the magnitude function for the case when T ¼ 1 s, rp ¼ 0:9, rz ¼ 2, f ¼ p=4 and u ¼ 0:2, 0:4, 0:6, 0:8, 1 rad. Comment on the results.

4.10 CONTROL SYSTEM TOOLBOX This chapter has emphasized analytical methods for obtaining continuous- and discrete-time system response to elementary types of inputs. In this section, we explore the use of MATLAB functions in the control system toolbox designed to facilitate the process of modeling and simulation of LTI dynamic systems. The control system toolbox is a supplement to MATLAB. The reader is encouraged to check out the entire suite of available functions either online or in the control system toolbox lab manual (from The Mathworks, Inc.). Many of the functions are discussed and illustrated in recent linear controls texts and companion lab manuals (D’Azzo and Houpis, 1995; Ogata 1998; Nekoogar 1999; Dorf and Bishop 2005). Continuous- and discrete-time transfer functions are deﬁned by specifying numerator and denominator polynomials in vector form. SISO and MIMO dynamic systems portrayed in block diagram form can be reduced to obtain speciﬁc transfer functions, which can be analyzed (by other control system toolbox functions) in the time and frequency domain. Impulse and step responses as well as responses to arbitrary inputs of both types of systems are easily obtained. The z-domain transfer functions for simulating continuous-time systems based on various methods of approximation

293

Linear Systems Analysis

are available. Conversion between state-space and transfer function descriptions of a system is accomplished using speciﬁc toolbox commands. This section contains some relatively simple examples of the control system toolbox functions. Exposition is kept to a minimum. For more information, the reader should check out the robust set of online interactive demos, tutorials, and case studies illustrating how the toolbox can be used to support modeling and simulation functions.

4.10.1 TRANSFER FUNCTION MODELS Continuous- and discrete-time transfer functions are constructed using ‘‘tf’’ with proper arguments and stored as a named MATLAB object such as ‘‘sys.’’ For example, the transfer function (10s þ 1)(s þ 2) (4:704) G1 (s) ¼ 25 4 2s þ 5s3 þ 4s þ 1 is implemented by the following statements: num ¼ 25*conv([10 1],[1 2]) den ¼ [2 5 0 4 1] sys_G1 ¼ tf (num, den) Note conv([10 1],[1 2]) produces the numerator vector [10 21 2]. A more intuitive way of creating the same transfer function is s ¼ tf(’s’) sys_G1 ¼ 25*(10*s^2þ21*sþ2)=(2*s^4þ5*s^3þ4*sþ1) A discrete-time system with sampling period T ¼ 0.01 s and pulse (z-domain) transfer function G2 (z) ¼

5z2 þ 3z þ 2 z2 þ 10z þ 4

(4:705)

is created from either of the two sets of statements below: num ¼ [5 3 2]; den ¼ [1 10 4] sys_G2 ¼ tf (num, den, 0.01) z ¼ tf(’z’,0.01) sys_G2 ¼ (5*z^2þ3*zþ2)=(z^2þ10*zþ2) The poles and zeros of a continuous- or discrete-time system transfer function are obtained using the ‘‘pzmap (sys)’’ command where ‘‘sys’’ refers to the MATLAB description of the transfer function. A pole-zero map of the transfer function G1(s) in Equation 4.704 is obtained from the command ‘‘pzmap (sys_G1)’’ and shown in Figure 4.87. The numerical values of the poles and zeros shown in Figure 4.87 are returned in ‘‘P’’ and ‘‘Z’’ after issuing the command ‘‘[P,Z] ¼ pzmap (sys_G1).’’ The result is P ¼ 2:7418, 0:2385 þ 0:8475i 0:2385 0:8475i, 0:2353 Z ¼ 2:0000, 0:1000

4.10.2 STATE-SPACE MODELS State-space models of continuous-time systems are described by matrices A, B, C, and D appearing in the state equations. The same holds for a discrete-time system, which also requires a sampling

Simulation of Dynamic Systems with MATLAB® and Simulink®

294 1 0.8 0.6 Imaginary axis

0.4 0.2 0 −0.2 −0.4 −0.6 −0.8 −1 −3

FIGURE 4.87

−2.5

−2

−1.5 −1 Real axis

−0.5

0

0.5

Pole-zero map for G1(s) in Equation 4.704.

time T for a complete representation. State-space models for continuous-time systems are created using ‘‘sys ¼ ss(A,B,C,D),’’ while discrete-time models in state space are generated by ‘‘sys ¼ ss(A,B,C,D,T).’’ A continuous-time second-order system with damping ratio z ¼ 0.5 and natural frequency vn ¼ 2 rad=s was approximated using trapezoidal integration with step size T ¼ 0.025 s in Section 4.7 resulting in discrete-time system state equations x kþ1 ¼ Axk þ Buk

(4:706)

y k ¼ Cxk þ Duk

(4:707)

with A, B, C, and D given in Equations 4.516 through 4.518. The resulting matrices A, B, C, and D and sampling time T appear in the M-ﬁle ‘‘Chap4_Tustin.m’’ statement ‘‘sys ¼ ss(A,B,C,D,T)’’ to create a discrete-time system state-space model with numerical values a ¼ x1 x2

x1 1.949 1

x1 x2

u1 1 0

y1

x1 0.002406

y1

u1 0.0006094

x2 0.9512 0

b ¼

c ¼

d ¼

Sampling time: 0.025 discrete-time model.

x2 2.971e-005

295

Linear Systems Analysis

The object ‘‘sys’’ can be referenced by other control system toolbox commands to investigate frequency response characteristics of the discrete-time system as well as dynamic response to speciﬁc types of forcing functions. It is also instrumental in the process of converting a statespace model to a transfer function representation, the next subject of discussion.

4.10.3 STATE-SPACE=Transfer Function Conversion The state equations for a submarine depth control system were developed in Section 2.8. The closed-loop control system is third order with three outputs, u (stern plane angle), v (depth rate), c (depth), and a single input r (commanded depth). The MATLAB ﬁle ‘‘Chap4_sub.m’’ below illustrates several commands for converting between state-space models of the system and the transfer function form.

% Chap4_sub.m KC ¼ 0.6; KI ¼ 0.1; tau ¼ 10; Kthd ¼ 20; Kth ¼ 10; a11 ¼ –Kthd*KC=tau; a12 ¼ (Kth– (Kthd=tau)); a13 ¼ Kthd*KI=tau; a21 ¼ –KC=tau; a22 ¼ –1=tau; a23 ¼ KI=tau; a31 ¼ –1; a32 ¼ 0; a33 ¼ 0; b1 ¼ Kthd*KC=tau; b2 ¼ KC=tau; b3 ¼ 1; c11 ¼ –KC; c12 ¼ 0; c13 ¼ KI; c21 ¼ –Kthd*KC=tau; c22 ¼ Kth– (Kthd=tau); c23 ¼ Kthd*KI=tau; c31 ¼ 1; c32 ¼ 0; c33 ¼ 0; d1 ¼ KC; d2 ¼ Kthd*KC=tau; d3 ¼ 0; A1 ¼ [a11 a12 a13; a21 a22 a23; a31 a32 a33]; B1 ¼ [b1; b2; b3]; C1 ¼ [c11 c12 c13; c21 c22 c23; c31 c32 c33]; D1 ¼ [d1; d2; d3]; sys_ss_1 ¼ ss(A1,B1,C1,D1)% sys_tf ¼ tf(sys_ss_1)% [num1,den1] ¼ ss2tf(A1,B1,C1,D1)%

sys_ss_2 ¼ ss(sys_tf)% [A3,B3,C3,D3] ¼ tf2ss(num1,den1)%

[num2,den2] ¼ ss2tf(A3,B3,C3,D3)%

creates state-space system object for (A1,B1,C1,D1) converts state-space system object to transfer function system object alternate method for converting state space (A1,B1,C1,D1) to transfer function converts transfer function object to state-space object converts transfer function to state-space control canonical form with matrices (A3,B3,C3,D3) converts state-space (A3, B3,C3,D3) to transfer functions

Simulation of Dynamic Systems with MATLAB® and Simulink®

296

Numerical values are assigned to matrices A1, B1, C1, and D1 using the baseline system parameter values from Section 2.8. The system matrices are A1 ¼

B1 ¼

C1 ¼

D1 ¼

1.2000 0.0600 1.0000 1.2000 0.0600 1.0000 0.6000 1.2000 1.0000 0.6000 1.2000 0

8.0000 0.1000 0

0.2000 0.0100 0

0 8.0000 0

0.1000 0.2000 0

The statement ‘‘sys_ss_1 ¼ ss(A1,B1,C1,D1)’’ creates the object ‘‘sys_ss_1’’ associated with the continuous-time system matrices A1, B1, C1, and D1. The next statement ‘‘sys_tf’’ (sys_ss_1)’’ creates the transfer function object ‘‘sys_tf’’ with embedded information about the three system transfer functions, one each from the command input to the three outputs. The transfer functions are displayed as Transfer function from input to output . . . 0.6 s^3 þ 0.16 s^2 þ 0.01 s 1.506e-018 #1: —————————s^3 þ 1.3 s^2 þ 0.8 s þ 0.1 1.2 s^3 þ 0.8 s^2 þ 0.1 s 3.474e-017 #2: —————————– s^3 þ 1.3 s^2 þ 0.8 s þ 0.1 1.2 s^2 þ 0.8 s þ 0.1 #3: —————————– s^3 þ 1.3 s^2 þ 0.8 s þ 0.1 Note that the ﬁrst two transfer functions are consistent with the control system simulation diagram (Figure 2.55), which shows direct paths from the input r to outputs u and v. The numerator of transfer function #3 is second order due to the presence of the integrator in the path from r to c. An alternative approach to ﬁnding the same three transfer functions uses ‘‘[num1,den1] ¼ ss2tf(A1,B1,C1,D1).’’ Output matrix ‘‘num1’’ (with three rows, one for each output) stores the coefﬁcients of the three numerator polynomials, and row vector ‘‘den1’’ contains the coefﬁcients of the denominator, that is, characteristic polynomial. The result is numl ¼

denl ¼

0.6000 1.2000 0 1.0000

0.1600 0.8000 1.2000 1.3000

0.0100 0.1000 0.8000 0.8000

0.0000 0.0000 0.1000 0.1000

297

Linear Systems Analysis

Converting the transfer function of an SISO system to a state-space model is achieved using either ‘‘ss’’ or ‘‘tf2ss.’’ The command ‘‘sys_ss_2 ¼ ss(sys_tf)’’ computes a state-space realization of the transfer function object ‘‘sys_tf’’ displayed as a ¼ x1 x2 x3

x1 1.3 2 0

x1 x2 x3

u1 1 0 0

y1 y2 y3

x1 0.62 0.76 1.2

y1 y2 y3

u1 0.6 1.2 0

x2 0.4 0 0.5

x3 0.1 0 0

x2 0.235 0.43 0.4

x3 0.06 0.12 0.1

b ¼

c ¼

d ¼

Referring to the above matrices as A2, B2, C2, and D2, it is not surprising that they differ from A1, B1, C1, and D1 since the state-space model representation of a continuous-time system is not unique. An alternative method for creating a state-space model from a transfer function is to use ‘‘[A3,B3,C3,D3] ¼ tf2ss(num1,den1)’’ where ‘‘num1’’ and ‘‘den1’’ are the numerator and denominator arrays, respectively, created previously by the command ‘‘ss2tf.’’ This results in creation of output matrices A3, B3, C3, and D3 given below: A3 ¼

B3 ¼

C3 ¼

D3 ¼

1.3000 1.0000 0 1 0 0 0.6200 0.7600 1.2000 0.6000 1.2000 0

0.8000 0 1.0000

0.1000 0 0

0.4700 0.8600 0.8000

0.0600 0.1200 0.1000

State-space models created by ‘‘tf2ss’’ are in controller canonical form (Ogata 1998). The last statement [num2,den2] ¼ ss2tf(A3,B3,C3,D3) in ‘‘Chap4_sub.m’’ converts the state-space model in controller canonical form back to the three transfer functions.

Simulation of Dynamic Systems with MATLAB® and Simulink®

298

TABLE 4.11 Three Different State-Space Models of Submarine Depth Control System i

Ai

2

1:2 4 0:06 1 2 1:3 4 2 0 2 1:3 4 1 0

1

2

3

3

2

8 0:2 0:1 0:01 5 0 0 3 0:4 0:1 0 0 5 0:5 0 3 0:8 0:1 0 5 0 1 0

Bi

3

2

0:6 4 1:2 1 2 0:62 4 0:76 1:2 2 0:62 4 0:76 1:2

1:2 4 0:06 5 1 2 3 1 405 0 2 3 1 405 0

Ci 0 8 0

3

2

0:1 0:2 5 0

3 0:235 0:06 0:43 0:12 5 0:4 0:1 3 0:47 0:06 0:86 0:12 5 0:80 0:1

Di

3 0:6 4 1:2 5 0 2 3 0:6 4 1:2 5 0 2 3 0:6 4 1:2 5 0

The state-space models for the submarine control system are summarized in Table 4.11. A good way of checking the results is to compute the eigenvalues of the coefﬁcient matrices A1, A2, and A3 in the table. The MATLAB command ‘‘eig(A)’’ returns the same characteristic roots, namely, 0.5687 j0.5400 and 0.1626, for all three matrices.

4.10.4 SYSTEM INTERCONNECTIONS Block diagrams can be systematically reduced in complexity using control system toolbox functions such as ‘‘parallel,’’ ‘‘series,’’ and ‘‘feedback.’’ Consider the block diagram shown in Figure 4.88.

10s þ 1 Gc (s) ¼ 5 , 2s þ 1 G1 (s) ¼

8 , 3s þ 1

G2 (s) ¼

s2

H(s) ¼

1 50s þ 1

(4:708)

sþ5 1 1 , G3 (s) ¼ , G4 (s) ¼ þ 12s þ 25 0:2s þ 1 s

(4:709)

Using block diagram algebra, the transfer function Y(s)=R(s) can be found by executing the statements below found in M-ﬁle ‘‘Chap4_block_diagram.m.’’ 1. 2. 3. 4. 5.

s ¼ tf(’s’); Gc ¼ 5*(10*sþ1)=(2*sþ1); G1 ¼ 8=(3*sþ1); G2 ¼ (sþ5)=(s^2þ12*sþ25); G3 ¼ 1=(0.2*sþ1);

G3(s) R(s) –

Gc(s)

–

G1(s)

G2(s) H(s)

FIGURE 4.88

Block diagram of a continuous-time system.

X(s)

G4(s)

Y(s)

299

Linear Systems Analysis

6. 7. 8. 9. 10. 11. 12. 13.

G4 ¼ 1=s; H ¼ 1=(50*sþ1); G1G2 ¼ series(G1,G2); G1G2_plus_G3 ¼ parallel(G1G2,G3); TF_inner_loop ¼ feedback(G1G2_plus_G3,H) G ¼ series(Gc,TF_inner_loop); G_forward_path_1 ¼ series(G,G4); TF_outer_loop_1 ¼ feedback(G_forward_path_1,1) The inner loop transfer function ‘‘TF_inner_loop’’ and outer loop transfer function TF_outer_loop_1 are Transfer function: 150 s^4 þ 1933 s^3 þ 5189 s^2 þ 3353 s þ 65 --------------------------------------------------------------------------------------------------------------30 s^5 þ 520.6 s^4 þ 2733 s^3 þ 4693 s^2 þ 1445 s þ 90 Transfer function: 7500 s^5 þ 97400 s^4 þ 269095 s^3 þ 193593 s^2 þ 20015 s þ 325 --------------------------------------------------------------------------------------------------------------60 s^7 þ 1071 s^6 þ 1.349e004 s^5 þ 1.095e005 s^4 þ 276678 s^3 þ 195218 s^2 þ 20105 s þ 325

Other transfer functions may be obtained by proper use of the three system interconnection commands. For example, X(s)=R(s) in Figure 4.88 can be found by deleting statement 11 and changing statements 12 and 13 to read 14. G_forward_path_2 ¼ series(Gc,TF_inner_loop); 15. TF_outer_loop_2 ¼ feedback(G_forward_path_2,G4) An alternate implementation of the transfer function X(s)=R(s) is possible by expressing it in terms of Y(s)=R(s). Starting with Y(s) ¼ G4 (s)X(s)

(4:710)

)

Y(s) X(s) ¼ G4 (s) R(s) R(s)

(4:711)

)

X(s) 1 Y(s) ¼ R(s) G4 (s) R(s)

(4:712)

The transfer function X(s)=R(s) can now be obtained by statement 14 below: 16. TF_outer_loop_2 ¼ series(1=G4,TF_outer_loop_1) The functions ‘‘parallel,’’ ‘‘series,’’ and ‘‘feedback’’ to reduce a system with forward and feedback connections apply to discrete-time system block diagrams as well.

4.10.5 SYSTEM RESPONSE The impulse and step response of continuous- and discrete-time LTI systems can be generated in either graphical form or stored in an array of data points. To illustrate, suppose we are interested in the step response of the submarine depth control system considered earlier. Unit step responses of the stern plane angle u, depth rate v, and depth c are obtained by appending ‘‘step (sys_ss_1)’’ or ‘‘step(sys_tf)’’ at the end of M-ﬁle ‘‘Chap4_sub.m.’’ The graphs are shown in Figure 4.89.

Simulation of Dynamic Systems with MATLAB® and Simulink®

300

To: Out(1)

0.6 0.4 0.2 0

To: Out(3)

To: Out(2)

−0.2 1 0.5 0

1 0.5 0

FIGURE 4.89

0

1

2

3

4

5 Time (s)

6

7

8

9

10

1.2

1.4

1.6

1.8

2

1.2

1.4

1.6

1.8

2

Unit-step response in u, v, and c.

Amplitude

1.5 1 0.5 0 0

0.2

0.4

0.6

0.8

(a)

1 Time (s)

Amplitude

10 5 0 −5 0 (b)

FIGURE 4.90

0.2

0.4

0.6

0.8

1 Time (s)

(a) Step and (b) impulse response of continuous-time system in Figure 4.88.

Step and impulse responses of the system in Figure 4.88 with y(t) as output are obtained by issuing the control system toolbox commands ‘‘step(TF_outer_loop_1)’’ and ‘‘impulse (TF_outer_loop_1)’’ in M-ﬁle ‘‘Chap4_block_diagram.m.’’ The step and impulse responses are shown in Figure 4.90. The response of an LTI system to an arbitrary input is obtained using ‘‘LSIM(SYS,U,T)’’ where ‘‘SYS’’ represents a MATLAB system object. ‘‘U’’ and ‘‘T’’ are arrays used to deﬁne the input (s) values and corresponding regularly spaced values of time, respectively.

301

Linear Systems Analysis

The case study in Section 3.7 involved the ascent of a diver subject to a vertical cable force fc. A state-space model was formulated and repeated as follows: 2

x_ 1

2

3

0

6 7 6 6 x_ 2 7 ¼ 6 0 4 5 4 x_ 3 2 4

y1

Kg 3

"

5¼

y2

1

0

g

0

32

2

3

3 0 76 7 6 g 7 6 7 6 7 0 7 54 x2 5 þ 4 W 5[fn ] x3 K 0 2 3 # x1 0 6 7 6 x2 7 4 5 1 x3

1 mg W 0

0

x1

(4:713)

(4:714)

The input fn ¼ W gV fc is the net force (weight – buoyant force – cable force) acting on the diver. The output y1 is depth below the surface, and y2 is the difference between the internal body pressure of the diver and the local (same depth as diver) underwater pressure. The states x1, x2, and x3 are depth, velocity, and internal pressure of the diver, respectively. The system parameters are m, W, and K; and g and g are physical constants. Suppose the diver’s ascent from an initial equilibrium state x1,e ¼ 500 ft, x2,e ¼ 0 ft=s, and x3,e ¼ gx1,e ¼ 62.4 lb=ft3 500 ft ¼ 31,200 lb=ft2 (216.7 psi) is required. A cable force fc (t) ¼ (W gV) þ F(1 et=t ),

t0

(4:715)

where F and t are design parameters is under investigation. The cable force fc(t) and the resulting net force fn(t) are plotted in Figure 4.91 for the case where F ¼ 25 lb and t ¼ 40 s (see M-ﬁle ‘‘Chap4_diver.m.’’) The M-ﬁle ‘‘Chap4_diver.m’’ includes a statement to create the state-space object ‘‘sys’’ from matrices A, B, C, and D in Equations 4.713 and 4.714. The time vector ‘‘t’’ is deﬁned and input 140 135 fc (lb)

130 125 120

_ F = 25 lb, τ = 40 s

115

Effective weight = W − γV = 112.8 lb

110

fn (lb)

(a)

(b)

FIGURE 4.91

0

10

20

30

40

50

60

70

80

90 100 110 120 130 140

0

10

20

30

40

50

60 70 t (s)

80

90 100 110 120 130 140

0 −4 −8 −12 −16 −20 −24

(a) Cable force and (b) net force on diver vs. time.

Simulation of Dynamic Systems with MATLAB® and Simulink®

302

Depth of diver vs. time 500 y1(t), ft

400 300 200 100 0

0

20

40

60

80

100

120

140

Differential pressure (internal diver pressure minus water pressure) vs. time 12 y2(t), psi

10 8 6 4 2 0 0

20

40

60

80

100

120

140

t (s)

FIGURE 4.92

Outputs y1 and y2 from diver state-space model with input fn.

vector ‘‘fn’’ is calculated from the equation fn ¼ (W gV) fc. The statement ‘‘y ¼ LSIM(sys, fn,t,x0),’’ where ‘‘x0’’ is the initial state vector, returns data points for outputs y1 and y2 in the array ‘‘y.’’ Graphs of y1(t) and y2(t) are shown in Figure 4.92.

4.10.6 CONTINUOUS-=DISCRETE-TIME SYSTEM CONVERSION We are well aware of the need to approximate the dynamics of continuous-time systems using discrete-time systems. Replacing the differential equations of LTI continuous-time system models with difference equations is an important aspect of continuous system simulation. Section 4.4.7 introduced a technique for accomplishing the task based on substitution of a suitable function of z for the Laplace variable s in the continuous-time system transfer function. Examples were presented illustrating how to obtain the z-domain transfer function of the discrete-time system based on the use of explicit Euler integration and trapezoidal integration, also known as Tustin’s method. Additional transformations s ¼ f (z) for other methods are discussed in a later chapter. For all but the simplest continuous-time systems, the algebraic manipulation required to obtain the z-domain or pulse transfer function in a suitable form is unwieldy at best. The MATLAB control system toolbox ‘‘c2d’’ function expedites the process of converting continuous-time models to discrete-time approximations. The required arguments are a MATLAB system object for the continuous-time system, the sample time (integration step size), and an optional string to select one of the ﬁve available approximation methods listed below: ‘zoh’ Zero–order hold on the inputs. ‘foh’ Linear interpolation of inputs (triangle appx.). ‘imp’ Impulse–invariant discretization. ‘tustin’ Bilinear (Tustin) approximation. ‘prewarp’ Tustin approximation with frequency prewarping. The critical frequency Wc (rad=sec) is specified as 4th input by SYSD ¼ C2D (SYSC,Ts,‘prewarp’,Wc) ‘matched’ Matched pole-zero method (for SISO systems only).

303

Linear Systems Analysis

To illustrate, consider the problem of approximating a second-order system with natural frequency vn ¼ 2 rad=s, z ¼ 0.5, and DC gain of unity. Example 4.27 presented solutions based on the use of explicit Euler integration and trapezoidal integration (Tustin’s method), also known as the bilinear transform method. The following statements are from the M-ﬁle ‘‘Chap4_Tustin.m,’’ which creates the continuous-time transfer function ‘‘H_s’’ and generates the discrete-time system transfer function ‘‘H_z’’ using Tustin’s method. T ¼ 0.025; wn ¼ 2; zeta ¼ 0.5; K ¼ 1; H_s ¼ tf(K*wn^2,[1 2*zeta*wn wn^2]) H_z ¼ c2d(H_s,T,’tustin’) The continuous- and discrete-time transfer functions appear in the MATLAB Command Window as Transfer function: 4 ------------------s^2 þ 2 s þ 4 Transfer function 0.0006094 z^2 þ 0.001219 z þ 0.0006094 --------------------------------------z^2 – 1.949 z þ 0.9512 Sampling time: 0.025 The pulse transfer function approximation of the continuous-time second-order system using Tustin’s method is (see Equation 4.503) K(vn T)2 (z2 þ 2z þ 1) H(z) ¼ 2 2 4(1 þ zvn T) þ (vn T) z þ 2 (vn T)2 4 z þ 4(1 zvn T) þ (vn T)2

(4:716)

Substituting the numerical values vn ¼ 2, z ¼ 0.5, K ¼ 1, and T ¼ 0.025 for the system parameters gives H(z) ¼ ¼

0:0025(z2 þ 2z þ 1) 4:1025z2 7:9950z þ 3:9025

(4:717)

0:00060938z2 þ 0:0012187z þ 0:00060938 z2 1:9488z þ 0:9512

(4:718)

in agreement with the result from using the ‘‘c2d’’ function. There is also a function called ‘‘d2c’’ for converting a discrete-time transfer function previously created as an object ‘‘sysd’’ to an equivalent continuous-time transfer function object ‘‘sysc.’’ The syntax is ‘‘SYSC ¼ D2C(SYSD,METHOD)’’ where the second argument is a string signifying the method of approximation.

4.10.7 FREQUENCY RESPONSE The magnitude and gain of a system transfer function at a particular frequency v were evaluated in earlier sections by substituting jv for s in continuous-time transfer functions and e jvT for z in discrete-time transfer functions. Choosing a range of values for v led to plots of magnitude, gain ¼ 20(log[magnitude]) and phase vs. frequency.

Simulation of Dynamic Systems with MATLAB® and Simulink®

304

U(s)

FIGURE 4.93

1 (τ1s + 1)n

X1(s)

s τ2s + 1

n

X2(s)

Low- and high-pass ﬁlters in series.

The control system toolbox provides an easier way of obtaining the frequency response characteristics of both continuous- and discrete-time system models. Assuming an LTI model object called ‘‘sys’’ has been created using ‘‘tf’’ or possibly ‘‘ss,’’ a Bode plot is drawn by execution of the command ‘‘BODE(sys).’’ If ‘‘sys’’ represents a discrete-time system, the call is modiﬁed to include an additional argument for the sampling time T, namely, ‘‘BODE(sys,T).’’ Optional arguments permit specifying multiple systems with different line plot characteristics and a user selectable range of frequencies. To illustrate, consider the two blocks in series shown in Figure 4.93. The ﬁrst component is a low-pass ﬁlter with transfer function G1 (s) ¼

X1 (s) 1 ¼ U(s) (t1 s þ 1)n

(4:719)

and break frequency v1 ¼ 1=t1. The second component transfer function X2 (s) ¼ G2 (s) ¼ X1 (s)

s t2 s þ 1

n (4:720)

represents a high-pass ﬁlter with break frequency v2 ¼ 1=t2. The frequency response characteristics of the series combination with transfer function n 1 s (t1 s þ 1)n t2 s þ 1 n s ¼ (t1 s þ 1)(t2 s þ 1)

G12 (s) ¼

(4:721) (4:722)

are obtained using the ‘‘BODE’’ function for a model object ‘‘sys’’ corresponding to Equation 4.722. The following M-ﬁle statements generate plots of the gain (magnitude in db) for the low-pass ﬁlter (t1 ¼ 1 s), high-pass ﬁlter (t2 ¼ 0.01 s), and the band-pass ﬁlter with pass band (v1 v v2) resulting from the combination of the two ﬁlters in series. The plots are shown in Figure 4.94. The exponent n was chosen to be three. tau1 ¼ 1; tau2 ¼ 0.01; n ¼ 3; sys1 ¼ tf(1,[tau1 1]) sys2 ¼ tf([1 0],[tau2 1]) for i ¼ 1:n-1 sysG1 ¼ SERIES(sys1,sys1) sysG2 ¼ SERIES(sys2,sys2) end sysG12 ¼ SERIES(sysG1,sysG2) BODEMAG(sysG1,‘b’,sysG2, ‘r’,sysG12, ‘k’)

305

Linear Systems Analysis Bode diagram 100 75

|G2(jω)|

Magnitude (dB)

50 25 0

|G1(jω)|

|G12(jω)|

−25 −50 −75 −100 −125 −150 10−2

FIGURE 4.94

10−1

10−0 101 102 Frequency (rad/s)

103

104

Gain of individual and combined blocks in Figure 4.93.

A discrete-time approximation of the continuous-time band-pass ﬁlter using Tustin’s method is obtained by adding the statements T ¼ pi=1e4; % sample time to make wN ¼ 10^4 rad=sec sysG12_d ¼ C2D(sysG12,T, ‘tustin’);% converts continuous-time filter % to discrete-time filter using Tustin’s method BODEMAG(sysG12_d, ‘r’) % plot gain of discrete-time filter BODEMAG(sysG12, ‘b’) % plot gain of continuous-time filter The sample time should be at least an order of magnitude less than t2 ¼ 0.01 s and possibly smaller depending on the frequency content of the continuous-time input. A value of T ¼ p=104 s was chosen to make the Nyquist frequency vN ¼ p=T ¼ 104 s, the same as the upper limit in Figure 4.94. Selecting appropriate values of T for discrete-time models is deferred until Chapter 8. A comparison of the continuous-time and discrete-time band-pass ﬁlter gains for (102 v vN ¼ 104) is shown in Figure 4.95. The two gains are nearly identical for v up to 103 rad=s. Frequency response includes phase characteristics as well as gain. The phase properties of the two ﬁlters are left for an exercise problem.

4.10.8 ROOT LOCUS For simple feedback control systems with a controller gain KC, the closed-loop system poles depend on the value of KC. A root-locus plot displays the location of all the poles as the design parameter KC varies from zero to inﬁnity. The starting point is creation of the open-loop system model ‘‘sys’’ followed by a call to the control system toolbox function ‘‘rlocus(sys).’’ The following example illustrates the use of ‘‘BODE’’ and ‘‘rlocus’’ to determine the limits of stability for a simple control system.

Simulation of Dynamic Systems with MATLAB® and Simulink®

306

Bode diagram 0

Magnitude (dB)

−20 −40 −60 |G12(jω)|

−80

|G12(e jωT)|

−100 −120 10−2

FIGURE 4.95

10−1

100 101 102 Frequency (rad/s)

103

104

Gain of continuous- and discrete-time band-pass ﬁlters.

Example 4.36 An overdamped second-order system is subject to proportional control as shown in Figure 4.96. A sensor is present in the feedback loop. Baseline values of the system and sensor parameters are Kp ¼ 15, (a) (b) (c) (d) (e) (f)

t1 ¼ 3 s,

t2 ¼ 15 s,

KT ¼ 0:1,

tT ¼ 0:25 s

Create a model ‘‘sys’’ for the open-loop system with KC ¼ 1. Use the control system toolbox to draw a Bode plot of the open-loop system. Determine the stability margins of the control system and the critical gain Kcr. Find v0, the frequency of oscillations for the marginally stable system. Check the results for Kcr using a root-locus plot and the characteristic equation. Plot step responses of the closed-loop system for KC ¼ 0.25Kcr, 0.5Kcr, 0.75Kcr, Kcr.

(a) The model object ‘‘sys’’ is created in ‘‘Chap4_Ex10_1.m’’ with the statements KP ¼ 15; tau1 ¼ 3; tau2 ¼ 15; KT ¼ 0.5; tauT ¼ 0.25; KC ¼ 1; denG ¼ conv([tau1 1],[tau2 1]) G ¼ tf(KP,denG); % process transfer function denH ¼ [tauT 1]; H ¼ tf(KT,denH); %sensor transfer function sys ¼ KC*SERIES(G,H)

R(s)

KC

KP (τ1 s + 1) (τ2 s + 1) KT (τT s + 1)

FIGURE 4.96

Feedback control system with proportional control.

Y(s)

307

Linear Systems Analysis Bode diagram

Magnitude (dB)

50 0 System: sys Gain margin (dB): 20.5 At frequency (rad/s): 1.27 Closed-loop stable? Yes

−50 −100

Phase (deg)

−150 0 System: sys Phase margin (deg): 50.5 At frequency (rad/s): 0.342 Closed-loop stable? Yes

−90

−180

−270 10−3

10−2

10−1

100

101

102

Frequency (rad/s)

FIGURE 4.97

Bode plot for control system in Figure 4.96.

(b) The command ‘‘BODE(sys)’’ results in the Bode plot in Figure 4.97. (c) The stability margins were deﬁned in Section 4.4.5. The gain margin is the open-loop system gain at the frequency where the phase of the open-loop system equals 1808. The phase margin is the difference between the open-loop phase and 1808 at the frequency where the gain is 0 db. Figure 4.97 shows the gain margin is 20.5 db and the phase margin is 50.58. Increasing the controller gain KC by the equivalent of 20.5 db moves the gain plot in a vertical direction to a point where the system is marginally stable, that is, the new gain margin is 0 db. Solving for Kcr in magnitude, 20 log Kcr ¼ 20:5 ) Kcr ¼ 1020:5=20 ¼ 10:5925 (d) The 0 db gain margin would occur at the same frequency as the 20.5 db gain margin in Figure 4.97, that is, 1.27 rad=s, which is also v0, the frequency of oscillations of the marginally stable system. (e) The root-locus plot is shown in Figure 4.98. The approximate value of Kcr is 10.6, that is, the value of KC where the locus intersects the imaginary axis. Note that the imaginary part of the complex pole is v0 ¼ 1.27 rad=s, in agreement with the crossover frequency shown in Figure 4.97. As a check on the value of Kcr from part (c), the statement [R,K] ¼ rlocus(sys,Kcr) returns the three closed-loop poles in array R ¼ [4.4006, 0.003 j1.2747]. The real part of the complex poles should be zero when Kc ¼ Kcr; however, 0.003 results because of the round-off in the gain margin value of 20.5 shown in Figure 4.97. The exact values of Kcr and v0 can be obtained from the characteristic equation KC KP KT þ (t1 s þ 1)(t2 s þ 1)(tT þ 1) ¼ 0

(4:723)

Simulation of Dynamic Systems with MATLAB® and Simulink®

308 8

System: sys Gain: 10.6 Pole: 0.00995 + 1.27i Damping:−0.00784 Overshoot (%): 102 Frequency (rad/s): 1.27

6

Imaginary axis

4 2 0 −2 −4 −6 −8 −12

FIGURE 4.98

−10

−8

−6

−4 −2 Real axis

0

2

4

Root-locus plot for control system in Figure 4.96.

with KC ¼ Kcr and s ¼ jv0. Setting the real and imaginary components of the resulting equation to zero leads to the following two equations: t1 þ t2 þ tT t1 t2 tT

(4:724)

[t1 t1 þ tT (t1 þ t2 )]v20 1 KP KT

(4:725)

v20 ¼ Kcr ¼

The solution is (see ‘‘Chap4_Ex10_1.m’’) Kr ¼ 10:5733, v0 ¼ 1.273665 rad=s.

Step response: KC = 0.25Kcr

Step response: KC = 0.5Kcr

3 Amplitude

Amplitude

3 2

1

0

0

6

12 18 Time (s)

24

2 1 0

30

0

4

3

3

2 1 0

FIGURE 4.99

20 30 Time (s)

40

50

Step response: KC = Kcr

4 Amplitude

Amplitude

Step response: KC = 0.75Kcr

10

2 1 0

0

15

30 45 Time (s)

60

75

0

Step responses of control system in Figure 4.96.

5

10 15 Time (s)

20

25

309

Linear Systems Analysis

(f) Step responses of the closed-loop system with KC ¼ 0.25Kcr, 0.5Kcr, 0.75Kcr, Kcr are generated by the statements for i ¼ 1:4 subplot(2,2,i) sys_cl ¼ FEEDBACK(0.25*i*KCR*G,H); % closed-loop system step(sys_cl) % step response end where ‘‘KCR’’ is the exact value for Kcr. The step responses, shown in Figure 4.99, exhibit less damping as the controller gain increases. The step response of the marginally stable system (KC ¼ Kcr) contains an oscillatory component at the frequency v0 ¼ 1.27 rad=s.

EXERCISES Use the control system toolbox whenever possible to do the following problems: 4.78 The block diagram of a typical feedback control system was presented in Figure 4.31 and redrawn below (Figure E4.78): R(s) Command input

E(s) –

GC (s) Controller UT (s)

UC (s)

GA (s)

UA(s)

Actuator

GP (s)

Y(s) Output

Plant

GT (s) Transmitter

FIGURE E4.78

Use the transfer functions given in Section 4.4.5 and the baseline parameter values unless stated otherwise. (a) Find the magnitude and phase of each component GC(s), GA(s), GP(s), and GT(s) at the open-loop system phase crossover frequency v0 ¼ 0.9936 rad=s. Compare the results to the magnitude and phase of the open-loop transfer function GOL(s) ¼ GC(s)GA(s)GP(s) GT(s) at the same frequency. (b) Input to the open-loop system (feedback path broken at summer) is r(t) ¼ sin v0t. Generate graphs of e(t) ¼ r(t), along with uC(t), uA(t), y(t), and uT (t). Comment on the stability of the closed-loop system. Hint: Recall the closed-loop system is unstable if the magnitude of uT (t) is greater than or equal to 1 at the phase crossover frequency v0, that is, the frequency where uT (t) lags e(t) by 1808. (c) Graph the step response of the closed-loop system. (d) Repeat parts (a), (b), and (c) using KC ¼ (KC)max ¼ 2.62. 4.79 The block diagram of a heading control system for a ship, presented in Section 4.4.4, is shown in Figure E4.79. The baseline parameter values are KC ¼ 10 V=8 (heading) KP ¼ 108 (rudder)=volt, tP ¼ 0.2 s, KS ¼ 0.58 (heading)=s=8 (rudder), tS ¼ 7.5 s (a) Find the closed-loop transfer functions E(s) , ucom (s)

U(s) , ucom (s)

R(s) , ucom (s)

and

u(s) ucom (s)

(b) For a step input ucom ¼ 58, t 0 graph e(t), u(t), r(t), and u(t).

Simulation of Dynamic Systems with MATLAB® and Simulink®

310

θcom(s)

E(s)

deg heading

–

KC s + 1 s + 10

U(s) Volts

Controller and power amplifier

KP (τP s + 1)

KS R(s) θ(s) deg s(τS s + 1) deg rudder heading Power converter Ship yaw dynamics and rudder

FIGURE E4.79

4.80 A system of two interacting tanks is shown in Figure E4.80a: F2(t)

F1(t)

H1(t) R12

A1

H2(t)

A2 F0,1(t)

R2

F0,2(t)

FIGURE E4.80a

The state equations are given as 2 3 2 1 1 " # 1 7 H1 6 A1 A1 R12 A1 R12 dH1 =dt 6 7 6 ¼6 4 dH2 =dt 1 1 1 5 H2 4 0 A2 R12 A2 R12 A2 R12 2 3 2 3 H1 1 0 6 7 6 7 H1 1 5 4 H2 5¼4 0 H2 H3 A1 A2

3

" # 7 F1 7 1 5 F2 A2 0

The parameter values are A1 ¼ 25 ft2,

A2 ¼ 100 ft2,

R12 ¼ 0.1 ft=ft3=min,

R2 ¼ 0.4 ft=ft3=min

(a) Find the transfer functions VT (s)=F1(s) and VT (s)=F2(s). (b) With both tanks initially empty, ﬁnd and graph H1(t) and H2(t) in response to (i) F1(t) ¼ 12 ft3=min, F2(t) ¼ 0 ft3=min (ii) F1(t) ¼ 0 ft3=min, F2(t) ¼ 12 ft3=min (iii) F1(t) ¼ 12 ft3=min, F2(t) ¼ 12 ft3=min (iv) F1(t) in Figure E4.80b F1(t), ft3/min

F2(t) = 0, t ≥ 0

50

t, min 0

FIGURE E4.80b

5

10

15

311

Linear Systems Analysis

4.81 The transfer function for the circuit in Figure E4.81 is (see Equation 4.183) C2 = 2.5 × 10–3 F v R = 0.2 Ω

R = 0.2 Ω

ei

C1 = 0.1 × 10–3 F

v0

FIGURE E4.81

V0 (s) R2 C1 C2 s2 þ 2RC2 s þ 1 ¼ 2 Ei (s) R C1 C2 s2 þ R(C1 þ 2C2 )s þ 1 (a) (b) (c) (d)

Convert the system transfer function to a state variable model with output v0. Use the state variable model to ﬁnd and plot the impulse response. Find the unit step response of the circuit by inverse Laplace transforming V0(s). Repeat part (c) using the control system toolbox to ﬁnd the unit step response. Compare the results from parts (c) and (d). (e) Approximate the continuous-time transfer function with a discrete-time z-domain transfer function based on Tustin’s method. Choose an appropriate integration step size. (f) Find and plot the unit step response of the discrete-time system. Compare the step responses of the continuous-time and discrete-time systems. 4.82 Use ‘‘BODE’’ instead of ‘‘BODEMAG’’ to plot the magnitude and phase plots for the ﬁlters with transfer functions in Equations 4.719 through 4.721. 4.83 Compare the phase characteristics of the continuous- and discrete-time band-pass ﬁlters introduced in this section. 4.84 A simple control system block diagram is shown in Figure E4.84: R(s)

–

G(s) =

KC = 1

25(s + 10) s(s2 + 4s + 29)

Y(s)

Controller

H(s) =

0.1 0.05s + 1

FIGURE E4.84

(a) (b) (c) (d) (e) (f)

Find the closed-loop transfer function of the system using block diagram reduction. Check your answer to part (a) using the control system toolbox. Draw a simulation diagram of the system. Represent the system in state variable form based on your simulation diagram. Use the control system toolbox to ﬁnd a state variable model for the system. Compare the eigenvalues (characteristic poles) of the coefﬁcient matrix A in parts (d) and (e). (g) Use ‘‘BODE’’ to plot the frequency response of the open-loop system transfer function. Find the gain and phase margins of the system.

Simulation of Dynamic Systems with MATLAB® and Simulink®

312

(h) Compute the maximum gain (KC )crit which makes the system marginally stable. Redraw the Bode plot for KC ¼ (KC )crit . (i) Check your answer to part (h) using a root-locus plot and identifying the value of gain KC where the locus is on the Imaginary axis. 4.85 A continuous-time system is modeled by the differential equation d3 y d2 y dy þ 5 þ 33 þ 29y ¼ u 3 3 dt dt dt Find the transfer function H(s) ¼ Y(s)=U(s) of the system. Create a model object ‘‘sys’’ to represent H(s). Use the control system toolbox to plot the impulse and step response of the system. Approximate the continuous-time transfer function H(s) with a discrete-time z-domain transfer function H(z) ¼ Y(z)=U(z) using Tustin’s method with appropriate sample time T. (e) Find the difference equation for the discrete-time system approximation. (f) Write a MATLAB M-ﬁle to ﬁnd and plot the step response of the discrete-time system. (g) Use the control system toolbox to plot the step response of the discrete-time system, and compare the result with your answer in part (f). (a) (b) (c) (d)

4.11 CASE STUDY: LONGITUDINAL CONTROL OF AN AIRCRAFT The equations of motion for an aircraft are derived using a moving coordinate system ﬁxed to the aircraft as shown in Figure 4.100. The x–y–z axes are referred to as body axes. The x-axis is aligned with the longitudinal axis of the airplane. The equations are based on Newton’s laws of motion for a rigid body in translation and rotation. The result is a system of six coupled nonlinear differential _ v_ , w_ in terms of body axis velocities equations. Three of the six equations express accelerations u, u, v, w, angular velocities p, q, r, and external, aerodynamic, and gravitational forces acting on the _ q, _ r_ to p, q, r and moments plane. The remaining three equations relate the angular accelerations p, produced by the external and aerodynamic forces about the plane’s center of mass. x, u

φ, p

v

y, v

θ, q

Rudder, δr

Aileron, δa p: roll rate q: pitch rate (about y-axis) r: yaw rate (about z-axis) ψ, r u, v, w: velocities in x, y, z directions

Elevators, δe Flight path

z, w

y΄

x΄

Earth-fixed coordinate system z΄

FIGURE 4.100

Body axis coordinates (x, y, z) and Euler angles (c, u, f).

313

Linear Systems Analysis

The position and orientation of the airplane are referenced to an inertial (earth-ﬁxed) coordinate system x0 –y0 –z0 also shown in Figure 4.100. The horizontal x 0 -axis is in the vertical plane containing the initial velocity vector, and the plane’s center of mass is located at the origin of the x 0 –y0 –z0 system at t ¼ 0. The plane’s attitude is ﬁxed by three rotations of the x–y–z axes starting from an orientation initially aligned with the x0 –y0 –z0 axes of the inertial coordinate system. The angular rotations c, u, and w are called Euler angles and denote the roll, pitch, and yaw of the plane, respectively. Solution to the ﬂight dynamics equations yields u, v, w in the x–y–z body axis coordinate system. The velocity vector v is converted from body axis components u, v, w to inertial components x_ 0 , y_ 0 , z_ 0 by a transformation matrix Ceb (Etkin 1982), 2

2

3 2 3 x_ 0 u 4 y_ 0 5 ¼ C b 4 v 5 e z_ 0 w cos u cos c

6 Ceb ¼ 4 cos u sin c sin u

sin f sin u cos c cos f sin c sin f sin u sin c þ cos f cos c sin f cos u

(4:726)

cos f sin u cos c þ sin f sin c

3

7 cos f sin u sin c sin f cos c 5 cos f cos u

(4:727)

The position of the plane’s center of mass in inertial coordinates x0 , y0 , z0 is obtained by integration of the respective velocities in Equation 4.726. Solving the equations of motion also yields the angular velocities p, q, r, which are transformed _ u, _ f_ by into c, 2 3 2 0 c_ 6_7 6 4 u 5 ¼ 40 f_

1

sin f sec u cos f sin f tan u

32 3 p 76 7 sin f 54 q 5

cos f sec u

cos f tan u

(4:728)

r

The Euler angles c, u, and f are obtained by integration of the respective velocities in Equation 4.728. Solution of the nonlinear ﬂight dynamics equations is complicated by the dependency of the aerodynamic forces and moments on the variable ﬂight conditions, for example, altitude, cruising speed, weight, angle of attack, side slip, and control surface positions. A simpler approach is based on a linearized model that describes the aircraft’s motion provided the excursions in ﬂight from a known steady state are small. The subject of linearization is treated in some detail in Chapter 7. When the conditions for linearization of the ﬂight equations are satisﬁed, the linearized model can be decoupled into two sets of equations. One set describes the longitudinal dynamics of the aircraft, and the remaining equations apply to the lateral dynamics. The longitudinal dynamics involve changes in u and w, the plane’s velocity in the x- and z-directions, and the pitch rate q about the y-axis. Lateral dynamics involve changes in side velocity v and the yaw and roll rates r and p about the z- and x-axes, respectively. Figure 4.100 shows the velocity vector v aligned differently from the x-axis. The projection of v in the x–z plane is vxz shown in Figure 4.101. The angle between vxz and the x-axis (longitudinal axis of plane) is called the angle of attack. Note that when the lateral dynamics of the plane are zero, the ﬂight path is conﬁned to the x–z plane, v ¼ vxz, and the instantaneous direction of ﬂight is given by g in Figure 4.101, the angle between the velocity vector and the horizontal direction. The thrust (dT) from the engine, the aerodynamic forces, lift (L) and drag (D), and the gravitational force (W) are also shown in Figure 4.101. The primary control surfaces for controlling the aircraft’s position and attitude are the elevators, ailerons, and rudder. The longitudinal dynamics respond to changes in elevator deﬂection de and

Simulation of Dynamic Systems with MATLAB® and Simulink®

314 x

L

u

δT θ

νxz

α γ c.m. w z

FIGURE 4.101

D

W

Illustration of angle of attack (a) and forces inﬂuencing ﬂight dynamics.

thrust dT. Elevator deﬂection and thrust result from changes to the – u yoke and throttle by the pilot (or autopilot). The rudder and ailerons x – – are used primarily to control the lateral response for banking and θ=α v0 turning maneuvers. – Our interest is solely in the longitudinal dynamics, speciﬁcally w pitch and altitude response of the aircraft to changes in elevator z deﬂection when the plane is ﬂying at a constant cruising speed in horizontal ﬂight under steady-state conditions. From Figure 4.101, FIGURE 4.102 Initial steadyfor the plane to be in level ﬂight, the velocity vector v must be state conditions of aircraft. horizontal, the ﬂight angle g ¼ 0, and the pitch is equal to the angle of attack. The plane is pitched slightly in order for the wings to develop sufﬁcient lift to overcome gravity. The steady-state conditions are shown in Figure 4.102 with v0 (horizontal cruising speed), u (longitudinal speed), w (speed in z-direction), u (pitch), and a (angle of attack). The elevator input and engine thrust necessary to maintain these conditions are de and dT , respectively. The deviations in u, a, u, w, and q from their steady-state operating levels are Du ¼ u u,

Dw ¼ w w ¼ w,

Da ¼ a a,

Du ¼ u u,

Dq ¼ q q ¼ q

(4:729)

Since we are considering only changes in elevator deﬂection, Dde ¼ de de , DdT ¼ dT dT ¼ 0

(4:730)

The state vector Dx in a linearized model of the longitudinal dynamics can be chosen as either [Du Dw Dq Du]T or [Du Da Dq Du]T. The relationship between u, w, and a is (see Figure 4.101) tan a ¼

w u

(4:731)

For small angles of attack, tan a ¼ sin a=cos a a. Replacing tan a in Equation 4.731 with a and solving for w give w ¼ ua

(4:732)

Solving for u, a, and w in Equation 4.729 and substituting the results into Equation 4.732, w þ Dw ¼ (u þ Du)(a þ Da) ¼ ua þ uDa þ aDu þ DuDw

(4:733)

315

Linear Systems Analysis

Recognizing that w ¼ ua and ignoring the high-order term DuDw lead to Dw ¼ uDa þ aDu

(4:734)

Suppose the linearized model of an aircraft cruising in level ﬂight under steady-state conditions with v0 ¼ 500 ft=s and a ¼ u ¼ 0:05 rad (2.868) is 2 3 2 32 3 2 3 Du 0:04 11:59 0 32:2 Du 0 0:1 7 6 6 7 6 d6 1 0 7 0 7 6 Da 7 ¼ 6 0:00073 0:65 76 Da 7 þ 6 0 7 Dde 0 54 Dq 5 4 0:014 0 5 DdT dt 4 Dq 5 4 0:000048 0:49 0:58 Du 0 0 1 0 Du 0 0 (4:735) where Du has units of ft=s Da, Du are in rad Dq is in rad=s Dde is in degree of elevator deﬂection DdT is in lb of thrust Choosing the output Dy ¼ Dx ¼ [Du Da Dq Du]T leads to the system of state equations D_x ¼ ADx þ þ DDu with A and B the matrices in Equation 4.735, C equal to the 4 4 identity BDu, Dy ¼ CDx matrix and D is a 4 2 matrix of zeros. Note that Du ¼ [Dde DdT]T is the input vector, not to be confused with Du, the ﬁrst component of the state vector. The linearized equations in state variable form can be converted to a transfer function matrix relating the four outputs Du(s), Da(s), q(s), and Du(s) to the two inputs Dde(s) and DdT (s). The transfer function matrix can be found using Equation 4.231, repeated again for convenience in Equation 4.736. 2 3 Du(s) Du(s) 6 Dde (s) DdT (s) 7 6 7 6 7 6 Da(s) Da(s) 7 6 7 6 7 6 Dde (s) DdT (s) 7 7 ¼ C(sI A)1 B þ D (4:736) G(s) ¼ 6 6 7 q(s) 7 6 q(s) 6 7 6 Dde (s) DdT (s) 7 6 7 6 7 4 Du(s) Du(s) 5 Dde (s) DdT (s) The control system toolbox in MATLAB contains a function ‘‘ss2tf’’ for expediting the process of converting from the state-space model to the transfer function description of an LTI system. Calling this function with arguments (A, B, C, D, i), where i ¼ 1 designates the ﬁrst input Dde and i ¼ 2 speciﬁes the second input DdT, generates the eight transfer functions in Equation 4.736. The MATLAB statement ‘‘[numG denG] ¼ ss2tf (A, B, C, D, 1)’’ returns numG ¼ 0 0.0000 0.0000 0.2906 0.2951 0 0.0000 0.0141 0.0006 0.0003 0 0.0141 0.0097 0.0005 0.0000 0 0.0000 0.0141 0.0097 0.0125 denG ¼ 1.0000

1.2700

0.9247

0.0406

0.0125

Simulation of Dynamic Systems with MATLAB® and Simulink®

316

The transfer function relating elevator input to aircraft pitch is therefore GDu Dde (s) ¼

Du(s) 0:0141s2 0:0097s 0:0005 ¼ 4 Dde(s) s þ 1:2700s3 þ 0:9247s2 þ 0:0406s þ 0:0125

(4:737)

Factoring the numerator and denominator gives GDu Dde (s) ¼

Du(s) Ku (s þ c1 )(s þ c2 ) ¼ Dde(s) (s2 þ a1 s þ b1 )(s2 þ a2 s þ b2 )

(4:738)

The constants in Equation 4.738, computed in M-ﬁle ‘‘Chap4_CaseStudy1.m,’’ are Ku ¼ 0:0141,

c1 ¼ 0:6358, c2 ¼ 0:0542, a1 ¼ 1:2440, b1 ¼ 0:8780, b2 ¼ 0:0143

a2 ¼ 0:0260,

The quadratic factors in the denominator of Equation 4.738 are both underdamped, regardless of whether the aircraft is a small passenger plane, a commercial jet, or a high-performance military aircraft. However, as we shall soon learn, the natural frequencies and damping ratios of each quadratic are quite different. We begin by ﬁnding the pitch response to a step change in elevator input of ‘‘A’’ deg. The Laplace transform of the response is Du(s) ¼

Ku (s þ c1 )(s þ c2 ) A (s2 þ a1 s þ b1 )(s2 þ a2 s þ b2 ) s

(4:739)

Using partial fraction expansion, Equation 4.739 is written as R1 R2 R3 R4 R5 þ þ þ þ Du(s) ¼ Ku A s p1 s p2 s p3 s p4 s

(4:740)

where p1 and p2 are the poles from the quadratic s2 þ a1s þ b1, and p3 and p4 are the poles associated with the quadratic s2 þ a2s þ b2. R1, R2, R3, R4, and R5 are the constants (residues) in the partial fraction expansion. Letting p1 ¼ a1 þ jb1 , p3 ¼ a3 þ jb3 and recognizing that p2 ¼ p1 ¼ a1 jb1 , p4 ¼ p3 ¼ a3 jb3 as well as R2 ¼ R1 , R4 ¼ R3 give Du(t) ¼ L1 {u(s)} ¼ Ku A[R1 ep1 t þ R1 ep1 t þ R3 ep3 t þ R3 ep3 t þ R5 ],

t0

(4:741)

It is left as an exercise to show that Rept þ Rept ¼ 2eat [Re(R) cos bt Im(R) sin bt]

(4:742)

where p ¼ a þ jb, p ¼ a jb, R ¼ Re(R) þ jIm(R), R ¼ Re(R) jIm(R) The pitch response (in rad) to an A ¼ 18 elevator deﬂection is given by Du(t) ¼ Ku {2ea1 t [Re(R1 ) cos b1 t Im(R1 ) sin b1 t] þ 2ea3 t [Re(R3 ) cos b3 t Im(R3 ) sin b3 t] þ R5 }

(4:743)

Assuming the aircraft’s natural dynamics are stable, the poles are located in the left-half plane, that is, a1 < 0 and a3 < 0. From Equation 4.739 and the ﬁnal value theorem and Equation 4.743 with t ! 1, the steady-state pitch response to a unit step input is

317

Linear Systems Analysis

Duss ¼

K u c1 c2 ¼ Ku R5 b1 b2

(4:744)

The poles and residues are obtained in ‘‘Chap4_CaseStudy1.m.’’ p1,2 ¼ 0:6220 j0:7008, p3,4 ¼ 0:0130 j0:1187 R1,2 ¼ 0:0331 j0:5586, R3,4 ¼ 1:3429 j2:9777,

R5 ¼ 2:7519

From Equation 4.743, the pitch step response is Du(t) ¼ 0:0141{2e0:6220t [0:0331 cos 0:7008t 0:5586 sin 0:7008t] þ 2e0:0130t [1:3429 cos 0:1187t 2:9777 sin 0:1187t] þ 2:7519}

(4:745)

The two damped oscillatory components are referred to as the short period and phugoid modes. The natural frequencies, damping ratios, and exponential envelope time constants are given in Table 4.12. The complete step response is shown in Figure 4.103. The steady-state pitch is from Equation 4.744, uss ¼ 0.0388 rad (2.22328). The short period and phugoid mode oscillation components of the step response are shown in Figure 4.104.

TABLE 4.12 Short Period and Phugoid Mode Parameters Mode Short period Phugoid

vn (rad=s)

Z

tenvelope ¼ 1=zvn (s)

0.9370 0.1194

0.6638 0.1089

1.6077 76.9042

0.02 0

Δu(t) (rad)

−0.02 −0.04 −0.06

v0 = 500 ft/s – = 0.05 rad a– = u

−0.08 −0.1 −0.12

FIGURE 4.103

0

50

100

150

200 t (s)

250

300

350

400

Linearized aircraft pitch response due to 18 step change in elevator deﬂection.

Simulation of Dynamic Systems with MATLAB® and Simulink®

318

Δushort period(t) (rad)

×10−3 6 4 Δδe = 1° 2 0 0

(a)

1

2

3

4

5

6

7

8

9

10

350

400

Δuphugoid (t) (rad)

0.05 0.025 0 −0.025 Δδe = 1°

−0.05 −0.075 0

50

100

150

(b)

FIGURE 4.104

200 t (s)

250

300

(a) Short period and (b) phugoid oscillations of elevator unit step response.

Shortly, we will look at the design of an autopilot to control the plane’s altitude. Before doing so, a way of determining altitude is needed. From Equations 4.726 and 4.727, z_ 0 ¼ (sin u)u þ ( sin w cos u)v þ ( cos w cos u)w

(4:746)

where z_ 0 is the rate of change of altitude, a positive value indicating that the plane is descending. For small values of u and motion in the longitudinal direction only, v ¼ 0, f ¼ 0, sin u u, cos u 1, sin f ¼ 0, cos f ¼ 1 and Equation 4.746 simpliﬁes to z_ 0 ¼ uu þ w

(4:747)

In terms of steady-state values and deviations, Equation 4.747 becomes d ( ( z þ Dz 0 ) ¼ (u þ Du)(u þ Du) þ w þ Dw dt d d ) (z0 ) þ (Dz0 ) ¼ (uu þ uDu þ uDu þ DuDu) þ w þ Dw dt dt d ( d ) ( z 0 ) þ (Dz 0 ) ¼ (uu þ w) uDu uDu DuDu þ Dw dt dt

(4:748) (4:749) (4:750)

Equation 4.747 evaluated at steady state is d 0 (z ) ¼ (uu þ w) dt

(4:751)

Subtracting Equation 4.751 from Equation 4.750, ignoring the higher order term Du Du, and recognizing that dDz0=dt ¼ d(z0 z0 )=dt ¼ dz0 =dt yield dz0 ¼ uDu uDu þ Dw dt

(4:752)

319

Linear Systems Analysis

Substituting Dw in Equation 4.734 into Equation 4.752 gives dz0 ¼ uDu uDu þ (uDa þ aDu) dt

(4:753)

¼ (u a)Du u(Du Da)

(4:754)

¼ u(Du Da)

(4:755)

Laplace transforming Equation 4.755, z_ 0 (s) ¼ u[Du(s) Da(s)]

(4:756)

The transfer function from elevator input Dde(t) to output z_ 0 (t) is z_ 0 (s) Du(s) Da(s) ¼ u Gz_ 0 (s) ¼ Dde (s) Dde (s) Dde (s)

(4:757)

The transfer function Da(s)=Dde(s) is obtained in the same way we found Du(s)=de(s) in Equation 4.738. The result is Da(s) Ka (s2 þ d1 s þ d0 ) ¼ 2 Dde (s) (s þ a1 s þ b1 )(s2 þ a2 s þ b2 )

(4:758)

where Ka ¼ 0.141, d1 ¼ 0.0400, and d0 ¼ 0.0235 are from ‘‘Chap4_CaseStudy1.m.’’ Substituting Equations 4.738 and 4.758 into Equation 4.757 gives

Ku (s þ c1 )(s þ c2 ) Ka (s2 þ d1 s þ d0 ) Gz_ 0 (s) ¼ u 2 (s þ a1 s þ b1 )(s2 þ a2 s þ b2 ) (s2 þ a1 s þ b1 )(s2 þ a2 s þ b2 ) ) Gz_ 0 (s) ¼

u[(Ku Ka )s2 þ {Ku (c1 þ c2 ) Ka d1 }s þ Ku c1 c2 Ka d0 ] (s2 þ a1 s þ b1 )(s2 þ a2 s þ b2 ) ) Gz_ 0 (s) ¼

l2 ¼ u(Ku Ka ),

(s2

l2 s2 þ l1 s þ l0 þ a1 s þ b1 )(s2 þ a2 s þ b2 )

l1 ¼ u[Ku (c1 þ c2 ) Ka d1 ],

(4:759)

(4:760) (4:761)

l0 ¼ u(Ku c1 c2 Ka d0 )

(4:762)

From ‘‘Chap4_CaseStudy1.m,’’ l2 ¼ 0, l1 ¼ 4.5768, and l0 ¼ 0.0771. For a step input in elevator deﬂection of A8, Equation 4.761 and l2 ¼ 0 give z_ 0 (s) ¼

l1 s þ l0 A (s2 þ a1 s þ b1 )(s2 þ a2 s þ b2 ) s

(4:763)

The partial fraction expansion of z_ 0 (s) is R1 R2 R3 R4 R5 þ þ þ þ z_ 0 (s) ¼ A s p 1 s p 2 s p3 s p4 s where the residues, evaluated in ‘‘Chap4_CaseStudy1.m,’’ are R1,2 ¼ 3:7283 j0:4124,

R3,4 ¼ 6:8081 j21:2231,

R5 ¼ 6:1596

(4:764)

Simulation of Dynamic Systems with MATLAB® and Simulink®

320

From Equations 4.763 and 4.764, the ﬁnal value of z_ 0 is given by z_ 0ss ¼

Al0 ¼ AR5 b1 b2

(4:765)

The step response is from Equation 4.764, z_ 0 (t) ¼ A[R1 ep1 t þ R2 ep2 t þ R3 ep3 t þ R4 ep4 t þ R5 ]

(4:766)

Equation 4.766 is converted to a trigonometric form with real coefﬁcients and real exponents similar to Equation 4.743 for Du(t). The unit step response is graphed in Figure 4.105. According to Equation 4.765, the steady-state value z_ 0ss ¼ AR5 ¼ 1 6:1596 ft=s. The change in altitude Dz(t) resulting from a step change in elevator input is obtained by integration of z_ 0 (t). From Equation 4.763, 1 1 l1 s þ l0 A (4:767) Dz0 (s) ¼ z_ 0 (s) ¼ 2 2 s s (s þ a1 s þ b1 )(s þ a2 s þ b2 ) s A(l1 s þ l0 ) (4:768) ¼ 2 2 s (s þ a1 s þ b1 )(s2 þ a2 s þ b2 ) The inverse transform of Equation 4.768 is left as an exercise problem. The change in altitude Dz0 (t) is graphed in Figure 4.105 below the derivative d_z0 =dt. The phugoid mode is an undesirable fact of life when it comes to control of an aircraft. In the previous example, it takes 300–400 s for the plane to establish a new steady-state pitch and rate of descent following a step change in the elevator position. Consider a scenario where the plane is required to decrease its cruising altitude by some amount. One approach is for the pilot to pull back on the yoke to increase the elevator deﬂection from its neutral position, which produces steady-state level ﬂight conditions. The plane will begin a descent similar to the one shown in Figure 4.105. The actual descent will depend on the magnitude of the elevator deﬂection. Some time later, the yoke is returned to the neutral position, and the plane Rate of change of altitude vs. time

dz΄/dt (ft/s)

40

v0 =_500 ft/s _ α = θ = 0.05 rad

20

Δδe = 1°

0

−20 0

50

100

150

200

250

300

350

400

350

400

Change in altitude from steady-state vs. time

Δz΄(t) (ft)

3000

1500 Δδe = 1°

750 0

FIGURE 4.105

v0 =_500 ft/s _ α = θ = 0.05 rad

2250

0

50

100

150

200 t (s)

250

300

Changes in altitude rate and altitude from steady-state ﬂight conditions.

321

Linear Systems Analysis

returns to level ﬂight conditions at a reduced altitude. To illustrate, suppose the pilot’s action results in an elevator deﬂection of D^ de degree for a period of Tpulse s. The aircraft’s altitude response to the pulse input in elevator deﬂection is obtained as the difference between the step response and the delayed step response, that is, de Dz1 (t) D^ de Dz1 (t Tpulse )^u(t Tpulse ) Dzp (t) ¼ D^

(4:769)

where Dz1(t) is the change in altitude response to a unit step elevator deﬂection ^ u(t Tpulse ) is the unit step function starting at t ¼ Tpulse Dzp(t) is the change in altitude response to a pulse elevator deﬂection of D^de deg lasting Tpulse s For a 58 elevator pulse input of 30 s, the aircraft’s descent is computed according to Equation 4.769 in ‘‘Chap4_CaseStudy1.m’’ and shown in Figure 4.106. The label ‘‘open-loop’’ refers to the lack of feedback used to determine the control surface deﬂection Dde(t). The open-loop response settles at a value of approximately 927.5 ft once the phugoid oscillations have disappeared. Some form of corrective action is necessary to dampen the excessive phugoid mode oscillations. A feedback control system or autopilot can automate the process without relying on human input. Figure 4.107 is a simpliﬁed block diagram of a control system for regulating an aircraft’s altitude. Sensors convert the plane’s altitude and rate of descent (or ascent) to voltages, which are transmitted 4000 3500 3000

Open-loop response: Δδe = 5° pulse of 30 s duration Δzss = 927.5 ft

2500

Δz (ft)

2000 1500 1000 500

Closed-loop response: Δzcom = 927.5 ft KˆC = 0.001

0

Δzss = 927.5 ft

−500 −1000 0

FIGURE 4.106

ft

100

150

200

250 t (s)

300

350

– ft

KzGc(s)

U(s) Volts

Ga(s) – Actuator

Controller

Volts

Δδe(s)

450

Block diagram for altitude control system.

Gz(s)

. z(s)

deg ft/sec Aircraft dynamics Kz. Sensor

FIGURE 4.107

400

500

Open- and closed-loop altitude response vs. time. eΔz(s)

Δzcom(s)

50

1 s

Δz(s) ft

Simulation of Dynamic Systems with MATLAB® and Simulink®

322

to the autopilot. In Figure 4.107, the gain of the altitude sensor Kz is shown combined with the controller transfer function GC(s), allowing the command signal Dzcom to be in ft rather than volts. (Note that the ’ symbol designating inertial coordinates is dropped from here on.) The inner loop provides feedback of the altitude rate, which improves the damping and speed of the outer altitude control loop. There are several ways of obtaining the closed-loop transfer function Dz(s)=Dzcom(s). The inner loop can be reduced to z_ (s) Ga (s)Gz_ (s) ¼ U(s) 1 þ Kz_ Ga (s)Gz_ (s)

(4:770)

Using the same block diagram reduction formula for the outer loop gives Dz(s) Kz Gc (s)[_z(s)=U(s)]1=s ¼ Dzcom (s) 1 þ Kz Gc (s)[_z(s)=U(s)]1=s

(4:771)

¼

Kz Gc (s)[Ga (s)Gz_ (s)=(1 þ Kz_ Ga (s)Gz_ (s))]1=s 1 þ Kz Gc (s)[Ga (s)Gz_ (s)=(1 þ Kz_ Ga (s)Gz_ (s))]1=s

(4:772)

¼

Kz Gc (s)Ga (s)Gz_ (s) [1 þ Kz_ Ga (s)Gz_ (s)]s þ Kz Gc (s)Ga (s)Gz_ (s)

(4:773)

To start with, a proportional controller Gc(s) ¼ Kc is considered. The product of the gain Kz and ^ C , that is, K ^ C ¼ Kz Kc is the effective controller gain for design purposes. For controller gain Kc is K now, we ignore the actuator dynamics and let Ga(s) ¼ Ka measured in deg=volt. Equation 4.773 becomes ^ C Ka Gz_ (s) Dz(s) K ¼ ^ C Ka Gz_ (s) Dzcom (s) [1 þ Kz_ Ka Gz_ (s)]s þ K

(4:774)

The DC gain of the autopilot is lim s!0

^ C Ka Gz_ (s) K Dz(s) ¼ lim ¼1 ^ C Ka Gz_ (s) Dzcom (s) s!0 [1 þ Kz_ Ka Gz_ (s)]s þ K

(4:775)

Substituting Equation 4.761 with l2 ¼ 0 for Gz_ (s) into Equation 4.774 gives ^ C Ka (l1 s þ l0 ) Dz(s) K ¼ 5 Dzcom (s) s þ m4 s4 þ m3 s3 þ m2 s2 þ m1 s þ m0 9 m 4 ¼ a1 þ a2 > > > > m 3 ¼ a1 a 2 þ b1 þ b 2 = m2 ¼ a1 b2 þ a2 b1 þ Kz_ Ka l1 > ^ C Ka l1 > m1 ¼ b1 b2 þ Kz_ Ka l0 þ K > > ; ^ C Ka l0 m0 ¼ K

(4:776)

(4:777)

‘‘Chap4_CaseStudy1.m’’ creates a system object for the control system transfer function in Equation 4.776 and then issues the MATLAB ‘‘step’’ command to acquire the unit step response values, which are multiplied by Dzcom and then plotted. The statements are num_cs_z ¼ Kc_hat*Ka*[lambda1 lambda0]; den_cs_z ¼ [1 mu4 mu3 mu2 mu1 mu0]; sys_cs_z ¼ tf(num_cs_z, den_cs_z)

323

Linear Systems Analysis

T ¼ linspace(0, 500, 1000); % t array for step response [Y,T] ¼ step(sys_cs_z,T); %Y is unit step response of control system z_com ¼ 927.5; % command input (ft) z_cs ¼ z_com*Y; % control system response to z_com plot(T,z_cs,’r’) Numerical values used to obtain the closed-loop response in Figure 4.106 were Dzcom ¼ 927.5 ft, ^ C ¼ 0:001. The closed-loop transfer function corresponding to Ka ¼ 18=V, Kz_ ¼ 0:1 volt=ft=s, and K those values is Dz(s) 0:004577s þ 0:00007713 ¼ Dzcom (s) s5 þ 1:27s4 þ 0:9247s3 þ 0:08634s2 þ 0:01787s þ 0:00007713

(4:778)

Both responses in Figure 4.106 approach 927.5 ft; however, the closed-loop response is far superior to the open-loop pulse response. The elevator deﬂection in the closed-loop system response must be small enough to justify the use of the linearized model in Equation 4.735, which assumes small deviations in u, a, q, and u. The small angle approximations and omission of high-order terms, key to the linearized model’s accuracy, may not hold if there are sizable changes in any of the responses. We must look at a graph of Dde(t) responsible for the closed-loop response in Figure 4.106. Dde(s)=Dzcom(s) can be obtained by observing from Figure 4.107 that 1 Dz(s) ¼ Gz_ (s)Dde (s) s

(4:779)

Solving Equation 4.779 for Dde(s) and then dividing both sides by Dzcom(s) lead to Dde (s) s Dz(s) ¼ Dzcom (s) Gz_ (s) Dzcom (s)

(4:780)

Substituting for Gz_ (s) the expression in Equation 4.761 gives ^ C Ka s(s2 þ a1 s þ b1 )(s2 þ a2 s þ b2 ) K Dde (s) ¼ 5 Dzcom (s) s þ m4 s4 þ m3 s3 þ m2 s2 þ m1 s þ m0

(4:781)

^ C ¼ 0:001, 0:003, and 0.005 along with The closed-loop elevator and altitude step responses for K the open-loop response are shown in Figures 4.108 and 4.109. Looking at Figure 4.108, it is clear that the closed-loop system elevator input Dde(t), t 0 remains less than the 58 pulse amplitude in the open-loop system. It is left as an exercise problem to investigate the deviations Du, Da, q, and Du as well. The proportional gain compensator for the autopilot is far too simplistic; however, the results are fairly dramatic even for this simple design. One of the problems with this design is related to ^ C ¼ 0:001) in Figure 4.109 is the most stable, yet the location of stability. The sluggish response (K the closed-loop system poles, which determine the transient response, is far from optimal. Table ^C. 4.13 lists the location of the closed-loop system poles corresponding to the values of K The reader should consult one of the numerous control system texts for a discussion of more sophisticated compensators to achieve superior dynamic response with increased stability margins.

Simulation of Dynamic Systems with MATLAB® and Simulink®

324

Open- and closed-loop elevator deflections for different controller gains 5 KˆC = 0.005 4

Δδe(t) (deg)

3

v0 = 500 ft/s – = 0.05 rad a– = u Δzcom = 927.5 ft

Kˆ C = 0.003

2 1 0

Kˆ C = 0.001 Open-loop

−1 0

FIGURE 4.108

50

100

150 t (s)

200

250

300

350

400

Elevator response for open- and closed-loop control of altitude.

The gain (magnitude in db) of the open- and closed-loop frequency response functions is shown in Figure 4.110. The open-loop j_z( jv)=Dde ( jv)j is obtained from the transfer function in Equation 4.761, (recall l2 ¼ 0). The open-loop jDz( jv)=Dde ( jv)j comes from the transfer function GDz (s) ¼

Dz(s) l1 s þ l0 ¼ Dde (s) s(s2 þ a1 s þ b1 )(s2 þ a2 s þ b2 )

(4:782)

Open- and closed-loop altitude responses for different controller gains

4000 3500

v0 = 500 ft/s – – α = θ = 0.05 rad Δzcom = 927.5 ft

Open-loop 3000 2500

Kˆ C = 0.005

Δz (ft)

2000 1500 1000 500 KˆC = 0.003

0

Kˆ C = 0.001

−500 −1000 0

FIGURE 4.109

50

100

150

200 t (s)

250

Altitude response for open- and closed-loop control.

300

350

400

325

Linear Systems Analysis

TABLE 4.13 Closed-Loop System Poles for Autopilot with Proportional Control ^C K 0.001 0.003 0.005

Closed-Loop Poles 0:5981 j0:6759, 0:0347 j0:1424, 0:0044 0:6066 j0:6748, 0:0240 j0:1772, 0:0088 0:6150 j0:6742, 0:0145 j0:2055, 0:0109

Bode diagram 80 60 40

|Δz(jω)/Δδe(jω)|

Magnitude (dB)

20

. |z(jω)/Δδe(jω)|

0 −20 −40 −60

Kˆ C = 0.005 |Δz(jω)/Δzcom(jω)| ωBW = 0.28 rad/s

−80 −100 −120 10−3

FIGURE 4.110

10−2

ωBW 10−1 Frequency (rad/s)

100

101

Open- and closed-loop magnitude functions.

The closed-loop jDz( jv)=Dzcom( jv)j is based on the transfer function in Equation 4.776 with ^ C ¼ 0:005. K Note that the resonant frequency in the open-loop functions at the natural frequency of the phugoid vn ¼ 0.1194 rad=s (see Table 4.12). The closed-loop system gain is close to 0 db from DC to somewhat less than the resonant frequency. The bandwidth of the control system is approximately 0.28 rad=s.

4.11.1 DIGITAL SIMULATION

OF

AIRCRAFT LONGITUDINAL DYNAMICS

A digital simulation of longitudinal dynamics requires z-domain transfer functions to approximate the corresponding continuous-time transfer functions. A z-domain transfer function to approximate the continuous-time transfer function in Equation 4.776 based on explicit Euler integration is

^ C Ka (l1 s þ l0 )

Dz(z) K

¼ 5 4 3 2 Dzcom (z) s þ m4 s þ m3 s þ m2 s þ m1 s þ m0 s¼(z1)=T

(4:783)

Simulation of Dynamic Systems with MATLAB® and Simulink®

326

Substituting (z 1)=T for s in Equation 4.783 leads to Dz(z) l1 z (l1 l0 T) ^ C Ka T 4 ¼K Dzcom (z) z5 þ g4 z4 þ g3 z3 þ g2 z2 þ g1 z þ g0

(4:784)

where 9 > > > > > > > =

g4 ¼ 5 þ m4 T g3 ¼ 10 4m4 T þ m3 T 2 g2 ¼ 10 þ 6m4 T 3m3 T 2 þ m2 T 3 g1 ¼ 5 4m4 T þ 3m3 T 2m2 T þ m1 T 2

3

4

g0 ¼ 1 þ m4 T m3 T 2 þ m2 T 3 m1 T 4 þ m0 T

> > > > > > > 5;

(4:785)

To simulate the altitude response to a step input command of magnitude Dzcom ¼ A, we need the difference equation relating Dzk and (Dzcom)k. Cross multiplying Equation 4.784 after multiplying numerator and denominator by z5 gives (1 þ g4 z1 þ g3 z2 þ g2 z3 þ g1 z4 þ g0 z5 )Dz(z) ^ C Ka T 4 [l1 z4 (l1 l0 T)z5 ]Dzcom (z) ¼K

(4:786)

Invert z-transforming both sides of Equation 4.786 and solving for Dzk give Dzk ¼ g4 Dzk1 g3 Dzk2 g2 Dzk3 g1 Dzk4 g0 Dzk5 ^ C Ka T 4 [l1 (Dzcom )k4 (l1 l0 T)(Dzcom )k5 ] þK

(4:787)

The ﬁrst several values of Dzk are evaluated sequentially from Equation 4.787 as k ¼ 0, 1, 2, 3:

Dzk ¼ 0

(4:788)

k ¼ 4:

^ C Ka T 4 l1 (Dzcom )0 ¼ K ^ C Ka T 4 l1 A Dz4 ¼ K

(4:789)

k ¼ 5:

^ C Ka T 4 [l1 (Dzcom )1 (l1 l0 T)(Dzcom )0 ] Dz5 ¼ g4 Dz4 þ K

(4:790)

^ C Ka T l1 A) þ K ^ C Ka T [l1 A (l1 l0 T)A] ¼ g4 (K

(4:791)

^ C Ka T A( g4 l1 þ l0 T) ¼K

(4:792)

4

4

4

Dzk, k ¼ 6, 7, 8, . . . is computed by recursion according to ^ C Ka T 5 Al0 Dzk ¼ g4 Dzk1 g3 Dzk2 g2 Dzk3 g1 Dzk4 g0 Dzk5 þ K

(4:793)

‘‘Chap4_CaseStudy1.m’’ contains statements to implement Equations 4.788, 4.789, 4.792, and ^ C ¼ 0:003 to the altitude 4.793. The simulated altitude response of the closed-loop system with K command previously considered (Dzcom ¼ 927.5 ft) is shown in Figure 4.111. The analytical solution previously plotted in Figure 4.109 is also presented. For purposes of clarity, the simulated points are plotted 1 s apart, that is, every 10th point is plotted. The exact and simulated responses are in close agreement.

327

Linear Systems Analysis Analytical and simulated (Euler T = 0.1 s) closed-loop system altitude response 1000 900 800

Δz(t) (ft)

700

500

v0 = 500 ft/s – – α = θ = 0.05 rad Δzcom = 927.5 ft

400

Kˆ C = 0.003

600

300 200

Analytical (continuous-time) Simulated (discrete-time)

100 0

FIGURE 4.111

0

50

100

150

200 t (s)

250

300

350

400

Altitude step responses of analytical and simulated closed-loop system.

4.11.2 SIMULATION

OF

STATE VARIABLE MODEL

The linearized model describing the longitudinal dynamics of an aircraft was given in state variable form in Equation 4.735. Subsequent analysis of dynamic response, however, was done using transfer function descriptions relating a speciﬁc input, namely, Dde(t), and a certain output, for example, Du(t), z_ (t), and Dz(t). The conversion from a state-space description to input–output models is accomplished using Equation 4.736 or the MATLAB function ‘‘ss2tf’’ available in the control system toolbox. The remainder of this section is devoted to simulation of the aircraft dynamics based on the continuous-time state-space model Dx ¼ ADx þ BDu,

Dy ¼ CDx þ DDu

(4:794)

where A, B, Dx, Du are evident from Equation 4.735 Dy is the output vector, which determines C and D Suppose a simulation of the state equations using trapezoidal integration is required. Equation 3.121 is the difference equation for updating the discrete-time state based on trapezoidal integration. It is repeated below (using the deviation variable notation) along with the equation for computing the output vector. Dx(n þ 1) ¼

1 1 1 1 1 1 I TA I þ TA Dx(n) þ TB[Du(n) þ Du(n þ 1)] (4:795) I TA 2 2 2 2 Dy(n) ¼ CDx(n) þ DDu(n)

(4:796)

Equations 4.795 and 4.796 represent a straightforward approach to simulation of the state equations using trapezoidal integration. The equations are implemented in the script ﬁle ‘‘Chap4_CaseStudy1.m’’

Simulation of Dynamic Systems with MATLAB® and Simulink®

328

0 T=1 s

Δα (rad)

100 T = 10 s

50 0

T=1 s

−0.1

−0.15 T = 10 s

0

100

0.05 Δq (rad/s)

−0.05

150

200 t (s)

300

−0.2

400

T=1 s

0 T = 10 s

−0.05

0

100

200 t (s)

300

400

300

400

T=1 s

0 Δθ (rad)

Δu (ft/s)

200

−0.2 −0.4

T = 10 s

−0.6 −0.1

FIGURE 4.112

0

100

200 t (s)

300

0

400

100

200 t (s)

Simulation of state vector using trapezoidal integration (de ¼ 5 deg).

for the case where Du ¼ [Dde DdT]T ¼ [58 0 lb]T, Dy ¼ [Du Da Dq Du]T . Accordingly, C is the 4 4 identity matrix and D is a 4 2 matrix of zeros. The simulated output Dy(n) ¼ [Du(n) Da (n) Dq(n) Du(n)]T was recorded for T ¼ 1, 5, 10 s and the results graphed for T ¼ 1 and 10 s in Figure 4.112. There was very little difference in the outputs for T ¼ 1 and 5 s suggesting that the higher value is appropriate for further simulation studies using trapezoidal integration. Setting D_x ¼ 0 in Equation 4.794 and solving for Dx at steady state give Dxss ¼ A1 BDu 2

Duss

2

3

0:04

6 6 7 6 0:00073 6 Dass 7 6 7 )6 ¼ 6 6 0:000048 7 4 4 Dqss 5 Duss

2

0

3

11:59

0

32:2

0:65

1

0

0:49

0:58

0

0

1

0

(4:797) 31 2 7 7 7 7 5

0

0:1

0

0

6 6 0 6 6 0:014 4

117:83 ft=s 6 7 6 0:13 rad 7 6 7 ¼6 7 4 0 rad=s 5

3

7" # 0 7 5 7 0 7 5 0

(4:798)

0:19 rad Setting Dx(n þ 1) ¼ Dx(n) ¼ Dx(1) in Equation 4.795, Dx(1) ¼

1 1 1 I TA I þ TA Dx(1) 2 2 1 1 1 I TA þ TB[Du(1) þ Du(1)] 2 2

(4:799)

329

Linear Systems Analysis

Solving for the steady-state vector Dx(1) gives "

1 #1 1 1 1 1 Dx(1) ¼ I I TA I þ TA I TA TBDu(1) 2 2 2

¼ [117:83 ft=s

0:13 rad

0 rad=s

0:19 rad]T

(4:800)

The continuous-time Dxss and discrete-time (simulated) Dx(1) are identical, in agreement with the values observed in Figure 4.112.

EXERCISES 4.86 Prove the relationship in Equation 4.742 involving complex numbers. 4.87 Use the control system toolbox to (a) Find the transfer functions Du(s)=DdT (s), Da(s)=DdT (s), q(s)=DdT (s), Du(s)=DdT (s): (b) Plot the unit step responses for the linearized model in Equation 4.735 with Dy ¼ Dx. 4.88 Find Dz0 (t) by inversion of Dz0 (s) in Equation 4.768. 4.89 (a) Use a similar approach to the one for ﬁnding Dz0 (s)=Dde (s) to determine Dx0 (s)=Dde (s). (b) Use the control system toolbox to plot Dx0 (t) in response to a step change in elevator input of 58. (c) Find the response Dz0 (t) to the same input. (d) Plot the aircraft’s ﬂight trajectory Dz0 vs. Dx0 for (0 Dx0 25,000 ft). 4.90 Find the time duration of a 58 elevator pulse input required to increase the plane’s elevation by 1500 ft. 4.91 The actuator that controls elevator deﬂection was assumed to exhibit negligible dynamics in the typical range of frequencies encountered. The actuator transfer function is ﬁrst-order with gain Ka ¼ 18=V and time constant ta ¼ 0.4 s. (a) Find the closed-loop transfer functions Dz(s)=Dzcom(s) and Dde(s)=Dzcom(s) with the actuator dynamics included. Express both transfer functions as a ratio of polynomials similar to Equations 4.776 and 4.781. ^ C ¼ 0:005) poles with and without the actuator dynamics. (b) Find the closed-loop system (K Comment on the results. ^ C ¼ 0:005, verify the assumption of negligible actuator dynamics by With K (c) Plotting the frequency response of the open-loop transfer function with and without actuator dynamics. (d) Comparing the elevator deﬂection response when Dzcom ¼ 500 ft with and without the actuator dynamics. (e) Comparing the aircraft altitude response when Dzcom ¼ 500 ft with and without the actuator dynamics. 4.92 For the conditions in Figure 4.111, ﬁnd the maximum deviation between the analytical and simulated altitude responses when using Euler integration with the step sizes shown in the table below. Fill in the table. Step Size

T ¼ 0.025 s

T ¼ 0.05 s

T ¼ 0.1 s

T ¼ 0.25 s

MaxjDzanal Dzsimj

4.93 Starting with the open-loop transfer function GDu Dde (s) ¼ Du(s)=Dde (s) in Equation 4.738, (a) Use Tustin’s method with a sample time of T ¼ 1 s to obtain a discrete-time system approximation GDu Dde (z). Use the control system toolbox function ‘‘c2d’’ if available, otherwise be prepared for some tedious algebraic work.

Simulation of Dynamic Systems with MATLAB® and Simulink®

330

(b) Use the pulse transfer function GDu Dde (z) to ﬁnd the difference equation relating Duk and (Dde)k. (c) Find the aircraft’s pitch response to a unit step change in elevator position by recursive solution of the difference equation. (d) Compare the simulated pitch step response in part (c) to the continuous-time pitch step response shown in Figure 4.103.

4.12 CASE STUDY: NOTCH FILTER FOR ELECTROCARDIOGRAPH WAVEFORM An electrocardiograph (ECG) signal is corrupted with 60 Hz noise from an electrical power source. A portion of the noisy signal, sampled regularly at 0.004 s intervals, is shown in Figure 4.113. A notch ﬁlter is needed to remove the noise. One realization of a second-order ﬁlter transfer function is given by (Orfanidis 1996) Y(z) 1 2( cos v0 T)z1 þ z2 ¼b H(z) ¼ 1 2b( cos v0 T) þ (2b 1)z2 U(z)

(4:801)

where v0 is the notch frequency (in rad=s). The ﬁlter parameter Q relates the notch frequency v0 to the width of the 3 db interval Dv on a plot of jH(e jvT)j2 vs. v. Q¼

v0 Dv

(4:802)

The higher Q is, the narrower is the 3 db interval Dv. The ﬁlter parameter b is obtained from b¼

1 1 þ tan (v0 T=2Q)

(4:803)

Two notch ﬁlters will be investigated. One with Q ¼ 10 and the other with Q ¼ 50. The M-ﬁle ‘‘Chap4_CaseStudy2.m’’ computes the ﬁlter coefﬁcients and plots both jH(e jvT)j2 vs. v and the magnitude function (in db), jH(e jvT)j vs. v (see Figures 4.114 through 4.117). Filter input: ECG + noise

1.6 1.4 1.2

u(t)

1 0.8 0.6 0.4 0.2 0

FIGURE 4.113

0

0.5

1

1.5

2

2.5 t (s)

3

3.5

4

4.5

5

ECG signal corrupted with 60 Hz noise sampled at T ¼ 0.004 s intervals.

331

Linear Systems Analysis 1 0.9 0.8 3 db

|H(ejωT)|2

0.7 0.6 0.5

Δω = 63 Hz − 57 Hz = 6 Hz

0.4 0.3 0.2 0.1 ω0 = 60 Hz

0 0

FIGURE 4.114

10

20

30

40

50 60 ω (Hz)

70

80

90

100

Magnitude squared function for notch ﬁlter (Q ¼ 10).

0

|H(e jωT)| (db)

−10 −20 −30 −40 −50 −60 100

FIGURE 4.115

ω0 = 60 Hz 101 ω (Hz)

102

Magnitude function (in db) for notch ﬁlter (Q ¼ 10).

Note, when jH(e jvT)j2 ¼ 0.5 it is 3 db below the DC value jH(e j0T)j2 ¼ 1. The ﬁltered outputs are shown in Figures 4.118 and 4.119. There is little difference in the outputs of the two ﬁlters except for the longer transient period of the ﬁlter with Q ¼ 50.

4.12.1 MULTINOTCH FILTERS When more than one notch frequency exists, a multinotch ﬁlter design is required. The previous reference includes several methods of designing a multinotch ﬁlter. One approach is to simply use the singlenotch design for each notch frequency and cascade the respective ﬁlters. To illustrate, suppose the ECG signal contains a 25 Hz square wave noise signal like the one shown in Figure 4.120.

Simulation of Dynamic Systems with MATLAB® and Simulink®

332 1 0.9 0.8

3 db

|H(e jωT)|2

0.7 0.6 Δω = 60.6 Hz − 59.4 Hz = 1.2 Hz

0.5 0.4 0.3 0.2 0.1

ω0 = 60 Hz

0 0

FIGURE 4.116

10

20

30

40

50 60 ω (Hz)

70

80

90

100

Magnitude squared function for notch ﬁlter (Q ¼ 50). 5 0 −5

|H(e jωT)| (db)

−10 −15 −20 −25 −30 −35 −40 −45 ω0 = 60 Hz

−50 100

FIGURE 4.117

101 ω (Hz)

102

Magnitude function (in db) for notch ﬁlter (Q ¼ 50).

The noise n(t) contains harmonics at multiples of the fundamental frequency v0 ¼ 2pf0 ¼ 50p rad=s. The Fourier Series expansion of n(t) is given by (see Exercise 4.95) n(t) ¼

1 1 1 sin v0 t þ sin 3v0 t þ sin 5v0 t þ p 3p 5p

(4:804)

Example 4.37 A clean ECG signal, 10 s in duration, is sampled every Ts ¼ 0.004 s and stored in the data ﬁle ‘‘clean_ecg_10sec.mat.’’ The time and signal data are stored in arrays ‘‘t’’ and ‘‘s.’’ (a) Sample the square wave noise shown in Figure 4.120 at the sampling frequency vs ¼ 1=Ts and plot the sampled noise n(t) and the noisy ECG signal s(t) þ n(t).

333

Linear Systems Analysis Filter input: ECG + noise 1.5

u(t)

1 0.5 0

0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

3.5

4

4.5

5

Filter output (Q = 10) 1.5

y(t)

1 0.5 0

FIGURE 4.118

0

0.5

1

1.5

2

2.5 t (s)

3

Output of notch ﬁlter (Q ¼ 10).

Filter input: ECG + noise

u(t)

1.5 1 0.5 0

0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

3.5

4

4.5

5

Filter output (Q = 50) 1.5

y(t)

1 0.5 0

0

0.5

1

1.5

2

2.5 t (s)

FIGURE 4.119

Output of notch ﬁlter (Q ¼ 50).

3

Simulation of Dynamic Systems with MATLAB® and Simulink®

334

Noise f0 = 25 Hz

n(t)

0.25

0

−0.25

0

FIGURE 4.120

0.04 0.08 0.12 0.16 0.2 0.24 0.28 0.32 0.36 0.4 t (s)

Square wave noise component of ECG signal.

(b) Design notch ﬁlters: (i) Hv0(z) to remove the fundamental frequency (ii) H3v0(z) to remove the ﬁrst nonzero harmonic term (iii) H5v0(z) to remove the second nonzero harmonic term Choose the Q values such that the 3 db width Dv for jH(e jvT)j2 vs. v is the same for each ﬁlter. (c) Draw the magnitude function (in db) for the following ﬁlters: (i) Hv0(z) (ii) Hv0 (z)H3v0 (z) (iii) Hv0 (z)H3v0 (z)H5v0 (z) (d) Filter the noisy ECG signal in part (a) using the three ﬁlters in part (c) and graph the results. (a) Figure 4.121 shows 5 s of the noise square wave n(t) and the combined signal plus noise s(t) þ n(t). (b) The ﬁlter parameter Q was chosen as 10 for the ﬁrst ﬁlter. From Equation 4.802 the 3 db width Dv ¼ 2.5 Hz. Using this value for notch frequencies 3v0 ¼ 75 Hz and 5v0 ¼ 125 Hz in Equation 4.802 gives Q¼

3v0 3(25) 5v0 5(25) ¼ ¼ ¼ 30, Q ¼ ¼ 50 Dv Dv 2:5 2:5

(4:805)

The M-ﬁle ‘‘Chap4_Ex12_1.m’’ computes the ﬁlter coefﬁcients for the three notch ﬁlters with Q values 10, 30, and 50 using Equations 4.801 and 4.803. The results are 1 1:6180z1 þ z2 (Q ¼ 10) Hv0 (z) ¼ 0:9695 1 1:5687z1 þ 0:9391 1 þ 0:6180z1 þ z2 H3v0 (z) ¼ 0:9695 (Q ¼ 30) 1 þ 0:5992z1 þ 0:9391 1 þ 2z1 þ z2 (Q ¼ 50) H5v0 (z) ¼ 0:9695 1 þ 1:9391z1 þ 0:9391

(4:806) (4:807) (4:808)

(c) ‘‘Chap4_Ex12_1.m’’ includes statements to plot the magnitude functions of Hv0 (z) and the cascaded ﬁlters Hv0 (z)H3v0 (z) and Hv0 (z)H3v0 (z)H5v0 (z). The results are shown in Figures 4.122 through 4.124.

335

Linear Systems Analysis 25 Hz square wave noise 0.4

n (t)

0.2 0 −0.2 −0.4

0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

4

4.5

5

ECG signal with 25 Hz square wave noise

s(t) + n(t)

1.5 1 0.5 0 0

FIGURE 4.121

0.5

1

1.5

2

2.5 t (s)

3

3.5

Square wave noise and noise-corrupted ECG signal.

(d) The three ﬁlters are shown in Figure 4.125 with their corresponding inputs and outputs. Output of the ﬁlter with transfer function Hv0 (z) in Equation 4.806 is shown in Figure 4.126. The simple notch ﬁlter was designed to remove the fundamental frequency term in Equation 4.804. Output of the ﬁrst ﬁlter y1(k) is passed to the notch ﬁlter with transfer function H3v0 (z) in Equation 4.807. Output y2(k) of the multinotch ﬁlter Hv0 (z)H3v0 (z) is shown in Figure 4.127. Finally, the output of the middle ﬁlter in Figure 4.125 is the input to the third ﬁlter in the series of cascaded ﬁlters. The output of the last ﬁlter y3(k) is plotted as y3(t) in Figure 4.128.

5 0

|H(e jωTs)| (db)

−5 −10 −15

Ts = 0.004 s Q = 10

−20 −25 −30 −35 100

FIGURE 4.122

ω0 = 25 Hz 101 ω (Hz)

Magnitude function (db) for notch ﬁlter Hv0 (z).

102

Simulation of Dynamic Systems with MATLAB® and Simulink®

336 5 0

|H(e jωTs)| (db)

−5 −10

Ts = 0.004 s

−15 3ω0 = 75 Hz −20 −25 −30 ω0 = 25 Hz

−35 100

FIGURE 4.123

101 ω (Hz)

102

Magnitude function (db) for multinotch ﬁlter Hv0 (z)H3v0 (z).

5 0

|H(e jωTs)| (db)

−5 −10

Ts = 0.004 s

5ω0 = 125 Hz

−15

3ω0 = 75 Hz

−20 −25 −30 ω0 = 25 Hz

−35 100

101

102 ω (Hz)

FIGURE 4.124

Magnitude function (db) for multinotch ﬁlter Hv0 (z)H3v0 (z)H5v0 (z).

u(k) = s(k) + n(k)

FIGURE 4.125

Hω0(z)

y1(k)

H3ω0(z)

y2(k)

H5ω0(z)

y3(k)

Multinotch ﬁlter for removing fundamental frequency and ﬁrst two nonzero harmonics.

337

Linear Systems Analysis ECG signal with 25 Hz square wave noise

s(t) + n(t)

1.5 1 0.5 0

0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

4

4.5

5

Output of notch filter Hω0(z) 1.5 y1(t)

1 0.5 0

FIGURE 4.126

0

0.5

1

1.5

2

2.5 t (s)

3

3.5

Input and output of notch ﬁlter Hv0 (z).

The multinotch ﬁlter output in Figure 4.128 is similar in appearance to the single notch ﬁlter outputs shown in Figures 4.118 and 4.119 (after the transient response has vanished) when the noise was a pure sinusoid at 60 Hz. Even though the square wave noise contains an inﬁnite number of harmonics, that is, odd multiples of the fundamental frequency (see Equation 4.804), all but the ﬁrst two nonzero harmonics 3v0 ¼ 75 Hz and 5v0 ¼ 125 Hz are above the Nyquist

ECG signal with 25 Hz square wave noise

s(t) + n(t)

1.5 1 0.5 0

0

1

2

3

4

5

4

5

Output of multinotch filter Hω0(z)H3ω0(z)

y2 (t)

1.5 1 0.5 0

0

1

2

3 t (s)

FIGURE 4.127

Input and output of multinotch ﬁlter Hv0 (z)H3v0 (z).

Simulation of Dynamic Systems with MATLAB® and Simulink®

338

ECG signal with 25 Hz square wave noise

s(t) + n(t)

1.5 1 0.5 0

0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

4.5

5

Output of multinotch filter Hω (z)H3ω (z)H3ω (z) 0 0 0

y3(t)

1.5 1 0.5 0

FIGURE 4.128

0

0.5

1

1.5

2

2.5 t (s)

3

3.5

4

Input and output of multinotch ﬁlter Hv0 (z)H3v0 (z)H5v0 (z).

frequency vnyq ¼ 0.5vs ¼ 0.5 (1=Ts) ¼ 125 Hz. Consequently, the harmonics at 7v0 ¼ 175 Hz, 9v0 ¼ 225 Hz, and so forth, are aliased back to the lower frequencies which are effectively removed by the multinotch ﬁlter in Figure 4.125.

EXERCISES 4.94 Create a noisy ECG signal u(tk) by starting with the clean signal s(tk), where tk ¼ kTs, k ¼ 0, 1, 2, . . . (Ts ¼ 0.004 s) in ‘‘clean_ecg_10sec.mat.’’ Add a 50 Hz sinusoidal noise n(tk) with amplitude of 0.75. (a) Design and implement an appropriate notch ﬁlter to remove the noise. (b) Graph the ﬁlter input u(tk) and its output y(tk) below it. (c) Compare the clean ECG signal s(tk) and the ﬁlter output y(tk). 4.95 The clean ECG signal described in Exercise 4.94 is corrupted by the periodic noise n(t) shown in Figure E4.95. The period P ¼ 1=30 s (v0 ¼ 30 Hz) and amplitude A ¼ 1. n(t) A

−P/2

FIGURE E4.95

0

P/2

P

t 2P

339

Linear Systems Analysis

(a) Sample the noise at the frequency vs ¼ 250 Hz (Ts ¼ 0.004 s), and add it to the clean ECG signal. Denote the corrupted signal by u(tk), where tk ¼ kTs, k ¼ 0, 1, 2, 3,. . . . (b) Expand the noise in a Fourier series expansion, n(t) ¼ v0 ¼

X a0 þ (ak cos kv0 t þ bk sin kv0 t), 2 k¼1, 2,...

2p 2p ¼ ¼ 60p rad=s P 1=30

2 ak ¼ P 2 bk ¼ P

P=2 ð

n(t) cos kv0 t dt, k ¼ 0, 1, 2, P=2 P=2 ð

n(t) sin kv0 t dt, k ¼ 1, 2, P=2

(c) Design and implement a multinotch ﬁlter to remove all the frequency components (except DC) below the Nyquist frequency vnyq ¼ 0.5vs ¼ 125 Hz. (d) Graph the ﬁlter input u(tk) and its output y(tk) below it. (e) Compare the clean ECG signal s(tk) and the ﬁlter output y(tk).

This page intentionally left blank

5

Simulink®

5.1 INTRODUCTION This chapter serves as an introduction to the continuous simulation program, Simulink®. It is similar in many ways to its predecessors such as CSMP (Continuous System Modeling Program), ACSL (Advanced Continuous Simulation Language), TUTSIM (Twente University of Technology Simulator), MATRIX-X, STELLA, and EASY5. The major advantage of Simulink stems from its tight integration with MATLAB®, the data analysis and visualization program with its own structured programming language. The numerous (37 at the time of this printing) MATLAB toolboxes in diverse areas of engineering, science, and business extend the capabilities of Simulink. In addition to the toolboxes, there are a number of Simulink blocksets that extend Simulink into various disciplines such as aerospace, communications, signal processing, image processing, and so forth. A complete list of toolboxes and blocksets with descriptions of each can be found at http:== www.mathworks.com=products=product_listing=index.html. Chapters 1 through 4 cover some basic essentials of linear continuous- and discrete-time systems. Elementary simulation techniques based on numerical integration are also introduced. In all but the simplest cases, the simulated solutions were programmed in MATLAB M-ﬁles. The early continuous-time system simulation languages (CSSLs) consisted of individual sections, for example, ‘‘Initial,’’ ‘‘Dynamic,’’ ‘‘Derivative,’’ and ‘‘Terminal’’ with special demarcation headers for inputting constants and system parameters, calculating new parameters, setting initial conditions for the states, evaluating inputs over time, numerically integrating the state derivative vector, and computing the system outputs (Korn 1978). The continuous-time system dynamics were conﬁned to a section containing expressions for the state derivatives. Lookup tables (in one or more dimensions) were often included in the section to evaluate the state derivatives. Crucial savings in simulation development time resulted from the built-in numerical integration routines and graphing capabilities. Despite minor variations among the CSSLs, they were classiﬁed as ‘‘equation-oriented’’ because expressions for the state derivatives, difference equations, and outputs were entered on one or more lines in equation format. Later, general-purpose, block-oriented simulation programs emerged with powerful graphical user interfaces (GUIs). Dragging and dropping blocks from libraries containing blocks of similar functionality is the most intuitive way for creating a simulation model. Even more so than equation-oriented CSSLs, block-oriented simulation programs such as Simulink free the simulationist from the tedious grunt work required to develop a model structure, implement numerical integration, and produce useful output. Our initial exploration of Simulink in this chapter is merely the ‘‘tip of the iceberg.’’ Later chapters will delve further into the world of Simulink and its capabilities.

5.2 BUILDING A SIMULINK® MODEL To begin our introduction to Simulink, we will demonstrate the procedure for creating a model of a simple system and run the model to obtain useful information about its dynamic response. Our purpose here is to get comfortable with the Simulink user interface at a macroscopic level. Mastering Simulink (Dabney 2001) and The Math Works Web page http:==www.mathworks. com=access=helpdesk=help=toolbox=simulink=ug=ug.html are excellent references for the beginner interested in getting started with Simulink. The Simulink models in this text were developed using Simulink Version 6. 341

Simulation of Dynamic Systems with MATLAB® and Simulink®

342

5.2.1 SIMULINK® LIBRARY The Simulink library contains blocks for representing the mathematical models of commonly occurring components in dynamic systems. The blocks are grouped in sublibraries according to function. The standard Simulink sublibraries are shown in the left pane of Figure 5.1. The blocks residing in the selected ‘‘Continuous’’ sublibrary are shown in the right pane. The ‘‘Integrator’’ block is selected, and there is a brief description of it in the top pane. The transfer function, 1=s, is used to designate the integrator. Building a Simulink model of a system consists of selecting the appropriate blocks and connecting them in a way that represents the mathematical model. Inputs, when present, are implemented using blocks from the ‘‘Sources’’ sublibrary, which can generate a host of input signals. Simulation output is saved and displayed using various blocks such as ‘‘Scopes,’’ ‘‘XY Graphs,’’ and ‘‘Displays’’ from the ‘‘Sinks’’ sublibrary. Our ﬁrst Simulink model will simulate the dynamics of the linear second-order system model introduced in Chapter 2. The differential equation is d2 d y(t) þ 2zvn y(t) þ v2n y(t) ¼ Kv2n u(t) 2 dt dt

(5:1)

Assuming for the moment that the second derivative term d2y=dt 2 is present in a new model window, it can be twice integrated as shown in Figure 5.2 where ‘‘ydd,’’ ‘‘yd,’’ and ‘‘y’’ are the Simulink variable names. The ‘‘Integrator’’ blocks are dragged or copied from the ‘‘Continuous’’ sublibrary into the model window. By inspection of Equation 5.1, the second derivative term is a linear combination of the input u(t), the output y(t), and its ﬁrst derivative dy=dt. The Simulink library browser allows us to search the standard sublibraries for the blocks needed to ‘‘build’’ the second derivative and, thus, complete the Simulink model.

FIGURE 5.1 The Simulink® Library Browser.

Simulink®

FIGURE 5.2

343

Integrating the second derivative ‘‘ydd’’ twice to obtain the ﬁrst derivative ‘‘yd’’ and output ‘‘y.’’

The system parameters K, vn, and z and the literal constant ‘‘2’’ are generated using a ‘‘Constant’’ block found in the ‘‘Sources’’ sublibrary. The ‘‘Math’’ sublibrary provides the additional blocks for addition and multiplication of the signals. We have yet to specify an input or forcing function, assuming there is one. For now, let us pick a simple step input applied at t ¼ 0. Looking in the ‘‘Sources’’ sublibrary, the step input can be implemented with a ‘‘Constant’’ or ‘‘Step’’ block; however, the latter is more ﬂexible should we later decide to delay the time at which the step is applied. Numerical values of the system parameters are set by selecting the individual blocks and typing in the appropriate values in a properties dialog box. Some Simulink blocks contain several parameters, all of which should be speciﬁed or else the default values will be used. For example, the ‘‘Step’’ block generally requires values for ‘‘Step time,’’ ‘‘Initial value,’’ and ‘‘Final value’’ as shown in Figure 5.3, and the ‘‘Integrator’’ block requires an ‘‘Initial condition.’’ Figure 5.4 shows a Simulink diagram for simulation of the unit step response of the second-order system. The choice of Simulink blocks and their location in a Simulink diagram is not unique. The appearance or layout of blocks depends to a large extent on individual user preferences. Some prefer

FIGURE 5.3 Dialog box for specifying input step parameter values.

344

Simulation of Dynamic Systems with MATLAB® and Simulink®

FIGURE 5.4 Simulink® diagram for step response of a second-order system.

that the diagram be the most economical in terms of Simulink blocks used. Others are more concerned with layout style, striving to make the diagram visually appealing. Oftentimes, the mathematical model of the system is available in block diagram form, as in the case of a control system. A Simulink diagram of the system will be strikingly similar, especially when Simulink blocks for modeling actual system components are available. An alternate Simulink diagram for the second-order system in Equation 5.1 is shown in Figure 5.5. A ‘‘Gain’’ block with a parameter value equal to the product 2zvn replaces the ‘‘Product’’ block in the inner feedback loop and the three constant blocks feeding it. Another ‘‘Gain’’ block is inserted in the outer feedback loop with a parameter value numerically equal to v2n replacing the ‘‘Product’’ and ‘‘Constant’’ blocks in Figure 5.4. The third ‘‘Gain’’ block is employed to multiply the input u(t) by Kv2n , further reducing the number of blocks required.

FIGURE 5.5 Alternate Simulink® diagram for a second-order system step response.

Simulink®

345

Note the similarity between the Simulink diagram in Figure 5.5 and the simulation diagram of the system in Figure 2.13. In fact, the thought process for preparing a simulation diagram of a system is nearly identical to the steps required to arrive at a Simulink diagram. Before we delve further into the Simulink library, let us run one of the Simulink models for simulating the step response of the second-order system.

5.2.2 RUNNING

A

SIMULINK® MODEL

The Simulink model is similar to a conventional block diagram of a system. For a system with analog components, it embodies the algebraic and differential equations of the continuous-time math model. For inherently discrete-time systems, the Simulink model encapsulates algebraic and difference equations governing the system’s behavior. Simulink models of hybrid systems containing analog and discrete-time components implement solutions to algebraic, differential, and difference equations. A computer program is created from the Simulink model to solve the equations that comprise the mathematical model of the system. Some of its functions include initialization of state variables, calculation of state derivatives, solution of algebraic equations, updating the state variables, and calculation of the system’s outputs. Simulink offers a variety of numerical integrators to advance the continuous-time state vector over an integration step. The user has the option of choosing a particular integrator and step size (applicable for ﬁxed-step size algorithms), tolerances for satisfying accuracy requirements, the simulation start and stop times, and exchanging simulation data with MATLAB via The MATLAB Workspace. Clicking on ‘‘Simulation’’ in the model window menu followed by ‘‘Configuration Parameters’’ leads to a dialog box like the one shown in Figure 5.6 where the simulation is conﬁgured according to the user’s preferences as previously described. The improved Euler integrator (Heun’s method) with a ﬁxed-step size of 0.01 s and simulation time of 5 s has been selected. After conﬁguring the simulation, the ‘‘Simulation’’ pull-down menu is reopened and ‘‘Start’’ is selected. The simulation terminates when the simulation time reaches the selected ‘‘stop time’’ of 5 s. The simplest way to view simulation output is to select one of the scopes and observe the time history of its input. The output of the second integrator ‘‘y’’ is displayed in several ways, as shown in Figures 5.7 through 5.9. Figure 5.7 is a screen capture of the scope labeled ‘‘y(t)’’ after running the simulation and viewing the scope output by double clicking on it.

FIGURE 5.6 Dialog box for conﬁguring simulation.

346

Simulation of Dynamic Systems with MATLAB® and Simulink®

FIGURE 5.7 Screen capture of scope output.

FIGURE 5.8 Screen capture of edited scope output.

Figure 5.8 is a screen shot of the edited scope output made possible by running an M-ﬁle ‘‘SimScopeControl.m,’’ which brings up the MATLAB Property Editor for editing graphs. Figure 5.9 is the result of copying the edited scope output to the clipboard and pasted into the text. Scope outputs throughout the text will be shown in one of the three formats. As expected, the step response reﬂects a moderately underdamped second-order system. The simulation results can also be imported to the MATLAB Workspace several different ways. In this example, the scopes were conﬁgured to communicate the results in named arrays speciﬁed in the parameters dialog box, which opens after clicking on the icon shown in Figure 5.10.

Simulink®

347

1 0.8 y(t)

0.6 0.4 0.2 0 0

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

t ®

FIGURE 5.9 Simulink plot of unit step response of a second-order system.

FIGURE 5.10

Icon to open the parameter dialog box of ‘‘y(t)’’ scope.

The ‘‘Data history’’ tab in Figure 5.11 was used to save the second integrator’s output in the array ‘‘t_y,’’ which consists of two columns. The ﬁrst consists of the time values for the simulation, and the second column contains the associated y(t) values output from the integrator. Once in the MATLAB Workspace, the various signals can be graphed as shown in Figure 5.12.

EXERCISES 5.1 For the ﬁrst-order system modeled by t

dy þ y ¼ Ku, dt u(t) ¼

y(0) ¼ 0

(t ¼ 3 s, K ¼ 0:1)

0,

t0

A,

t > 0 (A ¼ 5)

Simulation of Dynamic Systems with MATLAB® and Simulink®

348

FIGURE 5.11

Parameter dialog box for saving output to the MATLAB® Workspace.

1.2 y(t)

1.1 1 0.9 0.8 y(t)

0.7 0.6

u(t)

0.5

K = 1, ωn = 4 rad/s, ζ = 0.5

0.4 0.3 0.2 0.1 0 0

FIGURE 5.12

0.4

0.8

1.2

1.6

2 2.4 t (s)

2.8

3.2

3.6

4

MATLAB® plot of a second-order system unit step response.

with initial condition y(0) ¼ 0, (a) Prepare a Simulink diagram for simulating the response. (b) Plot y(t)=yss vs. t where yss ¼ limt!1 y(t) is the steady-state response. (c) Compare the results from part (b) with the exact solution. (d) Repeat parts (b) and (c) for y(0) ¼ 0.5yss, yss, and 1.5yss. 5.2 Simulate the second-order system unit step response for vn ¼ 25 rad=s and z ¼ 0.1 and (a) Prepare a MATLAB plot of y(t) vs. the dimensionless independent variable vnt. (b) Repeat part (a) for z ¼ 0.7, 1, 2.

Simulink®

349

5.3 The temperature T(t), in 8F, of a turkey baking in an oven is approximately governed by the differential equation C

d T(t) ¼ Qi (t) Q0 (t) dt

where C is the thermal capacity in (Btu=8F) of the turkey Qi(t) is the heat input to the turkey Q0(t) is the heat loss due to conduction and convection from the oven, both in Btu=h Expressions for Qi(t) and Q0(t) are as follows: Qi (t) ¼ Q, Q0 (t) ¼

t0

1 [T(t) T0 (t)] R

R is the overall thermal resistance (8F=Btu=h) of the oven, and T0(t) is the room temperature surrounding the oven. Simulate the baking of a 15 lb turkey in an oven with thermal resistance ¼ 4000 Btu=h. The room temperature is a R ¼ 0.0258F=Btu=h and constant heat input Q constant 758F. Note that the speciﬁc heat of turkey is c ¼ 1.25 Btu=lb=8F, and the thermal capacity of the turkey is given by C ¼ mc where m is the mass (in lb) of the turkey. Assume the initial temperature of the turkey is 408F. (a) Plot the temperature T(t) on one graph and heat ﬂows Qi(t) and Q0(t) on separate graphs. Be sure to run the simulation for a period of time sufﬁcient to examine the complete transient response. (b) Estimate the ﬁnal temperature of the turkey if left unattended in the oven. (c) Estimate the time required to heat the turkey to 1608F. (d) Compare the results in parts (a), (b), and (c) with results obtained using the solution to the continuous-time differential equation model for T(t). (e) What size turkey can be heated to 1508F in 2 h?

5.3 SIMULATION OF LINEAR SYSTEMS Simulink offers the user a variety of approaches when it comes to simulation of linear continuoustime systems. The form of the system model generally dictates the choice of blocks from the ‘‘Continuous’’ sublibrary to be used in the Simulink model. For example, a linear second-order system comprising two ﬁrst-order systems in series like that shown in Figure 5.13 suggests an overall Simulink model constructed using Simulink models of the individual ﬁrst-order systems. The Simulink diagram of the system is shown in Figure 5.14. Note that the two integrators are not in series like they were when the system model was a second-order differential equation. The state variables are x and y. A Simulink model of the cascaded ﬁrst-order systems employing consecutive ‘‘Integrator’’ blocks is easily obtained once the variable x is eliminated from the coupled ﬁrst-order differential equations in Figure 5.13. The resulting second-order differential equation in y and the Simulink diagram is left as an exercise. u

FIGURE 5.13

τ1 dx + x = K1u dt

x

τ2 dx + y = K2x dt

y

A second-order system comprised of two cascaded ﬁrst-order systems.

Simulation of Dynamic Systems with MATLAB® and Simulink®

350

FIGURE 5.14

Simulink® diagram of a second-order system shown in Figure 5.13.

5.3.1 TRANSFER FCN BLOCK A glimpse of the Simulink blocks in the ‘‘Continuous’’ sublibrary reveals additional options for simulation of linear system models. The ‘‘Transfer Fcn’’ and ‘‘Zero–Pole’’ blocks provide alternative representations for the dynamics of a linear continuous-time component. The n individual integrators and arithmetic blocks for a system component with nth-order dynamics are collapsed into a single block, incorporating the higher-order dynamics. The ‘‘Transfer Fcn’’ and ‘‘Zero– Pole’’ blocks correspond to transfer function models in polynomial and factored form, respectively. To illustrate the use of the ‘‘Transfer Fcn’’ block, consider a variation of the case study in Section 2.8 for the submarine depth control system. The reference signal vcom(t) for the control loop is the command depth rate and the controlled variable is the actual depth rate v(t) as shown in Figure 5.15. The depth y(t) is obtained by integrating the depth rate v(t). The submarine is assumed initially to be in steady state at the surface when the command depth rate is suddenly increased to 25 ft=s and held constant for 30 s and then returned to zero. The transfer function for the controller and stern plane actuator is GC (s) ¼

u(s) KC s þ KI ¼ s E(s)

(KC ¼ 0:6, KI ¼ 0:1)

(5:2)

and the submarine dynamics is modeled by the transfer function GP (s) ¼

V(s) Ku_ s þ Ku ¼ ts þ 1 u(s)

(Ku_ ¼ 20, Ku ¼ 10, t ¼ 10)

(5:3)

The Simulink diagram is shown in Figure 5.16. A ‘‘Transfer Fcn’’ block was used to model the controller and submarine dynamics. Note the use of two step blocks with the same amplitude (25 ft=s), the ﬁrst commencing at t ¼ 0 and the second starting at t ¼ 30 s along with the summation block to implement the overall command depth rate signal. The command and actual depth rates are multiplexed and fed to the scope in the upper right corner of the diagram. The submarine depth is captured by the scope directly below. The simulation was conﬁgured using Simulink’s ﬁxed-step ‘‘ode4’’ numerical integrator with step size 0.01 s. The ‘‘ode4’’ numerical integrator belongs to a family of numerical

vcom(t) ft/s

FIGURE 5.15

e(t) – ft/s

Controller and stern plane actuator

θ(t) deg

Submarine depth rate control system.

Submarine dynamics

ν(t) ft/s

1 s

y(t) ft

Simulink®

FIGURE 5.16

351

Simulink® diagram for sub depth control using transfer function blocks.

25

Velocity (ft/s)

20 15 10 5 0 0

FIGURE 5.17

10

20

30 Time (s)

40

50

60

Command and actual submarine depth rates.

integrators collectively referred to as Runga–Kutta. Chapter 6 includes a discussion of Runga–Kutta integration. The command and actual depth rate signals are shown in Figure 5.17. Note the discontinuity in the actual depth rate at t ¼ 0 and t ¼ 30 s. This implies the existence of a direct path from the command depth rate vcom to the actual depth rate v without integrators present. The direct path is not apparent in Figure 5.16; however, it would be evident on a simulation diagram of the system. The stern plane angle (8) and the actual submarine depth (ft) are shown in Figure 5.18. The presence of a direct path with only algebraic blocks from command input vcom to the actual submarine depth rate v is easier to visualize if we express the transfer functions in Figure 5.16 differently, that is, GC (s) ¼

u(s) KI ¼ KC þ s E(s)

(5:4)

GP (s) ¼

V(s) Ku_ s þ Ku ¼ ts þ 1 u(s)

(5:5)

Ku_ (Ku (Ku_ =t)) þ ts þ 1 t

(5:6)

¼

Simulation of Dynamic Systems with MATLAB® and Simulink®

352

800

6

600

2

y (ft)

u (deg)

4

0

−2

400 200

−4 0

10

20

(a)

FIGURE 5.18

30 40 Time (s)

50

0

60

0

10

20

(b)

30 40 Time (s)

50

60

Simulated (a) stern plane angle (deg) and (b) sub depth (ft).

Hence, the direct path starts from ‘‘v_com’’ through the summer and on through constant blocks with gains ‘‘KC’’ and ‘‘Kthd=tau’’ to the output ‘‘v.’’ The Simulink diagram in Figure 5.16 can be modiﬁed to implement the controller and submarine dynamics transfer functions as given in Equations 5.4 and 5.6 (see Exercise 5.5). The submarine depth, shown in Figure 5.16, is continuous at t ¼ 0 due to the presence of the integrator between ‘‘v’’ and ‘‘y.’’ Referring to Figure 5.15, the closed-loop transfer function is V(s) GC (s)GP (s) ¼ Vcom(s) 1 þ GC (s)GP (s)

(5:7)

¼

((KC s þ KI )=s)((Ku_ s þ Ku )=(ts þ 1)) 1 þ ((KC s þ KI )=s)((Ku_ s þ Ku )=(ts þ 1))

(5:8)

¼

(KC s þ KI )(Ku_ s þ Ku ) s(ts þ 1) þ (KC s þ KI )(Ku_ s þ Ku )

(5:9)

The steady-state value v(1) resulting from the step input ucom(t) ¼ 25, t 0 is obtained from the ﬁnal value theorem (Section 4.2), (KC s þ KI )(Ku_ s þ Ku ) 25 ¼ 25 (5:10) v(1) ¼ lim sV(s) ¼ lim s s!0 s!0 s(ts þ 1) þ (KC s þ KI )(Ku_ s þ Ku ) s conﬁrmed in Figure 5.17, which shows the depth rate v(t) approaching the commanded 25 ft=s once the transient response has vanished. The discontinuity in depth rate at t ¼ 0 shown in Figure 5.17 can also be veriﬁed. According to the initial value; theorem, v(0þ ) ¼ lim sV(s) ¼ lim s s!1

s!1

(KC s þ KI )(Ku_ s þ ku ) 25 s(ts þ 1) þ (KC s þ KI )(Ku_ s þ Ku ) s

¼ lim

s!1

¼

(KC þ (KI =s))(Ku_ þ (Ku =s)) 25 (t þ (1=s)) þ (KC þ (KI =s))(Ku_ þ (Ku =s))

(5:11)

25KC Ku_ 25(0:6)(20) ¼ ¼ 13:64 ft=s t þ KC Ku_ 10 þ (0:6)(20)

is in agreement with the graph of v(t) shown in Figure 5.17. The following example further illustrates the use of the ‘‘Transfer fcn’’ block.

(5:12) (5:13)

Simulink®

353

Example 5.1 For the submarine depth rate control system shown in Figure 5.15, (a) Find the analytical solution for the submarine depth rate v(t), 0 < t 30 in response to the command input vcom(t) ¼ 25, t 0. (b) Model the closed-loop control system dynamics using a ‘‘Transfer fcn’’ block for V(s)= Vcom(s) and use it to simulate the depth rate response to the command depth rate shown in Figure 5.17. Compare the simulated and analytical depth rate responses for v(t), 0 < t 30. (a) From Equation 5.9,

(KC s þ KI )(Ku_ s þ Ku ) Vcom (s) V(s) ¼ s(ts þ 1) þ (KC s þ KI )(Ku_ s þ Ku ) ¼ ¼

¼

(5:14)

KC Ku_ s2 þ (KC Ku þ KI Ku_ )s þ KI Ku 25 (t þ KC Ku_ )s2 þ (1 þ KC Ku þ KI Ku_ )s þ KI Ku s

(5:15)

12s2 þ 8s þ 1 25 22s2 þ 9s þ 1 s

(5:16)

25 12s2 þ 8s þ 1 22 s{s2 þ (9=22)s þ 1=22}

(5:17)

Using partial fraction expansion of the right-hand side of Equation 5.17 followed by inverse Laplace transformation, the solution for v(t), 0 < t 30 becomes v(t) ¼ 25

pﬃﬃﬃ pﬃﬃﬃ 7 7 25 9t=44 47 t pﬃﬃﬃ sin t , 10 cos e 44 44 22 7

0 < t 30

(5:18)

(b) The analytical solution for v(t) in Equation 5.18 is incorporated in Simulink using a ‘‘Sine Wave’’ block from the ‘‘Sources’’ sublibrary and a ‘‘Math Function’’ block from the ‘‘Math’’ sublibrary for the exponential term. The Simulink diagram appears in Figure pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ5.19. ﬃ The ‘‘Sine Wave’’ parameters dialog box for the cosine term cos ( 7=44 t) in the analytical solution, Equation 5.18, is shown in Figure 5.20. Note that the phase angle is p=2 rad to produce the cosine function. The control system loop with input vcom(t) and output v(t) in Figure 5.15 is replaced with the equivalent closed-loop transfer function V(s)=Vcom(s) in Figure 5.21. The Simulink diagram shown in Figure 5.22 includes a ‘‘Transfer fcn’’ block for implementing the closed-loop transfer function. The simulated and analytical depth rates for a time period 0 < t 12 s are shown in Figure 5.23. The graphs were generated in the MATLAB M-ﬁle ‘‘Chap5_Fig3_11.m’’ by saving the data in the scope shown with the heavy line multiplexed input in Figure 5.22. The complete set of time values along with the simulated and analytical results is saved in the MATLAB Workspace in a named array set in the scope dialog box. Also shown is the difference between the two depth rates. It is clear from looking at the difference that the simulated depth rate is nearly identical to the analytical solution.

5.3.2 STATE-SPACE BLOCK The process of transforming models consisting of linear algebraic and differential equations into state variable form was demonstrated in Section 2.6. Conversion of SISO (single input–single output) or MIMO (multiple input–multiple output) system transfer functions to state-space

354

Simulation of Dynamic Systems with MATLAB® and Simulink®

FIGURE 5.19

Simulink® diagram with simulated and analytical submarine depth rate.

FIGURE 5.20

‘‘Sine Wave’’ parameter box to generate cosine term in analytical solution.

Simulink®

355 (KC s + KI) (Kθ. s + Kθ) V(s) = Vcom(s) s(τs + 1) + (KC s + KI) (Kθ. s + Kθ)

Vcom(s)

FIGURE 5.21

V(s)

Closed-loop transfer function of submarine depth rate control system.

FIGURE 5.22 Simulink® diagram using ‘‘Transfer fcn’’ block for submarine closed-loop depth rate control system dynamics.

Simulated depth rate vs. time

Vsim (ft/s)

30 20 10 0

Analytical depth rate vs. time Vanal (ft/s)

30 20 10

Vsim–Vanal (ft/s)

0

FIGURE 5.23

5

Simulated–analytical depth rate vs. time

×10−3

0 −5

0

1

2

3

4

5

6 7 Time (s)

8

9

10

11

12

Analytical and simulated depth rate using ‘‘Transfer fcn’’ for V(s)=Vcom(s).

Simulation of Dynamic Systems with MATLAB® and Simulink®

356

FIGURE 5.24

The Simulink® ‘‘State-Space’’ block.

models and vice versa was illustrated using the control system toolbox in Section 4.10. Simulink provides a mechanism for incorporating state variable models of system components using the ‘‘State-Space’’ block located in the ‘‘Continuous’’ sublibrary. A partial description of the ‘‘State-Space’’ block is shown in Figure 5.24. The next example illustrates its use. Example 5.2 An automobile traveling along a level road at a constant speed v0 encounters a speed bump shown in Figure 5.25. The vehicle’s suspension system (front and rear springs and shock absorbers) is modeled by linear springs and dampers, and the compliance of the tires is modeled by front and rear springs. The vehicle cab motion is limited to heave in the y-direction and a small amount of pitch u of the vehicle’s longitudinal axis. The tires are assumed to remain in contact with the road surface at all times. The road proﬁle is responsible for the system’s input u ¼ [uf ur]T, where uf and ur are the height of the road (with respect to some reference) underneath the front and rear tires, respectively. The system has three translational degrees of freedom, y, yf, yr, which are the vertical displacements of the vehicle cab and both front and rear axles from their equilibrium positions. The lone rotational degree of freedom is the pitch angle u. Three of the four model equations are obtained by equating the sum of suspension and tire forces acting on the three masses to the appropriate acceleration term, M€ y, Mf y€f , and Mr y€r . The fourth equation sets the torques about the vehicle cab’s center of gravity created by the suspension forces equal to the inertial acceleration I€ u. The model equations are listed as follows: _ þ Krs [yr (y Lr u)] þ Br [y_ r (y_ Lr u)] _ M€ y ¼ Kfs [yf (y þ Lf u)] þ Bf [y_ f (y_ þ Lf u)]

(5:19)

¼ (Kfs þ Krs )y (Bf þ Br )y_ þ Kfs yf þ Bf y_ f þ Krs yr þ Br y_ r þ (Krs Lr Kfs Lf )u þ (Br Lr Bf Lf )u_

(5:20)

Simulink®

357 u Ab cos π x 2L −L

L

y

x

yf

yr

θ v0 uf

Lf

Lr

ur

x

D0 y θ Kfs Mf Kft

M

Bf yf

Krs

uf

Br

Mr Krt

FIGURE 5.25

yr ur

Moving vehicle and suspension system model.

_ þ Kft (uf yf ) Mf y€f ¼ Kfs [yf (y þ Lf u)] Bf [y_ f (y_ þ Lf u)] ¼ (Kfs þ Kft )yf Bf y_ f þ Kfs y þ Bf y_ þ Kfs Lf u þ Bf Lf u_ þ Kft uf _ þ Krt (ur yr ) Mr y€r ¼ Krs [yr (y Lr u)] Br [y_ r (y_ Lr u)] ¼ (Krs þ Krt )yr Br y_ r þ Krs y þ Br y_ Krs Lr u Br Lr u_ þ Krt ur

(5:21) (5:22) (5:23) (5:24)

_ f I€u ¼ {Kfs [yf (y þ Lf u)] þ Bf [y_ f (y_ þ Lf u)]}L _ r {Krs [yr (y Lr u)] þ Br [y_ r (y_ Lr u)]}L

(5:25)

¼ (Kfs L2f þ Krs L2r )u (Bf L2f þ Br L2r )u_ þ (Krs Lr Kfs Lf )y þ (Br Lr Bf Lf )y_ þ Kfs Lf yf Krs Lr yr þ Bf Lf y_ f Br Lr y_ r

(5:26)

Note that the equations are linear as a result of assuming small pitch angles, allowing the approximations sin u u and cos u 1. (a) Introduce state variables x1 ¼ y,

x3 ¼ yf ,

x5 ¼ yr ,

x7 ¼ u,

_ x2 ¼ y,

x4 ¼ y_ f ,

x6 ¼ y_ r ,

_ x8 ¼ u,

and solve for the state derivatives, that is, ﬁnd the matrices A and B in x_ ¼ Ax þ Bu. (b) Deﬁne the outputs as y1 ¼ y, y2 ¼ yf, y3 ¼ yr, and y4 ¼ u and ﬁnd matrices C and D in y ¼ Cx þ Du. (c) Simulate and plot the vehicle dynamics using the following values for the weight of the vehicle and tires, suspension parameters, forward speed, and speed bump proﬁle.

Simulation of Dynamic Systems with MATLAB® and Simulink®

358 W ¼ 4,200 lb,

Wf ¼ 125 lb,

Bf ¼ 25 lb s=in, I ¼ 40,000 in: lb s2 ,

Wr ¼ 125 lb,

Br ¼ 35 lb s=in, Lf ¼ 55 in:,

Kfs ¼ 120 lb=in,

Kft ¼ 1,100 lb=in,

Lr ¼ 65 in:,

Krs ¼ 180 lb=in,

Krt ¼ 1,100 lb=in,

v0 ¼ 20 mph,

Ab ¼ 4 in:,

L ¼ 1 ft

(a) Using the deﬁnition of the state variables and solving for the state derivatives in Equations 5.19 through 5.26 give x_ 1 ¼ x2 (Kfs þ Krs ) (Bf þ Br ) Kfs Bf Krs Br x3 þ x4 þ x5 þ x6 x1 x2 þ x_ 2 ¼ M M M M M M (Krs Lr Kfs Lf ) (Br Lr Bf Lf ) þ x7 þ x8 M M x_ 3 ¼ x4 Kfs Bf (Kfs þ Kft ) Bf Kfs Lf Bf L f Kft x1 þ x2 x3 x4 þ x7 þ x8 þ uf x_ 4 ¼ Mf Mf Mf Mf Mf Mf Mf x_ 5 ¼ x6 Krs Br (Krs þ Krt ) Br Krs Lr Br Lr Krt x1 þ x2 x5 x6 x7 x8 þ ur x_ 6 ¼ Mr Mr Mr Mr Mr Mr Mr x_ 7 ¼ x8 (Krs Lr Kfs Lf ) (Br Lr Bf Lf ) Kfs Lf Bf Lf x3 þ x4 x1 þ x2 þ x_ 8 ¼ I I I I 2 2 2 (Kfs Lf þ Krs Lr ) (Bf Lf þ Br L2r ) Krs Lr Br Lr x7 x8 x5 x6 I I I I

(5:27)

(5:28) (5:29) (5:30) (5:31) (5:32) (5:33)

(5:34)

The system matrix A and input matrix B are 2

0 6 (Kfs þ Krs ) 6 6 M 6 6 0 6 6 6 K fs 6 6 Mf 6 6 6 0 6 6 Krs 6 6 Mr 6 6 6 0 6 6 Krs Lr Kfs Lf 6 6 1 6 A¼6 6 0 6 6 K rs 6 6 M 6 6 0 6 6 6 6 0 6 6 6 6 0 6 6 (Krs þ Krt ) 6 6 Mr 6 6 6 0 6 4 Krs Lr I

1 (Bf þ Br ) M 0 Bf Mf

0 Kfs M 0 (Kfs þ Kft ) Mf

0 Bf M 1 Bf Mf

0 Br Mr 0 Br Lr Bf Lf 1 0 Br M 0

0

0

0

0

0 Kfs Lf 1 0 Krs Lr Kfs Lf M 0 Kfs Lf Mf

0 Bf Lf 1 0 Br Lr Bf Lf M 0 Bf Lf Mf

1 Br Mr 0

0 Krs Lr Mr 0

1 Br Lr Mr 1

Br Lr I

(Kfs L2f þ Krs L2r ) I

(Bf L2r þ Bf L2r ) I

0

3 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 5

(5:35)

Simulink®

359 2

0

6 6 0 6 6 0 6 6K 6 ft 6 6M B¼6 f 6 0 6 6 6 0 6 6 6 0 4 0

0

3

7 0 7 7 0 7 7 7 7 0 7 7 7 0 7 7 Kft 7 7 Mr 7 7 0 7 5 0

(5:36)

(b) The output matrix C and direct transmission matrix D are given by 1 60 6 C¼6 40

0 0 0 1 0 0

0 0 0 0 0 1

0 0 0 0 0 0

3 0 07 7 7, 05

0

0 0

0 0

0 1

0

2

3 0 0 60 07 7 6 D¼6 7 40 05 2

(5:37)

0 0

The direct transmission matrix D is all zeros, since the system inputs uf and ur are not directly coupled to the outputs, that is, step changes in either input are integrated before inﬂuencing the outputs, and, hence, the outputs are continuous at the time the step input(s) is applied. (c) The Simulink diagram for simulating the vehicle’s response as it travels over the speed bump is shown in Figure 5.26. The ‘‘State-Space’’ block parameters are the matrices A, B, C, and D of Equations 5.35 through 5.37, which have been deﬁned in a MATLAB M-ﬁle ‘‘Chap5_VehParams. m’’ for convenience. The input displacements uf and ur are based on the speed bump proﬁle shown in Figure 5.25 and the forward speed of the car. The front tire displacement is given by 8 D0 L > > 0, t< > > > v0 > > < p D0 L D0 þ L uf ¼ Ab cos (D0 v0 t), (5:38) t > 2L v0 v0 > > > > D0 þ L > > : 0, t> v0

FIGURE 5.26

Simulink® diagram for vehicle response traveling over a speed bump.

Simulation of Dynamic Systems with MATLAB® and Simulink®

360

Front tire displacement vs. time

uf (in.)

4 3 2 1 0 1.75

1.95 2 2.05 2.1

2.45

Rear tire displacement vs. time

ur (in.)

4 3 2 1 0 1.75

FIGURE 5.27

t (s)

2.3 2.35 2.4 2.45

Inputs uf and ur for vehicle traveling at constant speed v0.

The Simulink blocks to implement uf (and ur) are shown in the top left (and lower left) corner of Figure 5.26. Note the use of the ‘‘Clock’’ from the ‘‘Sources’’ sublibrary to generate the simulation time variable ‘‘t.’’ Also, the wider (and heavier) arrows in and out of the ‘‘StateSpace’’ block designate the presence of nonscalar signals, and the ‘‘2’’ and ‘‘4’’ indicate the number of components in each. The inputs uf and ur are captured in a scope and plotted for 1.75 < t 2.5 s in the M-ﬁle ‘‘Chap5_Figs3_15and3_16.m’’ (see Figure 5.27). The output vector ‘‘y’’ of the ‘‘State-Space’’ block is decomposed in a ‘‘Demux’’ block and sent to a scope with four input channels (one for each output). It is also saved for use by the M-ﬁle ‘‘Chap5_Figs3_15and3_16.m.’’ The results are plotted for the interval 1.5 t 3.5 s in Figure 5.28. The vehicle cab displacement varies from 0.189 to 0.627 in. despite the 4 in. height of the speed bump. Also, the pitch of the vehicle is constrained to 0.4038 u 0.3588. The ‘‘Data history’’ tab in the ‘‘Scope’’ with multiplexed input containing ‘‘uf’’ and ‘‘ur’’ is shown in Figure 5.29. Simulation time values and front and rear tire displacements are saved to the MATLAB Workspace in array ‘‘uf_ur.’’ The following MATLAB statements placed at the beginning of M-ﬁle ‘‘Chap5_ Figs3_15and3_16.m’’ store the saved values of the time array and tire displacements in arrays ‘‘t,’’ ‘‘uf,’’ and ‘‘ur’’ and produce the graph shown in Figure 5.27. Chap5_VehParams sim(‘CarDynamics’) t ¼ uf_ur(:,1); uf ¼ uf_ur(:,2); ur ¼ uf_ur(:,3); figure(1) % begin Figure 5.27 subplot(2,1,1) plot(t,uf) ylabel(‘uf (in)’,‘Font Size’,11) title(‘Front Tire Displacement vs. Time’, ‘FontSize’,11) subplot(2,1,2) plot(t,ur)

Simulink®

361

y (in.)

Vehicle c.g. displacement vs. time 3 2 1 0 1.75

2

2.25

2.5

2.75

3

3.25

3.5

3.25

3.5

3

3.25

3.5

3

3.25

3.5

yf (in.)

Front axle displacement vs. time 3 2 1 0 1.75

2

2.25

2.5

2.75

3

yr (in.)

Rear axle displacement vs. time 3 2 1 0 1.75

2

2.25

2.5

2.75

θ (deg)

Vehicle pitch angle vs. time 0.4 0 −0.4 1.75

2

2.25

2.5

2.75 t (s)

FIGURE 5.28

Outputs y, yf, yr, and u of vehicle suspension system for 1.5 t 4 s.

FIGURE 5.29

Saving ‘‘uf’’ and ‘‘ur’’ for plotting in M-ﬁle ‘‘Chap5_Figs3_15and3_16.m.’’

ylabel(‘ur (in)’,‘FontSize’,11) xlabel(‘\itt \rm(sec)’,‘FontSize’,11) title(‘Rear Tire Displacement vs. Time’,‘FontSize’,11) The ﬁrst statement runs another M-ﬁle ‘‘Chap5_VehParams.m,’’ which loads the parameter values. The next command sim(‘‘CarDynamics’’) causes execution of the Simulink model ‘‘CarDynamics.mdl.’’

Simulation of Dynamic Systems with MATLAB® and Simulink®

362

EXERCISES 5.4 For the second-order system shown in Figure 5.13, (a) Find the second-order differential equation relating the output y and input u. (b) Draw a Simulink diagram of the system with two integrators in series. 5.5 For the submarine depth control system shown in Figure 5.15, (a) Draw a simulation diagram. Is there a direct connection from vcom to v? (b) Redraw the Simulink diagram in Figure 5.16 using the alternate expressions for the controller and submarine dynamics transfer functions in Equations 5.4 and 5.6. (c) Run the Simulink model and compare the responses for v(t), y(t), and u(t) with those shown in the text. 5.6 Two linear tanks are arranged in series as shown in Figure E5.6: F1(t) F0(t)

H1(t)

A1 R1

H2(t)

A2 R2

F2(t)

FIGURE E5.6

(a) Write the differential equation models for the tanks. (b) The system parameters are A1 ¼ 50 ft2, A2 ¼ 100 ft2, R1 ¼ 0.2 ft=ft3=min, and R2 ¼ 0.3 ft=ft3=min Prepare a Simulink diagram of the system, and simulate the response of both tank levels under the following conditions: (i) H1(0) ¼ 0, H2(0) ¼ 0, F1(t) ¼ 40 ft3=min, t 0 0, t 0 (ii) H1(0) ¼ 0, H2(0) ¼ 10, F1(t) ¼8 5t, 0t5 > > < (iii) H1(0) ¼ 0, H2(0) ¼ 0, F1 (t) ¼ 5t þ 50, 5 < t 10 > > : 0, t>0 Obtain one graph with time histories of H1(t) and H2(t) and a second graph with F0(t), F1(t), and F2(t). (c) Eliminate H1(t) from the two ﬁrst-order differential equations in part (a) to obtain a secondorder differential equation relating H2(t) and F1(t). (d) Prepare a Simulink diagram based on the continuous-time model in part (c). (e) Run the Simulink model for the same conditions in part (b), and compare the response for H2(t) with the one obtained in part (b). (f) Find the analytical solution [H2(t)]anal when both tanks are initially empty and F1(t) ¼ 40 ft3=min, t 0. Compare the analytical solution [H2(t)]anal with the simulated solution [H2(t)]sim obtained in part (b). Hint: Use Simulink to implement the analytical solution and feed both [H2(t)]sim and [H2(t)]anal into a summer to obtain the difference. 5.7 Solve Exercise 2.3 using Simulink. 5.8 Solve Exercise 2.4 using Simulink.

Simulink®

363

5.4 ALGEBRAIC LOOPS Execution of the Simulink model in this chapter, Figure 5.16, poses a dilemma often encountered when simulating dynamic systems with feedback loops. A runtime warning (default) or error appears in the MATLAB Command Window stating Warning:Block diagram ‘SubDepth_A’ contains 1 algebraic loop(s). Found algebraic loop containing block(s): ‘SubDepth_A=Controller and Stern Plane Actuator Transfer Fcn’ ‘SubDepth_A=Sub Dynamics Transfer Fcn’ ‘SubDepth_A=Sum1’ (algebraic variable) An algebraic loop is any closed loop appearing in the Simulink diagram composed of strictly algebraic and implicit blocks such as the implicit discrete-time numerical integrators (discussed in Section 5.6). Consequently, the output of any block in an algebraic loop is ultimately an implicit function of itself. In large scale simulations with several 100 blocks, it is nearly impossible to identify the presence of an algebraic loop by visual inspection. The Simulink diagrams of even relatively simple simulations with only a handful of blocks may contain algebraic loops, which escape detection. Simulink (and other block-oriented continuous simulation languages) detects the presence of an algebraic loop and reports the blocks comprising it. Before we discuss its implications, let us conﬁrm the existence of an algebraic loop in the Simulink model ‘‘SubDepth_A.mdl’’ consisting of the two ‘‘Transfer fcn’’ blocks and the ‘‘Sum’’ block. Referring to Figure 5.16, the controller and stern plane actuator transfer function can be rewritten as follows: GC (s) ¼

0:6s þ 0:1 0:1 ¼ 0:6 þ s s

(5:39)

and the submarine dynamics transfer function is expressible as GP (s) ¼

20s þ 10 8 ¼2þ 10s þ 1 10s þ 1

(5:40)

leading to an equivalent block diagram shown in Figure 5.30. The algebraic loop is shown in bold, and a similar algebraic loop is present in the Simulink diagram for ‘‘SubDepth_A.mdl.’’ Note that if the controller and stern plane actuator transfer function were replaced by a pure gain, the diagram would still have an algebraic loop due to the direct path from the input to the output in the submarine dynamics transfer function.

vcom

e(t) −

0.6

0.1 s Controller and stern plane actuator

FIGURE 5.30

θ(t)

2

v(t)

8 10s + 1 Submarine dynamics

Block diagram for submarine depth control showing algebraic loop.

1 s

y(t)

364

Simulation of Dynamic Systems with MATLAB® and Simulink®

The dilemma posed by algebraic loops can be demonstrated by looking at the equations the Simulink program is attempting to solve in the submarine example at the time t ¼ 0. After initializing the state u(0) and v(0) and evaluating the input vcom(0), Simulink calculates e(0) according to e(0) ¼ vcom (0) v(0)

(5:41)

Existence of direct paths, that is, pure gain (zero-order dynamics), from e(t) to u(t) and u(t) to v(t) implies v(0) ¼ 2u(0)

(5:42)

u(0) ¼ 0:6e(0)

(5:43)

Substituting u(0) in Equation 5.43 into Equation 5.42 gives v(0) ¼ 2[0:6e(0)] ¼ 1:2e(0)

(5:44)

Replacing e(0) in Equation 5.44 with e(0) in Equation 5.41 results in v(0) ¼ 1:2[vcom (0) v(0)]

(5:45)

The circular nature of algebraic loops is demonstrated by Equation 5.45, an implicit equation with v(0) on both sides. In the general case, the implicit equation is nonlinear. Simulink attempts to solve the implicit equations associated with an algebraic loop using the iterative Newton–Raphson method (Chapra 2002). Solving implicit equation(s) at each iteration, especially nonlinear ones, can dramatically decrease the simulation execution speed. Further, the method can fail to converge to a solution. The initial depth rate value, more precisely, the value at t ¼ 0þ in the submarine example, is easily veriﬁed from Equation 5.45. v(0þ ) ¼ 1:2[vcom (0) v(0þ )] ) v(0þ ) ¼

1:2 1:2 vcom (0) ¼ (25) ¼ 13:64 2:2 2:2

(5:46) (5:47)

in agreement with the value given in Equation 5.13 as well as the graph for v(t) shown in Figure 5.17.

5.4.1 ELIMINATING ALGEBRAIC LOOPS The most desirable method for eliminating an algebraic loop is by means of algebraic manipulation of the loop equations to produce an equivalent system explicit in nature. It is up to the user to obtain an explicit solution, if one exists, and modify the Simulink diagram accordingly. Simulink does not perform the symbolic math operations necessary to obtain the solution shown in Equation 5.47. To illustrate, consider the block diagram of a system shown in Figure 5.31. The algebraic loop is shown in bold. By algebraic manipulation or similar block diagram reduction techniques, the transfer function Y(s)=R(s) is obtained as Y(s) K þ (1 þ K)G(s) ¼ R(s) (1 þ K) þ (2 þ K)G(s)

(5:48)

Simulink®

365 K R(s)

FIGURE 5.31

–

G(s)

–

Y(s)

Block diagram of system with algebraic loop.

Suppose the constant K ¼ 1 and the transfer function G(s) ¼ 1=(s þ 10). The transfer function Y(s)=R(s) reduces to Y(s) 0:5(s þ 12) ¼ R(s) s þ 11:5

(5:49)

It is left as an exercise to demonstrate that a Simulink diagram based on the block diagram in Figure 5.31 and one with a single ‘‘Transfer Fcn’’ to implement Equation 5.49 produce identical outputs. Unfortunately, the dynamic model equations rarely permit this approach. In most cases, the algebraic loop entails nonlinear blocks, making it difﬁcult or impossible to reformulate the equations to produce a new block diagram with the algebraic loop removed. Several algebraic loops with shared blocks may exist, complicating matters even further. A second approach to dealing with algebraic loops consists of inserting a ‘‘Memory’’ block into the loop. A ‘‘Memory’’ block is equivalent to a one-integration step delay. Its output is the input from the previous time step. This allows Simulink to calculate outputs of all the blocks in the algebraic loop in the proper sequence. The system shown in Figure 5.32 consists of a cart with an inverted pendulum. The position of the cart x(t) and the angle of the pendulum from the vertical u(t) are of interest. The pendulum is free to rotate without friction in a plane, and the cart moves along a frictionless surface. The input is a horizontal force u. The outputs are x and u. From Newton’s second law (translation and rotation), the equations of motion are (M þ m)€x mlu_ 2 sin u þ ml€u cos u ¼ u

(5:50)

m€x cos u þ ml€ u ¼ mg sin u

(5:51)

where l is the length of the pendulum m is the pendulum mass (assumed to be concentrated at the end) M is the mass of the cart g is the gravitational constant m θ

l x

u

FIGURE 5.32

Inverted pendulum.

M

Simulation of Dynamic Systems with MATLAB® and Simulink®

366

FIGURE 5.33

Simulink® model of inverted pendulum with ‘‘Memory’’ block.

Later, in Section 5.6, Equations 5.50 and 5.51 will be converted into a pair of equations, one for €x _ and the other with € u where both are explicit functions of the state variables u and u. A Simulink diagram of the system is shown in Figure 5.33. The algebraic loop shown in bold is broken by the insertion of a ‘‘Memory’’ block, eliminating the need for the Newton–Raphson iterative root solving at each integration step. A simulation of the inverted pendulum when u(t) ¼ 0, t 0 was run for a period of 10 s using a ﬁxed-step numerical integrator. All initial conditions are zero except the initial pendulum deﬂection, u(0) ¼ p=2 rad. The output u(t) is shown in Figure 5.34. It is important to verify the results obtained when ‘‘Memory’’ blocks are employed to break algebraic loops. The delay introduced by the ‘‘Memory’’ block adversely affects the numerical accuracy and stability of the simulation. A considerable reduction in the time required to execute a simulation is hardly a suitable trade-off for inaccurate results. In other words, if the integration step size has to be reduced signiﬁcantly to combat the existence of the ‘‘Memory’’ block, then the overall savings in execution time may be insigniﬁcant, or worse yet, the net result might be an overall increase in time of execution. A ‘‘Memory’’ block is worth considering when Simulink reports difﬁculty in converging to a solution of the implicit equations arising from an algebraic loop.

Angular displacement (deg) vs. time (s) 300

θ(t) (deg)

250 200 150 100 50

FIGURE 5.34

0

1

2

3

4 t (s)

5

6

Simulink® output for u(t), t 0 using a ‘‘Memory’’ block.

7

Simulink®

367

5.4.2 ALGEBRAIC EQUATIONS While Simulink is generally used for simulating dynamic systems described by ordinary differential equations, it can also be used to solve a system of algebraic equations. For example, the algebraic equations

y ¼ f (x) (5:52) x ¼ g(y) comprise an algebraic loop. Consider the dynamic system modeled by 9 dy ¼ F(x, y) ¼ f (x) y = dt ; x ¼ g(y)

(5:53)

The two parts of Equation 5.53 represent the model of a ﬁrst-order autonomous system, that is, dy þ y f [g(y)] ¼ 0 dt

(5:54)

Suppose we are able to ﬁnd an equilibrium point y0 of the system described by Equation 5.54. Then (x0, y0), where x0 ¼ g(y0), constitutes a solution to the system of algebraic equations in Equation 5.52. To illustrate, let us attempt to ﬁnd a point that lies on the circle x2 þ y2 ¼ 100 and the curve x ¼ y2=5. In this case, y ¼ f (x) ¼ (100 x2 )1=2 x ¼ g(y) ¼

y2 5

(5:55)

The Simulink diagram in Figure 5.35 incorporates an integrator for solution to dy ¼ f (x) y ¼ (100 x2 )1=2 y dt along with the block to generate x from the second of the two equations in Equation 5.55.

FIGURE 5.35

Simulink® diagram for solving algebraic equations in Equation 5.55.

(5:56)

Simulation of Dynamic Systems with MATLAB® and Simulink®

368

x vs. t 8 x

6 4 2 0 y vs. t 8 y

6 4 2 0

0

0.5

1

1.5

2

2.5

t

FIGURE 5.36

Graph of x(t) and y(t) from Simulink® scope block.

The search for the solution to the algebraic equations in Equation 5.55 begins at (x(0), y(0)) where y(0) is the initial condition of the integrator and x(0) ¼ g[y(0)]. Starting from the point (0, 0), the approach to the equilibrium point y0 and corresponding value of x0 is viewable by clicking on the ‘‘Scope’’ block. The edited output is shown in Figure 5.36. The solution x0 ¼ 7.804, y0 ¼ 6.247 is visible in the respective ‘‘Display’’ blocks shown in the Simulink diagram. The ‘‘XY Graph’’ block allows a view of the trajectory x ¼ g(y) ¼ y2=5 from (0, 0) up to the solution (x0, y0), as shown in Figure 5.37. If the simulation fails to converge to an equilibrium point, restarting from a new point (x(0), y(0)) may help. Only stable equilibrium points of Equation 5.53 can be discovered. Keep in mind that nonlinear algebraic equations may possess none, one, or several equilibrium points, and the number of such points may not be known beforehand.

FIGURE 5.37

Trajectory from initial point x(0) ¼ 0, y(0) ¼ 0 to solution (x0, y0).

Simulink®

FIGURE 5.38

369

Using algebraic constraint blocks to solve algebraic equations in Equation 5.55.

A more direct approach to solving nonlinear algebraic equations with Simulink involves the use of an ‘‘Algebraic Constraint’’ block. This block changes its output in an iterative manner until its input approaches zero indicating that the algebraic constraint equation is satisﬁed, that is, the existence of a solution. Note that a feedback path must exist from the output to the input. The previous system of algebraic equations is solved using ‘‘Algebraic Constraint’’ blocks as shown in Figure 5.38. Initial guesses for the variables x and y are required. Note that the inputs to both ‘‘Algebraic Constraint’’ blocks have converged to zero and the algebraic states x and y are in agreement with the previous solution. The ‘‘Algebraic Constraint’’ block is an effective tool for locating the equilibrium points of a nonlinear dynamic system.

EXERCISES Run the Simulink model in Figure 5.33 using the ‘‘ode1’’ Euler integrator, and determine the largest step size possible for simulating the inverted pendulum dynamics with u(t) ¼ 0, t 0, and u(0) ¼ p=2 for a period of 10 s. Repeat without the ‘‘Memory’’ block. 5.10 Starting with Equations 5.50 and 5.51 for the inverted pendulum, _ u) and g(u, u, _ u) where (a) Find explicit functions f(u, u, 5.9

_ u) and €x ¼ f (u, u,

€u ¼ g(u, u, _ u)

_ and (b) Introduce state variables x1, x2, x3, and x4 where x1 ¼ x, x2 ¼ x_ , x3 ¼ u, and x4 ¼ u, ﬁnd the state derivative functions f1(x1, x2, x3, x4, u), f2(x1, x2, x3, x4, u), f3(x1, x2, x3, x4, u), and f4(x1, x2, x3, x4, u), where x_ 1 ¼ f1 (x1 , x2 , x3 , x4 , u) x_ 2 ¼ f2 (x1 , x2 , x3 , x4 , u) x_ 3 ¼ f3 (x1 , x2 , x3 , x4 , u) x_ 4 ¼ f4 (x1 , x2 , x3 , x4 , u)

370

Simulation of Dynamic Systems with MATLAB® and Simulink®

(c) The outputs are y1 ¼ x and y2 ¼ u. Find the output functions g1(x1, x2, x3, x4, u) and g2(x1, x2, x3, x4, u), that is, y1 ¼ g1 (x1 , x2 , x3 , x4 , u) y2 ¼ g2 (x1 , x2 , x3 , x4 , u) (d) Prepare a Simulink diagram of the system based on the nonlinear state equations obtained in parts (b) and (c). Is an algebraic loop present? (e) Compare outputs for u(t), t 0 using the Simulink diagram from Figure 5.33 and a Simulink diagram based on the state equations x_ ¼ f ( x, u ), y ¼ g( x, u ) for the following cases: (i) u(t) ¼ 0, t 0 and x1(0) ¼ x2(0) ¼ 0, x3(0) ¼ 18, x4(0) ¼ 0 (ii) u(t) ¼ 0, t 0 and x1(0) ¼ x2(0) ¼ x3(0) ¼ 0, x4(0) ¼ 108=s 5.11 Rework the example designed to ﬁnd the ﬁrst quadrant solution to y ¼ f (x) ¼ (100 x2 )1=2

and

x ¼ g(y) ¼

y2 5

by looking for an equilibrium point of dx ¼ G(x, y) ¼ g(y) x dt y ¼ f (x) 5.12 Find both solutions to the algebraic equations y ¼ ex 1,

y ¼ 5 (x 1)2

using ‘‘Algebraic Constraint’’ blocks. 5.13 Consider the system represented in block diagram form in Figure 5.31 and the equivalent closed-loop transfer function in Equation 5.48. (a) Find the differential equation relating the output y(t) and input r(t) when K1 ts þ 1

(i)

K1 (t1 s þ 1) t2 s þ 1

(ii)

K1 þ 2zvn s þ 1

(iii)

G(s) ¼ G(s) ¼ G(s) ¼

s2

(b) Prepare Simulink diagrams to simulate the block diagram and transfer function representations of the system when G(s) ¼ 2=(0.5s þ 1) and K ¼ 10. Find and plot the responses to the following inputs: (i) r(t) ¼ û(t), the unit step input (ii) r(t) ¼ et=2, t 0 (iii) See graph of r(t) in Figure E5.13

Simulink®

371 r(t) 2 1

0

0.5

t

1

2

FIGURE E5.13

5.5 MORE SIMULINK® BLOCKS In this section, we introduce additional Simulink blocks to extend the simulation capabilities developed so far. The next example is a common one from the ﬁeld of trafﬁc engineering. The objective is to formulate a mathematical model suitable for describing the characteristics of a driver=vehicle attempting to follow a lead vehicle in a single lane of trafﬁc. The result is referred to as a microscopic car-following model. Car-following models are an essential component of trafﬁc simulation software used to predict trafﬁc ﬂows in tunnels and other roads where passing is restricted. The basic situation is illustrated in Figure 5.39, which shows a lead vehicle (n 1) and a following vehicle (n), each of length L. The system, comprised of the lead and following vehicle, is driven (no pun intended) by the speed of the lead vehicle x_ n1 , and the outputs include {xn1 , xn , x_ n , €xn } in addition to the following quantities, which relate directly to the combination of lead and following vehicle movements. Vehicle spacing: sn ¼ xn1 xn

(5:57)

Vehicle following distance: dn ¼ (xn1 L) xn

(5:58)

Speed difference: D_xn ¼ x_ n1 x_ n

(5:59)

Vehicle gap: gn ¼

xn1 xn x_ n

(5:60)

The subscripts ‘‘n 1’’ and ‘‘n’’ are used, so that we can model a platoon consisting of a lead vehicle and several following vehicles. Except for the platoon leader and the last vehicle in the platoon, each vehicle operates in a following and lead vehicle mode as depicted in Figure 5.39. Platoon dynamics is considered in the next section. We have yet to formulate a mathematical model that governs the motion of the following vehicle in the case of small-to-moderate vehicle spacing. Note that car-following models are not applicable at low trafﬁc densities since each vehicle is essentially a leader moving independently of the preceding vehicle. L

L

. xn

xn

FIGURE 5.39

Diagram showing lead and following vehicles.

. xn−1

xn−1

Simulation of Dynamic Systems with MATLAB® and Simulink®

372

. . xn − xn−1 (xn−1 − L) − xn . xn

0

G g=

xn−1 − xn . xn

e1

. K1 (e1, xn)

–

.. xn(t + T)

. Kg (eg , xn)

eg –

Driver/vehicle

FIGURE 5.40

Block diagram of a car-following model.

Standard practice is to postulate an equation for the acceleration of the following vehicle in response to certain stimuli that are based on the relative movements of the two vehicles, that is, €xn (t þ T) ¼ f (xn1 (t), xn (t), x_ n1 (t), x_ n (t))

(5:61)

The acceleration response is delayed by an amount T, which represents the sum of the driver’s cognition and reaction times in addition to the vehicle response time. The literature is replete with articles and chapters in books describing suitable candidates for the function ‘‘f ()’’ in Equation 5.61 (Bender and Fenton 1966; Haberman 1977; Mesterton-Gibbons 1988; Aycin and Benekohal 2001). The block diagram in Figure 5.40 represents a speciﬁc function developed by the author used to simulate realistic trafﬁc in a driving simulator. The driver=vehicle combination behaves like a regulatory controller with output €xn (t þ T ), a function of two error terms e1 , eg and the following vehicle’s speed x_ n . The ﬁrst error term e1 is the difference between 0 and x_ n x_ n1 weighted by the reciprocal of the spacing (xn1 L) xn . The second term eg represents a gap error, that is, the difference between some desirable gap G and the actual gap g. The driver=vehicle controller attempts to drive both errors to zero by implementation of the control law €xn (t þ T) ¼ K1 (e1 , x_ n ) e1 þ Kg (eg , x_ n ) eg Note that when x_ n1 is constant and both errors are zero, the following vehicle is traveling at the same speed with a separation xn1 xn ¼ G_xn1 . The functions K1 (e1 , x_ n ) and Kg (eg , x_ n ) are implemented as shown in Tables 5.1 and 5.2. The constants K1,a , K1,d , Kg,d , and Kg,a are gain parameters reﬂecting driver aggressiveness, SL is the speed limit, and D is a threshold above the speed limit. A block diagram of the system is shown in Figure 5.41. The blocks to limit the acceleration and speed are self-explanatory. The spacing limiter assures that the minimum vehicle separation xn1 xn is greater than one car length at all times. A Simulink diagram of the system is shown in Figure 5.42. The M-ﬁle ‘‘Chap5_cfparams1.m’’ assigns values to the system parameters referenced in a number of the Simulink blocks. Accordingly, it must be run prior to executing the simulation model ﬁle ‘‘car_ following.mdl.’’ The new Simulink blocks in Figure 5.42 and their function are described brieﬂy as follows.

(5:62) TABLE 5.1 Function K 1 (e1 , x_ n ) x_ n e1

SL þ D

> SL þ D

>0 0

K1,a K1,d

0 K1,d

TABLE 5.2 Function Kg (eg , x_ n ) x_ n eg

SL þ D

> SL þ D

>0 0

Kg,d Kg,a

Kg,d 0

Simulink®

373 . xn−1

xn−1

∫

–

xn

. . xn−1 − xn

÷

– (xn−1 − L) − xn

L

–

. xn

xn−1

e1 G

.. xn

eg

. xn

∫

xn –

∫

– Driver/vehicle

g

Acceleration limiter

Speed limiter xn−1 − xn

÷

Spacing limiter

L L

FIGURE 5.41

Block diagram of a car-following system.

FIGURE 5.42

Simulink® diagram for a car-following system.

1. ‘‘Clock’’: Outputs the simulation time variable ‘‘t’’ for the ‘‘Lookup Table’’ block. 2. ‘‘Lookup Table’’: Linearly interpolates between speciﬁed data points to generate the lead car speed proﬁle. 3. ‘‘MATLAB fcn’’: Passes the inputs ‘‘x1d,’’ ‘‘e1,’’ and ‘‘eg’’ to the MATLAB function ‘‘acc.m,’’ which computes the vehicle’s acceleration response. 4. ‘‘Saturation’’: Sets limits for minimum and maximum vehicle acceleration. 5. ‘‘Transport Delay’’: Delays vehicle acceleration by T, the driver=vehicle reaction time.

374

Simulation of Dynamic Systems with MATLAB® and Simulink®

6. ‘‘Limited Integrator’’: An integrator conﬁgured to limit vehicle speed between zero and a maximum value of ‘‘vmax.’’ 7. ‘‘Switch’’: Logical blocks that limit the spacing ‘‘x0–x1’’ to at least L þ 1 ft and the speed ‘‘x1d’’ to at least 1 ft=s for calculation of the gap g. Access to the MATLAB Workspace during execution allows Simulink block parameters to be variables speciﬁed in MATLAB script ﬁles. For example, The ‘‘Lookup Table’’ block parameters ‘‘T0,’’ ‘‘T1,’’ ‘‘T2,’’ ‘‘A1,’’ and ‘‘A2’’ shown in Figure 5.43 are set in the M-ﬁle ‘‘Chap5_cfparams1.m.’’ The ‘‘MATLAB Function’’ block is a powerful feature of Simulink, which exploits the tight integration between MATLAB and Simulink. The Simulink block outputs ‘‘x1d,’’ ‘‘e1,’’ and ‘‘eg’’ are accessible as inputs to the MATLAB function M-ﬁle ‘‘acc.m,’’ which implements the carfollowing algorithm in Equation 5.62. The computed output is sent to the ‘‘Acceleration Limiter’’ block in Figure 5.42. The M-ﬁle ‘‘acc.m’’ is listed as follows. % function acc.m computes the temporary commanded acceleration function y ¼ acc(x1d,e1,eg,K1d,K1a,Kgd,Kga,SL,delta) if e1< ¼ 0 y1 ¼ K1d*e1; elseif x1d< ¼ SLþdelta y1 ¼ K1a*e1; else y1 ¼ 0 end if eg>0 yg ¼ Kgd*eg; elseif x1d< ¼ SLþdelta yg ¼ Kga*eg; else yg ¼ 0; end y ¼ y1þyg;

FIGURE 5.43

‘‘Lookup Table’’ block parameters.

Simulink®

375

The results of simulating a pair of initially stopped vehicles, with one car length separation, followed by the lead vehicle accelerating (with constant acceleration) to 60 mph in 30 s are obtained by running the M-ﬁle ‘‘Chap5_Figs5_6thru5_10.m’’ and shown in Figures 5.44 through 5.48. The commanded gap G is 2 s, the value recommended for highway driving by The American Automobile Association.

Lead car displacement vs. time

x0 (ft)

6000 4500 3000 1500 0

0

10

20

30

40

50

60

70

80

90

70

80

90

Following car displacement vs. time

x1 (ft)

6000 4500 3000 1500 0

FIGURE 5.44

0

10

20

30

40 50 Time (s)

60

Lead and following vehicle positions.

Lead car speed vs. time

v0 (mph)

60 45 30 15 0

0

10

20

30

40

50

60

70

80

90

70

80

90

Following car speed vs. time

v1 (mph)

60 45 30 15 0

FIGURE 5.45

0

10

20

30

Lead and following vehicle speeds.

40 50 Time (s)

60

Simulation of Dynamic Systems with MATLAB® and Simulink®

376

Actual and desired gap vs. time 3 2.7

Actual gap

2.4 2.1 Desired gap

g, G(s)

1.8 1.5 1.2 0.9 0.6 0.3 0

0

10

20

30

40

50

60

70

80

90

70

80

90

Time (s)

FIGURE 5.46

Desired and actual gaps.

Following distance vs. time 225 200 175

x0 – x1 (ft)

150 125 100 75 50 25 0

0

10

20

30

40

50

60

Time (s)

FIGURE 5.47

Following distance.

The initial blip in speed of the following vehicle (see Figure 5.45) is due to the excessive gap g that results whenever the following vehicle is moving at very low speeds. The car-following model, Equation 5.62, implemented in the M-ﬁle ‘‘acc.m’’ is not robust, that is, it is not valid at following vehicle speeds close to zero, which occurs when the simulation begins. Similar artifacts are present in the gap (Figure 5.46) and acceleration (Figure 5.48) plots. One of the exercise problems addresses this point further.

Simulink®

377 Following vehicle acceleration vs. time 10 7.5

a1 (ft/s2)

5 2.5 0 −2.5 −5 0

FIGURE 5.48

10

20

30

40 50 Time (s)

60

70

80

90

Simulink® output of following vehicle acceleration.

5.5.1 DISCONTINUITIES Each of the nonlinear elements presented in Section 2.7 are available as blocks in Simulink. From within the Simulink Library Browser, click on ‘‘Discontinuities’’ to display the element blocks as shown in Figure 5.49. In the right-hand column are nonlinear blocks for friction, dead zone, saturation, backlash, hysteresis (relay), and quantization.

5.5.2 FRICTION Figure 5.50 shows the ‘‘Coulomb and Viscous Friction’’ parameter dialog box. While the default conditions are shown in Figure 5.50, a more practical way to use the block is to assign a scalar value to the Coulomb friction value (Offset). This would represent the coefﬁcient of static friction as in the case of initiating the motion of a sliding mass. Of course, the Coefficient of viscous friction (Gain) corresponds to the kinetic friction as the coefﬁcient of the velocity term in the dynamic equations of motion. A detailed description of the ‘‘Coulomb and Viscous Friction’’ block can found by clicking on Help from the dialog box.

5.5.3 DEAD ZONE AND SATURATION Figure 5.51 shows the ‘‘Dead Zone’’ parameter dialog box. The parameter dialog box for the dead zone block is rather intuitive. The user simply sets the beginning and the end of the dead zone according to the input being sent to the block. In the default example, the output is zero if the input signal is between 0.5 and 0.5. Otherwise, the output tracks the input. A detailed description of the ‘‘Dead Zone’’ block can found by clicking on Help from the dialog box. Figure 5.52 shows the ‘‘Saturation’’ parameter dialog box.

378

Simulation of Dynamic Systems with MATLAB® and Simulink®

FIGURE 5.49

Simulink® Library Browser—Discontinuities.

FIGURE 5.50

‘‘Coulomb and Viscous Friction’’ parameter dialog box.

The parameter dialog box for the saturation block is also intuitive. The user simply sets the beginning and the end of the saturation limits according to the input being sent to the block. In the default example, the output is 0.5 for input values less than 0.5, the output tracks the input between 0.5 and 0.5, and the output is 0.5 for input values greater than 0.5. A detailed description of the ‘‘Saturation’’ block can found by clicking on Help from the dialog box.

Simulink®

379

FIGURE 5.51

‘‘Dead Zone’’ parameter dialog box.

FIGURE 5.52

‘‘Saturation’’ parameter dialog box.

5.5.4 BACKLASH Figure 5.53 shows the ‘‘Backlash’’ parameter dialog box. For the backlash block, the user sets the Deadband width and the Initial output. If the defaults are taken, the output of the backlash block is split evenly between upper and lower values of the input. For example, if the input is a square wave with an upper limit of þ1 and a lower limit of 1, the deadband width is centered on zero (the Initial output default), and half of the Deadband width (0.5) is taken from the upper limit while the other half of the Deadband width is taken from the lower limit yielding an output of þ0.5 (when the input is þ1) and an output of 0.5 (when the input is 1).

Simulation of Dynamic Systems with MATLAB® and Simulink®

380

FIGURE 5.53

‘‘Backlash’’ parameter dialog box.

Clarifying, if the Deadband width is 0.4, then 0.2 will be taken from each of the input values, that is, the output is a square wave between þ0.8 and 0.8 (using the input square wave between þ1 and 1). If the Initial output is nonzero and exceeds the input value, then the backlash block can be used to simulate gears that have yet to be engaged. Continuing with the same square wave input between þ1 and 1, if the Initial output is set to 2, then the output is þ1 plus half of the Deadband width or þ1.2. It is only when the gears engage that the output returns to the limits of þ0.8 and 0.8. A detailed description of the ‘‘Backlash’’ block can found by clicking on Help from the dialog box.

5.5.5 HYSTERESIS One of the examples in Section 2.7 on nonlinear systems dealt with maintaining the temperature inside a building using a thermostat to control the heat from a furnace. The building temperature and thermostat control are governed by the equations repeated as follows. t

Q¼

dT þ T ¼ RQ þ T0 dt

(5:63)

8 > T Td D > < Q,

or

Td D < T < T d þ D

and

> > : 0, T > Td þ D

or Td D < T < Td þ D

and

where T is the building temperature (8F) Q is the heat input from furnace (Btu=h) T0 is the outside temperature (8F) R is the thermal resistance of building (8F=Btu=h) t is the time constant of building temperature response (h) is the rating of furnace (Btu=h) Q Td is the thermostat setting (8F) D is the dead zone parameter for thermostat

dT >0 dt dT

> >

P > > : v0 ,

0 t P=4 P=4 < t 5P=4 t > 5P=4

Plot graphs similar to the ones shown in Figures 5.44 through 5.48.

Simulink®

383

TABLE E5.14 Parameters v0 A P G x0 (0) x_ 1 (0) x1 (0) SL D amin amax vmax K1,a K1,d Kg,a Kg,d T (delay) L

Case I

Case II

Case III

50 mph 5 mph 30 s 2s Gv0 v0 0 ft v0 5 mph 10 ft=s2 10 ft=s2 90 mph 3 ft=s 3 ft=s 5 ft=s3 4 ft=s3 0.5 s 15 ft

60 mph 5 mph 30 s 2.5 s Gv0 v0 0 ft v0 10 mph 12 ft=s2 12 ft=s2 90 mph 4 ft=s 4 ft=s 5 ft=s3 4 ft=s3 0.75 s 15 ft

70 mph 10 mph 60 s 3s Gv0 v0 0 ft v0 55 mph 15 ft=s2 15 ft=s2 90 mph 5 ft=s 5 ft=s 5 ft=s3 4 ft=s3 1s 15 ft

5.15 Consider the second column of Table E5.14 as baseline numerical values for simulation of a pair of vehicles. Perform a simulation study to analyze the effect of the desirable gap G on the following vehicle’s ability to follow at or near the desirable gap. Run the simulation for G ¼ {1, 1.5, 2, 2.5, 3, 3.5, 4} for a duration of 3P s, and record the value of the average absolute gap error, that is, 3ðP 1 jg(t) Gjdt jeg jave ¼ 2P P

Plotjeg jave vs: G

. x0(t), mph

5.16 Improve the robustness of the car-following simulation to make the output more realistic at very low vehicle speeds. Speciﬁcally, modify the code in ‘‘acc.m’’ and add additional blocks as necessary to the Simulink diagram in Figure 5.42. Use the baseline values from Table E5.14 to simulate the following vehicle’s response to a lead car with speed proﬁle shown in Figure E5.16. 60

0

80

20

100

t, s

FIGURE E5.16

5.17 The Simulink diagram in Figure 5.42 contains a ‘‘Switch’’ block to maintain the vehicle separation xn xn1 greater than L þ 1. This effectively eliminates the possibility of a rear end collision.

Simulation of Dynamic Systems with MATLAB® and Simulink®

384

(a) Remove the ‘‘Switch’’ block and add the necessary Simulink blocks to detect the existence of a collision and halt the simulation. (b) Use the lead car proﬁle in Figure E5.16 and adjust the parameters D and K1,a , K1,d , Kg,a , Kg,d to force a rear-end collision. 5.18 Flow into the tank shown in Figure E5.18a is either on or off. It turns on when the level falls below 20 ft and remains on when the tank is ﬁlling until there is 25 ft of liquid in the tank. It remains off as the tank empties until the level falls below 20 ft. In the on condition, the ﬂow rate is 18 ft3=min. The tank dynamics are described by A

dH þ F0 ¼ F1 , F0 ¼ aH 1=2 dt

where A ¼ 50 ft2 , a ¼ 3 ft3=min=ft1=2 , and H(0) ¼ 0 ft. (a) Develop your own Simulink diagram or use the one shown in Figure E5.18b to simulate the tank dynamics for a period of time sufﬁcient to see several cycles of ﬁlling and emptying. Plot the tank level and the two ﬂows vs. time. (b) What is the minimum ﬂow necessary to assure the tank is capable of ﬁlling to a level of 25 ft? Find the answer analytically and verify with Simulink. (c) Supplement your Simulink diagram with additional blocks to measure the percentage of time during a cycle in which the tank is ﬁlling up. (d) Instead of switching the ﬂow off and on immediately when the level reaches 25 and 20 ft, respectively, suppose the ﬂow switches off 30 s after the tank level reaches 25 ft and switches on 30 s after the tank level falls to 20 ft. The tank is 25 ft tall. Add Simulink blocks to account for spillover from the tank. Plot the ﬂow in, ﬂow out, spillover, and tank level vs. time. F1(t)

A

18 ft3/min

H(t) F0(t)

FIGURE E5.18a

FIGURE E5.18b

F1

20 ft

25 ft

H

Simulink®

385

5.19 Cascading the dead zone and saturation blocks, model the valve described in Section 2.7.2. Set the dead zone block’s parameters to model opening currents of 0.5 and 0.5 amp (default settings) and set the saturation block’s parameters to model saturation currents of 1.0 and 1.0 amp. Verify that the valve is modeled correctly by using a ramp input and observing the characteristics shown in Figure 2.39.

5.6 SUBSYSTEMS As the physical systems we model become progressively more complex, the Simulink representation increases in size, that is, the number of blocks required to model the systems’ dynamics grows signiﬁcantly. A Simulink diagram with hundreds of blocks makes it difﬁcult, if not impossible, to understand the interactions among the systems’ components. A more instructive approach consists of grouping speciﬁc blocks associated with various subsystems into single entities. At the highest level, the system is viewed in terms of the interactions between these entities. This hierarchical approach is illustrated for the case of modeling the dynamics of an automobile. Figure 5.58 shows a block diagram of the top level description for modeling the dynamics. At this level, the important interconnections between individual subsystems are identiﬁed. The next step requires the development of concrete descriptions of the individual subsystems, either in mathematical or block diagram form. The mathematical models are transformed into Simulink models that are reusable, much in the same way a procedural function is used in highlevel programming languages. Multiple levels are possible in this modeling hierarchy. Moving down one or more levels from the top subsystem level provides more of a microscopic, that is, detailed, description involving low-level components. An advantage of this approach is the distribution of the modeling effort to individuals with expertise necessary for modeling the individual subsystems. For example, the ‘‘Tire Model’’ subsystem is a critical component in modeling vehicle response. A person knowledgeable in tire=road surface interaction phenomena and the properties of speciﬁc tires is needed to develop models that will produce correct tire forces required by the equations of motion. Suppose a question arises concerning the handling characteristics of a vehicle with different classes of tires. The existing vehicle subsystem models are already in place and can be reused with a ‘‘Tire Model’’ developed speciﬁcally for the class of tire under consideration. Path error feedback Brake pressure Steering, δSW

Throttle δT Power train

TP

Steering Torque feedback system

Brake system

Motion feedback

S

TB Wheel spin modes

Driver or automatic controller

MZ FY ωT

FX

δW

Tire model

FX FY

Vehicle dynamics

. γ, v, u, ψ, FZ

Road grade

. ψ u, v

Vehicle-road kinematics

Road curvature

FIGURE 5.58 Top-level description of vehicle dynamics model. (From Allen, R.W. and Rosenthal, T. Systems technology=requirements for vehicle dynamics simulation models, Society of Automotive Engineers, SAE 941075, 1994.)

Simulation of Dynamic Systems with MATLAB® and Simulink®

386

5.6.1 PHYSBE PHYSBE is a benchmark simulation of the human circulatory system. It was ﬁrst introduced by John Mcleod in 1966 in an article titled ‘‘PHYSBE . . . a Physiological Simulation Benchmark Experiment.’’ Over the years, it has appeared in numerous references involving modeling and simulation. The underlying dynamics have been simulated using the popular continuous simulation programs including Simulink. The human circulatory system is represented by three main components: the lungs (pulmonary circulation), heart (coronary circulation), and the rest of the body (systemic circulation). Coronary and systemic circulations were further divided into subsystems as shown in the Simulink diagram in Figure 5.59 (provided by The Mathworks, Inc.). The simulation computes pressures, blood ﬂows, volumes, temperatures, and heat ﬂows after a number of parameters describing the physical nature of each subsystem have been speciﬁed. The dynamics of each subsystem are hidden in the macroscopic view of the human circulatory system in Figure 5.59. A detailed description of the individual subsystem models is accessible by ‘‘looking inside’’ each of the blocks. For example, the LUNGS subsystem opens up to reveal the components used in modeling the blood ﬂow, blood temperature, heat content, and heat dissipation within the lungs (see Figure 5.60). The modular structure of the overall system makes it relatively simple to simulate, for example, the effects of partial blockages in the blood vessels of the systemic regions or the effect of changes in vascular compliance on blood pressure.

5.6.2 CAR-FOLLOWING SUBSYSTEM The next example of Simulink subsystems involves the dynamic behavior of a platoon of vehicles, that is, a lead car (platoon leader) followed by several vehicles whose motion is governed by the dynamics of the preceding vehicle. The Simulink diagram in Figure 5.42 was used to simulate carfollowing behavior. Deleting the ‘‘Scope’’ blocks, the ‘‘Clock’’ and ‘‘Lookup’’ blocks for generating the lead vehicle speed proﬁle, and the integrator block for creating the lead vehicle position leaves the essential blocks for deﬁning a Simulink car-following subsystem.

FIGURE 5.59

Simulink® diagram of PHYSBE model.

Simulink®

FIGURE 5.60

387

Subsystem model description of LUNGS.

Input and output ports to the subsystem are created using Simulink ‘‘In’’ and ‘‘Out’’ blocks from the ‘‘Ports and Subsystems’’ sublibrary. A certain amount of discretion is possible when choosing subsystem inputs and outputs. For example, ‘‘In’’ blocks can be connected to the lead vehicle speed ‘‘x0d’’ and position ‘‘x0,’’ while the following vehicle speed ‘‘x1d’’ and position ‘‘x1’’ are selected as outputs by connecting them to ‘‘Out’’ blocks. Alternatively, the subsystem could be described in terms of a single input, namely, vehicle speed ‘‘x0d,’’ and a single output such as vehicle acceleration ‘‘x1dd.’’ A ‘‘car–following’’ subsystem is created by enclosing selected blocks in the Simulink diagram with a bounding box and choosing ‘‘Edit: Create Subsystem’’ from the menu. The selected blocks collapse into the ‘‘car–following’’ subsystem with renamed inputs and outputs as shown in Figure 5.61. Opening (double clicking) the subsystem reveals the underlying Simulink blocks that can be edited at any time. The ‘‘car–following’’ subsystem constituent blocks are shown in Figure 5.62. Note that conversion factors from mph to fps (3600=5280) and vice versa were added (see ‘‘Gain’’ blocks in Figure 5.62) to maintain the vehicle speeds in and out of the subsystem in mph, while internal to the subsystem, vehicle speeds are in fps. Simulation of a platoon of vehicles is accomplished by repeated use of the ‘‘car–following’’ subsystem block. Suppose we wish to simulate the dynamics of a ﬁve-vehicle platoon in response to a lead vehicle that decelerates and then accelerates back to a constant steady-state speed. In particular, our interest will focus on the induced perturbations in the stream of trafﬁc. At the beginning of the simulation, each vehicle is traveling at the speed ‘‘SL,’’ separated in time by the desired gap G, as shown in Figure 5.63. x_in x_out

v_in

v_out

Car-following

FIGURE 5.61 ‘‘Car–following’’ subsystem with lead vehicle inputs ‘‘x_in,’’ ‘‘v_in’’ and following vehicle outputs ‘‘x_out,’’ ‘‘v_out.’’

Simulation of Dynamic Systems with MATLAB® and Simulink®

388

FIGURE 5.62

Simulink® blocks comprising the car-following subsystem.

#4

0

SL L

#3

SL

L + G · SL

#2

SL

L + 2G · SL

#1

#0 SL

L + 3G · SL

SL L + 4G · SL

FIGURE 5.63

Initial conditions of the platoon vehicles.

FIGURE 5.64

Simulink® diagram with multiple instances of the ‘‘car–following’’ subsystem.

Simulink®

v4

v3

v2

v1

v0

389

FIGURE 5.65

60 40 20 60 40 20 60 40 20

0

50

100

150

200

250

300

0

50

100

150

200

250

300

0

50

100

150

200

250

300

0

50

100

150

200

250

300

0

50

100

150 t (s)

200

250

300

60 40 20 60 40 20

Speeds (mph) of platoon leader and following vehicles vs. time (s).

The ﬁle ‘‘Chap5_cfparams2.m’’ loads the parameters required by the Simulink subsystems and ‘‘Lookup Table’’ block for setting the lead vehicle speed. A top-level view of the model ‘‘car_following_platoon.mdl’’ is shown in Figure 5.64. Initial conditions, namely, speeds and positions, of the trailing vehicles are set in the integrators of the appropriate subsystem blocks. The initial position of the lead vehicle is determined by the parameter of the integrator block feeding the ﬁrst subsystem. The ‘‘Mux’’ block (lower right) multiplexes the ﬁve vehicle speeds on a single line for input to a ‘‘Scope’’ block that draws the ﬁve plots on a single set of axes. The heavy arrow emanating from the ‘‘Mux’’ indicates the presence of multiple signals. Speeds of the lead vehicle and four following vehicles are shown in Figure 5.65. Figure 5.66 is a graph of the successive gaps between the vehicles of the platoon. The responses in Figures 5.65 and 5.66 indicate that the platoon achieves a new steady state identical to the initial one after the perturbations die out. The ‘‘Car–following’’ subsystem can be daisy-chained as shown in Figure 5.64 to simulate the response of platoons of vehicles of any size. Furthermore, the following vehicles can be individualized by including a vector of randomly chosen driver=vehicle parameters as an additional input to each ‘‘Car–following’’ subsystem block.

5.6.3 SUBSYSTEM USING FCN BLOCKS The ‘‘Fcn’’ block is a convenient time saver when the mathematical model of the system consists primarily of algebraic and differential equations. Lengthy expressions are evaluated in equation form instead of being constructed from Simulink blocks. To illustrate, the frictionless inverted pendulum introduced in Section 5.4 can be treated as a subsystem with the governing equations for €x and € u implemented by the use of ‘‘Fcn’’ blocks. Equations 5.50 and 5.51 are implicit in nature as a result of €x and € u appearing in both equations. (Recall the presence of an algebraic loop in the Simulink diagram.) This can be overcome by solving for the second derivative terms explicitly leading to Equations 5.65 and 5.66.

Simulation of Dynamic Systems with MATLAB® and Simulink®

390

g1

3 2 1 0

0

50

100

150

200

250

300

0

50

100

150

200

250

300

0

50

100

150

200

250

300

0

50

100

150

200

250

300

g2

3 2 1

g3

3 2 1 0

g4

3 2 1 0

t (s)

FIGURE 5.66

Gaps (s) of following vehicles vs. time (s).

€x ¼

mlu_ 2 sin u mg cos u sin u þ u M þ m sin2 u

mlu_ 2 cos u sin u þ (m þ M)g sin u u cos u € u¼ l(M þ m sin2 u)

(5:65) (5:66)

Figure 5.67 shows the top layer with the ‘‘cart model’’ subsystem. _ into its It includes Simulink blocks to generate the input u, decompose the state vector [x, x_ , u, u] components, and feed the components to individual ‘‘scope’’ blocks. Note the use of the Simulink supplied ‘‘R2D’’ block for converting from radians to degrees. It is found in the ‘‘Simulink Extras’’ sublibrary under the ‘‘Transformations’’ heading. A number of useful coordinate transformation blocks are available there.

FIGURE 5.67

Top layer of a Simulink® diagram for simulating an inverted pendulum.

Simulink®

FIGURE 5.68

391

Cart subsystem using ‘‘Fcn’’ blocks.

Opening the ‘‘cart model’’ subsystem reveals the blocks shown in Figure 5.68. Note that the ‘‘Display option’’ of the ‘‘Mux’’ parameter blocks is set to ‘‘signals’’ in order to identify its inputs. The parameters of the two ‘‘Fcn’’ blocks are expressions relating the accelerations ‘‘xdd’’ and ‘‘thetadd’’ to the inputs ‘‘x,’’ ‘‘xd,’’ ‘‘u,’’ ‘‘thetad,’’ and ‘‘theta’’ (from the ‘‘mux’’ block). The ‘‘Fcn’’ block input notation is u[1], u[2], . . . ,u[5] where u[1] is the ﬁrst input ‘‘x,’’ u[2] is ‘‘xd,’’ and so forth. From Equation 5.65, the ‘‘Fcn’’ block parameter expression for ‘‘xdd’’ is (m*l*u[4]^2*sin(u[5])–m*g*cos(u[5])*sin(u[5])þu[3])= (Mþm*sin(u[5])^2) Referring to Equation 5.66, the ‘‘Fcn’’ block parameter expression for ‘‘thetadd’’ is (–m*l*u[4]^2*cos(u[5])*sin(u[5])þ(mþM)*g*sin(u[5])–u[3]* cos(u[5])=(l*(Mþm*sin(u[5])^2)) The angular position of the pendulum u(t) is plotted in Figure 5.69 for the case when the cart and pendulum are initially at rest, that is, x(0) ¼ x_ (0) ¼ u(0) ¼ u_ (0) ¼ 0, and the input u(t) is the triangular pulse shown in Figure 5.70. The numerical values of the system parameters are M ¼ 2 kg, m ¼ 0.1 kg, and l ¼ 0.5 m. Angular position theta vs. time

800

Theta (deg)

600 400 200 0 −200 −400

FIGURE 5.69

0

5

10 15 Time (s)

u(t) vs. t for u(t) shown in Figure 5.70.

20

25

Simulation of Dynamic Systems with MATLAB® and Simulink®

u(t), N

392

0.275

0

15

10

5

t, s

FIGURE 5.70

Force u(t) applied to cart.

EXERCISES 5.20 Randomize the car-following behavior by assuming that the desired gap G and driver=vehicle delay T are both normally distributed random variables, that is, T N(mT , sT ),

mT ¼ 0:75 s, sT ¼ 0:15 s

G N(mG , sG ), mG ¼ 2:5 s,

5.21

5.22

5.23

5.24

sG ¼ 0:3 s

Use MATLAB to generate {Gi,Ti}, i ¼ 1, 2, 3, 4 for four following vehicles, and repeat the simulation of the ﬁve vehicles shown in Figure 5.63. Six vehicles are stopped at a trafﬁc light with a distance of L feet from the rear bumper of the car in front to the front bumper of the following vehicle. The lead car accelerates uniformly from zero mph to the speed limit SL ¼ 45 mph in 30 s and continues traveling at the speed limit. Use the robust car-following model developed in Exercise 5.16 to simulate the transient response of the platoon. Use the baseline conditions in the second column of Table E5.14 for the parameters, or choose a new set of appropriate values. Obtain time history plots of (a) Vehicle positions (b) Vehicle speeds (c) Vehicle gaps (d) Vehicle-following distances A total of 11 cars are traveling at the speed limit SL with initial spacing similar to those in Figure 5.63. At t ¼ 0, the lead car speed begins to vary sinusoidally with amplitude of 3 mph and period of 20 s. Determine the peak amplitude in speed of the following vehicles for the nine combinations: SL ¼ 30, 45, 60 mph and G ¼ 1.5, 2, 3 s. Starting with Equations 5.65 and 5.66 for the cart and inverted pendulum, (a) Develop a state variable model of the system, that is, x_ ¼ f (x, u) and y ¼ g(x, u) where the _ T and output y ¼ [x, u]T . state x ¼ [x, x_ , u, u] (b) Find the state equations for updating the discrete-time state x A (n) and computing y A (n) using forward Euler integration with step size T. (c) Solve the equations in part (b) recursively to ﬁnd x A (n) and y A (n), n ¼ 1, 2, . . . , nf where T ¼ 0.05 s, Tﬁnal ¼ nfT ¼ 5 s, u(t) ¼ 0, t 0, and x(0) ¼ [0, 0, p=6, 0]. (d) Plot the discrete-time state vector x A (n), n ¼ 0, 5, 10, . . . , nf. (e) Simulate the response with Simulink for the same conditions in part (c) using the ode1 (Euler) integrator. Plot the state vector and compare the results to part (d). Show that the frictionless cart and pendulum have two equilibrium points when the input u(t) ¼ 0, t 0, namely, x1,e ¼ 0 m,

x2,e ¼ 0 m=s,

x3,e ¼ 0 rad, x4,e ¼ 0 rad=s

x1,e ¼ 0 m,

x2,e ¼ 0 m=s,

x3,e ¼ p rad,

x4,e ¼ 0 rad=s

and verify by using Simulink that the ﬁrst equilibrium point is unstable and the second one is stable. Is the second equilibrium point asymptotically stable?

Simulink®

393

5.25 Develop a subsystem model of the cart and pendulum where the pendulum rotation is opposed by a damping torque TD ¼ cu_ and the cart motion is subject to a constant friction force fm ¼

m(m þ M)g sgn(_x), 0,

x_ 6¼ 0 x_ ¼ 0

Simulate the response of the cart and pendulum, starting from the stable equilibrium point, to the input 8 < 0, u(t) ¼ U0 , : 0,

0t < 0,

T t > : A,

(5:99)

Its Fourier Series expansion (O’Neil 1983) is u(t) ¼ a0 þ

1 X

an sin nv0 t

(5:100)

n¼1,3,5,...

where v0 ¼ 2p=T is called the fundamental frequency un(t) ¼ an sin nv0t, n ¼ 1, 3, 5, . . . is the nth harmonic the Fourier coefﬁcients are a0 ¼

A 2 , an ¼ , 2 np

n ¼ 1, 3, 5, . . .

(5:101)

Suppose u(t) is the input to a second-order system with transfer function G(s) ¼

Y(s) v2n ¼ 2 U(s) s þ 2zvn s þ v2n

(5:102)

By the principle of superposition, y(t) is equal to the sum of the second-order system response to the harmonic components un(t), n ¼ 1, 3, 5, . . . Fourier the constant a0 and the responses to P coefﬁcients of the truncated series a0 þ 19 n¼1,3,5,... an sin nv0 t are evaluated in the M-ﬁle ‘‘Chap5_ Fourier_Series.m,’’ a portion of which is listed as follows: % MATLAB Script File Chap5_Fourier_Series.m % Fourier Series of periodic function u(t) % f(t) ¼ A, 0 < ¼ t < T=2 % ¼ 0, T=2 < ¼ t < T n ¼ 19; % order of truncated Fourier Series of u(t) k ¼ 1:2:n; % harmonics of u(t) A ¼ 10; % amplitude of u(t) a ¼ 2*A.=(k.*pi); % Fourier Series coefficients a(k), k ¼ 1,3,5, . . . ,n a0 ¼ 0.5*A; % ave value of u(t) T ¼ 0.1; % period of u(t) w0 ¼ 2*pi=T; % input frequency wh ¼ k*w0; % harmonic frequencies wr ¼ wh(5); % Set resonant frequency equal to freq of 9th harmonic wn ¼ 1.01*wr; % calculate natural frequency zeta ¼ sqrt( (1– (wr=wn)^2)=2); % calculate damping ratio w ¼ linspace(0,1500,500); % range of freq for jG(jw)j plot s ¼ j*w; % complex freqs magG_w ¼ (wn.^2).=abs(s.^2 þ 2*zeta*wn*s þ wn^2); % jG(jw)j plot(w,magG_w) hold on,s ¼ j*wh; magG_wh ¼ (wn.^2).=abs(s.^2 þ 2*zeta*wn*s þ wn^2); % jG(jwh)j plot(wh,magG_wh,‘‘.’’,‘‘MarkerSize’’,12) num ¼ [wn^2]; % numerator of G(s) denom ¼ [1 2*zeta*wn wn^2]; % denominator of G(s)

Simulink®

413

SYS ¼ TF (num, denom); % transfer function of G(s) Figure, bode(SYS,{50, 1500}) [MAG, PHASE, wh] ¼ BODE (SYS, wh); % Evaluate jG(jwh)j and Angle(G(jwh)) sim(‘‘resonance’’) % call Simulink model ‘‘resonance.mdl’’ subplot(4, 2, 1); plot(t, harmonics (:,1)) subplot (4, 2, 3); plot(t, harmonics (:,2)) The truncated series expansion of u(t) is evaluated and compared to the input u(t) as part of a Simulink simulation shown in Figure 5.99. The Fourier coefﬁcients and harmonic frequencies are used to set the parameters in the ‘‘Sine Wave’’ blocks. A comparison of the signal u(t) and the truncated Fourier Series is shown in Figure 5.100.

FIGURE 5.99

Simulink® diagram for ﬁnding the response to u(t) and truncated Fourier Series of u(t). u(t) and its truncated Fourier Series Truncated Fourier Series of u(t)

12 10

u(t) 8 6 4 2 0 −2 0

FIGURE 5.100

0.025

0.05

0.075

0.1 t

0.125

0.15

0.175

Periodic signal u(t) (t ¼ 0.1 s) and 19th-order truncated series.

0.2

Simulation of Dynamic Systems with MATLAB® and Simulink®

414

The resonant frequency vr of the second-order system with transfer function G(s) is set equal to the frequency of the ninth harmonic 9v0 ¼ 9(2p=T) ¼ 565.49 rad=s. The natural frequency vn is chosen slightly higher, that is, vn ¼ 1.01vr producing a lightly damped system with damping ratio of approximately 0.1 calculated from (Ogata 1988) sﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 1 (vr =vn )2 z¼ 2

(5:103)

The second-order system response to u(t) and its response to the truncated Fourier Series representation of u(t) are shown in Figure 5.101. Clearly, enough harmonics of u(t) have been retained in the truncated Fourier Series to accurately predict the response of the second-order system under consideration. Next, we discuss how MATLAB and Simulink can be used effectively to demonstrate the phenomenon of resonance. The M-ﬁle ‘‘Chap5_Fourier_Series.m’’ evaluates the magnitude function jG( jv)j over the frequency range 0 v 1500 rad=s and plots the results with the harmonic frequencies shown in Figure 5.102. Note that the resonant frequency vr where the peak amplitude of jG( jv)j occurs is in fact equal to the frequency of the ninth harmonic. A similar ﬁnding is possible using the control system toolbox to specify the transfer function and draw a Bode plot or merely compute the magnitude function with ‘‘MAG’’ at selected frequencies and plot the results. The Fourier coefﬁcients of the truncated series expansion of u(t) are shown in Table 5.3. Also listed are the frequency response characteristics of the second-order system at the harmonic frequencies. The peak magnitude at the resonant frequency is Max jG( jv)j ¼ jG( jvr )j ¼ 5:0624

(5:104)

v0

Second-order system response y(t) to input u(t) 20 15 10 5 0 −5 −10

0

0.025

0.05

0.075

0.1

0.125

0.15

0.175

0.2

Second-order system response to truncated Fourier Series of u(t) 20 15 10 5 0 −5 −10

FIGURE 5.101

0

0.025

0.05

0.075

0.1 t

0.125

0.15

0.175

0.2

Response of a second-order system to u(t) and its truncated Fourier Series.

Simulink®

415 6 G(s): second order ωn = 571.14 rad/s ζ = 0.1 ωr = 565.49 rad/s

9ω0

5

|G ( jω)|

4

Harmonic frequencies 3 7ω0

2 1 0

ω0 0

3ω0

11ω0

5ω0

13ω0 19ω0

250

500

750

1000

1250

1500

ω (rad/s)

FIGURE 5.102

Magnitude function of a second-order system.

TABLE 5.3 Fourier Coefﬁcients and Magnitude Function at Selected Frequencies n

nv0 (rad=s)

an

jG( jnv0)j

ﬀG( jnv0) (rad)

0 1 3 5 7 9 11 13 15 17 19

0 v0 ¼ 62.8 3v0 ¼ 188.5 5v0 ¼ 314.2 7v0 ¼ 439.8 9v0 ¼ 565.5 11v0 ¼ 691.2 13v0 ¼ 816.8 15v0 ¼ 942.5 17v0 ¼ 1068.1 19v0 ¼ 1193.8

5 6.3662 2.1221 1.2732 0.9095 0.7074 0.5787 0.4897 0.4244 0.3745 0.3351

1 1.0120 1.1192 1.4166 2.3002 5.0624 1.9126 0.9232 0.5702 0.3960 0.2946

0 0.0221 0.0734 0.1553 0.3593 1.4709 2.6642 2.8764 2.9537 2.9940 3.0190

The harmonic components un(t), n ¼ 1, 7, 9, 11 in the truncated series expansion of u(t) in Figure 5.98 are given by u1 (t) ¼ a1 sin v0 t ¼ 6:3662 sin 62:8t

(5:105)

u7 (t) ¼ a7 sin 7v0 t ¼ 0:9095 sin 439:8t

(5:106)

u9 (t) ¼ a9 sin 9v0 t ¼ 0:7074 sin 565:5t

(5:107)

u11 (t) ¼ a11 sin 11v0 t ¼ 0:5787 sin 691:2t

(5:108)

Simulation of Dynamic Systems with MATLAB® and Simulink®

416

The second-order system response to the above components is y1 (t) ¼ jG( jv0 )ja1 sin [v0 t þ ﬀG( jv0 )]

(5:109)

¼ 1:0120(6:3662) sin (62:8t 0:0221)

(5:110)

¼ 6:4426 sin (62:8t 0:0221)

(5:111)

y7 (t) ¼ jG( j7v0 )ja7 sin [7v0 t þ ﬀG( j7v0 )]

(5:112)

¼ 2:3002(0:9095) sin (439:8t 0:3593)

(5:113)

¼ 2:0920 sin (439:8t 0:3593)

(5:114)

y9 (t) ¼ jG( j9v0 )ja9 sin [9v0 t þ ﬀG( j9v0 )]

(5:115)

¼ 5:0624(0:7074) sin (565:5t 1:4709)

(5:116)

¼ 3:5811 sin (565:5t 1:4709)

(5:117)

y11 (t) ¼ jG( j11v0 )ja11 sin [11v0 t þ ﬀG( j11v0 )]

(5:118)

¼ 1:9126(0:5787) sin (691:2t 2:6642)

(5:119)

¼ 1:1068 sin (691:2t 2:6642)

(5:120)

The Simulink data for the signals in Equations 5.105 through 5.108, 5.111, 5.114, 5.117, and 5.120 are returned to the MATLAB Workspace (see Figure 5.99) for use by M-ﬁle ‘‘Chap5_Fourier_ Series.m’’ in preparing the graph shown in Figure 5.103. The input and output components can be identiﬁed by referring to the amplitudes in Equations 5.105 through 5.120. Note that y1(t) has a larger amplitude than y9(t), the system response to the harmonic component at the resonant frequency. This results from jG(jv0)ja1 ¼ 6.4426 being larger than jG(j9v0)ja9 ¼ 3.5811. As a ﬁnal comment, the line in ‘‘Chap5_Fourier_Series.m’’ sim(‘resonance’) % call Simulink model ‘resonance.mdl’ enables the MATLAB script ﬁle ‘‘Chap5_Fourier_Series.m’’ to initiate execution of the Simulink model ﬁle ‘‘resonance.mdl.’’ With additional parameters in the ‘‘sim’’ command, the user has control of many of the settings entered in the Simulink ‘‘Simulation Parameters’’ dialog box. u1(t) and y1(t) 5

u7(t) and y7(t) 5

ω0 = 62.8 rad/s

2.5 0

0

−2.5

−2.5

−5

−5 0

0.025

0.05

0.75

0.1

u9(t) and y9(t)

5

0

0.025

0.05

0.075

0.1

u11(t) and y11(t)

5

2.5

2.5

0

0

−2.5

−2.5

−5

0.025

0.05 t (s)

0.75

11ω0 = 691.2 rad/s

−5

ωr = 9ω0 = 565.5 rad/s 0

FIGURE 5.103

7ω0 = 439.8 rad/s

2.5

0.1

0

0.025

0.05 t (s)

0.075

0.1

Several harmonic components of u(t) and response of second-order system.

Simulink®

417

EXERCISES 5.34 A spring mass system described by m€y þ ky ¼ F is subject to an external periodic force F(t) shown in Figure E5.34: F(t) A

−T − T 0 2 4

T T 4 2

t

T

FIGURE E5.34

(a) The Fourier series expansion of F(t) is f (t) ¼

2 a0 ¼ T

T=2 ð

F(t)dt, T=2

1 a0 X 2p þ an cos nv0 t, v0 ¼ 2 T n¼1

2 an ¼ T

T=2 ð

F(t) cos T=2

2npt dt, n ¼ 1, 2, 3, . . . T

Find expressions for the Fourier coefﬁcients an, n ¼ 0, 1, 2, 3,. . . . (b) The mass m ¼ 1 slug and the natural frequency of the system is vn ¼ 25 rad=s. The period of the forcing function T is related to the natural frequency according to T ¼ 2Np=cvn where N is a positive integer and c is a constant. Write a MATLAB script ﬁle that reads values of c and N and computes the period T and Fourier coefﬁcients an, n ¼ 0, 1, 2, 3, . . . , 3N. For A ¼ 1, c ¼ 1, and N ¼ 5, use the MATLAB script ﬁle to (c) Plot on the same graph F(t) and the truncated Fourier Series fFS (t) ¼

3N a0 X þ an cos nv0 t 2 n¼1

for 0 t 3T. Comment on the results. (d) Prepare a Simulink diagram for simulating the response of the system with zero initial conditions. Call the simulation from the script ﬁle using the same values for c and N. Return the values of {t, y(t)} to the MATLAB Workspace and plot the response. (The simulation should run long enough to recognize the steady-state response.) Comment on the results. 5.35 The dynamic interaction of rabbit and fox populations in a forest is under investigation. The predator–prey ecosystem is illustrated in block diagram form in Figure E5.35a: hR (t) hF (t)

FIGURE E5.35a

Rabbit and fox ecosystem

R (t) F (t)

Simulation of Dynamic Systems with MATLAB® and Simulink®

418

R(t) ¼ Population of rabbits after ‘‘t’’ weeks F(t) ¼ Population of foxes after ‘‘t’’ weeks hR(t) ¼ Rate of rabbit hunting (rabbits=week) hF(t) ¼ Rate of fox hunting (fox=week) A Simulink diagram of the system is shown in Figure E5.35b: aR dR/dt

1 hR

1/s

R

bR

vF cR

bR*R

aR – bR – cR*F x

R

cF *R cR*F

F ++

2 hF

dF/dt

1/s

F

bF

+ − +

bF *F

aF – bF *F + cF *R

x

aF

FIGURE E5.35b

aR, aF, (a) (b) (c)

bR, cR ¼ constant parameters deﬁning the growth rate of rabbits bF, cF ¼ constant parameters deﬁning the growth rate of foxes Find the mathematical model governing the system dynamics. Find the nontrivial equilibrium points (Re, Fe) when hR(t) ¼ 0, t 0 and hF(t) ¼ 0, t 0. Write a MATLAB script ﬁle to set the following baseline parameter values:

aR ¼ 0:05

rabbits=week , rabbit2

bR ¼ 5 107

rabbits=week , rabbit3

foxes=week , fox2

bF ¼ 2 105

foxes=week , fox3

aF ¼ 0:04

hR (t) ¼ 0, t 0

cR ¼ 1:25 105 cF ¼ 8 107

rabbits=week rabbit2 fox

foxes=week foxes2 rabbit

hF (t) ¼ 0, t 0

R(0) ¼ 50, 000 F(0) ¼ 1,000 (d) Run the simulation and plot R(t) and F(t) vs. t until the system reaches equilibrium. (e) Obtain a solution trajectory R vs. F. Place a vertical line at F ¼ Fe and a horizontal line at R ¼ Re. This will allow you to verify by inspection if the solution trajectory approaches the theoretical equilibrium.

Simulink®

419

(f) Investigate the effect of changes in cR, a parameter that measures the interaction between foxes and rabbits. Plot families of appropriate responses corresponding to 0%–50% change in cR. (g) Establish a policy for hunting rabbits that makes the number of foxes equal to approximately 2500 at equilibrium. (h) Establish a policy for hunting foxes that makes the number of rabbits equal to approximately 35,000 at equilibrium. 5.36 The tank shown in Figure E5.36 has a brine solution ﬂowing into it. The solution is stirred well enough, so that the concentration of salt in the tank is uniform. c1: Brine concentration (lbs/gal)

c1, F1

F1: Brine flow (gal/min) c: Salt concentration in tank (lbs/gal)

H

A

Q: Quantity of saltin tank (lbs) H: Liquid level in tank (ft)

c, Q

V: Volume of liquid in tank (gal) c, F0

F0: Flow rate from tank (gal/min)

FIGURE E5.36

The mathematical model consists of the following equations: dQ ¼ c1 F1 cF0 dt c¼ A

Q , V ¼ AH V

dH þ F0 ¼ F1 , F0 ¼ aH 1=2 dt

The system baseline parameter values are A ¼ 20 ft2 and a ¼ 6 gal=min per ft1=2. Note: 1 ft3 of water is roughly 8.3 gal. (a) Draw a simulation diagram of the system. (b) Choose the state variables as x1 ¼ Q and x2 ¼ H and the outputs y1 ¼ c, y2 ¼ Q, and y3 ¼ V. Write the state equations in the form x_ 1 ¼ f1 (x1 , x2 , c1 , F1 ),

y1 ¼ g1 (x1 , x2 , c1 , F1 )

x_ 2 ¼ f2 (x1 , x2 , c1 , F1 ),

y2 ¼ g2 (x1 , x2 , c1 , F1 ) y3 ¼ g3 (x1 , x2 , c1 , F1 )

(c) Find expressions for the steady-state values of the states x1(1) and x2(1) and the outputs y1(1), y2(1), and y3(1) assuming c1 and F1 are constant. (d) The tank is initially ﬁlled with 100 gal of water (no salt). Brine starts ﬂowing into the tank at the rate of 12 gal=min. The salt concentration of the brine is 0.25 lb=gal. Both the ﬂow rate and salt concentration of the brine ﬂow remain constant. Using explicit Euler integration, ﬁnd the discrete-time state equations

Simulation of Dynamic Systems with MATLAB® and Simulink®

420

x A (n þ 1) ¼ f [(x A (n), u(n)] y A (n) ¼ g[(x A (n), u(n)] used to obtain an approximate solution for the continuous-time states and outputs. (e) Solve the discrete-time state equations recursively for the discrete-time states x1,A (n) and x2,A(n) and the outputs y1,A(n), y2,A(n), and y3,A(n). Graph the transient responses. Comment on the value of T used for the numerical integrator. (f) Compare the steady-state results obtained in part (e) with the predicted values from part (c). Comment on the results. (g) Use Simulink to verify the responses obtained in part (e).

5.9 HYBRID SYSTEMS: CONTINUOUS- AND DISCRETE-TIME COMPONENTS Hybrid systems consist of continuous- and discrete-time components and the interfaces bridging the gap between them. A good example is a digital controller (microprocessor or general-purpose digital computer) determining discrete-time input(s) to a continuous-time process. Figure 5.104 shows a digital controller used to regulate the temperature inside a chamber. The DC voltage input to the heater v(t) is determined by a digital control algorithm represented by discrete-time transfer function D(z). The heat input to the chamber is assumed proportional to the square of the heater voltage. A temperature sensor with gain KS produces a voltage signal vS(t) for comparison with a reference voltage vR(t). The reference voltage is based on the commanded temperature TR(t) (not shown in Figure 5.104). The error signal e(t) is sampled every T s in an analog-to-digital (A=D) converter. The A=D converter functions as an interface between the continuous-time inputs (sensor and reference voltage) and the discrete-time digital controller. The error signal e(k) is processed by the digital controller, resulting in an output v(k), the intended voltage to the heater. A digital-to-analog (D=A) converter, operating synchronously with the A=D, produces the voltage. Internal circuitry in the D=A latches the discrete-time input for the duration of the sampling period, resulting in a stepwise constant voltage v(t) applied to the heater. The D=A converter serves as an interface between the discrete-time and continuous-time components. It is modeled by a zero-order hold (ZOH) in Figure 5.104. The digital controller implements a linear difference equation for v(k) in terms of past values v(k 1), v(k 2), . . . , v(k n) as well as present and past values e(k), e(k 1), . . . , e(k p). Digital controllers are often synthesized by approximating continuous-time controllers. For example, the transfer function of a continuous-time proportional-integral-derivative (PID) controller is V(s) KI ¼ K P þ þ KD s s E(s)

(5:121) T0(t) °F

vR(t) Volts

e(t)

e(k)

–Volts

A/D Sampler

Volts

D(z) Digital controller

v(k) Volts

D/A Zero-order hold

Volts

KS Sensor

Digital control of chamber temperature.

T(t) °F

Btu/min

Volts Heater

Process

vS(t)

FIGURE 5.104

QH(t)

v(t)

Chamber

Simulink®

421

Approximating the integral by trapezoidal integration and the derivative by a backward difference equation leads to the equivalent digital transfer function (Jacquot 1981) D(z) ¼

c1 z 2 þ c 2 z þ c3 z2 z

(5:122)

where c1 ¼ K P þ

KI T KD , þ T 2

c2 ¼

KI T 2KD , KP T 2

c3 ¼

KD T

(5:123)

The continuous-time process model is (see Section 2.7) C

dT 1 1 þ T ¼ T0 þ QH dt R R

(5:124)

where C is the thermal capacitance of the interior space (objects and volume of air assumed to be at the same temperature) R is the effective thermal resistance of the material separating the inside and outside of the chamber The heater output is QH (t) ¼

v2 (t) Re

(5:125)

where Re is the electrical resistance of the heater coil. A temperature sensor produces a voltage proportional to the interior temperature vs (t) ¼ Ks T(t)

(5:126)

A Simulink diagram of the system is shown in Figure 5.105. The commanded reference temperature TY is converted to a reference voltage input with a Units Converter, that is, a ‘‘Gain’’ block with

FIGURE 5.105

Simulink® diagram of a digital control system for chamber temperature.

422

Simulation of Dynamic Systems with MATLAB® and Simulink®

parameter equal to KS. A ‘‘Saturation’’ block limits the actual voltage v(t) to the heater. The ‘‘Zero–Order Hold’’ and ‘‘Rate Transition’’ blocks are included to resolve timing issues related to the faster simulation execution rate (based on the integration step) and the slower sampling rate of the digital controller. System parameters were set in the MATLAB script ﬁle ‘‘Chap5_dig_cont.m.’’ Chamber: R ¼ 0.1758F=Btu=min, C ¼ 50 Btu=8F Sensor: KS ¼ 0.25 V=8F Controller: KP ¼ 2, KI ¼ 2, KD ¼ 0.25 Heater: Re ¼ 1.25 V, vmax ¼ 100 V Inputs: TR(t) ¼ 1258F, t 5, T0(t) ¼ 758F, t 0 Timing: T ¼ 0.02 min (sample time), Dt ¼ 0.002 min (integration step size) Figure 5.106 shows the voltage v(k) computed from the digital control algorithm and the actual voltage v(t) to the heater. Note the initial spike due to the presence of the proportional control and derivative action in the controller. The initial continuous-time voltage to the heater is ‘‘maxed out’’ at a 100 V, the upper limit of the saturation block. Figure 5.107 shows the heat ﬂows to and from the chamber. Note the constant heat ﬂow to the chamber when the heater is at saturation. At the end of the transient response period, the heat ﬂows have equalized, and the chamber interior is in thermal equilibrium with its surroundings. Figure 5.108 is a graph of the chamber temperature increasing from its initial value of 758F to the commanded value of 1258F. The step response is typical of a slightly underdamped second-order system with a settling time between 50 and 60 min. The thermal time constant of the chamber is t ¼ RC ¼ 0:175

F Btu 50 ¼ 8:75 min F Btu= min

The sampling time T ¼ 0.02 min of the A=D converter is chosen several orders of magnitude less than the process time constant in order to capture the transient behavior of the chamber temperature. A more precise way of determining the sampling rate will be discussed in a subsequent chapter. The control system is nonlinear as a consequence of Equation 5.125. Laplace transforms cannot be used to ﬁnd an analytical solution for the system variables. Simulation is the only viable approach to examining the system dynamics.

FIGURE 5.106

Digital controller output v(k) and heater input v(t).

Simulink®

423

FIGURE 5.107

Heater input QH(t) and heat loss Q0(t) from chamber to surroundings.

FIGURE 5.108

Chamber temperature response T(t) to reference input TR(t) ¼ 1258F, t 5.

EXERCISES In Exercises 5.37 through 5.40, use baseline values for the system parameters found in ‘‘Chap5_ dig_cont.m’’ unless otherwise stated. 5.37 Plot the simulated chamber temperature responses (on the same graph) corresponding to a range of sampling intervals from 0.01 to 0.25 min. Comment on the results. 5.38 The maximum output from the chamber heater in watts is (QH)max ¼ v2max =Re . (a) Find Tmax, the maximum temperature achievable in the chamber. (b) Note: 1 kW ¼ 56.896 Btu=min.

424

Simulation of Dynamic Systems with MATLAB® and Simulink®

(c) Simulate the chamber temperature when the commanded temperature is set to (i) Tmax (ii) 10% higher than Tmax (iii) 25% higher than Tmax 5.39 Simulate the temperature response of the control system with proportional control only, that is, KI ¼ 0 and KD ¼ 0. The set point temperature is 2008F. Vary KP from 1 to 10 and plot the responses on the same graph. 5.40 Suppose the chamber temperature has been constant at TR ¼ 1258F for some time. Simulate the chamber temperature T(t) when (a) the heater is turned off (b) the reference temperature is set to 1508F 5.41 Simulate the chamber temperature using a digital controller obtained by approximating the continuous controller in Equation 5.121 using Tustin’s method (trapezoidal integration). Compare the results with those shown in Figures 5.106 through 5.108.

5.10 MONTE CARLO SIMULATION The dynamic systems, which have been simulated to this point, were all deterministic, that is, there have been no random components associated with either the system’s parameters or inputs. In reality, knowledge of the values of a system’s parameters is inexact for a number of reasons. Precise measurement or observation of the parameters may be difﬁcult, or it is possible that the numerical values drift over time as the components age. Quantitative descriptions of the input signals a priori may be probabilistic in nature. The existence of random inputs and uncertain system parameter values leads to stochastic differential equation models with solutions in the form of stochastic processes. An alternate approach is based on the technique of Monte Carlo simulation. An empirical rather than analytical method, its name stems from the random nature of gambling and associated probabilities. The underlying premise in Monte Carlo simulation is that by repeatedly sampling from known probability distributions, the probabilities of events or probability distributions of functions of a random variable(s) can be approximated. Sampling from the probability distribution of a random variable (or random variables) to generate random deviates is substituted for the process of making observations of the random variable(s) from the real world or physical process itself. In other words, random samples obtained by actual measurements or observations of a random variable are replaced by simulated random samples based on random number generators and known probability distributions. Consider a simple mechanical system with mass M, spring constant K, and damping coefﬁcient B described by M€y þ B_y þ Ky ¼ f (t)

(5:127)

where y is the displacement of the mass from equilibrium f(t) is a force acting on the mass Suppose M, B, and K are continuous random variables with known probability density functions (pdf’s) fM(u), fB(u), and fK(u), respectively. The damping ratio z B z ¼ z(M, B, K) ¼ pﬃﬃﬃﬃﬃﬃﬃﬃ 2 MK

(5:128)

is a new random variable, which, along with the natural frequency, characterizes the system’s natural dynamics. Finding the theoretical probability distribution of z, that is, its pdf fz(u), is a formidable task despite the relative simplicity of Equation 5.128. The following example demonstrates a Monte Carlo simulation to obtain what we shall refer to as an empirical probability density

Simulink®

425

function denoted ^fz (u) to distinguish it from the true pdf fz(u). The empirical pdf can be used to approximate probability distributions of other random variables functionally related to the damping ratio such as the overshoot in the step response of underdamped second-order systems. The parameters M, B, and K are each assumed to vary uniformly between speciﬁed limits. The pdf for random variable M is the uniform pdf, denoted U(Ml, Mu) where Ml and Mu are the lower and upper limits of M, respectively. In mathematical terms, the pdf is given by 8 1 < , Ml u Mu (5:129) fM (u) ¼ Mu Ml : 0, elsewhere Similar expressions apply for the pdfs of random variables B and K, that is, 8 < 1 , B uB l u fB (u) ¼ Bu Bl : 0, elsewhere 8 1 < , Kl u Ku fK (u) ¼ Ku Kl : 0, elsewhere

(5:130)

(5:131)

A random variable, uniformly distributed between 0 and 1, also referred to as a random number, is generated by the MATLAB function ‘‘rand.’’ To be more precise, the generated numbers are actually pseudo random numbers, which depend on the speciﬁc algorithm implemented for generation. A random number Ri uniformly distributed U(0, 1) is transformed to a new random variable Xi with pdf U(A, B) by Xi ¼ A þ (B A)Ri

(5:132)

The MATLAB M-ﬁle ‘‘Chap5_MonteCarlo_damping_ratio.m’’ generates 100,000 random vectors (Mi, Bi, Ki), i ¼ 1, 2, . . . , 100,000 using lower and upper limits Ml ¼ 0.9, Mu ¼ 1.1, Bl ¼ 1.75, Bu ¼ 2.25, Kl ¼ 3.8, and Ku ¼ 4.2. The corresponding 100,000 damping ratios zi, i ¼ 1, 2, . . . , 100,000 computed from Equation 5.128 are segregated into equal intervals of width 0.005, several of which are shown in Table 5.4.

TABLE 5.4 Monte Carlo Simulation Results for Damping Ratio Interval (zi1 z zi)

Center of Interval zi

Frequency of Occurrence ni

Normalized Frequency of Occurrence fi

(0.3975, 0.4025) (0.4025, 0.4075) (0.4075, 0.4125) (0.4875, 0.4925) (0.4925, 0.4975) (0.4975, 0.5025) (0.5025, 0.5075) (0.5075, 0.5125) (0.5875, 0.5925) (0.5925, 0.5975) (0.5975, 0.6025)

0.4000 0.4050 0.4100 0.4900 0.4950 0.5000 0.5050 0.5100 0.5900 0.5950 0.6000

0 0 33 4053 4098 4062 4033 3986 341 164 59

0 0 0.0660 8.1060 8.1960 8.1240 8.0660 7.9720 0.6820 0.3280 0.1180

Simulation of Dynamic Systems with MATLAB® and Simulink®

426

Histogram of damping ratio values

Damping ratio pdf 8

3500

7

3000

6

2500 2000 1500

5 4

Ml = 0.9, Mu = 1.1

3 Bl = 1.75, Bu = 2.25

1000

2

Kl = 3.8, Ku = 4.2

500

1

fi Empirical pdf

0

FIGURE 5.109

Approximation of fζ(u)

Frequency of occurrence, ni

100,000 trials 4000

0.4

0.45 0.5 0.55 Damping ratio, u

0.6

0

0.4

0.45 0.5 0.55 Damping ratio, u

0.6

Histogram of z values and empirical pdf ^fz (u).

A histogram based on the ﬁrst and third columns of the complete table is shown in the left graph of Figure 5.109. The empirical probability density function ^fz (u) is obtained by connecting the points (zi , ni ) and rescaling the ordinate values to fi using Equation 5.133 to make the area under the resulting curve equal to 1. fi ¼

ni ni ni ¼ ¼ Number of trials width of interval 100,000 0:005 500

(5:133)

Finally, a data point is added at zi ¼ 0:6050, fi ¼ 0 to assure the pdf ^fz (u) returns to zero at the upper tail. The result is shown in the right graph of Figure 5.109. The theoretical probability of z falling in a certain interval is the area under fz(u) for that interval. It is approximated by the area under the empirical pdf ^fz (u) for the same interval. For example, the estimate of Pr(0.45 z 0.5) is computed in the M-ﬁle ‘‘Chap5_MonteCarlo_damping_ratio.m’’ to be 0.4105. The empirical pdf ^fz (u) can be used to approximate probabilities involving various performance measures related to the damping ratio. For example, the percent overshoot in the unit step response and the peak amplitude of the frequency response pﬃﬃﬃﬃﬃﬃﬃ2ﬃ P:O: ¼ f1 (z) ¼ 100ezp= 1z 1 Mpv ¼ f2 (z) ¼ pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 2z 1 z 2

(5:134) (5:135)

How shall we go about determining the empirical pdf ^fMpv (u)? A table similar to Table 5.4 with equally spaced intervals of Mpv and frequencies of occurrence is needed. The ﬁrst step is to generate a random sample from a population with pdf ^fz (u). The random sample (z1, z2, . . . , zn) and Equation 5.135 are used to generate the sample [(Mpv)1, (Mpv)2, . . . , (Mpv)n] needed for the new table.

Simulink®

427 Generation of random ζi values

Empirical cumulative distribution function

1 0.9 0.8 0.7

0.5 0.4 0.3

Ri

0.2 0.1 0 0.35

FIGURE 5.110

Fˆζ(u)

0.6

ζi 0.4

0.45

0.5 0.55 Damping ratio, u

0.6

0.65

^ z (u). Illustration of method for generating zi using cdf F

The random sample (z1, z2, . . . , zn) can be generated in several ways. One method relies on the use of random numbers (R1, R2, . . . , Rn) and the cumulative probability distribution function (cdf), ^z (u) given by F ^z (u) ¼ F

ðu

^fz (x)dx,

1 2 rad=s]. 5.44 Repeat Exercise 5.43 if the mass M is normally distributed with mean mM ¼ 1 slug and standard deviation sM ¼ 0.25 slugs. Assume B and K are no longer random, instead B ¼ 2 lb s=ft and K ¼ 4 lb=ft. 5.45 Suppose the arrow and target with mass and aerodynamic properties given in the text are dropped from an airplane in level ﬂight at a cruising speed of vcr ¼ 600 ft=s. (a) Find expressions for the terminal velocities of both. (b) Simulate their descent from an altitude of 10,000 ft with zero initial velocity. (c) Plot the acceleration of each during their descent. 5.46 Neglecting aerodynamic damping forces and assuming that the initial ﬁring angle of the arrow is equal to the sight angle to the target, perform a simulation study to produce the missing graphs in Figure E5.46:

Simulink®

435 Elevation at which target is struck

Time required for arrow to strike target

Initial speed of arrow

Initial speed of arrow

FIGURE E5.46

5.47 A boy is throwing rocks, aiming at a circular target with diameter D. The center of the target is xT ft down range from where he is located (see Figure E5.47). The aerodynamic drag force is proportional to the speed of the rock with drag constant a. The rocks are launched from a height of y0 at an angle w(0) and initial speed v(0). The weight of the rock is W. The distance downrange where the rock lands is R. y

v

fD = αv W = mg

v(0) (0)

D

y0

xT

0

R

x

FIGURE E5.47

Baseline system parameter values are y0 ¼ 6 ft, xT ¼ 160 ft, D ¼ 4 ft, a ¼ 9 104 lb=ft=s, W0 ¼ 0.5 lb, w(0) ¼ 458, and v(0) ¼ 75 ft=s (a) Write the equations comprising the mathematical model of the system in state variable form x_ ¼ f (x, u) where the state vector x ¼ [x x_ y y_ ]. (b) Use Simulink to simulate the system under baseline conditions, and verify the stone trajectory shown in Figure E5.47: Trajectory of stone 45

Height of stone, y (ft)

40 35 30 25 20 15 10 5 0

FIGURE E5.47

0

20

40 60 80 100 120 140 Horizontal distance of stone, x (ft)

160

Simulation of Dynamic Systems with MATLAB® and Simulink®

436

(c) The boy picks up a rock, the weight of which is uniformly distributed between 0.25 and 0.75 lb, and throws it with initial speed and angle given by the baseline values. Find the probability of the rock landing on the target. (d) Prepare a histogram for the random variable D ¼ jR xTj, and use it to ﬁnd the empirical probability density function ^f D (u), D 0. (e) Repeat parts (d) and (e) if W ¼ W0 ¼ 0.5 lb and u(0) U(408, 508). 5.48 A particle slides without friction along a path given by y ¼ f(x) ¼ x1=2 under the inﬂuence of gravity as shown in Figure E5.48: x0

(0, 0)

y = f (x)

x

(x0, y0)

y

FIGURE E5.48

The time required for the particle to slide down the curve starting from the origin to the point (x0, y0) is (Speckhart 1976) 1 t0 ¼ pﬃﬃﬃﬃﬃ 2g

xðo

sﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 1 þ (dy=dx)2 dx y

0

The termination value x0 is a random variable uniformly distributed between 1 and 5 along the curve. Implement a Monte Carlo experiment culminating in a histogram for the random variable t0. 5.49 Consider the second-order system €y þ 2z vn y_ þ v2n y ¼ 0 with initial conditions y(0) ¼ y0 , y_ (0) ¼ 0. Introduce state variables x1 ¼ y, x2 ¼ y_ . Phase plots for an underdamped (z ¼ 0.25), critically damped (z ¼ 1), and overdamped (z ¼ 2) case with vn ¼ 1 rad=s and y0 ¼ 1 are shown in Figure E5.49: Phase trajectories of unforced second-order system 0.3

ωn = 1 rad/s

0.2

x1(0) = 1, x2(0) = 0

0.1 0 ζ=2

x2

−0.1 −0.2 ζ=1

−0.3 −0.4 −0.5

ζ = 0.25

−0.6 −0.7 −0.8

FIGURE E5.49

−0.5

−0.25

0

0.25 x1

0.5

0.75

1

Simulink®

437

(a) Plot a histogram for the distance from the initial point x1(0) ¼ 1, x2(0) ¼ 0 to the steadystate equilibrium point x1(1) ¼ 0, x2(1) ¼ 0 along the trajectories in state space if the damping ratio is uniformly distributed between 0 and 2. Note that the distance from the initial point (1,0) to the point [x1(t), x2(t)] along the trajectory is given by ðt s(t) ¼

x_ 21 þ x_ 22

1=2

dt

0

(i) Repeat part (a) for the case where z ¼ 0.25, and the natural frequency vn is uniformly distributed between 0 and 100 rad=s. (ii) Repeat part (a) for the case where z ¼ 1, and the natural frequency vn is uniformly distributed between 0 and 12.5 rad=s. (iii) Repeat part (a) for the case where z U(0, 2), vn U(0, 100), and y0 U(0, 1).

5.11 CASE STUDY: PILOT EJECTION Several benchmark applications of continuous-time simulation using analog and digital computers have been around for decades. Simulation of a pilot and seat ejected from a ﬁghter aircraft falls in this category (Korn 1978). The system is shown in Figure 5.120. When forced to eject, the combination of pilot and seat trajectory is controlled by a set of guide rails until it is clear of the plane. The ejection velocity vE is constant along a direction uE from the y axis of the plane. Ejection occurs when the pilot and seat have traveled a vertical distance y1. After ejection from the aircraft, the pilot and seat follow a ballistic trajectory subject to an aerodynamic drag force and its own weight. The equations of motion can be developed in the x–y coordinate system or n–t coordinate system, where n and t refer to directions normal and tangential to the ﬂight of the pilot and seat as shown in Figure 5.121. Summing forces in the n and t directions, X

Ft ¼ mat

(5:154)

) FD W sin u ¼ m_v X Fn ¼ man ) W cos u ¼ m

(5:155) (5:156)

v2 R

(5:157)

y vE θE y1

vA

FIGURE 5.120

Diagram of pilot ejection.

x

Simulation of Dynamic Systems with MATLAB® and Simulink®

438

Pilot and seat at time t n θ

v

t

FD

y

y R vA

W θ

Aircraft at ejection (prior to time t)

FIGURE 5.121

vA Aircraft at time t

Trajectory of pilot and seat after ejection.

where R is the instantaneous radius of curvature of the pilot and seat trajectory. The plane is assumed to be traveling in a horizontal direction at constant speed vA. The forward velocity v and angular velocity u_ are related by v ¼ Ru_

(5:158)

Solving for R in Equation 5.158 and substituting the result in Equation 5.157 give W cos u ¼ mvu_

(5:159)

With W ¼ mg and state variables v and u, the state derivatives are obtained from Equations 5.155 and 5.159 as (

0 y < y1 FD g sin u, y y1 m ( 0, 0 y < y1 g cos u u_ ¼ , y y1 v

v_ ¼

0,

(5:160)

(5:161)

The intervals 0 y < y1 and y y1 correspond to before and after ejection. Additional state variables x and y, the relative coordinates of the pilot and seat with respect to the moving aircraft, are needed to view its trajectory with respect to the plane in order to determine if it safely clears the plane’s rear vertical stabilizer. The state derivatives are expressed as (see Figure 5.121) x_ ¼ v cos u vA

(5:162)

y_ ¼ v sin u

(5:163)

It is convenient to start the simulation, that is, integrating the state derivatives, at the moment of ejection. The initial conditions are obtained with the help of Figure 5.122. The initial states v(0) and u(0) are computed from h i1=2 v(0) ¼ v2x (0) þ v2y (0)

(5:164)

) v(0) ¼ [(vA vE sin uE )2 þ (vE cos uE )2 ]1=2

(5:165)

Simulink®

439 y

x(0)

θE

v(0) =

x(0) = −y1 tan θE

θE

y(0) = y1

vx(0) vy(0)

=

vE cos θE

v(0)

θ(0)

vE

vA − vE sin θE

vA

x

FIGURE 5.122

Initial states x(0), y(0), v(0), and u(0) at ejection (t ¼ 0).

u(0) ¼ tan1 ) u(0) ¼ tan1

vy (0) vx (0)

vE cos uE vA vE sin uE

(5:166) (5:167)

Finally, the drag force FD is obtained from 1 FD ¼ CD rAv2 2

(5:168)

where CD is the drag coefﬁcient r is the density of air A is the surface area of the pilot and seat normal to the velocity vector A simulation study is required to investigate the combinations of aircraft speed vA and altitude h associated with safe ejection, that is, pilot and seat clear the rear vertical stabilizer by a predetermined amount. First, we shall simulate a single case where vA ¼ 500 ft=s and h ¼ 0 (sea level). A Simulink diagram is shown in Figure 5.123.

FIGURE 5.123

Simulink® diagram of pilot ejection.

Simulation of Dynamic Systems with MATLAB® and Simulink®

440 20 18

Pilot and seat trajectory

16 14

y (ft)

12 10 8 6

Vertical stabilizer Starting point

4 2

Plane profile

0 −60

FIGURE 5.124

−50

−40

−30 x (ft)

−20

−10

0

Plot of pilot and seat trajectory relative to the aircraft (h ¼ 0 ft, vA ¼ 500 ft=s).

Baseline numerical values of the system parameters are uE ¼ 158, vE ¼ 40 ft=s, m ¼ 8 slugs, A ¼ 10 ft2, CD ¼ 1, and y1 ¼ 4 ft. The ‘‘Lookup Table’’ contains air density r (slug ft2) vs. altitude h (ft) data points from sea level to 60,000 ft. The pilot and seat trajectory relative to the aircraft is obtained by calling the Simulink model ‘‘ejection_seat.mdl’’ from the M-ﬁle ‘‘Chap5_eject.m’’ using the command ‘‘sim(‘ejection_ seat’).’’ Figure 5.124 illustrates the relative separation between the pilot and seat combination and the plane during the time when the pilot and seat are located above the plane. The pilot and seat safely clear the vertical stabilizer.

Safe conditions for pilot ejection 1600

Aircraft speed, vA (ft/s)

1400 1200 1000 800 600

Region of safe ejection

400 200 0

FIGURE 5.125

0

0.5

1

1.5

2 2.5 3 Altitude, h (ft)

3.5

4

4.5

Lower and upper aircraft speeds at a given altitude for safe ejection.

5 ×104

Simulink®

441 Pilot and seat height above plane vs. time 20

y (ft)

15 10 5 0

0

0.25

0.5

0.75

1

1.25

1.5

1.75

2

1.75

2

Pilot and seat angle of trajectory vs. time

θ (deg)

5 0 −5 −10 0

FIGURE 5.126

0.25

0.5

0.75

1 t (s)

1.25

1.5

Pilot and seat height above plane and trajectory after ejection.

At a given altitude h, the pilot and seat trajectory will safely clear the stabilizer provided the aircraft cruising speed vA falls within a range of values. At slow speeds, the exit velocity is insufﬁcient to propel the pilot and seat safely over the stabilizer, while at very high speeds, the excessive drag force and backward velocity (relative to the plane) produce a similar outcome. A simulation study was performed to determine a region of safe ejection conditions, that is, altitude and speed combinations resulting in a clearance of 5 ft when the pilot and seat are directly over the back part of the rear stabilizer. The M-ﬁle ‘‘Chap5_safe_eject.m’’ calls the simulation model for altitudes from zero to 50,000 ft (in increments of 5,000 ft) and ﬁnds the range of aircraft speeds for a safe ejection. The result is shown in Figure 5.125. Figure 5.126 shows a plot of y(t), the height of the pilot and seat combination above the plane, corresponding to the safe ejection trajectory shown in Figure 5.124. The lower graph shows u(t), the angle between the velocity vector and the horizontal. Can you locate the point on each plot where the pilot and seat are located at the rear of the plane?

EXERCISES 5.50 With respect to the ballistic trajectory of the pilot and seat, (a) Develop an alternate mathematical model using x, y coordinates. The states are x, x_ , y, and y_ . (b) Prepare a Simulink diagram for simulating the trajectory following ejection. (c) Run the simulation for the same conditions as in Figure 5.124 and compare results. (d) Suppose the aircraft is cruising at 30,000 ft in level ﬂight when ejection occurs. Simulate pilot and seat trajectories corresponding to vA ¼ 500, 600, . . . , 1200 ft=s. Plot the entire set of trajectories (with respect to the plane) on the same axes with the plane proﬁle similar to Figure 5.124. Are the results consistent with the safe ejection conditions portrayed in Figure 5.125?

442

Simulation of Dynamic Systems with MATLAB® and Simulink®

5.51 Use either n–t or x–y coordinate systems to model the pilot and seat trajectory and obtain plots of (a) x vs. t (b) y vs. t (c) u vs. t when ejection occurs from 50,000 ft at a speed of 900 ft=s. 5.52 Reexamine the limiting plane speeds for a safe ejection from 25,000 ft as the mass of the pilot and seat varies from 8 slugs to 12 slugs. How important is the combined mass of the pilot and seat with respect to the limiting plane speeds at 25,000 ft? 5.53 Obtain new curves for lower and upper safe ejection speeds in terms of altitude if the criterion for a safe ejection is that the pilot and seat simply clear the rear vertical stabilizer. Use the baseline value for m ¼ 8 slugs. 5.54 Modify the code in M-ﬁle ‘‘Chap5_safe_eject.m’’ to check whether the pilot and seat have cleared the rear stabilizer over its entire length of 48–60 ft back from the point of ejection. How does this affect the curves in Figure 5.125?

5.12 CASE STUDY: KALMAN FILTERING Estimations of the Moon and planetary orbits were performed by early pioneers such as Kepler, Legendre, and Gauss. More recent estimation algorithms have been developed in an effort to obtain the optimal estimate of a dynamic object, the Kalman ﬁlter being the most popular. In this case study, the continuous-time Kalman ﬁlter, the steady-state Kalman ﬁlter, and the discrete-time Kalman ﬁlter (Simon 2006) are applied to the trajectory of an asteroid. First, the algorithms of the different ﬁlters will be presented in summary form, and then simulations will be run in Simulink for comparison.

5.12.1 CONTINUOUS-TIME KALMAN FILTER The state equations of a continuous dynamic system are given by x_ ¼ Ax þ Bu þ w y ¼ Cx þ v

(5:169)

where x is the state vector u is the input vector y is the output vector A is the system matrix B is the input matrix C is the output matrix In the state equations, w and v are zero-mean, uncorrelated, continuous-time, white noise with process covariance matrix Qc and measurement covariance matrix Rc , respectively. Mathematically, w (0, Qc ) v (0, Rc ) E[wwT ] ¼ Qc dij E[vv ] ¼ Rc dij T

E[vwT ] ¼ 0

(5:170)

Simulink®

443

The algorithm of the continuous-time Kalman ﬁlter is given by K ¼ PCT R1 c x^_ ¼ Ax^_ þ Bu þ K(y C^ x)

(5:171)

T P_ ¼ PCT R1 c CP þ AP þ PA þ Qc

where the last equation in 5.171 is referred to as the Riccati equation. The algorithm is initialized with the expectation values of the state and state covariance x^(0) ¼ E[x(0)] P(0) ¼ E[(x(0) x^(0))(x(0) x^(0))T ]

(5:172)

5.12.2 STEADY-STATE KALMAN FILTER In the case of the steady-state Kalman ﬁlter, the system dynamics do not change with respect to time; therefore, P_ ¼ 0, so that the Riccati equation of 5.171 becomes T 0 ¼ PCT R1 c CP þ AP þ PA þ Qc

(5:173)

5.12.3 DISCRETE-TIME KALMAN FILTER The state equations of a discrete dynamic system are given by xk ¼ Fk1 xk1 þ Gk1 uk1 þ wk1 yk ¼ Hk1 xk1 þ vk1

(5:174)

where Fk1 is the system matrix Gk1 is the input matrix Hk1 is the output matrix In this case, wk1 and vk1 are zero-mean, uncorrelated, discrete-time, white noise with process covariance matrix Qk and measurement covariance matrix Rk , respectively. Mathematically, wk (0, Qk ) vk (0, Rk ) h i E wk wTj ¼ Qk dkj h

i

E vk vTj ¼ Rk dkj h i E wk vTj ¼ 0

(5:175)

444

Simulation of Dynamic Systems with MATLAB® and Simulink®

The algorithm of the discrete-time Kalman ﬁlter is given by ^þ x^ k ¼ Fk1 x k1 þ Gk1 uk1 þ T P k ¼ Fk1 Pk1 Fk1 þ Qk1 1 T T K k ¼ P k H k H k Pk H k þ Rk ^ ^ x^þ k ¼x k þ K k yk H k x k

(5:176)

T T Pþ k ¼ (I K k H k )Pk (I K k H k ) þ K k Rk K k

and is initialized with the expectation values of the state and state covariance x^þ 0 ¼ E[x0 ] h T i ^þ Pþ x0 x^þ 0 ¼ E x0 x 0 0

(5:177)

5.12.4 SIMULINK® SIMULATIONS The three different Kalman ﬁlters (continuous, steady-state, and discrete) are used to estimate the kinematics (position and velocity) of an incoming meteorite. It is assumed that the meteorite is tracked with a radar system that picks up the object at a range of 200,000 m with a velocity of 5,000 m=s. The measurement error R of the radar tracking station is 100 m. The process noise statistics Q in range, velocity, and acceleration are 1 m, 0.1 m=s, and 0.1 m=s2, respectively. Since the initial conditions of the meteorite are unknown, the diagonal elements of the state covariance matrix P are large. The meteorite is tracked for 30 s at a frequency of 10 Hz. Figure 5.127 shows a Simulink diagram for estimating the range of the meteorite with a continuous-time Kalman ﬁlter. (In most cases, element blocks retained their default names for ease of locating them in the Simulink library. A few subsystem names were changed to reﬂect their contents.) At the top of the continuous-time Kalman ﬁlter hierarchy, two major subsystems are shown: (1) the actual range of the meteorite corrupted by noise and (2) the estimated range containing the continuous-time Kalman ﬁlter elements. To run this model, execute the MATLAB M-ﬁle CTKF_Model_Data.m. By double clicking on the ‘‘Actual’’ subsystem, Figure 5.128 shows the elemental blocks that calculate the kinematics of the meteorite y ¼ y0 þ v0 t þ 1=2at 2 and v ¼ v0 þ at where the initial conditions are represented by xhat0, a vector deﬁned in the MATLAB M-ﬁle.

FIGURE 5.127

Top view of the continuous-time Kalman ﬁlter.

Simulink®

445

FIGURE 5.128

The ‘‘Actual’’ subsystem.

FIGURE 5.129

The continuous-time Kalman ﬁlter algorithm.

Returning to the top-level view and then double clicking on the ‘‘Estimates’’ subsystem, Figure 5.129 shows the elemental blocks of the continuous-time Kalman ﬁlter algorithm, Equation 5.171. The integrator block requires the initial conditions xhat0 deﬁned in the MATLAB M-ﬁle. For legibility, the computation of the state covariance matrix P is placed into its own subsystem. By double clicking on the ‘‘P’’ subsystem, Figure 5.130 shows the elemental blocks that update the state covariance matrix P, Equation 5.171. The integrator in this subsystem requires the initial conditions P0 deﬁned in the M-ﬁle. Simulating the model by executing the MATLAB M-ﬁle CTKF_Model_Data.m created the following plots. Figure 5.131 shows the actual range R and the estimated range Rhat of the meteorite vs. time. The meteorite is picked up at a range of 200,000 m and tracked for 30 s. Over this time period, the meteorite traveled approximately 150,000 m. The continuous-time Kalman ﬁlter performs very well, such that it is difﬁcult to see any differences between the actual range and the estimated range. Figure 5.132 shows the actual velocity V and the estimated velocity Vhat of the meteorite vs. time. The continuous-time Kalman ﬁlter takes approximately 10 s for transients to settle before obtaining reasonable velocity estimates. Figure 5.133 shows the actual acceleration A and the estimated acceleration Ahat of the meteorite vs. time. It is unnecessary to estimate the acceleration of gravity, but it is shown here for

Simulation of Dynamic Systems with MATLAB® and Simulink®

446

FIGURE 5.130

Simulink® diagram of the continuous-time Kalman ﬁlter.

Range and range estimate (m)

2

×105 R Rhat

1.8 1.6 1.4 1.2 1 0.8 0.6 0.4

0

5

10

15

20

25

30

Time (s)

FIGURE 5.131

Plot of range and range estimates (m) vs. time (s). –4900 V Vhat

Velocity and velocity estimate (m/s)

–4950 –5000 –5050 –5100 –5150 –5200 –5250 –5300

FIGURE 5.132

0

5

10

15 Time (s)

20

Plot of velocity and velocity estimates (m=s) vs. time (s).

25

30

Simulink®

447 Acceleration and acceleration estimate (m/s/s)

25

FIGURE 5.133

Graviational acceleration Ahat

20 15 10 5 0 –5 –10 –15 –20 –25

0

5

10

15 Time (s)

20

25

30

Plot of acceleration and acceleration estimates (m=s=s) vs. time (s).

150

Range error (m) compared with theoretical bounds Simulation Theory

Range error (m)

100 50 0 –50

–100 –150 0

FIGURE 5.134

5

10

15 Time (s)

20

25

30

Plot of range error vs. time.

completeness. Again, the transients take approximately 10 s to settle before obtaining reasonable estimates. Figure 5.134 shows the range error, the difference between the actual range and the estimated range, vs. time. In theory, the range error should be bounded by the standard deviation of the 1,1 element of the state covariance matrix, which it is. It appears as if the maximum range error at any given time is about 50 m. Recall (Figure 5.131) that the meteorite traveled roughly 150,000 m over 30 s. An error of 50 m, even at the end of the 30 s when the meteorite is at a range of 50,000 m, is 0.1%. Figure 5.135 shows the velocity error, the difference between the actual velocity and the estimated velocity, vs. time. In this case, the velocity error should be bounded by the standard deviation of the 2,2 element of the state covariance matrix, which it is. After the ﬁlter transients settle out, the maximum velocity error appears to be less than 10 m=s. Recall (Figure 5.132) that the meteorite obtained a speed of roughly 5300 m=s over 30 s. An error of 10 m=s is less than 0.2%.

Simulation of Dynamic Systems with MATLAB® and Simulink®

448

Velocity error (m/s) compared with theoretical bounds 150 Simulation Theory

Velocity error (m/s)

100

50

0

–50

–100

–150

FIGURE 5.135

0

5

10

15 Time (s)

20

25

30

Plot of velocity error vs. time.

This concludes the implementation and analysis of the continuous-time Kalman ﬁlter as applied to the range and velocity estimates of an incoming meteorite. Next, the steady-state Kalman ﬁlter is applied to the same problem for comparison with the continuous-time Kalman ﬁlter. The only difference between the two models is the calculation of the state covariance matrix P. In the continuous-time algorithm, the Riccati equation is time dependent; for the steady-state algorithm, the Riccati equation is independent of time, Equation 5.173. With regard to model structure, the top-level diagram and ‘‘Actual’’ subsystem diagram are the same for the steady-state Kalman ﬁlter as they were for the continuous-time Kalman ﬁlter. However, the ‘‘Estimates’’ subsystem reﬂects the difference with regard to the Riccati equation, which is represented by a constant element block called ‘‘SSP’’ seen in Figure 5.136.

FIGURE 5.136

The steady-state Kalman ﬁlter algorithm.

Simulink®

449

2

×105 R Rhat

Range and range estimate (m)

1.8 1.6 1.4 1.2 1 0.8 0.6 0.4

0

5

10

15

20

25

30

Time (s)

FIGURE 5.137

Plot of range and range estimates (m) vs. time (s).

Simulating the model by executing the MATLAB M-ﬁle SSCTKF_Model_Data.m created the following plots. Figure 5.137 shows the actual range R and the estimated range Rhat of the meteorite vs. time. From this plot, it appears that the steady-state Kalman ﬁlter performs just as well as the continuous-time Kalman ﬁlter. As before, it is difﬁcult to see any differences between the actual range and the estimated range. Figure 5.138 shows the actual velocity V and the estimated velocity Vhat of the meteorite vs. time. From this plot, it can be seen that the steady-state Kalman ﬁlter performs better than the continuous ﬁlter in estimating the velocity of the meteorite. Obviously missing from this plot are the transients associated with the time-dependent state covariance updates. The steady-state Kalman

Velocity and velocity estimate (m/s)

–4900 V Vhat

–4950 –5000 –5050 –5100 –5150 –5200 –5250 –5300 0

FIGURE 5.138

5

10

15 Time (s)

20

Plot of velocity and velocity estimates (m=s) vs. time (s).

25

30

Simulation of Dynamic Systems with MATLAB® and Simulink®

450

Acceleration and acceleration estimate (m/s/s)

25 Gravitational acceleration Ahat

20 15 10 5 0 –5 –10 –15 –20 –25 0

FIGURE 5.139

5

10

15 Time (s)

20

25

30

Plot of acceleration and acceleration estimates (m=s=s) vs. time (s).

ﬁlter eliminates the need to perform this calculation—which may be signiﬁcant for an application where real-time processing is limited. Figure 5.139 shows the actual acceleration A and the estimated acceleration Ahat of the meteorite vs. time. As mentioned before, it is unnecessary to estimate the acceleration of gravity, but it is shown for completeness. Again, there are no transients with the steady-state Kalman ﬁlter. Figure 5.140 shows the range error, the difference between the actual range and the estimated range, vs. time. Again, the range error is bounded by the standard deviation of the 1,1 element of the state covariance matrix, which is constant. The maximum range error at any given time is negligible for the steady-state Kalman ﬁlter.

Range error (m) compared with theoretical bounds 150 Simulation Therory

Range error (m)

100

50

0

–50

–100

–150

FIGURE 5.140

0

5

Plot of range error vs. time.

10

15 Time (s)

20

25

30

Simulink®

451 Velocity error (m/s) compared with theoretical bounds 150 Simulation Theory

Velocity error (m/s)

100

50

0

–50

–100

–150

FIGURE 5.141

0

5

10

15 Time (s)

20

25

30

Plot of velocity error vs. time.

Figure 5.141 shows the velocity error, the difference between the actual velocity and the estimated velocity, vs. time. The velocity error is bounded by the standard deviation of the 2,2 element of the state covariance matrix, which is constant. Here, too, the maximum velocity error at any given time is negligible for the steady-state Kalman ﬁlter. This concludes the implementation and analysis of the steady-state Kalman ﬁlter as applied to the range and velocity estimates of an incoming meteorite. Next, the discrete-time Kalman ﬁlter is applied to the same problem for comparison with the continuous-time Kalman ﬁlter. The dynamic system of the meteorite kinematics are discretized, Equation 5.174, and then simulated with the discrete-time Kalman ﬁlter algorithm, Equation 5.176. At this time, a few comments regarding the algorithm are in order. The ﬁrst two equations of the algorithm x^ k and Pk are known as the a priori state and state covariance estimates, respectively. They take the name ‘‘a priori’’ because the calculations are performed before the meteorite’s state is measured. The third equation of the algorithm Kk is the Kalman gain. The last two equations of the þ algorithm x^þ k and Pk are known as the a posteriori state and state covariance estimates, respectively. They take the name ‘‘a posteriori’’ because the calculations are performed after the meteorite’s state is measured. As in the previous two cases, the top-level diagram and ‘‘Actual’’ subsystem diagram are the same for the discrete-time Kalman ﬁlter. However, the ‘‘Estimates’’ subsystem, shown in Figure 5.142, shows the Simulink diagram for the discrete-time Kalman ﬁlter algorithm. From this view, the a priori state and state covariance, the Kalman gain, and the a posteriori state and state covariance subsystems are clearly represented. By double clicking on the ‘‘a priori state’’ subsystem, Figure 5.143 shows the elemental blocks that calculate the a priori state estimate of the algorithm. The initial conditions are represented by xm0, a vector deﬁned in the corresponding MATLAB M-ﬁle. Returning to the top-level view and then double clicking on the ‘‘a priori covariance’’ subsystem, Figure 5.144 shows the elemental blocks that calculate the a priori state covariance estimate of the algorithm. The initial conditions are represented by Pm0, a matrix deﬁned in the corresponding MATLAB M-ﬁle. Returning to the top-level view and then double clicking on the ‘‘Kalman gain’’ subsystem, Figure 5.145 shows the elemental blocks that calculate the Kalman gain of the algorithm.

452

Simulation of Dynamic Systems with MATLAB® and Simulink®

FIGURE 5.142

The discrete-time Kalman ﬁlter algorithm.

FIGURE 5.143

The ‘‘a priori state’’ subsystem.

FIGURE 5.144

The ‘‘a priori covariance’’ subsystem.

Simulink®

453

FIGURE 5.145

The ‘‘Kalman gain’’ subsystem.

FIGURE 5.146

The ‘‘a posteriori state’’ subsystem.

By double clicking on the ‘‘a posteriori state’’ subsystem, Figure 5.146 shows the elemental blocks that calculate the a posteriori state estimate of the algorithm. Returning to the top-level view and then double clicking on the ‘‘a posteriori covariance’’ subsystem, Figure 5.147 shows the elemental blocks that calculate the a posteriori state covariance estimate of the algorithm. Simulating the model by executing the MATLAB M-ﬁle DTKF_Model_Data.m created the following plots. Figure 5.148 shows the actual range R and the estimated range Rhat of the meteorite vs. time. The meteorite is picked up at a range of 200,000 m and tracked for 30 s. Over this time period, the meteorite traveled approximately 150,000 m. Like the previous two ﬁlters, the discrete-time Kalman ﬁlter performs very well. Indeed, it is difﬁcult to see any differences between the actual range and the estimated range. Figure 5.149 shows the actual velocity V and the estimated velocity Vhat of the meteorite vs. time. The discrete-time Kalman ﬁlter takes approximately 10 s for transients to settle before obtaining reasonable velocity estimates. This is similar to the behavior of the continuous-time Kalman ﬁlter.

Simulation of Dynamic Systems with MATLAB® and Simulink®

454

FIGURE 5.147

The ‘‘a posteriori covariance’’ subsystem.

2

×105 R Rhat

Range and range estimate (m)

1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0

FIGURE 5.148

5

10

15 Time (s)

20

25

30

Plot of range and range estimates (m) vs. time (s).

Figure 5.150 shows the actual acceleration A and the estimated acceleration Ahat of the meteorite vs. time. The transients take approximately 15 s to settle before obtaining reasonable estimates, 5 s more than the continuous-time Kalman ﬁlter. Figure 5.151 shows the range error, the difference between the actual range and the estimated range, vs. time. In theory, the range error should be bounded by the standard deviation of the 1,1 element of the state covariance matrix. For the discrete-time Kalman ﬁlter, a few data points lie outside this theoretical limit, but only marginally. Recall (Figure 5.149) that the meteorite traveled roughly 150,000 m over 30 s. An error of 100 m, even at the end of the 30 s when the meteorite is at a range of 50,000 m, is 0.2%. Figure 5.152 shows the velocity error, the difference between the actual velocity and the estimated velocity, vs. time. Again, in theory, the velocity error should be bounded by the standard deviation of the 2,2 element of the state covariance matrix. After the discrete-time Kalman ﬁlter transients settle

Simulink®

455

Velocity and velocity estimate (m/s)

–4900

–5000 –5050 –5100 –5150 –5200 –5250 –5300

FIGURE 5.149

V Vhat

–4950

0

5

10

15 Time (s)

20

25

30

Plot of velocity and velocity estimates (m=s) vs. time (s).

Acceleration and acceleration estimate (m/s/s)

25

15 10 5 0 –5 –10 –15 –20 –25 0

FIGURE 5.150

Gravitational acceleration Ahat

20

5

10

15 Time (s)

20

25

30

Plot of acceleration and acceleration estimates (m=s=s) vs. time (s).

out, the maximum velocity error appears to be less than 10 m=s. Recall (Figure 5.149) that the meteorite obtained a speed of roughly 5300 m=s over 30 s. An error of 10 m=s is less than 0.2%.

5.12.5 SUMMARY Three different Kalman ﬁlters (continuous, steady-state, and discrete) were used to estimate the kinematics (position and velocity) of an incoming meteorite. Once ﬁlter transients settled out, both the continuous-time and discrete-time Kalman ﬁlters provided acceptable results with regard to meteorite range and velocity estimation as evidenced by comparing the range and velocity errors with actual range and velocity magnitudes. If real-time processing poses limitations, it is recommended to use the steady-state Kalman ﬁlter.

Simulation of Dynamic Systems with MATLAB® and Simulink®

456

Range error (m) compared with theoretical bounds 150 Simulation Theory

Range error (m)

100

50

0

–50

–100

–150

FIGURE 5.151

0

5

10

15 Time (s)

20

25

30

Plot of range error vs. time.

Velocity error (m/s) compared with theoretical bounds

150

Simulation Theory

Velocity error (m/s)

100

50

0

–50

–100

–150

FIGURE 5.152

0

5

10

15 Time (s)

20

25

30

Plot of velocity error vs. time.

EXERCISE 5.55 Develop the steady-state Kalman ﬁlter for the discrete model. Hint: Combine the a priori and ^ ^ the a posteriori equations into a single equation and note in the steady-state, x^ k ¼ x k1 ¼ x þ þ þ þ þ þ Pk ¼ Pk1 ¼ P in the a priori case or x^k ¼ x^k1 ¼ x^ Pk ¼ Pk1 ¼ P in the a posteriori case.

6

Intermediate Numerical Integration

6.1 INTRODUCTION We continue our exposition of numerical integration introduced in Chapter 3. Additional algorithms to approximate the solution of differential equation models of continuous-time systems will be examined. In previous chapters, there was no mention of how to quantify the degree of accuracy one could expect with the simple Euler and trapezoidal integrators. Truncation errors are introduced in this chapter as a way of remedying this omission. This chapter introduces two broad classiﬁcations of numerical integrators known as one-step methods and multistep formulas and presents a case for when to use each type. Adaptive techniques for changing the integration step size when using one-step methods are discussed. Later on, a property of system models referred to as ‘‘stiffness’’ is explored along with ways of dealing with it to make sure accurate and stable simulations result. Numerical stability is mentioned only brieﬂy near the end of the chapter; however, more will be mentioned about this important property when we revisit numerical integration in Chapter 8. This chapter concludes with a case study that relies on one of the numerical integration methods introduced earlier in the chapter.

6.2 RUNGE–KUTTA (RK) (ONE-STEP METHODS) One-step methods refer to a family of numerical integration algorithms designed to update the current state across an interval of time, called the integration step, in such a way that the state derivative function is evaluated at one or more points of the interval. In contrast, multistep methods incorporate computed state values from previous intervals in the process of updating the state. Our discussion of one-step methods begins with an autonomous system involving a single state variable x ¼ x(t) with state derivative function f (t, x). dx ¼ f (t, x) dt

(6:1)

The state derivative function could be written f (t, x, u) when there are external inputs present. The reason for choosing a ﬁrst-order system is simple. Dynamic system models are typically higher than ﬁrst order; however, the differential equations comprising an nth-order model can be recast as a set of coupled ﬁrst-order differential equations for the state derivatives x_ 1 (t), x_ 2 (t), . . . , x_ n (t) in terms of the state variables x1(t), x2(t), . . . , xn(t) and when present, inputs u1(t), u2(t), . . . , ur(t). The algorithms derived for numerical integration of Equation 6.1 are easily extended to the case of more than one state variable. Suppose x(ti), the solution to Equation 6.1 at time t ¼ ti, were known and denoted xi for short. A way of approximating xiþ1 ¼ x(tiþ1), the state x(t) at t ¼ tiþ1 ¼ ti þ T, is needed. The approximation is written as xA(i þ 1) (see Figure 6.1).

457

Simulation of Dynamic Systems with MATLAB® and Simulink®

458

x(t) xi+1 xA(i + 1)

xi

1

i

T ti

t

ti + 1

FIGURE 6.1 Graphical representation of calculation for new state xA(i þ 1).

We can proceed along a line whose slope is wi (see Figure 6.1) starting from the point (ti, xi) on the solution x(t) and terminating when t ¼ tiþ1. This leads to xA (i þ 1) ¼ xi þ Twi

(6:2)

The slope wi is a suitably chosen approximation to the state derivative function f (t, x) over the interval ti t tiþ1. We shall return to this notion of a line with slope wi from (ti, xi) to [tiþ1, xA(i þ 1)] momentarily.

6.2.1 TAYLOR SERIES METHOD Consider the Taylor Series expansion of the function x(t) shown in Figure 6.1. Expanding the function x(t) in a Taylor Series about the point ti, xiþ1 ¼ xi þ

d 1 d2 1 d3 x(ti )T þ x(ti )T 2 þ x(ti )T 3 þ 2 dt 2! dt 3! dt 3

(6:3)

Equation 6.3 can be expressed in terms of the state derivative function, f (t, x) ¼ ) xiþ1 ¼ xi þ f (ti , xi )T þ

d x(t) dt

(6:4)

1 d 1 d2 f (ti , xi )T 3 þ f (ti , xi )T 2 þ 2! dt 3! dt 2

(6:5)

The derivatives (d=dt)f(ti, xi), (d2=dt2)f(ti, xi), and so forth can be obtained from the chain rule. For example, the ﬁrst derivative is d q q d f (ti , xi ) ¼ f (ti , xi ) þ f (ti , xi ) x(ti ) dt qt qx dt

(6:6)

¼ ft (ti , xi ) þ fx (ti , xi )f (ti , xi )

(6:7)

q f (ti , xi ), qt

(6:8)

where ft (ti , xi ) ¼

fx (ti , xi ) ¼

q f (ti , xi ) qx

459

Intermediate Numerical Integration

Substituting Equation 6.7 into Equation 6.5 yields xiþ1 ¼ xi þ Tf (ti , xi ) þ

T2 [ft (ti , xi ) þ fx (ti , xi )f (ti , xi )] þ 2

(6:9)

Truncating Equation 6.9 after the second term produces the explicit Euler integrator xA (i þ 1) ¼ xi þ Tf (ti , xi )

(6:10)

xA (i þ 1) ¼ xA (i) þ Tf [ti , xA (i)]

(6:11)

which would normally be written as

since xi is known only at the initial point (0, x0). Truncating Equation 6.9 after the third term results in a more accurate approximation of the true value xiþ1, namely, xA (i þ 1) ¼ xA (i) þ Tf [ti , xA (i)] þ

T2 { ft [ti , xA (i)] þ fx [ti , xA (i)] f [ti , xA (i)]} 2

(6:12)

The Taylor Series method can be used to obtain difference equations such as Equations 6.11 and 6.12 for updating the discrete-time state xA(i). However, it is rarely attempted because expressions for the higher-order derivatives of f (t, x) are often complex functions involving higher-order partial derivatives of f (t, x). What is needed is an algorithm for computing xA(i þ 1) with comparable accuracy to the truncated Taylor Series without requiring partial derivatives of f (t, x).

6.2.2 SECOND-ORDER RUNGE–KUTTA METHOD Recalling our previous discussion of wi, the slope of the line from the point (ti, xi) to [tiþ1, xA(i þ 1)] in Figure 6.1, suppose we choose it to be a weighted sum of the state derivative f(t, x) evaluated at several points on the interval. In particular, if wi is a weighted average of f (t, x) at two points on the interval ti t tiþ1, the result is wi ¼ a 1 k 1 þ a 2 k 2

(0 a1 1, 0 a2 1, a1 þ a2 ¼ 1)

(6:13)

where k1 is the state derivative function f(t, x) at (ti, xi), that is, k1 ¼ f (ti , xi )

(6:14)

and k2 is the state derivative function f(t, x) at [ti þ pT, xi þ qTf(ti, xi)], that is, k2 ¼ f [ti þ pT, xi þ qTf (ti , xi )],

(0 p 1, 0 q 1)

(6:15)

Lines with slopes k1 and k2 are shown in Figure 6.2. From Equations 6.14 and 6.15, k2 ¼ f [ti þ pT, xi þ qTk1 ]

(6:16)

indicating that k2 can be determined once k1 is known. The weights a1 and a2 as well as the constants p and q are to be determined.

Simulation of Dynamic Systems with MATLAB® and Simulink®

460

xi+1

k2

xi

xˆ A(i + 1) = xi + Tf (ti, xi) xi + qTf (ti, xi)

k1

x(t) ti

ti + pT

t

ti+1

FIGURE 6.2 Representation of wi ¼ a1k1 þ a2k2 as weighted sum of f(t, x) at two points.

Substituting Equation 6.13 into Equation 6.2 gives xA (i þ 1) ¼ xi þ T(a1 k1 þ a2 k2 )

(6:17)

The derivative function f(t, x) can be expanded in a two-dimensional Taylor Series about the point (ti, xi) as follows: f (ti þ Dt, xi þ Dx) ¼ f (ti , xi ) þ ft (ti , xi )Dt þ fx (ti , xi )Dx 1 þ ftt (ti , xi )Dt 2 þ 2ftx (ti , xi )DtDx þ fxx (ti , xi )Dx2 þ 2

(6:18)

Letting Dt ¼ pT, Dx ¼ qTf(ti, xi) in Equation 6.18 makes k2 in Equation 6.16 equal to k2 ¼ f (ti , xi ) þ ft (ti , xi )pT þ fx (ti , xi )qTf (ti , xi ) o 1n ftt (ti , xi )(pT)2 þ 2ftx (ti , xi )(pT)[qTf (ti , xi )] þ fxx (ti , xi )½qTf (ti , xi )2 þ þ 2

(6:19)

Substituting Equation 6.14 for k1 and Equation 6.19 for k2 into Equation 6.17 results in xA (i þ 1) ¼ xA (i) þ Ta1 f (ti , xi ) þ Ta2 [f (ti , xi ) þ ft (ti , xi )pT þ fx (ti , xi )qTf (ti , xi )] 1 þ Ta2 ftt (ti , xi )(pT)2 þ 2ftx (ti , xi )(pT)[qTf (ti , xi )] þ fxx (ti , xi )[qTf (ti , xi )]2 þ 2 (6:20) Simplifying Equation 6.20 by collecting terms involving powers of T leads to xA (i þ 1) ¼ xi þ (a1 þ a2 )Tf (ti , xi ) þ a2 T 2 [pft (ti , xi ) þ qfx (ti , xi )f (ti , xi )] þ

(6:21)

Equating the right-hand sides of Equations 6.9 and 6.21 gives a1 þ a2 ¼ 1,

1 a2 p ¼ , 2

a2 q ¼

1 2

(6:22)

The ﬁrst three terms in Equation 6.3 comprise the second-order truncated Taylor Series expansion of x(t) about the point ti, that is, x2 (ti þ T) ¼ x(ti ) þ

d 1 d2 x(ti )T 2 x(ti )T þ dt 2! dt 2

(6:23)

461

Intermediate Numerical Integration

where the subscript ‘‘2’’ indicates that the Taylor Series is truncated after the term containing T 2. Hence, by choosing the constants a1, a2, p, and q according to Equation 6.22, we can be certain that the computed state xA(i þ 1) in Equation 6.21 achieves comparable accuracy as the second-order truncated Taylor Series. There are, however, an inﬁnite number of solutions to the three equations in four unknowns in Equation 6.22. Numerical integrators based on the use of Equation 6.17 with a1, a2, p, and q satisfying the constraints in Equation 6.22 are referred to as second-order RK or RK-2 integrators.

6.2.3 TRUNCATION ERRORS The local truncation error eT is the difference between the exact solution x(ti þ T ) and the approximate solution xA(i þ 1) obtained by the Taylor Series method or some other numerical approximation technique such as the RK-2 integrators. Hence, eT ¼ x(ti þ T) xA (i þ 1)

(6:24)

For the approximation based on the second-order truncated Taylor Series method, Equation 6.24 becomes 1 d 2 (6:25) f (ti , xi )T eT ¼ x(ti þ T) xi þ f (ti , xi )T þ 2! dt Thus, the local truncation error reduces to the sum of all the terms in the Taylor Series expansion for x(ti þ T) beginning with the term containing T 3. That is, eT ¼

1 d3 1 d4 x(ti )T 3 þ x(ti )T 4 þ 3 3! dt 4! dt 4

(6:26)

Since the ﬁrst term on the right-hand side of Equation 6.26 is generally the dominant term (magnitude-wise), the local truncation error is proportional to T3 and is said to be of order T 3, denoted eT O(T 3). The global truncation error ET is the accumulation of individual truncation errors incurred in the process of numerically integrating over several intervals. It turns out that ET is proportional to T 2 or equivalently ET O(T 2). It is important to distinguish between the order of the local truncation error and its actual value for a particular numerical integrator. We should not expect to ﬁnd the numerical value of eT in the process of computing xA(i), i ¼ 0, 1, 2,. . . . Were that possible, the exact solution x(ti), i ¼ 0, 1, 2, . . . could be computed from Equation 6.24. We have seen that RK-2 integrators achieve comparable accuracy to the second-order truncated Taylor Series method and, as a result, are referred to as second-order accurate. The local truncation error eT O(T 3) regardless of how we solve for a1, a2, p, and q in Equation 6.22. The numerical value of eT will, however, be sensitive to the particular RK-2 integrator. Knowing eT O(T 3) and ET O(T 2) for RK-2 integrators makes the consequence of adjusting the integration step size predictable. For example, halving the step size reduces the local and 1 1 global truncation errors by a factor of and , respectively. For the explicit Euler integrator (RK-1), 8 4 1 eT O(T2) and ET O(T) implying the local truncation error are reduced by while the global 4 1 truncation is approximately as large when the step size is halved. 2 We now investigate two possible choices for the set of constants a1, a2, p, and q. Solution I: a1 ¼ a2 ¼ 1=2 and p ¼ q ¼ 1 From Equations 6.2 and 6.13, the RK-2 integrator becomes xA (i þ 1) ¼ xi þ

T (k1 þ k2 ) 2

(6:27)

Simulation of Dynamic Systems with MATLAB® and Simulink®

462

Since xi is unknown after the initial step, it must be replaced by xA(i) in Equation 6.27 to yield the difference equation for a numerical integrator. Using the deﬁnitions for k1 and k2 in Equations 6.14 and 6.15 and remembering that p ¼ q ¼ 1 give xA (i þ 1) ¼ xA (i) þ

T {f [ti , xA (i)] þ f [ti þ T, xA (i) þ Tf [ti , xA (i)]]} 2

(6:28)

Denoting xA(i) þ Tf [ti, xA(i)] by ^xA (i þ 1) in Equation 6.28 gives xA (i þ 1) ¼ xA (i) þ

T {f [ti , xA (i)] þ f [ti þ T, ^xA (i þ 1)]} 2

(6:29)

You should recognize ^xA (i þ 1) as the explicit Euler estimate of xiþ1 in Equation 6.11 (see Figure 6.2). Hence, the explicit Euler (an RK-1 integrator) establishes the second point [ti þ T, ^xA (i þ 1)] for evaluating the derivative function, and the average derivative function or slope is then used to update the state according to Equation 6.29. The RK-2 integrator of Equation 6.29 is the improved Euler or Heun’s method introduced in Section 3.6. At that time, it was developed using a geometrical argument instead of the formal approach presented here. The second solution for the constants a1, a2, p, and q will also look familiar. Solution II: a1 ¼ 0, a2 ¼ 1 and p ¼ q ¼ 1=2. From Equations 6.2 and 6.13, the RK-2 integrator is xA (i þ 1) ¼ xi þ Tk2

(6:30)

As in the case of the improved Euler integrator, the difference equation for xA(i) results from replacing xi by xA(i) in Equation 6.30 giving T T xA (i þ 1) ¼ xA (i) þ Tf ti þ , xA (i) þ f [ti , xA (i)] 2 2

(6:31)

Introducing the notation 1 T ¼ xA (i) þ f [ti , xA (i)] xA i þ 2 2

(6:32)

implies the new state xA(i þ 1) is calculated according to T 1 xA (i þ 1) ¼ xA (i) þ Tf ti þ , xA i þ 2 2

(6:33)

Equation 6.33 is identical to the modiﬁed Euler integrator in Section 3.6. In summary, the Taylor Series method (second order and higher) for approximating x(ti þ T) requires the derivative function f(ti, xi) as well as its derivatives (see Equation 6.5). RK-2 integrators produce estimates of xiþ1 to the same accuracy as the ﬁrst three terms in Equation 6.5 without requiring the total derivative (d=dt)f(t, x). The price is an extra derivative function evaluation f(t, x). The following example illustrates use of the Taylor Series method and the RK-2 integrators. Results are compared with the ﬁrst-order explicit Euler (RK-1) integrator and the exact solution.

463

Intermediate Numerical Integration v(t)

v(t)

m(t)

f(t)

f(t)

m(t)

fD(t)

FIGURE 6.3 Moving object with decreasing mass.

Example 6.1 The object shown in Figure 6.3 is initially at rest and then subjected to a constant force f (t) ¼ F, t 0. The motion of the object is opposed by the damper force fD(t) ¼ av(t). The contents of the object are leaking so that the object’s mass diminishes from its initial value m0 to a ﬁnal mass mf. At a given time t, the mass of the object is given by

m(t) ¼

8 > > < m0 ct, > > : mf ,

(m0 mf ) c (m0 mf ) t> c 0t

(6:34)

(a) Find an expression for the state derivative function f(t, v) while the mass of the object is still decreasing. (b) Find the difference equation for updating the state vA(i) using the second-order Taylor Series method. (c) Find the difference equation for updating the state vA(i) using the RK-1 explicit Euler integrator. (d) Find the difference equation for updating the state vA(i) using the RK-2 improved Euler integrator. (e) Find the difference equation for updating the state vA(i) using the RK-2 modiﬁed Euler integrator. (f) Find the exact solution for the state v(t). (g) Numerical values of the system parameters are m0 ¼ 1 slug, mf ¼ 0.2 slugs, c ¼ 0.05 slugs=min, and a ¼ 0.25 lb=ft=min and the external force is F ¼ 10 lb. Tabulate and graph the results when T ¼ 0.5 min. (a) The differential equation model for the system is

m(t)

dv ¼ F av dt

(6:35)

Solving for the derivative function, dv F av , ¼ f (t, v) ¼ dt m0 ct

0t

(m0 mf ) c

(6:36)

(b) From Equation 6.9, viþ1 ¼ vi þ Tf (ti , vi ) þ

T2 [ft (ti , vi ) þ fv(ti , vi )f (ti , vi )] þ 2

(6:37)

Simulation of Dynamic Systems with MATLAB® and Simulink®

464

Partial differentiation of Equation 6.36 gives ft (ti , vi ) ¼ (F avi ) fv (ti , vi ) ¼

c (m0 cti )2

(6:38)

a m0 cti

(6:39)

Substituting Equations 6.36, 6.38 and 6.39 into Equation 6.37 yields

viþ1

F avi T 2 c(F avi ) a F avi þ þ ¼ vi þ T m0 cti 2 (m0 cti )2 (m0 cti ) m0 cti

(6:40)

Truncating Equation 6.40 after the T2 term, replacing vi by vA(i), viþ1 by vA(i þ 1), and setting t ¼ iT lead to the difference equation F avA (i) (c a) F avA (i) 2 T Tþ vA (i þ 1) ¼ vA (i) þ m0 ciT 2 (m0 ciT)2

(6:41)

(c) The RK-1 explicit Euler integrator is v^A (i þ 1) ¼ v^A (i) þ Tf [ti , v^A (i)] F a^ vA (i) ¼ v^A (i) þ T m0 ciT

(6:42) (6:43)

(d) The RK-2 improved Euler integrator, Equation 6.29, is T vA (i þ 1) ¼ vA (i) þ {f [ti , vA (i)] þ f [ti þ T, v^A (i þ 1)]} 2 T F avA (i) F a^ vA (i þ 1) ¼ vA (i) þ þ 2 m0 ciT m0 c(i þ 1)T

(6:44) (6:45)

(e) The RK-2 modiﬁed Euler integrator, Equations 6.32 and 6.33, is 1 T vA i þ ¼ vA (i) þ f [ti , vA (i)] 2 2 T F avA (i) ¼ vA (i) þ 2 m0 ciT 1 vA (i þ 1) ¼ vA (i) þ Tf tiþ1=2 , vA i þ 2 3 2 1 F avA i þ 6 2 7 7 ¼ vA (i) þ T 6 4 1 5 m0 c i þ T 2

(6:46) (6:47) (6:48)

(6:49)

(f) The exact solution for v(t) is obtained from Equation 6.36 by integration. ðv v(0)

dv0 ¼ F av0

ðt 0

dt0 m0 ct0

F F ct a=c , ) v(t) ¼ v(0) 1 a a m0

0t

(6:50)

(m0 mf ) c

(6:51)

465

Intermediate Numerical Integration

TABLE 6.1 Taylor Series Method, RK-1 (Explicit Euler), RK-2 (Improved Euler), RK-2 (Modiﬁed Euler) with T ¼ 0.5 min, and Exact Solution i 0 1 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30

ti ¼ iT

Taylor Series Method vA(i)

RK-1 Explicit Euler v^A (i)

RK-2 Improved Euler vA(i)

RK-2 Modiﬁed Euler vA(i)

Exact Solution

0 0.5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 4.75 9.0375 16.3617 22.2287 26.8677 30.4826 33.2532 35.3370 36.8704 37.9706 38.7368 39.2515 39.5826 39.7843 39.8991 39.9586

0 5.0 9.4872 17.0828 23.0849 27.7584 31.3371 34.0256 36.0013 37.4162 38.3992 39.0575 39.4792 39.7345 39.8783 39.9519 39.9847

0 4.7436 9.0257 16.3421 22.2045 26.8415 30.4562 33.2280 35.3139 36.8501 37.9534 38.7226 39.2403 39.5741 39.7782 39.8948 39.9559

0 4.7468 9.0317 16.3520 22.2168 26.8548 30.4696 33.2408 35.3256 36.8604 37.9622 38.7298 39.2460 39.5785 39.7814 39.8970 39.9573

0 4.7562 9.0488 16.3804 22.2518 26.8928 30.5078 33.2772 35.3588 36.8896 37.9869 38.7500 39.2619 39.5904 39.7899 39.9028 39.9609

(g) For the numerical values given, results from the Taylor Series method, the three numerical integrators, and the exact solution are tabulated in Table 6.1 at 1 min intervals after the ﬁrst two steps. Figure 6.4 contains a graph of the four numerical integrators and the exact solution. Both the table and ﬁgure conﬁrm the improved accuracy possible with the use of the Taylor Series method and RK-2 integration compared to the explicit Euler (RK-1) integrator. Knowing the exact solution, we can check the results obtained from the Taylor Series method. For the numerical values given, the exact solution in Equation 6.51 becomes v(t) ¼ 40 40(1 0:05t)5 ,

0 t 16

(6:52)

The second-order truncated Taylor Series v2(t) about the point t ¼ 0 is v2 (T) ¼ v(0) þ

d 1 d2 v(0)T 2 v(0)T þ dt 2 dt2

(6:53)

Setting v(0) to zero, differentiating Equation 6.52 to ﬁnd the ﬁrst two derivatives and substituting the results into Equation 6.53 give 1 v2 (T) ¼ 10T þ (2)T 2 2 ) v2 (0:5) ¼ 10(0:5) (0:5)2 ¼ 4:75 which agrees with the value in Table 6.1.

(6:54)

Simulation of Dynamic Systems with MATLAB® and Simulink®

466 40 35 30

v(t), vA(i)

25 20 15 Taylor series method Euler (RK-1), T = 0.5 min Improved Euler (RK-2), T = 0.5 min Modified Euler (RK-2), T = 0.5 min Exact

10 5 0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

t

FIGURE 6.4 Comparison of numerical integrators and exact solution for Example 6.1.

6.2.4 HIGH-ORDER RUNGE–KUTTA METHODS Higher-order RK formulas are derived in the same manner as the RK-2 integrators. For RK-3 integration, the formula for updating the state xA(i), is xA (i þ 1) ¼ xA (i) þ T(a1 k1 þ a2 k2 þ a3 k3 )

(6:55)

where k1, k2, and k3 are derivative function evaluations at speciﬁc points. There are now three constants p, q, and r, which determine the points at which the derivatives are to be evaluated. Matching coefﬁcients of powers of T in the expression for xA(i þ 1) using Equation 6.55 with the truncated Taylor Series for x(t) through the T3 term generates four equations in the six unknowns a1, a2, and a3 and p, q, and r. One particular solution leads to the frequently used RK-3 integration formula xA (i þ 1) ¼ xA (i) þ

T (k1 þ 4k2 þ k3 ) 6

(6:56)

where k1 ¼ f [ti , xA (i)] 1 1 k2 ¼ f ti þ T, xA (i) þ k1 T 2 2 k3 ¼ f [ti þ T, xA (i) k1 T þ 2k2 T]

(6:57) (6:58) (6:59)

The local truncation error of an RK-3 integrator eT O(T 4) and the global truncation error ET O(T 3).

467

Intermediate Numerical Integration xˆ A(i + 1) 1 xˆ A i + — 2

k3

k2

k2 k1

xA(i) k1 ti

k4 xA(i + 1)

k3 1 (k + 2k + 2k + k ) — 2 3 4 6 1

1 xA i + — 2

1 ti+(1/2) = ti + — T 2

ti+1 = ti +T

FIGURE 6.5 Illustration of an RK-4 integrator.

Fourth-order RK formulas are the most common of all the RK numerical integrators for reasons we shall discuss shortly. The derivation is patterned after the approach used for the lower-order RK methods. Flexibility in the choice of several parameters results in a family of RK-4 integrators. A popular RK-4 integrator is illustrated in Figure 6.5. The derivative function evaluations are computed according to 1 T xA i þ ¼ xA (i) þ k1 2 2 1 1 T k2 ¼ f tiþ1=2 , xA i þ , ^xA i þ ¼ xA (i) þ k2 2 2 2 1 k3 ¼ f tiþ1=2 , ^xA i þ , ^xA (i þ 1) ¼ xA (i) þ Tk3 2

k1 ¼ f [ti , xA (i)],

k4 ¼ f [tiþ1 , ^xA (i þ 1)]

(6:60) (6:61) (6:62) (6:63)

and the updated state xA(i þ 1) is obtained from xA (i þ 1) ¼ xA (i) þ

T (k1 þ 2k2 þ 2k3 þ k4 ) 6

(6:64)

Note that of the four required derivative evaluations, one is at the beginning of the interval, two occur at the midpoint, and the last one takes place at the end of the interval. The algorithm is straightforward to program because of the sequential nature in the calculations of k1, k2, k3, and k4. RK-1 through RK-4 (and higher) integrators are incorporated in simulation and numerical analysis software packages. MATLAB® and Simulink® offer a choice of RK-1 through RK-5 integrators.

6.2.5 LINEAR SYSTEMS: APPROXIMATE SOLUTIONS USING RK INTEGRATION The special case of linear system models is worth looking at in some detail. Suppose the derivative function in Equation 6.1 is linear in x, that is, dx ¼ f (t, x) ¼ ax dt

(6:65)

Simulation of Dynamic Systems with MATLAB® and Simulink®

468

Applying RK-1, RK-2, RK-3, and RK-4 integrators to the linear system in Equation 6.65 produces the following difference equations for updating the state xA(i): RK-1: xA (i þ 1) ¼ (1 þ aT)xA (i) 1 2 RK-2: xA (i þ 1) ¼ 1 þ aT þ (aT) xA (i) 2! 1 1 RK-3: xA (i þ 1) ¼ 1 þ aT þ (aT)2 þ (aT)3 xA (i) 2! 3! 1 1 1 RK-4: xA (i þ 1) ¼ 1 þ aT þ (aT)2 þ (aT)3 þ (aT)4 xA (i) 2! 3! 4!

(6:66) (6:67) (6:68) (6:69)

The general solutions to Equations 6.66 through 6.69 are easily obtained by recursion. The results are RK-1: xA (i) ¼ (1 þ aT)i x(0) i 1 RK-2: xA (i) ¼ 1 þ aT þ (aT)2 x(0) 2! i 1 1 RK-3: xA (i) ¼ 1 þ aT þ (aT)2 þ (aT)3 x(0) 2 2! i 1 1 1 2 3 4 RK-4: xA (i) ¼ 1 þ aT þ (aT) þ (aT) þ (aT) x(0) 2 3! 4!

(6:70) (6:71) (6:72) (6:73)

where x(0) is the initial condition. In general, an RK-m integrator applied to the linear system model, Equation 6.65, results in " xA (i) ¼

m X (aT)k

k¼o

#i

k!

x(0)

(6:74)

i 1 1 1 2 3 m ¼ 1 þ aT þ (aT) þ (aT) þ þ (aT) x(0) 2! 3! m!

(6:75)

In the case of more than a single state variable, that is, x_ ¼ Ax, a similar result applies for RK-m integrators. " x A (i) ¼

m X (TA)k k¼o

k!

#i x(0)

(6:76)

i 1 1 1 2 3 m ¼ I þ TA þ (TA) þ (TA) þ þ (TA) x(0) 2! 3! m!

(6:77)

Equation 6.76 for the explicit Euler integrator (m ¼ 1) as well as the improved and modiﬁed Euler integrators (m ¼ 2) was ﬁrst introduced in Section 3.6. The discrete-time signal xA(i), i ¼ 0, 1, 2, 3, . . . is intended to approximate the continuous-time state x(t)jt ¼ iT, i ¼ 0, 1, 2, 3, . . . The solution x(t) to Equation 6.65 is x(t) ¼ x(0)eat ,

t0

) x(iT) ¼ x(0)eaiT ¼ x(0)(eaT )i

(6:78) (6:79)

469

Intermediate Numerical Integration

Expanding eaT in a Taylor Series about zero, Equation 6.79 becomes i 1 1 1 2 3 m x(iT) ¼ 1 þ aT þ (aT) þ (aT) þ þ (aT) þ x(0) 2! 3! m!

(6:80)

From Equations 6.74 and 6.80 with i ¼ 1, the m þ 1 terms in the approximate value xA(1) are identical to the ﬁrst m þ 1 terms of the inﬁnite series expression for x(T). After one step, the local truncation error of an RK integrator is eT ¼ x(T) xA (1)

(6:81)

1 1 1 eT ¼ eaT x(0) 1 þ aT þ (aT)2 þ (aT)3 þ þ (aT)m x(0) 2! 3! m!

(6:82)

For an RK-m integrator,

Replacing eaT in Equation 6.82 by its Taylor Series expansion leads to 1 1 (aT)mþ1 þ (aT)mþ2 x(0) eT ¼ (m þ 1)! (m þ 2)!

(6:83)

and, therefore, eT O(T mþ1) as expected. All RK-m integrators are said to be of mth order, not to be confused with their local truncation error, which is of order m þ 1, that is, eT O(T mþ1). The mth order reference stems from the high-order term in the truncated Taylor Series. For an RK-m integrator, the global truncation error ET O(T m). RK-1 through RK-4 integrators require one to four derivative function evaluations per step. RK integrators of order higher than four are not as efﬁcient. For example, an RK-5 integrator requires six derivative function evaluations per step for comparable agreement with the ﬁfth-order Taylor Series expansion of the solution. A penalty of one additional derivative function evaluation per step is the price incurred in moving from an RK-4 integrator with eT O(T5) to an RK-5 integrator with eT O(T6). The computational effort during each integration step results primarily from evaluating the derivative function. Hence, the penalty is nontrivial. Worse yet, RK-6 integrators require eight derivative function evaluations to achieve a local truncation error eT O(T7). RK-4 methods are popular because they are the highest order one-step integrators that do not require more derivative function evaluations than their order.

6.2.6 CONTINUOUS-TIME MODELS

WITH

POLYNOMIAL SOLUTIONS

The Taylor Series method for ﬁnding xA(i þ 1) starting from the point (ti, xi) on the solution x(t) is xA (i þ 1) ¼ xi þ

d 1 d2 1 dm x(ti )T þ x(ti )T 2 þ þ x(ti )T m 2 dt 2! dt m! dt m

(6:84)

where the total derivatives (d2=dt2)x(ti), (d3=dt3)x(ti), . . . , (dm=dtm)x(ti) are computed from partial derivatives of the derivative function f (ti, xi). Suppose the exact solution is the mth-order polynomial x(t) ¼ a0 þ a1 t þ a2 t 2 þ þ am t m

(6:85)

2 m x(tiþ1 ) ¼ a0 þ a1 tiþ1 þ a2 tiþ1 þ þ am tiþ1

(6:86)

The exact solution at t ¼ tiþ1 is

Simulation of Dynamic Systems with MATLAB® and Simulink®

470

With xA(0) set equal to x(0), Equations 6.84 and 6.86 produce identical results at the discrete points 0, T, 2T, . . . In other words, xA (i þ 1) ¼ x(tiþ1 ),

i ¼ 0, 1, 2, . . .

(6:87)

Proof for the case when m ¼ 2 follows. Starting with xA (i þ 1) ¼ xi þ

d 1 d2 x(ti )T þ x(ti )T 2 dt 2! dt 2

(6:88)

The two derivatives in Equation 6.88 are obtained from the exact solution for x(t) in Equation 6.85 with m ¼ 2. Substituting them into Equation 6.88 and simplifying give 1 xA (i þ 1) ¼ xi þ (a1 þ 2a2 ti )T þ (2a2 )T 2 2 ¼ (a0 þ a1 ti þ a2 ti2 ) þ a1 T þ 2a2 ti T þ a2 T 2 ¼ a0 þ a1 (ti þ T) þ a2 (ti þ T)

2

¼ x(tiþ1 )

(6:89) (6:90) (6:91) (6:92)

The proof is similar for higher-order polynomial solutions. In Example 6.1, the exact solution v(t) in Equation 6.52 is a ﬁfth-order polynomial. Hence, the Taylor Series method using the ﬁfth-order truncated Taylor Series would agree with the exact solution at 0, T, 2T,. . . . However, in Example 6.1, a second-order Taylor Series was used to generate the discrete-time values vA(1), vA(2), vA(4), vA(6), . . . , vA(30) shown in Table 6.1. This explains the discrepancy between the discrete-time values and the exact solution v(t1), v(t2), v(t4), v(t6), . . . , v(t30) shown in the last column of the table. In general, when x(t) is an mth-order polynomial, unlike the mth-order Taylor Series method, RK-m integrators will not generate the true solution values x(t1), x(t2), x(t3),. . . . Different RK-m integrators will produce different discrete-time solutions; however, they achieve comparable accuracy with the Taylor Series method in the sense that the local truncation errors are the same order of magnitude. A similar result holds for RK integrators and the truncated Taylor Series method when both are the same order and less than m. In that case, the Taylor Series method will no longer be exact. The following example illustrates this point. Example 6.2 In Example 6.1, if we change the value of a from 0.25 to 0.1, the exact solution to Equation 6.35 becomes 1 v(t) ¼ 100 (20 t)2 4

(6:93)

Approximate the solution for v(t) using the second-order Taylor Series, RK-1 integration, and both RK-2 integrators with a step size of T ¼ 0.5. Compare results with the exact solution. The state derivative function, Equation 6.36, is given by f (ti , vi ) ¼

F avi 10 0:1vi 100 vi ¼ ¼2 m0 cti 1 0:05ti 20 ti

(6:94)

The ﬁrst partials in Equations 6.38 and 6.39 become ft (ti , vi ) ¼ 2

100 vi (20 ti )2

(6:95)

471

Intermediate Numerical Integration

TABLE 6.2 Comparison of Taylor Series Method, RK-1, RK-2, and Exact Solution i 0 1 2 4 6 8 10

ti

Taylor Series vA(i)

RK-1 Explicit vA(i)

RK-2 Improved vA(i)

RK-2 Modiﬁed vA(i)

Exact v(ti)

0 0.5 1.0 2.0 3.0 4.0 5.0

0 4.9375 9.7500 19.0000 27.7500 36.0000 43.7500

0 5.0000 9.8718 19.2308 28.0769 36.4103 44.2308

0 4.9359 9.7468 18.9938 27.7410 35.9883 43.7357

0 4.9367 9.7484 18.9970 27.7455 35.9942 43.7430

0 4.9375 9.7500 19.0000 27.7500 36.0000 43.7500

fv (ti , vi ) ¼

2 (20 ti )

(6:96)

and the Taylor Series method for calculating the approximation to v(t þ T ) is vA (i þ 1) ¼ vA (i) þ Tf [ti , vA (i)] þ

T2 {ft [ti , vA (i)] þ fv [ti , vA (i)]f [ti , vA (i)]} 2

(6:97)

From Equations 6.94 through 6.97 with i ¼ 0, ti ¼ t0 ¼ 0 and vA(i) ¼ vA(0) ¼ v(0) ¼ 0, 1 vA (1) ¼ 10T T 2 4

(6:98)

For a step size of T ¼ 0.5, vA(1) ¼ 4.9375. The exact solution v(T)jT ¼ 0.5 is computed from

1 ¼ 4:9375 v(t)jt¼T¼0:5 ¼ 100 (20 t)2

4 t¼T¼0:5 which agrees with the result from the Taylor Series method. Results for the Taylor Series method, RK-1, both RK-2 integrators, and the exact solution are tabulated in Table 6.2.

6.2.7 HIGHER-ORDER SYSTEMS The application of RK numerical integration to higher-order systems is straightforward. The differential equations of an nth-order system model are expressed as a system of ﬁrst-order differential equations as shown in Equations 6.99 through 6.101. dx1 ¼ f1 (t, x1 , x2 , . . . , xn ) dt

(6:99)

dx2 ¼ f2 (t, x1 , x2 , . . . , xn ) dt

(6:100)

.. . dxn ¼ fn (t, x1 , x2 , . . . , xn ) dt

(6:101)

472

Simulation of Dynamic Systems with MATLAB® and Simulink®

Updating the current discrete-time state vector [x1,A(i), x2,A(i), . . . , xn,A(i)] to the new vector [x1,A(i þ 1), x2,A(i þ 1), . . . , xn,A(i þ 1)] with RK-m integration consists of determining, in the proper sequence, the derivatives kj,p, j ¼ 1, 2, . . . , m and p ¼ 1, 2, 3, . . . , n. By the proper sequence, we mean k1,1, k1,2, . . . , k1,n, followed by k2,1, k2,2, . . . , k2,n up through by km,1, km,2, . . . , km,n. To illustrate, suppose we are dealing with a third-order (n ¼ 3) system and choose to implement a fourth-order (m ¼ 4) RK-4 integrator to update the discrete-time state. The three derivative functions are each calculated four times in the following order: 9 k1,1 ¼ f1 [ti , x1,A (i), x2,A (i), x3,A (i)] > = k1,2 ¼ f2 [ti , x1,A (i), x2,A (i), x3,A (i)] > ; k1,3 ¼ f3 [ti , x1,A (i), x2,A (i), x3,A (i)] 9 k2,1 ¼ f1 [ti þ 0:5T, x1,A (i) þ 0:5Tk1,1 , x2,A (i) þ 0:5Tk1,2 , x3,A (i) þ 0:5Tk1,3 ] > = k2,2 ¼ f2 [ti þ 0:5T, x1,A (i) þ 0:5Tk1,1 , x2,A (i) þ 0:5Tk1,2 , x3,A (i) þ 0:5Tk1,3 ] > ; k2,3 ¼ f3 [ti þ 0:5T, x1,A (i) þ 0:5Tk1,1 , x2,A (i) þ 0:5Tk1,2 , x3,A (i) þ 0:5Tk1,3 ] 9 k3,1 ¼ f1 [ti þ 0:5T, x1,A (i) þ 0:5Tk2,1 , x2,A (i) þ 0:5Tk2,2 , x3,A (i) þ 0:5Tk2,3 ] > = k3,2 ¼ f2 [ti þ 0:5T, x1,A (i) þ 0:5Tk2,1 , x2,A (i) þ 0:5Tk2,2 , x3,A (i) þ 0:5Tk2,3 ] > ; k3,3 ¼ f3 [ti þ 0:5T, x1,A (i) þ 0:5Tk2,1 , x2,A (i) þ 0:5Tk2,2 , x3,A (i) þ 0:5Tk2,3 ] 9 k4,1 ¼ f1 [ti þ T, x1,A (i) þ Tk3,1 , x2,A (i) þ Tk3,2 , x3,A (i) þ Tk3,3 ] > = k4,2 ¼ f2 [ti þ T, x1,A (i) þ Tk3,1 , x2,A (i) þ Tk3,2 , x3,A (i) þ Tk3,3 ] > ; k4,3 ¼ f3 [ti þ T, x1,A (i) þ Tk3,1 , x2,A (i) þ Tk3,2 , x3,A (i) þ Tk3,3 ]

(6:102)

(6:103)

(6:104)

(6:105)

The components of the state are updated according to x1,A (i þ 1) ¼ x1,A (i) þ

T (k1,1 þ 2k2,1 þ 2k3,1 þ k4,1 ) 6

(6:106)

x2,A (i þ 1) ¼ x2,A (i) þ

T (k1,2 þ 2k2,2 þ 2k3,2 þ k4,2 ) 6

(6:107)

x3,A (i þ 1) ¼ x3,A (i) þ

T (k1,3 þ 2k2,3 þ 2k3,3 þ k4,3 ) 6

(6:108)

An example of a second-order system model using RK-4 integration is now presented. The standard form of a linear second-order system is d2 x dx þ 2zvn þ v2n x ¼ Kv2n u dt 2 dt

(6:109)

Letting x1 ¼ x and x2 ¼ dx=dt leads to the state equation model dx1 ¼ f1 (t, x1 , x2 , u) ¼ x2 dt dx2 ¼ f2 (t, x1 , x2 , u) ¼ v2n x1 2zvn x2 þ Kv2n u dt where the last argument u of f1(t, x1, x2, u) and f2(t, x1, x2, u) refers to the system input.

(6:110) (6:111)

473

Intermediate Numerical Integration

Expressions for the derivatives k1, k2, k3, and k4 associated with states x1 and x2 are k1,1 ¼ f1 [ti , x1,A (i), x2,A (i), u(ti )]

(6:112)

¼ x2,A (i)

(6:113)

k1,2 ¼ f2 [ti , x1,A (i), x2,A (i), u(ti )]

(6:114)

¼ v2n x1,A (i) 2zvn x2,A (i) þ Kv2n u(ti ) k2,1 ¼ f1 [ti þ 0:5T, x1,A (i) þ 0:5Tk1,1 , x2,A (i) þ 0:5Tk1,2 , u(ti þ 0:5T)] ¼ x2,A (i) þ 0:5Tk1,2

(6:115) (6:116) (6:117)

k2,2 ¼ f2 [ti þ 0:5T, x1,A (i) þ 0:5Tk1,1 , x2,A (i) þ 0:5Tk1,2 , u(ti þ 0:5T)] ¼ v2n [x1,A (i) þ 0:5Tk1,1 ] 2zvn [x2,A (i) þ 0:5Tk1,2 ] þ Kv2n u(ti þ 0:5T) k3,1 ¼ f1 [ti þ 0:5T, x1,A (i) þ 0:5Tk2,1 , x2,A (i) þ 0:5Tk2,2 , u(ti þ 0:5T)] ¼ x2,A (i) þ 0:5Tk2,2

(6:118) (6:119) (6:120) (6:121)

k3,2 ¼ f2 [ti þ 0:5T, x1,A (i) þ 0:5Tk2,1 , x2,A (i) þ 0:5Tk2,2 , u(ti þ 0:5T)] ¼ v2n [x1,A (i) þ 0:5Tk2,1 ] 2zvn [x2,A (i) þ 0:5Tk2,2 ] þ Kv2n u(ti þ 0:5T) k4,1 ¼ f1 [ti þ T, x1,A (i) þ Tk3,1 , x2,A (i) þ Tk3,2 , u(ti þ T)] ¼ x2,A (i) þ Tk3,2

(6:122) (6:123) (6:124) (6:125)

k4,2 ¼ f2 [ti þ T, x1,A (i) þ Tk3,1 , x2,A (i) þ Tk3,2 , u(ti þ T)] ¼ v2n [x1,A (i) þ Tk3,1 ] 2zvn [x2,A (i) þ Tk3,2 ] þ Kv2n u(ti þ T)

(6:126) (6:127)

The updated state [x1,A(i), x2,A(i)] is obtained from x1,A (i þ 1) ¼ x1,A (i) þ

T (k1,1 þ 2k2,1 þ 2k3,1 þ k4,1 ) 6

(6:128)

x2,A (i þ 1) ¼ x2,A (i) þ

T (k1,2 þ 2k2,2 þ 2k3,2 þ k4,2 ) 6

(6:129)

An example illustrating the application of Equations 6.110 through 6.129 follows. Example 6.3 A simpliﬁed model to predict the levels of a drug in an individual is accomplished using compartmental analysis similar to the iodine model in Section 4.3. After oral ingestion, a drug enters the gastrointestinal tract (compartment 1) and is then distributed into the bloodstream (compartment 2) where it is metabolized and eliminated. State equations describing the drug dynamics in each compartment are Gastrointestinal tract: Bloodstream:

dm1 ¼ c1 m1 þ u dt

dm2 ¼ c1 m1 c2 m2 dt

where m1 and m2 are the amounts of drug in each compartment (mg) u is the ingestion rate of the drug (mg=min) c1 and c2 are drug distribution and elimination constants of the individual (min1)

(6:130) (6:131)

Simulation of Dynamic Systems with MATLAB® and Simulink®

474

The output y is the amount of drug in the bloodstream, that is, m2. (a) Convert the state equations into a single second-order differential equation relating the output y and input u. Find z, vn, and K for the second-order system. (b) Deﬁne x1 ¼ y ¼ m2 and x2 ¼ dy=dt ¼ dm2=dt and simulate the response using classic RK-4 integration with a step size T ¼ 1 min for the following conditions: m1 (0) ¼ 0 mg,

c1 ¼ 0:06 min1 ,

m2 (0) ¼ 0 mg,

c2 ¼ 0:015 min1

and

Assume the drug ingestion rate is given by u(t) ¼ Met=t ,

t 0 (M ¼ 5 mg=min , t ¼ 4 min )

(6:132)

(c) Find the exact solution for x1(t). (d) Plot the simulated response x1,A(i) and the exact solution x1(t) on the same graph. (a) Elimination of m1 from Equations 6.130 and 6.131 is easily accomplished by Laplace transforming the equations and algebraically solving for M2(s), which is also Y(s). (s þ c1 )M1 (s) ¼ U(s)

(6:133)

(s þ c2 )M2 (s) ¼ c1 M1 (s)

(6:134)

c1 M1 (s) Y(s) ¼ M2 (s) ¼ s þ c2 c1 1 U(s) ¼ s þ c2 s þ c1

(6:135) (6:136)

Inverse Laplace transformation of Y(s) leads to the differential equation d2 y dy þ (c1 þ c2 ) þ c1 c2 y ¼ c1 u dt2 dt

(6:137)

Comparing Equation 6.137 with the standard form of Equation 6.109 yields vn ¼ (c1 c2 )1=2 ,

z¼

c1 þ c2 2(c1 c2 )1=2

,

K¼

1 c2

(6:138)

Solving for the second-order system parameters, vn ¼ (c1 c2 )1=2 ¼ [(0:06)(0:015)]1=2 ¼ 0:03 rad=min z¼

c1 þ c2 1=2

¼

0:06 þ 0:015 ¼ 1:25 2(0:03)

2(c1 c2 ) 1 1 min1 ¼ 66:66 K¼ ¼ c2 0:015

(b) The RK-4 calculations follow the procedure outlined in Equations 6.112 through 6.129. The integration step begins with the k1 derivative evaluation for each state, that is, k1,1 ¼ x2,A (0) ¼ x2 (0) ¼ 0 k1,2 ¼ v2n x1,A (0) 2zvn x2,A (0) þ Kv2n u(0) ¼ v2n x1 (0) 2zvn x2 (0) þ Kv2n M ¼ 0:0009(0) 2(1:25)(0:03)(0) þ ¼ 0:3

1 (0:0009)(5) 0:015

475

Intermediate Numerical Integration followed by the k2 derivative evaluation for each state, that is, 1 k2,1 ¼ x2,A (0) þ k1,2 T 2 1 ¼ 0 þ (0:3)(1) 2

k2,2

¼ 0:15 1 1 1 ¼ v2n x1,A (i) þ k1,1 T 2zvn x2,A (i) þ k1,2 T þ Kv2n u ti þ T 2 2 2 1 1 ¼ 0:0009 0 þ (0)(1) 2(1:25)(0:03) 0 þ (0:3)(1) 2 2 1 þ (0:0009)5e0:5=4 0:015 ¼ 0:2535

The remaining derivative evaluations are obtained in a similar fashion. k3,1 ¼ 0:1267,

k3,2 ¼ 0:2552,

k4,1 ¼ 0:2552,

k4,2 ¼ 0:2144

M-ﬁle ‘‘Chap6_Ex2_3.m’’ recursively solves the RK-4 difference equations for the discrete-time states x1,A(i) and x2,A(i). Table 6.3 contains selected values of x1,A(i). (c) The exact solution for x1(t) ¼ y(t) can be determined by substituting the Laplace transform of u(t) into Equation 6.136, c1 1 M X1 (s) ¼ s þ c2 s þ c1 s þ (1=t)

(6:139)

TABLE 6.3 Approximate (RK-4, T ¼ 1 min) and Exact Solutions i 0 1 2 3 4 5 25 50 100 150 200 250 300

ti

x1,A(i)

x1(ti)

0 1 2 3 4 5 25 50 100 150 200 250 300

0.0 0.13477907 0.48560007 0.98658006 1.58751933 2.25036682 11.68143041 11.65359364 6.24296647 2.98572189 1.41218500 0.66716006 0.31514864

0.0 0.13477243 0.48558842 0.98656465 1.58750114 2.25034661 11.68141034 11.65357994 6.24295986 2.98571876 1.41218352 0.66715936 0.31514831

Simulation of Dynamic Systems with MATLAB® and Simulink®

476

RK-4 integration (T = 1 min)

15 x1 = m2 (mg)

x1,A(i), i = 0, 4, 8, ... x1(t)

10

5

0

0

50

100

150 t (min)

200

250

300

x2 = dm2/dt (mg/min)

0.8 x2,A(i), i = 0, 4, 8, ...

0.6 0.4 0.2 0 −0.2

0

50

100

150 t (min)

200

250

300

FIGURE 6.6 Discrete-time signals x1,A(i) and x2,A(i) and continuous-time signal x1(t). Inverse Laplace transforming Equation 6.139 gives the exact solution, x1 (t) ¼

h i Mc1 t (1 c1 t)ec2 t (1 c2 t)ec1 t þ (c1 c2 )tet=t (c1 c2 )(1 c1 t)(1 c2 t)

(6:140)

(d) Table 6.3 contains values of the discrete-time response x1,A(i) and the exact solution x1(t) at different times. The approximate and exact solutions agree to four places after the decimal point. Figure 6.6 contains plots of the discrete-time states x1,A(i) and x2,A(i) and the exact solution x1(t). Every fourth point of the discrete-time signals is plotted for the sake of clarity. Before we proceed further, it would be useful to know the total amount of drug ingested by the individual. Integrating the rate of drug ingestion over time, 1 ð

MT ¼

1 ð

u(t)dt ¼ 0

Met=t dt ¼ Mt

(6:141)

0

For a continuous-time integrator, the derivative function f(t, x) is equal to the input u(t) to the integrator. Hence, MT in Equation 6.141 can be found for an arbitrary input function u(t) using any of the numerical integrators we have studied. Of course, the upper limit must be ﬁnite, presumably the time required for the drug to be fully ingested. We conclude this section with a simple nonlinear system model.

Example 6.4 The cooling of a high-temperature oven is governed by the following differential equation (McClamroch 1980): C

~ dT ~4 T4) ¼ Kc (T~ T0 ) Kr (T 0 dt

(6:142)

477

Intermediate Numerical Integration where ~ ¼ T(t) ~ is the oven temperature (8R) T T0 is the surrounding temperature (8R) C is the thermal capacity of the oven Kc and Kr are convective and radiation heat loss coefﬁcients

Simulate the oven’s cooling from an initial temperature of 10008R if the surrounding temperature is 5008R. Numerical values of the thermal parameters are C ¼ 24 Btu= R,

Kc ¼ 8 Btu=h= R, Kr ¼ 2 108 Btu=h= R4

RK-1 through RK-4 integrators were used to numerically integrate the derivative function

~ ¼ f (T)

~ dT Kc ~ Kr ~ 4 T04 ) T0 ) (T ¼ (T C C dt

(6:143)

The results are shown in Table 6.4. The integration step size was chosen for each integration method to make the total number of derivative function evaluations and, hence, the computational effort, roughly the same. The last column is labeled ‘‘Exact’’; however, the exact solution is not easily obtained. The numbers in the last column were obtained using RK-4 integration with a small enough step size (T ¼ 0.005 h) to generate approximate values in agreement with the exact solution values to at least one place after the decimal point. How can we check this assumption? Figure 6.7 shows the results of using RK-1 and RK-4 to integrate the derivative function, Equation 6.143, with step sizes T ¼ 0.1, 0.2, 0.3 h and T ¼ 0.3, 0.6, 0.9 h, respectively. RK-1 produces reasonably accurate results only with T ¼ 0.1 h whereas RK-4 integration generates accurate approximations to the ‘‘exact’’ solution for T ¼ 0.4 h and T ¼ 0.8 h.

TABLE 6.4 Comparison of RK-1, 2, 3, 4 Integrators with Different Step Sizes and Exact Solution

i 0 2 3 4 6 8 9 10 12 16 20 30 40 48

RK-1

RK-2

RK-3

RK-4

T ¼ 0.1

T ¼ 0.2

T ¼ 0.3

T ¼ 0.4

‘‘Exact’’

e TA(i)

e TA(i)

1000.0

1000.0 859.9 813.2 775.5 718.0 676.2 659.3 644.4 619.5 583.6 559.6 526.7 512.3 506.7

ti

e TA(i)

i

ti

e TA(i)

i

0 0.2 0.3 0.4 0.6 0.8 0.9 1.0 1.2 1.6 2.0 3.0 4.0 4.8

1000.0 841.0 793.1 755.6 699.8 660.0 644.0 630.1 607.0 573.9 552.1 522.7 510.2 505.4

0 1

0 0.2

1000.0 864.1

0

0

1

0.3

806.2

2 3 4

0.4 0.6 0.8

784.9 730.8 691.1

2

0.6

713.5

3

0.9

656.1

4

1.2

617.2

10

3.0

526.2

16

4.8

506.6

5 6 8 10 15 20 24

1.0 1.2 1.6 2.0 3.0 4.0 4.8

660.6 636.4 600.8 576.3 540.7 523.3 515.4

ti

e TA(i)

i

1000.0

0

0

1

0.4

774.3

2

0.8

675.6

3 4 5

1.2 1.6 2.0

619.1 583.4 559.4

10 12

4.0 4.8

512.3 506.7

ti

Simulation of Dynamic Systems with MATLAB® and Simulink®

478

RK-1 integration with step size T = 0.1, 0.2, 0.3 h

T (deg R)

1000

Exact T = 0.1 h T = 0.2 h T = 0.3 h

800 600 400

0

0.5

1.5

2

2.5

3

3.5

4

5

Exact T = 0.4 h T = 0.8 h T = 1.2 h

800 600 400

4.5

RK-4 integration with step size T = 0.4, 0.8, 1.2 h

1000 T (deg R)

1

0

0.5

1

1.5

2

2.5 t (h)

3

3.5

4

4.5

5

FIGURE 6.7 RK-1 and RK-4 solution of oven cooling with three different step sizes.

EXERCISES 6.1 Show that the difference equation resulting from using RK-m integration to approximate the behavior of dx=dt ¼ f (t, x) ¼ ax is 1 1 1 2 3 m xA (i þ 1) ¼ 1 þ aT þ (aT) þ (aT) þ þ (aT) xA (i) 2! 3! m! 6.2 The mass m of a radioactive material in a container decays according to the equation dm ¼ km dt

subject to m(0) ¼ m0

where m ¼ m(t) k is a constant for the speciﬁc radioactive material m0 is the initial mass of radioactive material in the container The half-life of a radioactive material, T1=2, is related to the decay constant k by T1=2 ¼ ln 2=k. Suppose the half-life of a radioactive material is 2 years and there is initially 1 kg of material present in the container. (a) Use RK-1 through RK-4 integration to obtain approximations of the mass of radioactive material present in the container every month until less than 0.25 kg of material remains. (b) Compare the results from part (a) with the exact solution for m(t). 6.3 The amount of ﬁsh in a lake at any time is assumed to obey the following logistic growth model: dx ¼ Kx(M x) u dt where x ¼ x(t) is the number of ﬁsh present u ¼ u(t) is the rate at which ﬁsh are harvested

479

Intermediate Numerical Integration

Nominal values of the system parameters are K ¼ 2.5 107 (ﬁsh-day)1 and M ¼ 200,000 ﬁsh. The lake is initially stocked with 50,000 ﬁsh. (a) Use RK-4 integration with appropriate step size T to approximate the ﬁsh population in the absence of harvesting. Plot the results. (b) Plot the exact solution x(t) ¼ M=(1 [1 M=x(0)]eKMt) on the same graph. (c) Repeat part (a) for a constant harvesting rate u ¼ 2750 ﬁsh=day. (d) Repeat part (a) for a constant harvesting rate u ¼ 2250 ﬁsh=day. 6.4 For the system in Example 6.1, let a ¼ 0.15, c ¼ 0.05, m0 ¼ 1, F ¼ 0, and v(0) ¼ 2. The derivative function is dv 3v ¼ f (t, v) ¼ , dt 20 t

0 t 16

v(t) ¼ 2(1 0:05t)3 ,

0 t 16

and the exact solution is

Show that v(0.5) and vA(1) are identical, where vA(1) is the result of using RK-3 integration with a step size T ¼ 0.5. 6.5 Repeat Example 6.3 using RK-1 and RK-2 integrator with a step size T ¼ 1 min. Compare the accuracy of each with the RK-4 method results shown in Table 6.3. 6.6 In Example 6.3, choose the states x1 ¼ m1 and x2 ¼ m2 and the outputs y1 ¼ x1 and y2 ¼ x2. (a) Find the matrices A, B, C, and D in the continuous-time state variable model of the system. (b) Apply RK-4 integration with T ¼ 1 min to obtain approximate solutions for the amount of drug in the gastrointestinal tract and the bloodstream. Compare the results of drug amounts in the bloodstream with results in Table 6.3. (c) Use RK-4 integration with T ¼ 1 min to ﬁnd an approximate solution for the case where m1(0) ¼ 20 mg, m2(0) ¼ 0 mg, and u(t) ¼ 0, t 0. (d) Verify the results in part (c) by using

i 1 1 1 2 3 4 x A (i) ¼ I þ TA þ (TA) þ (TA) þ (TA) x(0) 2! 3! 4! 6.7 Approximate the amount of drug ingested by an individual using RK-1 through RK-4 integration (using an appropriate step size T) when the drug ingestion rate is (a) u(t) ¼ Met=t, t 0 (M ¼ 5 mg=min, t ¼ 4 min) (b) u(t) ¼ Met=t, t 0 (M ¼ 1 mg=min, t ¼ 45 min) (c) u(t) ¼ A sin(2pt=P), 0 t P=2 (A ¼ 2 mg=min, P ¼ 30 min) (d) u(t) is available in tabular form in the following table:

t (min) u(t) (mg=min)

0 0.0

0.5 0.4

1.0 1.0

1.5 3.0

2.0 2.2

2.5 1.4

3.0 0.8

3.5 0.4

4.0 0.2

4.5 0.1

5.0 0.0

6.8 Since RK-4 integrators require four times the number of derivative function evaluations as RK-1 integrators and RK-2 integrators require twice the number of derivative function evaluations as RK-1 integrators, it is reasonable to compare the three integrators when the computational effort is roughly the same for all three. In other words, if the step size for the RK-1

Simulation of Dynamic Systems with MATLAB® and Simulink®

480

integrator is T, then the RK-2 and RK-4 integrators should be run with step sizes 2T and 4T, respectively. Simulate the response of the system in Example 6.1 where dv 2v ¼ f (t, v) ¼ 5 , v(0) ¼ 0 dt 20 t using RK-1, RK-2 (improved or modiﬁed Euler), and the classic RK-4 integrator using step sizes of 0.25, 0.5, and 1 s, respectively. Enter the results in the following table. Comment on the results. RK-1 (T ¼ 0.25)

RK-2 (T ¼ 0.5)

RK-4 (T ¼ 1)

i

ti

vA(i )

v(ti)

i

ti

vA(i)

v(ti)

i

ti

vA(i)

v(ti)

0 4 8 12 16 20 24 28 32

0 1 2 3 4 5 6 7 8

0.00000

0.00000

0 2 4 6 8 10 12 14 16

0 1 2 3 4 5 6 7 8

0.00000

0.00000

0 1 2 3 4 5 6 7 8

0 1 2 3 4 5 6 7 8

0.00000

0.00000

6.9 The model for ﬁnding the temperature in the oven of Example 6.4 when there is an internal heat source is

C

dT~ ¼ Kc (T~ T0 ) Kr (T~ 4 T04 ) þ u dt

where u ¼ u(t) is the heat source. Suppose the oven and its surroundings are in equilibrium at a temperature of 6008R. (a) Simulate the transient response of the oven temperature using an RK-2 integrator with step size T ¼ 0.25 h when the heat transferred to the oven is as shown in Figure E6.9: u, Btu/h

12,000

0

10

t, h

FIGURE E6.9

~ (b) Find the exact solution for T(t) to one place after the decimal point by solving for ~ i ), i ¼ 0, 1, 2, 3, . . . using RK-4 integration with step size T ¼ 0.001 h. Compare T~A (i) T(t the results with those from part (a) and (b).

481

Intermediate Numerical Integration

6.3 ADAPTIVE TECHNIQUES The computational efﬁciency of RK methods can be improved if the step size is allowed to vary during a simulation. A reasonable criterion must be established for determining when it is appropriate to modify the step size and by how much. The criterion is usually based on an estimate of the local truncation error as the simulation progresses with time. If an estimate of the local truncation error is outside an acceptable tolerance, then it is possible to either reduce the step size when the estimated error is too large or quite possibly increase the step size if it appears that the error is unnecessarily small. Techniques for estimating the local truncation error and modifying the step size, if warranted, are referred to as adaptive step size control.

6.3.1 REPEATED RK WITH INTERVAL HALVING If we use the local truncation error as the basis for determining when the step size needs adjustment, then a method is needed for approximating it. One approach requires that we obtain two estimates of the updated state from an RK integrator and use the difference to estimate the local truncation error. Interval halving refers to the case where the step sizes differ by a factor of 2. Refer to Figure 6.8 to understand how the method works. Let xA(i þ 1jT) be the approximate solution to x_ ¼ f (t, x) at tiþ1 obtained using a step size of T. Similarly, let xA(i þ 1jT=2) be the approximate solution to x_ ¼ f (t, x) at tiþ1 obtained after two steps using a step size of T=2. Assume xA(i) is exact, that is, xA(i) ¼ x(ti). It follows that x(tiþ1 ) ¼ xA (i þ 1jT) þ eT

T þ eT=2 x(tiþ1 ) ¼ xA i þ 1

2

(6:144) (6:145)

where eT and eT=2 are the local truncation errors in xA(i þ 1jT) and xA (i þ 1jT=2), respectively. From Equations 6.144 and 6.145,

T (6:146) þ eT=2 xA (i þ 1jT) þ eT ¼ xA i þ 1

2 Suppose the numerical integrator is an RK-4 with local truncation error eT O(T5). Then eT can be expressed as eT ¼ cT 5

(6:147)

and eT=2 , which is the sum of local truncation errors for the two half-intervals, is given by 5 5 5 T T T 1 1 eT=2 ¼ c þc ¼ 2c ¼ cT 5 ¼ eT (6:148) 2 2 2 16 16 εT/2 x(ti+1) x(i)

xA i + 1 T 2 2

xA i + 1 T 2 xA(i + 1) T

εT

xA(i)

x(ti) ti

ti+(1/2)

ti+1

t

FIGURE 6.8 Illustration of interval halving for estimation of local truncation error.

Simulation of Dynamic Systems with MATLAB® and Simulink®

482

TABLE 6.5 Step Size Adjustment Based on Outcome of j«T=2 j Outcome

Action (Next Integration Step)

eL > jeT=2 j eL jeT=2 j eU jeT=2 j > eU

Double current step size Keep current step size Halve current step size

In reality, c in Equation 6.147 and the two occurrences of c in Equation 6.148 are different and depend on the derivative function and the intervals; however, for suitably small T, the differences are negligible. Eliminating eT from Equations 6.146 and 6.148 gives

T (6:149) þ eT=2 xA (i þ 1jT) þ 16eT=2 ¼ xA i þ 1

2 Solving for eT=2 in Equation 6.149 gives

eT=2

T xA (i þ 1jT) xA i þ 1

2 ¼ 15

(6:150)

eT=2 in Equation 6.150 is an estimate of the local truncation error of the RK-4 integrator when the step size is T=2. It can be used to adjust the step size in subsequent calculations. For example, Table 6.5 shows a possible approach to step size adjustment using predetermined tolerance limits eL and eU. The truncation error eT=2 can be added to xA (i þ 1j(T=2)) to obtain a ﬁfth-order accurate estimate of x(ti þ 1), that is, a new estimate xA(i þ 1) with local truncation error eT O(T5). This gives eL jeT=2 j eU

T 16xA i þ 1

xA (i þ 1jT) 2 ¼ 15

(6:151)

(6:152)

The following example includes a one-step numerical integrator with the step size determined by the interval halving method previously described. F1

Example 6.5 A cone-shaped tank is ﬁlling with water at a constant rate F1 (t) ¼ F as shown in Figure 6.9. The initial level is h0. Water evaporates from the tank at a rate proportional to the surface area of liquid. The constant of proportionality is a. (a) Find the derivative function in the continuous-time model of the tank. (b) For F ¼ p ft3=min, a ¼ 0.01 ft=min, and h0 ¼ 10 ft, estimate the local truncation error in the RK-4 estimate hA(1) when T ¼ 1 in using interval halving, that is, ﬁnd eT=2 .

h

h

FIGURE 6.9 evaporation.

Conical tank with

483

Intermediate Numerical Integration

(c) Use eT=2 to obtain a ﬁfth-order accurate estimate of h(T). (d) Simulate the tank dynamics for a period of time sufﬁcient to allow the tank level to increase by 90% of the ultimate change in level. Use an adaptive step size based on the algorithm in Table 6.5 with eL ¼ 1013 and eU ¼ 1011. (e) Find the analytical solution of the continuous-time model and plot it along with the simulated solution. (a) The continuous-time model of the tank is dV ¼ F1 (t) aS dt

(6:153)

where V is the volume of water in the tank S is the surface area of water at the top where evaporation occurs For the conical shape in Figure 6.9, V¼

ph3 , 12

S¼

ph2 4

(6:154)

Substituting Equation 6.154 into Equation 6.153 and solving for the derivative function give dh 4F a ¼ dt ph2

(6:155)

(b) Using the given values for a and F gives dh 4 ¼ 0:01 dt h2

(6:156)

Starting from the initial point (0, h0) ¼ (0, 10), the results from interval halving after one integration step are given in Table 6.6. The second column contains the results from a single-step RK-4 integrator with step size T ¼ 1 min. The last two columns list the results from two consecutive steps of an RK-4 integrator with step size T ¼ 0.5 min. From Equation 6.150, an estimate of the local truncation error in hA (1j(T=2)) is given by

eT=2 ¼

T hA 1

hA (1jT) 2

15 10:02988067543399 10:02988067543460 ¼ 15 ¼ 0:40619359727619 1013

TABLE 6.6 Results after One Step of Interval Halving Using RK-4 (T ¼ 1 min) t1 ¼ T k1 k2 k3 k4

0.03000000000000 0.02988026946101 0.02988074623874 0.02976202120809 hA(1jT) ¼ 10.02988067543460

t1=2 ¼ T=2

t1 ¼ T=2 þ T=2

0.03000000000000 0.02994006743256 0.02994018702867 0.02988050764055 1 T ¼ 10:01497008471359 hA

2 2

0.02988050771064 0.02982108077964 0.02982119883721 0.02976202170051

T hA 1

¼ 10:02988067543399 2

Simulation of Dynamic Systems with MATLAB® and Simulink®

484

(c) From Equation 6.152, the ﬁfth-order accurate estimate of h(T) is

hA (1) ¼

T 16hA 1

hA (1jT) 2

15 16(10:02988067543399) 10:02988067543460 ¼ 15 ¼ 10:02988067543395

(d) The steady-state tank level is easily obtained by setting the derivative function to zero in Equation 6.155 and solving for h ¼ h(1). sﬃﬃﬃﬃﬃﬃﬃ rﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ 4F 4p ) h(1) ¼ ¼ ¼ 20 ft pa p(0:01)

(6:157)

The tank dynamics were simulated using RK-4 integration with interval halving for step size control in ‘‘Chap6_Ex3_1.m.’’ The ultimate change in tank level is h(1) h(0) ¼ 20 10 ¼ 10 ft. The simulation terminates when hA(i) exceeds the level h(0) þ 0.9[h(1) h(0)] ¼ 10 þ 0.9(10) ¼ 19 ft. Table 6.7 summarizes how the step size was changed in accordance with the given tolerances on the estimated local truncation error. Note the signiﬁcant increase in step size from the starting value of T ¼ 1 min as the simulation progresses. (e) The analytical solution is an implicit function for h(t). The derivation is left as an exercise. The result is 60 3h(t) 100 10 h(t) 10 ln ¼t (6:158) h(t) þ 20 Data points were obtained by increasing h(t) from 10 to 19 ft in small increments, solving for the corresponding value of t, and plotted in Figure 6.10 with t values along the abscissa. The simulated results (every fourth point) are also plotted demonstrating the close agreement with the exact solution. Notice that the step size is progressively increased as the slope, that is, derivative of the solution, gradually decreases. The average of the estimated local truncation errors is eT=2 ¼

169 X

(eT=2 )i ¼ 1:6653 1012

i¼1

TABLE 6.7 Simulation Time Interval and the Constant Step Size T Using Interval Halving for Adaptive RK-4 Integration Time Interval

Step Size, T

0t1 1 t < 69 69 t < 209 209 t < 313 313 t < 1673

1 2 4 8 16

(6:159)

485

Intermediate Numerical Integration Simulated and analytical tank level vs. time

20

h(t) hA(i), i = 0, 3, 7, ...

19 18

h(t), hA (ft)

17 16 15 14 13 12 11 10

FIGURE 6.10

0

200

400

600

800 1000 t (min)

1200

1400

1600

Results of RK-4 integration with adaptive step size control.

In this example, the simulated time was approximately 1670 min, which would have required 1670 integration steps if the step size had remained constant at T ¼ 1 min. With adaptive step size control, the number of integration steps was 169, a nearly 90% reduction. Of course, each of the 169 integration steps requires two passes, one using a full step size and the other using two half-steps. The number of derivative function evaluations for each method is summarized below.

6.3.2 CONSTANT STEP SIZE (T ¼ 1 min) Total number of function evaluations ¼

1670 min function evaluations 4 ¼ 6680 1 min=step step

6.3.3 ADAPTIVE STEP SIZE (INITIAL T ¼ 1 min) 1. Number of function evaluations (ﬁrst pass) 169 steps 4

function evaluations ¼ 676 step

2. Number of new function evaluations (second pass) function evaluations ¼ 507 first half interval function evaluations 169 steps 4 ¼ 676 second half interval

169 steps 3

Total number of function evaluations ¼ 676 þ 507 þ 676 ¼ 1859. The number of derivative function evaluations has been reduced by over 72%. This comparison is clearly sensitive to the order of the RK integrator used as well as the constant step size T and total simulation time. For example, halving the value of T from 1 to 0.5 min doubles the number of derivative function evaluations in the ﬁrst case where the step size remains constant. With interval halving and adaptive step size control, the total number of steps would remain nearly the same

Simulation of Dynamic Systems with MATLAB® and Simulink®

486

regardless of the initial step size. Consequently, the total number of derivative function evaluations would remain about the same in either case. The step size control logic is also signiﬁcant. The adaptive step size control is typically more complex (Borse 1997; Chapra and Canalel 2002) than the simple approach presented here where the new step size is either one half, the same, or twice the current step size. Since an implicit solution for h(t) is known (Equation 6.158), it is possible to compare the estimated local truncation error with the actual local truncation error, although not in a straightforward manner due to the implicit nature of the solution.

6.3.4 RK–FEHLBERG In the case of RK-4 integration, the interval halving method requires seven additional derivative function evaluations for the second pass over the two half-intervals. A total of 11 function evaluations are required for each interval, independent of the interval size. An alternative method for estimating the local truncation error is based on the difference of two different order RK integrators over the same integration time step. By choosing two RK integrators with several common points for the derivative function evaluations, efﬁciency is improved signiﬁcantly compared to the interval halving method. The RK–Fehlberg method employs RK-4 and RK-5 integrators where the four function evaluations k1, k2, k3, and k4 of the RK-4 integrator are used in the RK-5 integrator as well. Recall that RK-5 integration methods require six function evaluations per step. Therefore, RK–Fehlberg methods combining RK-4 and RK-5 integrators employ a total of six derivative function evaluations per interval. A common RK–Fehlberg integrator is given as follows (Rao 2002): k1 ¼ f [ti , xA (i)] 1 1 k2 ¼ f ti þ T, xA (i) þ Tk1 4 4 3 3 9 k3 ¼ f ti þ T, xA (i) þ Tk1 þ Tk2 8 32 32 12 1932 7200 7296 k4 ¼ f ti þ T, xA (i) þ Tk1 Tk2 þ Tk3 13 2197 2197 2197 439 3680 845 k5 ¼ f ti þ T, xA (i) þ Tk1 8Tk2 þ Tk3 Tk4 216 513 4104 1 8 3544 1859 11 Tk3 þ Tk4 Tk5 k6 ¼ f ti þ T, xA (i) Tk1 þ 2Tk2 2 27 2565 4104 40

(6:160) (6:161) (6:162) (6:163) (6:164) (6:165)

The estimate of x[(i þ 1)T] using RK-4 integration is

25 1408 2197 1 xA (i þ 1) ¼ xA (i) þ T k1 þ k3 þ k 4 k5 216 2565 4104 5

(6:166)

The RK-5 estimate of x[(i þ 1)T] and eventual updated state is

16 6656 28561 9 2 xA (i þ 1) ¼ xA (i) þ T k1 þ k3 þ k 4 k5 þ k 6 135 12825 56430 50 55

(6:167)

487

Intermediate Numerical Integration

The local truncation error incurred in the ith integration interval is estimated from the difference of Equations 6.167 and 6.166. Thus,

1 128 2197 1 2 k1 k3 k 4 þ k5 þ k 6 Estimate of (eT )i ¼ T 360 4275 75240 50 55

(6:168)

Example 6.6 illustrates the use of RK–Fehlberg integration, speciﬁcally, the RK-4 and RK-5 methods previously described. Example 6.6 A motor boat is being driven across a river L ft wide to the opposite side as shown in Figure 6.11. The boat departs from point 0, the origin of an x–y coordinate system, attempting to reach a point H ft upstream. The boat travels at a constant speed vb mph relative to the water that ﬂows downstream at a speed of vr mph. The boat is continuously steered in the direction of its intended destination. The boat’s heading is given by the angle u as shown in the diagram. Numerical values of the system parameters are L ¼ 1000 ft, H ¼ 5000 ft, vb ¼ 15 mph, and vr ¼ 5 mph. (a) Choose the state variables as x(t) and y(t) and obtain expressions for the state derivative functions in terms of x and y and the system parameters L, H, vb, and vr. (b) Use the ‘‘ode45’’ numerical integrator in Simulink and simulate the boat’s x and y position as a function of time. Plot x vs. t, y vs. t, and u vs. t. (c) Plot the steering angle u vs. horizontal position x. (d) Find an expression for the derivative dy=dx in terms of x and y and the system parameters L, H, vb, and vr. (e) Write a program to implement the RK–Fehlberg method to numerically integrate dy=dx. Adjust the step size when the estimated local truncation error falls outside an acceptable tolerance range. Choose the initial integration step to be T ¼ 1 ft. (f) Find the exact solution for y(x) and compare it with the simulated results. (a) From the diagram, the state derivatives are dx Lx ¼ vb cos u ¼ vb dt [(L x)2 þ (H y)2 ]1=2 dy ¼ vr þ vb sin u dt ¼ vr þ vb

(6:170)

Hy [(L x) þ (H y)2 ]1=2 2

H

vb vr

(x, y)

0

FIGURE 6.11

Boat trajectory crossing the river.

(6:169)

θ

L

(6:171)

Simulation of Dynamic Systems with MATLAB® and Simulink®

488

FIGURE 6.12

Simulink® diagram of boat crossing.

(b) A Simulink diagram of the system is shown in Figure 6.12. Selecting the ‘‘ode45’’ integrator with maximum step size set to 20 and relative tolerance equal to 106 produces graphs of the state variables x(t) and y(t) and the additional output u(t) shown in Figure 6.13. The exact solutions for x(t), y(t), and u(t) were approximated using Simulink’s RK-4 integrator with a very small step size, namely, T ¼ 0.01 s. The adaptive step size control quickly adjusts the step size to its maximum value and maintains it at the upper limit until the simulation is nearly complete. Comparison with the ‘‘exact’’ (T ¼ 0.01 s) solution shows that the truncation errors are minimal.

x (ft)

Results of boat crossing simulation 1000 750 500 250 0

ode45 x(t)

0

50

100

150

200

250

300

350

100

150

200

250

300

350

100

150

200

250

300

350

y (ft)

6000 ode45 y(t)

4000 2000 0

0

θ (deg)

90

50 ode45 θ(t)

85 80 0

50

t (s)

FIGURE 6.13 Time histories of state variables x(t) and y(t) and output u(t) using Simulink® variable-step integrator ‘‘ode45’’ and ‘‘exact’’ solutions (RK-4 with T ¼ 0.01).

489

Intermediate Numerical Integration Steering angle vs. horizontal distance 90

θA(i) using ode45 θ(x)

89 88 87

θ (deg)

86 85 84 83 82 81 80 79 78

0

100 200 300 400 500 600 700 800 900 1000 x (ft)

FIGURE 6.14 Steering output u vs. horizontal location x with Simulink® variable-step integrator ‘‘ode45’’ and ‘‘exact’’ solution. (c) A plot of steering angle u vs. horizontal position x is shown in Figure 6.14. Note that the river current causes the boat to be steered at increasingly greater angles as it approaches the right bank of the river. (d) States x(t) and y(t) represent a parametric description of the boat’s trajectory y ¼ y(x). The trajectory can be found in one of two ways. First, the parameter t can be eliminated from equations for the states x(t) and y(t). Since we have not developed the solutions for x(t) and y(t), we resort to the second approach, namely, integration of the derivative dy=dx. Dividing Equation 6.170 by Equation 6.169 gives dy vr þ vb sin u ¼ dx vb cos u

(6:172)

Expressing sin u and cos u in terms of the distances x, y, L, and H (see Figure 6.11) and simplifying the result yield " #1=2 dy H y vr Hy 2 1þ (6:173) ¼ dx L x vb Lx (e) The RK–Fehlberg Equations 6.160 through 6.168 are solved in ‘‘Chap6_Ex3_2.m.’’ A simulation summary is shown in Table 6.8.

TABLE 6.8 Summary of RK–Fehlberg Simulation Results for Boat Crossing Minimum tolerance Minimum tolerance Minimum step size Minimum step size Number of integration steps Average step size Average estimated local truncation error

107 ft 105 ft 0.1 ft 25 ft 87 11.49 ft 1.6427 104

Simulation of Dynamic Systems with MATLAB® and Simulink®

490

Path of boat 5000

RK-Fehlberg: yA(i), i = 0, 1, 2, 3, ... Exact: y(x)

4500 4000

y (ft)

3500 3000 2500 2000 1500 1000 500 0

FIGURE 6.15

0

100 200 300 400 500 600 700 800 900 1000 x (ft)

Simulated (RK–Fehlberg) and exact solutions for y(x) in boat crossing.

(f) Derivation of the exact solution to Equation 6.173 is left as an exercise. The result is " # Lx (L x)k k c(L x) y(x) ¼ H c 2

(6:174)

where pﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃﬃ c ¼ Lk1 (H þ L2 þ H2 ) k ¼ vr=vb Plots of the approximate solution yA(i) obtained in part (e) and the exact solution, Equation 6.174, are shown in Figure 6.15.

EXERCISES 6.10 In Example 6.5, (a) Find the analytical solution to the continuous-time model of Equation 6.155. (b) Write a program to numerically integrate the derivative function using RK-4 with adaptive control of step size. Compare your results with those in Tables 6.6 and 6.7. (c) Experiment with the tolerances used to establish the step size, and plot the results on the same graph with the analytical solution. (d) Is the tank initially in equilibrium? Explain. Find the constant ﬂow in F1 for which the tank is in equilibrium when the height of water is 15 ft. (e) With 15 ft of water in the tank and equilibrium conditions established, the ﬂow in is decreased by 50%. Simulate the response using RK-4 with step size control. (f) For the same conditions as in part (e), ﬁnd the estimated and true local truncation errors resulting from the use of RK-4 numerical integration when the water level is 14.9 ft. Hint: Find the actual time required for the tank level to reach 14.9 ft, and use that value as the initial integration step size.

491

Intermediate Numerical Integration

6.11 In Example 6.6, (a) Find the analytical solution y ¼ y(x) to Equation 6.173 repeated as follows: " #1=2 dy H y vr Hy 2 ¼ 1þ dx L x vb Lx Hint: Let ^x ¼ L x, ^y ¼ H y, introduce u ¼ ^y=^x, and obtain an implicit solution of the separable differential equation in u. (b) Compute the estimated and actual local truncation errors using RK-4 with interval halving to adjust the step size. Choose the initial step size T ¼ 1 ft. 6.12 Find the trajectory of the boat in Example 6.6, assuming it is steered continuously at the destination point (L, H), if the river current varies sinusoidally according to vr (x) ¼ A sin

p x, L

0xL

where A ¼ 10 mph. 6.13 In the boat-crossing problem of Example 6.6, suppose the boat steering angle u is an input to the continuous-time model. (a) Find the state derivative functions in dx=dt ¼ f1(x, y, u) and dy=dt ¼ f2(x, y, u). For parts (b) through (d), ﬁnd the analytical solution and check your answer using Simulink with the ‘‘ode45’’ solver. (b) The steering angle u is held constant at the initial heading of the destination point, that is, H , t0 u(t) ¼ u ¼ tan1 L Find the location of the boat when it reaches the other side. Use the values of vr, vb, L, and H from Example 6.6. (c) The captain wishes to cross the river and reach the opposite shore line at x ¼ L, y ¼ 0, which is directly across from where he started. Find the constant heading u, which allows him to accomplish this. Assume the river current is constant at vr ¼ 6 mph and the boat moves at a constant speed of vb ¼ 24 mph. Plot the boat’s trajectory. (d) Make a plot of y(L) vs. u for 0 u < p=2 where y(L) is the y coordinate of the location where the boat reaches the opposite side of the river. Assume vr ¼ 10 mph and vb ¼ 25 mph. (e) The captain observes a large ﬁsh swimming upstream at a constant speed of vf ¼ 6 mph in the middle of the river (x ¼ L=2). Starting from (0, 0), he begins to steer directly at the ﬁsh when it is directly across from him, that is, located at (L=2, 0). Find and plot the boat’s trajectory until it catches up with the ﬁsh if the river current is 0 mph and the boat speed is 10 mph. 6.14 A hydraulic accumulator is shown in Figure E6.14. Its purpose is to damp ﬂuctuations in the input ﬂow rate f1(t) caused by pressure peaks upstream. The ﬂow exits downstream of the accumulator through a linear resistance. The continuous-time model for the pressure p(t) in the accumulator section is (Palm 1983) A2 dp 1 ¼ f1 (p p0 ) k dt R where A is the area of the accumulator plate k is the spring constant R is the ﬂuid resistance

Simulation of Dynamic Systems with MATLAB® and Simulink®

492

The input ﬂow rate is given by 8 3 > < 0:01 ft =s, f1 (t) ¼ 0:05 ft3 =s, > : 0:01 ft3 =s,

t 0s 0 < t 0:01 s t > 0:01 s

Numerical values of the system parameters are A ¼ 0:0055 ft2 , (a) (b) (c) (d) (e)

k ¼ 30 lb=ft,

R ¼ 105 lb s=ft2 ,

p0 ¼ 14:7 lb=in:2

The system is at steady state prior to the pulse input in ﬂow. Use the RK–Fehlberg integrator to simulate the transient response of p(t). Find the analytical solution for p(t). Find the solution for p(t) without the accumulator present. Plot the responses from parts (a), (b), and (c) on the same graph. Simulate the response for p(t) with Simulink using the ‘‘ode45’’ integrator, and compare the results with those in parts (a) and (b).

k A R p

f1

p0

f2

FIGURE E6.14

6.4 MULTISTEP METHODS RK integrators were classiﬁed as one-step methods. The calculations for determining xA(i þ 1), the approximate solution to the continuous-time model dx ¼ f (t, x) dt

(6:175)

at t ¼ tiþ1, relies on the previous estimate xA(i) and one or more derivative function evaluations on the interval ti t tiþ1. The previous state estimate xA(i) is ignored once xA(i þ 1) has been computed. In contrast, multistep methods exploit knowledge of previous state estimates because they provide information about the local behavior of x(t) that can be used to advance the state. Formulas for multistep methods are derived by integrating Equation 6.175 from ti to tiþ1, x(tðiþ1 )

tiþ1 ð

dx ¼ x(ti )

f [t, x(t)]dt

(6:176)

ti tiþ1 ð

) x(tiþ1 ) ¼ x(ti ) þ

f [t, x(t)]dt ti

The integrand f [t, x(t)] is unknown since x(t) is the solution to Equation 6.175.

(6:177)

493

Intermediate Numerical Integration

6.4.1 EXPLICIT METHODS An mth-order interpolating polynomial Pm(t) that passes through the current derivative f [ti, xA(i)] and previous m derivatives f [ti1, xA(i 1)], f [ti2, xA(i 2)], . . . , f [tim, xA(i m)] can be used to obtain an approximation of the integral in Equation 6.177 (see Figure 6.16). Replacing the integrand in Equation 6.177 by the interpolating polynomial Pm(t) gives tiþ1 ð

xA (i þ 1) ¼ xA (i) þ

Pm (t)dt

(6:178)

ti

where the approximations xA(i) and xA(i þ 1) are used instead of x(ti) and x(tiþ1), the actual points on the solution x(t). The integral in Equation 6.178 is equal to the shaded area under the polynomial Pm(t), which has been extrapolated over the current integration interval (ti, tiþ1). To illustrate, suppose the polynomial is the linear function passing through {ti1, f [xA(i 1)]} and {ti, f [xA(i)]}. Then m ¼ 1 and

f [ti , xA (i)] f [ti1 , xA (i 1)] (t ti ) P1 (t) ¼ f [ti , xA (i)] þ ti ti1

(6:179)

Integrating P1(t) and substituting the result in Equation 6.178 yield after simplifying xA (i þ 1) ¼ xA (i) þ

T {3f [ti , xA (i)] f [ti1 , xA (i 1)]} 2

(6:180)

The formula in Equation 6.180 is known as the two-step Adams–Bashforth (AB-2) method. ‘‘Two-step’’ refers to the use of two intervals, (ti1, ti) and (ti, tiþ1), to compute the new state xA(i þ 1). Note that the method is explicit since xA(i þ 1) does not appear on the right-hand side of Equation 6.180.

x(t) xA(i) xA(i − m)

ti–m

xA(i − 2)

ti−2

xA(i − 1)

ti−1

Pm(t) f (ti−m, xA(i − m)) ti−m

FIGURE 6.16

ti

ti+1

t

f(ti, xA(i)) f(ti−2, xA(i − 2)) ti−2

f(ti−1, xA(i − 1))

ti−1

ti

ti+1

t

An mth-order interpolating polynomial for approximating integrand in Equation 6.177.

Simulation of Dynamic Systems with MATLAB® and Simulink®

494

The Taylor Series expansion of the derivative function f(t, x) leads to an alternative derivation of Equation 6.180, which also provides an expression for the local truncation error of the AB-2 integrator. The Taylor Series expansion of x(t) about ti evaluated at tiþ1 is given by d 1 d2 x(ti )(tiþ1 ti )2 þ x(ti )(tiþ1 ti ) þ dt 2 dt 2 T2 d ¼ x(ti ) þ Tf [ti , x(ti )] þ f [ti , x(ti )] þ 2 dt

x(tiþ1 ) ¼ x(ti ) þ

(6:181) (6:182)

where T is the ﬁxed-step size, that is, T ¼ tiþ1 ti ¼ ti ti1 ¼ . The Taylor Series expansion of the derivative function f(t, x) about ti evaluated at ti1 is d 1 d2 f [ti , x(ti )](ti1 ti ) þ f [ti , x(ti )](ti1 ti )2 þ dt 2 dt 2 d T 2 d2 f [ti , x(ti )] þ ¼ f [ti , x(ti )] T f [ti , x(ti )] þ 2 dt 2 dt

f [ti1 , x(ti1 )] ¼ f [ti , x(ti )] þ

(6:183) (6:184)

Solving for T(d=dt)f [ti, x(ti)] in Equation 6.184 and substituting into Equation 6.182 give x(tiþ1 ) ¼ x(ti ) þ

T 5 d2 {3f [ti , x(ti )] f [ti1 , x(ti1 )]} þ T 3 2 f [ti , x(ti )] þ 2 12 dt

(6:185)

Truncating Equation 6.185 after the linear term and replacing x(ti1), x(ti), x(tiþ1) with xA(i 1), xA(i), xA(i þ 1) lead to the AB-2 formula in Equation 6.180. Furthermore, since the ﬁrst term omitted in Equation 6.185 is of order T3, the local truncation error eT O(T 3). The global truncation error ET O(T 2) and AB-2 is said to be second-order accurate. More accurate Adams–Bashforth integration formulas exist. It is simply a question of the number of points, that is, m þ 1 in Figure 6.16, used to establish the interpolating polynomial Pm(t). Several higher-order AB integrators are listed as follows using the simpler notation fA(i) ¼ f [ti, xA(i)], fA(i 1) ¼ f [ti1, xA(i 1)], etc. T [23fA (i) 16fA (i 1) þ 5fA (i 2)] 12 T AB-4: xA (i þ 1) ¼ xA (i) þ [55fA (i) 59fA (i 1) þ 37fA (i 2) 9fA (i 3)] 24 T AB-5: xA (i þ 1) ¼ xA (i) þ [1901fA (i) 2774fA (i 1) þ 2616fA (i 2) 720

AB-3: xA (i þ 1) ¼ xA (i) þ

1274fA (i 3) þ 251fA (i 4)]

(6:186) (6:187)

(6:188)

Local truncation errors for AB integrators are obtained using the Taylor Series expansion approach illustrated for deriving the AB-2 formula. Truncating the respective series to obtain Equations 6.186 through 6.188 results in (3=8)T4(d3=dt3)f [ti, x(ti)], (251=720)T5(d4=dt4)f [ti, x(ti)], and (475=1440) T6(d5=dt5)f [ti, x(ti)] as the ﬁrst omitted terms in the AB-3, AB-4, and AB-5 formulas. The local and global truncation errors for the third-order accurate AB-3 integrator are eT O(T 4) and ET O(T 3), respectively. An mth-order accurate AB-m integrator has a local truncation error eT O(T m þ 1) and global truncation error ET O(T m).

Intermediate Numerical Integration

495

Both AB and RK integrators rely on a weighted sum of derivative function evaluations. In the case of one-step RK integration, the derivative function is evaluated numerous times over a single interval in contrast to the multistep AB integrators, which rely on derivative evaluations from previous intervals. The mth-order accurate multistep integration formulas are more efﬁcient than one-step methods of identical order because the same derivative function fA(i) is utilized m times for updating the state over m consecutive intervals. Another way of looking at it is only a single new derivative function evaluation fA(i) is required to advance the state from xA(i) to xA(i þ 1). For example, suppose we have just determined the state xA(i) using AB-3 integration. Since fA(i 1) and fA(i 2) are still in memory, only fA(i) ¼ f [ti, xA(i)] is needed to compute the new state xA(i þ 1) in Equation 6.186. Multistep methods are not self-starting. One approach is to utilize a one-step method for the ﬁrst several integration steps before transitioning to a multistep formula. Alternatively, a one-step method followed by lower-order multistep methods can be used prior to implementing a speciﬁc multistep method. Once again, let us choose the AB-3 integrator for illustration purposes. From Equation 6.186 with i ¼ 0, 1 T [23fA (0) 16fA (1) þ 5fA (2)] 12 T xA (2) ¼ xA (1) þ [23fA (1) 16fA (0) þ 5fA (1)] 12

xA (1) ¼ xA (0) þ

(6:189) (6:190)

It is impossible to know fA(1) and fA(2) without knowing x(T) and x(2T). Hence, two integrations are performed using a one-step method starting from the known initial point [0, x(0)] to determine xA(1) and xA(2). Subsequent state estimates xA(3), xA(4), . . . are computed from the AB-3 formula. The ‘‘weakest link in the chain’’ argument dictates the choice of an appropriate onestep method to initiate the numerical solution. In other words, for a third-orde