www.it-ebooks.info Advanced Dynamic-system Simulation Model-replication Techniques and Monte Carlo Simulation Granino A. Korn University of Arizona Tucson, Arizona WILEY-INTERSCIENCE A JOHN WILEY & SONS, INC., PUBLICATION www.it-ebooks.info www.it-ebooks.info Advanced Dynamic-system Simulation www.it-ebooks.info www.it-ebooks.info Advanced Dynamic-system Simulation Model-replication Techniques and Monte Carlo Simulation Granino A. Korn University of Arizona Tucson, Arizona WILEY-INTERSCIENCE A JOHN WILEY & SONS, INC., PUBLICATION www.it-ebooks.info Copyright © 2007 by John Wiley & Sons, Inc. All rights reserved. Published by John Wiley & Sons, Inc., Hoboken, New Jersey Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400, fax 978-750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, 201-748-6011, fax 201-748-6008, or online at http://www.wiley.com/go/permission. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at 877-762-2974, outside the United States at 317-572-3993 or fax 317-572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats. For more information about Wiley products, visit our web site at www.wiley.com. Library of Congress Cataloging-in-Publication Data: Korn, Granino Arthur, 1922- Advanced dynamic-system simulation : model-replication techniques and Monte Carlo simulation / by Granino A. Korn. p. cm. Includes index. ISBN 978-0-470-08188-4 (cloth/cd) 1. System analysis Simulation methods. 2. Monte Carlo method. I. Title. QA402. K665 2007 003' .85 dc22 200601618 Printed in the United States of America 10987654321 www.it-ebooks.info v Contents Preface xiii Chapter 1. Introduction to Dynamic-system Simulation 1 DYNAMIC-SYSTEM MODELS AND COMPUTER PROGRAMS 1 1-1. Computer Modeling and Simulation 1 1-2. Differential-equation Models 2 1-3. Interactive Modeling—Experiment Protocol and Simulation Studies 3 1-4. Simulation Software 4 1-5. OPEN DESIRE and DESIRE 4 HOW A SIMULATION RUN WORKS 5 1-6. Sampling the DYNAMIC Segment Variables 5 1-7. Numerical Integration 10 (a) Euler Integration 10 (b) Improved Integration Rules 10 1-8. Sampling Times and Integration Steps 11 1-9. Sorting Defined-variable Assignments 12 EXAMPLES OF SIMPLE APPLICATIONS 12 1-10. Oscillators and Computer Displays 12 (a) A Linear Harmonic Oscillator 12 (b) A Nonlinear Oscillator and Duffing’s Differential Equation 15 1-11. Space Vehicle Orbits—Variable-step Integration 15 1-12. A Population-dynamics Model 18 1-13. Splicing Multiple Simulation Runs: Billiard-ball Simulation 20 www.it-ebooks.info CONTROL-SYSTEM EXAMPLES 22 1-14. An Electrical Servomechanism with Motor Field Delay and Saturation 22 1-15. Control-system Frequency Response 24 1-16. Simulation of a Simple Guided Missile 25 (a) A Guided Torpedo 25 (b) The Complete Simulation Program 28 WHAT DO WE DO WITH ALL THIS? 29 1-17. Simulation Studies in the Real World: A Word of Caution 29 REFERENCES 30 Chapter 2. Models with Difference Equations, Limiters, and Switches 32 SAMPLED-DATA ASSIGNMENTS AND DIFFERENCE EQUATIONS 32 2-1. Sampled-data Difference Equation Systems 32 2-2. “Incremental” Form of Simple Difference Equations 34 2-3. Combining Differential Equations and Sampled-data Operations 35 2-4. A Simple Example 36 2-5. Initializing and Resetting Sampled-data Variables 38 EXAMPLES OF MIXED CONTINUOUS/SAMPLED-DATA SYSTEMS 38 2-6. The Guided Torpedo with Digital Control 38 2-7. Simulation of a Plant with a Digital PID Controller 40 MODELING LIMITERS AND SWITCHES 42 2-8. Limiters, Switches, and Comparators 42 (a) Limiter Functions 42 (b) Switching Functions and Comparators 42 2-9. Numerical Integration of Switch and Limiter Outputs, Event Prediction, and Display Problems 45 2-10. Using Sampled-data Assignments 46 2-11. Using the step Operator and Heuristic Integration-step Control 46 2-12. Example: Simulation of a Bang-bang Servomechanism 47 LIMITERS, SWITCHES, AND DIFFERENCE EQUATIONS 49 2-13. Limiters, Absolute Value, and Maximum/Minimum Selection 49 2-14. Output-limited Integration 50 2-15. Modeling Signal Quantization 50 2-16. Continuous-variable Difference Equations with Switching and Limiter Operations 51 (a) Introduction 51 (b) Track-hold Simulation 52 (c) Maximum- and Minimum-value Holding 53 vi Contents www.it-ebooks.info (d) Simple Backlash and Hysteresis Models 53 (e) The Comparator with Hysteresis (Schmitt Trigger) 54 2-17. Signal Generators and Signal Modulation 56 REFERENCES 58 Chapter 3. Programs with Vector/Matrix Operations and Submodels 59 VECTOR ASSIGNMENTS AND VECTOR DIFFERENTIAL EQUATIONS 59 3-1. Arrays, Subscripted Variables, and State-variable Declarations 59 3-2. Vector Operations in DYNAMIC Program Segments— The Vectorizing Compiler 60 (a) Vector Assignments and Vector Expressions 60 (b) Vector Differential Equations 61 (c) Vectorization and Model Replication—Significant Applications 62 3-3. Matrix-vector Products in Vector Expressions 63 (a) Definition 63 (b) A Simple Example: Resonating Oscillators 64 3-4. Vector Sampled-data Assignments and Vector Difference Equations 64 3-5. Sorting Vector and Subscripted-variable Assignments 66 MORE VECTOR OPERATIONS 66 3-6. Index-shifted Vectors 66 3-7. Sums, DOT Products, and Vector Norms 67 (a) Sums and DOT Products 67 (b) Euclidean, Taxicab, and Hamming Norms 67 3-8. Maximum/Minimum Selection and Masking 68 (a) Maximum/Minimum Selection 68 (b) Masking Vector Expressions 69 MATRIX OPERATIONS 69 3-9. Matrix Operations in Experiment-protocol Scripts 69 3-10. Matrix Assignments and Difference Equations in DYNAMIC Program Segments 70 3-11. Vector and Matrix Operations using Equivalent Vectors 71 VECTORS IN PHYSICS AND CONTROL-SYSTEM PROBLEMS 71 3-12. Vectors in Physics Problems 71 3-13. Simulation of a Nuclear Reactor 72 3-14. Linear Transformations and Rotation Matrices 72 3-15. State-equation Models for Linear Control Systems 74 USER-DEFINED FUNCTIONS AND SUBMODELS 75 3-16. User-defined Functions 75 Contents vii www.it-ebooks.info [...]... Introduction to Dynamic-system Simulation DYNAMIC-SYSTEM MODELS AND COMPUTER PROGRAMS 1-1 Computer Modeling and Simulation Simulation is experimentation with models Simulation for engineering design, research, and education studies must rapidly exercise a wide variety of models and then store and access a large volume of results This is practical only with models programmed on computers Dynamic-system. .. optimizations As another example, Monte Carlo simulations simplemindedly measure statistics over repeated experiments to solve problems that are too complicated for probability theory analysis Simulation results must eventually be validated by real experiments, just like analytical results Advanced Dynamic-system Simulation: Model-replication Techniques and Monte Carlo Simulation By Granino A Korn Copyright... and Monte Carlo Simulation 4-5 Generating Random Parameters and Random Initial Values 88 88 89 MONTE CARLO SIMULATION OF DYNAMIC SYSTEMS 4-6 Repeated-run Monte Carlo Simulation (a) Taking Statistics on Repeated Simulation Runs (b) Sequential Monte Carlo Studies (c) Example: Effects of Gun-elevation Errors on the 1776 Cannon 89 89 89 91 91 4-7 Vectorized (Model-replicating) Monte Carlo Simulation (a)... -solving simulation run) (reset initial values) (change model parameters) (try another run) www.it-ebooks.info 4 Introduction to Dynamic-system Simulation Each drun command calls a differential-equation-solving simulation run, and reset resets initial conditions Typed commands ought to execute immediately to permit interactive modeling The operator inspects the solution output after each simulation. .. Preface Simulation is experimentation with models This book describes new computer programs for interactive modeling and simulation of dynamic systems, such as aerospace vehicles, control systems, and biological systems Simulation studies for design or research can involve many hundreds of model changes, so programming must be convenient, and computations must be as fast as possible This book is about advanced. .. Copyright © 2007 by John Wiley & Sons, Inc 1 www.it-ebooks.info 2 Introduction to Dynamic-system Simulation Computer simulations can be speeded up or slowed down at the experimenter’s convenience You can simulate a flight to Mars or to Alpha Centauri in one second Periodic clock interrupts synchronizing suitably scaled simulations with real time permit “hardware in the loop”: you can “fly” a real autopilot—or... voltage with continuous time Computer simulation of such systems started in the aerospace industry and is now indispensable in biology, medicine, and agroecology as well as in all engineering disciplines At the same time, discrete-event simulation has gained importance for business and military planning Simulation is at its best when combined with mathematical analyses But simulation results can often provide... DESIRE The simulation programs described in this book, and, in particular, our new techniques for model replication (vectorization), Monte Carlo simulation, and submodels (Chapters 3–7), use the open-software simulation package OPEN DESIRE for Linux, Unix including Cygwin (Unix under Windows), and Microsoft WindowsTM, or the commercially available DESIRE/2000 program for Windows.1 DESIRE simulation. .. window, and an editor window using the open-source Crimson Editor The original display was in color www.it-ebooks.info 8 Introduction to Dynamic-system Simulation variables [Eq (1-1b)] Unless stopped, simulations run from the initial time t = t0 to t = t0 + TMAX You can stop a simulation run by typing ctrl c and space (zz under Windows), and restart or extend a run with drun DESIRE normally samples DYNAMIC-segment... DYNAMIC -d/dt x = xdot | d/dt xdot = - ww * x - r * xdot dispt x FIGURE 1-3a This complete simulation program for a linear oscillator produces five simulation runs with different values of the damping coefficient r www.it-ebooks.info 14 Introduction to Dynamic-system Simulation + 0 – –1.0 scale = 1 –0.5 0.0 x,xdot 0.5 1.0 FIGURE 1-3b A phase-plane plot (xdot versus x) for the linear . PUBLICATION www.it-ebooks.info www.it-ebooks.info Advanced Dynamic-system Simulation www.it-ebooks.info www.it-ebooks.info Advanced Dynamic-system Simulation Model-replication Techniques and Monte Carlo Simulation Granino. xv www.it-ebooks.info www.it-ebooks.info 1 Introduction to Dynamic-system Simulation DYNAMIC-SYSTEM MODELS AND COMPUTER PROGRAMS 1-1. Computer Modeling and Simulation Simulation is experimentation with models. Simulation for engineering design,. Cataloging-in-Publication Data: Korn, Granino Arthur, 1922- Advanced dynamic-system simulation : model-replication techniques and Monte Carlo simulation / by Granino A. Korn. p. cm. Includes index. ISBN