Advanced Dynamic-System Simulation - Granino A. Korn - E-Book

Advanced Dynamic-System Simulation E-Book

Granino A. Korn

0,0
94,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

A unique, hands-on guide to interactive modeling and simulation of engineering systems This book describes advanced, cutting-edge techniques for dynamic system simulation using the DESIRE modeling/simulation software package. It offers detailed guidance on how to implement the software, providing scientists and engineers with powerful tools for creating simulation scenarios and experiments for such dynamic systems as aerospace vehicles, control systems, or biological systems. Along with two new chapters on neural networks, Advanced Dynamic-System Simulation, Second Edition revamps and updates all the material, clarifying explanations and adding many new examples. A bundled CD contains an industrial-strength version of OPEN DESIRE as well as hundreds of program examples that readers can use in their own experiments. The only book on the market to demonstrate model replication and Monte Carlo simulation of real-world engineering systems, this volume: * Presents a newly revised systematic procedure for difference-equation modeling * Covers runtime vector compilation for fast model replication on a personal computer * Discusses parameter-influence studies, introducing very fast vectorized statistics computation * Highlights Monte Carlo studies of the effects of noise and manufacturing tolerances for control-system modeling * Demonstrates fast, compact vector models of neural networks for control engineering * Features vectorized programs for fuzzy-set controllers, partial differential equations, and agro-ecological modeling Advanced Dynamic-System Simulation, Second Edition is a truly useful resource for researchers and design engineers in control and aerospace engineering, ecology, and agricultural planning. It is also an excellent guide for students using DESIRE.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 258

Veröffentlichungsjahr: 2013

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Contents

Cover

Title Page

Copyright

Preface

Chapter 1: Dynamic-System Models and Simulation

SIMULATION IS EXPERIMENTATION WITH MODELS

ANATOMY OF A SIMULATION RUN

SIMPLE APPLICATION PROGRAMS

INRODUCTION TO CONTROL-SYSTEM SIMULATION

STOP AND LOOK

REFERENCES

Chapter 2: Models with Difference Equations, Limiters, and Switches

SAMPLED-DATA SYSTEMS AND DIFFERENCE EQUATIONS

TWO MIXED CONTINUOUS/SAMPLED-DATA SYSTEMS

DYNAMIC-SYSTEM MODELS WITH LIMITERS AND SWITCHES

EFFICIENT DEVICE MODELS USING RECURSIVE ASSIGNMENTS

REFERENCES

Chapter 3: Fast Vector–Matrix Operations and Submodels

ARRAYS, VECTORS, AND MATRICES

VECTORS AND MODEL REPLICATION

MORE VECTOR OPERATIONS

VECTOR EQUIVALENCE DECLARATIONS SIMPLIFY MODELS

MATRIX OPERATIONS IN DYNAMIC-SYSTEM MODELS

VECTORS IN PHYSICS AND CONTROL-SYSTEM PROBLEMS

USER-DEFINED FUNCTIONS AND SUBMODELS

REFERENCES

Chapter 4: Efficient Parameter-Influence Studies and Statistics Computation

MODEL REPLICATION SIMPLIFIES PARAMETER-INFLUENCE STUDIES

STATISTICS

COMPUTING STATISTICS BY VECTOR AVERAGING

REPLICATED AVERAGES GENERATE SAMPLING DISTRIBUTIONS

RANDOM-PROCESS SIMULATION

SIMPLE MONTE CARLO EXPERIMENTS

REFERENCES

Chapter 5: Monte Carlo Simulation of Real Dynamic Systems

INTRODUCTION

REPEATED-RUN MONTE CARLO SIMULATION

VECTORIZED MONTE CARLO SIMULATION

SIMULATION OF NOISY CONTROL SYSTEMS

ADDITIONAL TOPICS

REFERENCES

Chapter 6: VECTOR MODELS OF NEURAL NETWORKS

ARTIFICIAL NEURAL NETWORKS

SIMPLE VECTOR ASSIGNMENTS MODEL NEURON LAYERS

SUPERVISED TRAINING FOR REGRESSION

MORE NEURAL-NETWORK MODELS

PATTERN CLASSIFICATION

PATTERN SIMPLIFICATION

NETWORK-TRAINING PROBLEMS

UNSUPERVISED COMPETITIVE-LAYER CLASSIFIERS

SUPERVISED COMPETITIVE LEARNING

EXAMPLES OF CLEARN CLASSIFIERS

REFERENCES

Chapter 7: DYNAMIC NEURAL NETWORKS

INTRODUCTION

NEURAL NETWORKS WITH DELAY-LINE INPUT

STATIC NEURAL NETWORKS USED AS DYNAMIC NETWORKS

RECURRENT NEURAL NETWORKS

PREDICTOR NETWORKS

OTHER APPLICATIONS OF DYNAMIC NETWORKS

MISCELLANEOUS TOPICS

REFERENCES

Chapter 8: More Applications of Vector Models

VECTORIZED SIMULATION WITH LOGARITHMIC PLOTS

MODELING FUZZY-LOGIC FUNCTION GENERATORS

PARTIAL DIFFERENTIAL EQUATIONS [11,12]

FOURIER ANALYSIS AND LINEAR-SYSTEM DYNAMICS

REPLICATION OF AGROECOLOGICAL MODELS ON MAP GRIDS

REFERENCES

Appendix: Additional Reference Material

A-1 Example of a Radial-Basis-Function Network

A-2 Fuzzy-Basis-Function Network

REFERENCES

Using the book cd

Index

Copyright © 2013 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 (800) 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 A. (Granino Arthur), 1922– Advanced dynamic-system simulation : model replication and Monte Carlo studies / by Granino A. Korn. – Second edition. pages cm Includes bibliographical references. ISBN 978-1-118-39735-0 (hardback) 1. System analysis–Simulation methods. 2. Open source software. 3. Computer software–Development. I. Title. QA402.K665 2013 003′.85–dc23 2012034771

PREFACE

Simulation is experimentation with models. In this book we describe efficient interactive computer programs that model dynamic systems such as control systems, aerospace vehicles, and biological systems. Simulation studies can involve many hundreds of model changes, so programs must be fast and user-friendly.

For hands-on experiments with each program example, the book CD now includes industrial-strength open-source simulation software for both WindowsTM and Linux, not just toy demonstration programs. The Desire modeling/simulation program implements very fast and respectably large simulations on personal computers. Runtime-compiled programs display results immediately to permit true interactive modeling.

A readable mathematical notation, for example,

lets readers try different parameter values without learning details of the programming language. Note that one can read ebook pages and run live simulations on the same computer display.

In Chapter 1 we introduce our subject with a few familiar differential-equation models and a small guided-missile simulation. The remainder of the book presents more advanced topics; most of our example programs were rewritten to clarify the modeling technique and to increase computing speed.

Chapter 2 begins with a newly revised systematic procedure for programming difference equations and applies this to model plants with digital controllers. We then discuss limiters and switches and model useful devices such as track/hold circuits, trigger circuits, and signal generators with simple difference equations. Last but not least, we propose a simplified technique for numerical integration of switched variables.

Advanced simulation programs must handle differential and difference equations with vector and matrix assignments. In Chapter 3 we introduce runtime vector compilation. This speeds up conventional vector and matrix operations, but more significantly, personal computers can now implement model replication (vectorization), a technique originally developed for supercomputers. A single vector-model run replaces hundreds or thousands of conventional simulation runs. Chapter 3 also demonstrates the convenience of user-defined submodels.

In the remaining chapters we describe applications of vectorization. In Chapter 4 we discuss parameter-influence studies and introduce vectorized statistics computation, including rapid estimation of probability densities. We then introduce Monte Carlo simulation of random processes. In Chapter 5 we apply Monte Carlo simulation to several real engineering systems. Vectorization lets us study time histories of random-process statistics. An inexpensive 3-GHz personal computer running under 64-bit Linux can exercise over 1000 random-input control-system models in 1 second.

In Chapters 6 and 7 we demonstrate vector models of neural networks; our simple vector notation has been particularly useful for short courses on neural networks. In Chapter 6 we apply backpropagation, functional-link, and radial-basis-function networks to classical regression and pattern-classification problems and describe several competitive-learning schemes. In the newly added Chapter 7 we turn to dynamic neural networks for prediction, pattern classification, and model matching. The chapter includes a new method for online prediction and simplified programs for recurrent networks.

Chapter 8 deals with vectorized programs for fuzzy-set controllers, partial differential equations, and agroecological models replicated at over 1000 points of a landscape map. The Appendix gets a small selection of reference material out of the way of the main text.

The writer would like to express his sincere thanks to Professor M. Main of the University of Colorado for his assistance with Windows graphics, to Dr. R. Wieland of the Leibniz Center for Agricultural Landscape Research (ZALF) for much good advice, and above all to Theresa M. Korn for her consistent help with this and many other projects.

GRANINO A. KORN

Wenatchee, Washington

CHAPTER 1

DYNAMIC-SYSTEM MODELS AND SIMULATION

SIMULATION IS EXPERIMENTATION WITH MODELS

1-1 Simulation and Computer Programs

Simulation is experimentation with models. For system design, research, and education, simulations must not only construct and modify many different models but also store and access a large volume of results. That is practical only with models programmed on computers [1,2].

In this book we model changes of system variables with time; we represent physical time by the simulation time variable t. Our models then attempt to predict different time histories y1=y1(t), y2=y2(t), … of system variables such as velocity, voltage, and biomass. Static models simply relate values of system variables x(t), y(t), … at the same time t; a gas pressure P(t), for instance, might be a function P=aT of the slowly changing temperature T(t).

Dynamic-system models predict values of model-system state variablesx1(t), x2(t), … by relating them to past states [x1(t), x2(t), … ] (Sec. 1-2). Computer simulation of such systems was applied first in the aerospace industry. Simulation is now indispensable not only in all engineering disciplines, but also in biology, medicine, and agroecology. At the same time, discrete-event simulation gained importance for business and military planning.

Simulation is most effective when it is combined with mathematical analyses. But simulation results often provide insight and suggest useful decisions where exact analysis is difficult or impossible. This was true for many early control-system optimizations. As another example, Monte Carlo simulations simply measure statistics over repeated experiments to solve problems too complicated for explicit probability-theory analysis. All simulation results must eventually be validated by real experiments, just like analytical results.

Computer simulations can be speeded up or slowed down for the experimenter's convenience. One 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”: One can “fly” a real autopilot—or a human pilot—on a tilt table controlled by computer flight simulation. In this book we are interested in very fast simulation because we need to study many different model changes very quickly. Specifically, we would like to

enter and edit programs in convenient editor windows.use typed or graphical-interface commands to start, stop, and pause simulations, to select displays, and to make parameter changes. Displays of simulation results ought to appear immediately to provide an intuitive “feel” for the effects of model changes (interactive modeling).program systematic parameter-optimization studies and produce cross-plots and statistics.

1-2 Dynamic-System Models

(a) Difference-Equation Models1

The simplest way to relate present values x(t) and past values of a state variablex=x(t) is a difference equation such as the simple recurrence

More general difference-equation models relate several state variables and their past values. In Chapter 2 we discuss such models in detail.

(b) Differential-Equation Models

Much of classical physics and engineering is based on differential-equation models that relate delayed interactions of continuous differential-equationstate variablesx1(t), x2(t), … with first-order ordinary differential equations (state equations)2

(1.1a)

Here t again represents the time, and the quantities

(1.1b)

are defined variables. a1,  a2, … and b1,  b2, … are constant model parameters.

A computer-implemented simulation run exercises such a model by solving the state-equation system (1.1) to produce time histories of the system variables xi=xi(t) and yj=yj(t) for t=t0 to t=t0+TMAX. An integration routine increments the model time t and integrates the derivatives (1-1a) to produce successive values of xi(t) (Sec. 1-7), starting with given initial values xi=xi(t0).

Each state variable xi is a model output. There are three types of defined variables yj:

1. model inputs (specified functions of the time t),
2. model outputs, and
3. intermediate results needed to compute the derivatives fi.

The defined-variable assignments (1-1b) must be sorted into a procedure that derives updated values for all yj from current values of the state variables xi, already computed yj values, and/or t without “algebraic loops” (Sec. 1-9).

Some dynamic systems (e.g., systems involving linkages in automotive engineering and robotics) are modeled with differential equations that cannot be solved explicitly for state-variable derivatives as in Eq. (1-1a). Simulation then requires solution of algebraic equations at each integration step. Such differential-algebraic-equation systems are not treated in this book. References 6 to 11 describe suitable mathematical methods and special software.

(c) Discussion

Much of classical physics (Newtonian dynamics, electrical-circuit theory, chemical reactions) uses differential equations. As a result, most legacy simulation programs are basically differential-equation solvers and relegate difference equations to accessory “procedural” program segments. Modern engineering systems, though, often involve digital controllers and thus sampled-data operations that implement difference equations. In this book we introduce a program package specifically designed to handle such problems. We start with differential-equation problems in Chapter 1 and go on to difference equations and mixed continuous/sampled-data models in Chapter 2.

1-3 Experiment Protocols Define Simulation Studies

Effective computer simulation is not simply a matter of programming model equations. It must also be truly convenient to modify models and to try many different experiments (see also Sec. 1-5). In addition to program segments that list model equations such as those in Sec. 1-2, every simulation needs an experiment-protocol program that sets and changes initial conditions and parameters, calls differential-equation-solving simulation runs, and displays or lists solutions.

A simple experiment protocol implements a sequence of successive commands: say

Each drun command calls a new simulation run. The command reset resets initial conditions for new runs.

A command intepreter executes typed commands immediately. Users can inspect the solution output after each simulation run and then enter new commands for another run. Command-mode operation permits interactive programming and program debugging [2].

Graphical-user-interface (GUI) simulation programs replace typed commands with windows for entering model parameters and menus and/or buttons for executing such commands as run and reset using mouse clicks. This is convenient for special-purpose simulation programs with simple experiment protocols. Typed and programmed commands entered in a console window (command window) permit a much wider choice of operations.

A programmed simulation study combines experiment-protocol commands into a stored program called an experiment-protocol script. Such a program can branch and loop to call repeated simulation runs (e.g., for parameter optimization or statistical studies). Proper experiment-protocol scripts require a full-fledged computer language with functions, procedures, program loops, conditional execution, and file operations.

Simulation studies can involve many model and parameter changes, so program execution must be prompt and fast. We can interpret experiment-protocol scripts. But “dynamic” program segments that implement simulation runs update system variables hundreds or thousands of times. Such time-critical operations must be compiled.3

1-4 Simulation Software

Equation-oriented simulation programs such as ACSLTM accept model equations in a more or less human-readable notation, sort defined-variable assignments as needed, and feed the sorted equations to a Fortran or C compiler [1]. Berkeley Madonna and Desire (see below) have runtime equation-language compilers and execute immediately. Block-diagram interpreters (e.g., SimulinkTM and the free open-source Scicoslab program) let users compose block-diagram models on the display screen. Such programs execute interpreted simulation runs immediately but relatively slowly. To improve computing speed, most block-diagram interpreters admit precompiled equation-language blocks for complicated expressions, and production runs are sometimes translated into C for faster execution. Alternatively, ACSL, Easy5TM, and Berkeley Madonna have block-diagram preprocessors for compiled simulation programs. Differential-algebraic (DAE) models need substantially more complicated software, preferably using the Modelica Language [3,4,5,6]. DynasimTM and MaplesimTM are examples.

1-5 Fast Simulation Program for Interactive Modeling

The simulation programs in this book employ the open-source Desire program4 on the book CD.5 Command scripts and model descriptions use a natural mathematical notation similar to Basic: for example,

so that the system is easy to learn. You can run all our program examples and make simple parameter changes without learning language details (Table 1-1). The Reference Manual on the CD describes Desire operations in detail, and Ref. 2 is an elementary textbook. Sections 1-10 to 1-12 list simple example programs.

Table 1-1 Desire Under Windows

Easy InstallationSimply copy or unzip the distribution folder mydesire on a hard disk or flash stick to produce a complete, ready-to-run simulation system with an editor, help files, graphics, and many user-program examples. Deleting the installation folder un-installs the package without leaving any trace. Unlike most Windows programs Desire never involves the Windows registry. Run a User ProgramDouble-click the Wdesire.bat icon (or a shortcut icon) to open a Command Window and an empty Editor Window (Fig. 1-1a).Drag a user-program icon into the Editor window to load the program for editing.Clicking the editor's OK button transfers the edited program to Desire, and a typed erun (or more simply zz) command starts execution.The Graph Window displays solution graphs. The Command Window shows error messages and output listings. Additional Editor Windows can be added by typed commands. Multiple Editor Windows let you run and compare different programs, or different versions of the same program (Fig. 1-1a).

Desire runs under WindowsTM, Linux, and Unix and solves up to 40,000 differential equations in scalar and vector form. Difference equations are handled equally well. Double-precision floating-point arithmetic is used throughout.

The dual-monitor displays in Fig. 1-1 show Desire running under Windows, Linux, and Unix. Programs are entered and edited in editor windows and controlled by commands typed into a command window. Solution graphs display in a graph window. The graphs in Fig. 1-1 are black-on-white for publication, but ordinarily, different curves are displayed in bright colors.

Each Desire program begins with an interpreted experiment-protocol script that defines the experiment. Subsequent DYNAMIC program segments define models that generate time-history output. When the experiment-protocol script encounters a drun statement, a built-in runtime compiler automatically compiles a DYNAMIC program segment.6 A simulation run solving the state equations then executes at once and displays solution time histories.

Fast runtime compilation (under 40 ms) permits truly interactive modeling since results of screen-edited program changes appear immediately. Multiple editor windows let users enter, edit, and simulate different models to compare results. Runtime displays show solution time histories and error messages during rather than after each simulation run. This lets users save time by aborting undesirable runs before they complete.

Experiment protocols can call multiple DYNAMIC segments with different models, different versions of the same model, and/or different input/output operations.

Table 1-1 shows how to run Desire and our program examples under Windows. Under Linux, Desire also installs simply by unzipping a distribution folder. Desire then uses a Linux editor rather than its own editor. The Reference Manual describes the editor installation and its association with user-program text files. Once this is done, simply clicking a program-file icon displays the program in an editor window, ready to run as under Windows (Fig 1-1b).

Figure 1-1a Desire running under Windows. The dual-monitor display shows the command window, a file-manager (explorer) window, two editor windows, and the graphics window. The red OK button on each Desire editor window transfers the edited program to Desire. Multiple editor windows let you run and compare two or more programs, or modified versions of the same program.

Figure 1-1b Desire running under Linux, showing the command, file-manager, and graphics windows and three editor windows. The Linux Editor's Save button transfers the edited program to Desire, just like the OK button in Fig. 1-1a.

ANATOMY OF A SIMULATION RUN

1-6 Dynamic-System Time Histories Are Sampled Periodically

When drun calls a simulation run, the program initializes input/output operations specified in the DYNAMIC program segment. The simulation time t and the differential-equation state variables start with initial values assigned by the experiment protocol.7 A first pass through the DYNAMIC-segment code (1.1) next produces the resulting initial values of the defined variables (1-1b). Unless stopped, the simulation then runs from t=t0 to t=t0+TMAX. One can pause a simulation run with a mouse click (Windows) or by typing ctrl c and space (Linux), and restart or extend a run with drun.

Desire normally samples DYNAMIC-segment variables for output or sampled-data operations at NN uniformly spaced sampling times (communication times)

(1.2)

The experiment-protocol script sets appropriate values of t0, TMAX, and NN or uses default values listed in the Reference Manual.

If the DYNAMIC program segment contains differential equations (d/dt or Vectr d/dt statements), t0 defaults to t0=0 if no other value is specified. Starting at t=t0, the integration routine then increments t by successive constant or variable DT steps until t reaches the next data-sampling communication point (Fig 1.2a). Within integration steps; numerical integration approximates continuous updating of the “continous” model variables t, xi, and yj. Each integration step usually requires more than one derivative call executing the model equations (1-1) (Sec. 1-7 and Refs. 3 to 11).

Figure 1-1c Cygwin (Unix under Windows) display with a Unix console window serving as the Desire command window. The single editor window uses the open-source Crimson Editor.

Figure 1-1d Dual-screen display that lets you read textbook pages on the left and run live Desire simulation examples on the right.

Figure 1-1e Here Linux displays two simultaneous simulations controlled by separate command windows. Multiple file-manager and editor windows could be added.

Figure 1-2a Time history of a simulation variable, showing sampling times t=t0, t0+COMINT, t0+2COMINT, … , t0+TMAX and some integration steps. In the figure all integration steps end on a sampling point. That is always true for variable-step integration rules, but fixed integration steps DT may overshoot the sampling points by a small fraction of DT, as shown in Fig. 1-2b.

In DYNAMIC program segments without differential equations, t0 defaults to t0=1 unless the experiment-protocol script specifies a different value. All operations in such a DYNAMIC segment are then sampled-data assignments and execute at successive communication times (1-2). Assignments preceded by a SAMPLE m statement, where m is an integer > 1, execute only at t=t0+COMINT and then at every mth communication point. This permits multirate sampling.

DYNAMIC-segment input/output (e.g., output to displays and listings) occurs at the NN communication points (1.2) unless the system variable MM, which defaults to 1, is set to an integer > 1. In that case, input/output occurs at t=t0+COMINT and then at every MMth sampling point, and finally at t=t0+TMAX. NN can thus be set to a larger value than the desired number of input/output points. This can provide fast sampling for pseudorandom noise (Sec.4-14) and/or for sampling switch and limiter functions (Secs. 2-10 and 2-11).

Some defined-variable assignments (1-1b) do not affect state variables but only scale or modify model output. Such operations are not needed at every derivative call but only at sampling points. Simulations run faster if one programs such assignments as sampled-data operations following an OUT statement.

Finally, Desire is designed to solve problems that combine differential equations with difference equations. Differential-equation-solving DYNAMIC segments can include difference-equation code that must not execute in the middle of integration steps. In particular, sampled-data assignments modeling digital controllers and noise generators execute only at periodic sampling points and must be collected in sections following an OUT and/or SAMPLE m statement at the end of the DYNAMIC program segment. Nonperiodic difference-equation code (recursive assignments) must similarly follow a step statement. These topics are discussed in Chapter 2.

1-7 Numerical Integration (see also Table A-1)

(a) Euler Integration

The simplest procedure that approximates continuous updating of a state variable x in successive integration steps is the explicitEuler integration rule

(1.3)

where fi is the value of dx/dt calculated by the derivative call executing Eq. (1-1) at the time t.

The integration routine loops until t reaches the next communication point (1.2), where the solution is sampled for input/output and sampled-data operations. The simulation run terminates after accessing the last sample at t=t0+TMAX, unless the run is stopped either by the user or by a programmed termination (term) statement.

(b) Improved Integration Rules [6–11]

The Euler integration rule (1-3) simply increments each state variable by an amount proportional to its last-computed derivative. That is an acceptable approximation to true integration only for very small integration steps DT. Improved updating requires multiple derivative calls per integration step DT. This can reduce the total number of derivative calls (the main computing load of a simulation) required for a specified accuracy. In particular,

multistep rules extrapolate updated xi values as polynomials based on values of the x1, x2, … and f1, f2, … at several past times .Runge–Kutta rules precompute two or more approximate derivative values in the interval (t, t+DT) by Euler-type steps and use their weighted average for updating.

Coefficients in such integration formulas are chosen so that polynomials of degree N integrate exactly (Nth-order integration formula).

Explicit integration rules such as Eq. (1-3) express future values xi(t+DT) in terms of already computed past state-variable values. Implicit rules such as the implicit Euler rule

(1.4)

require a program that solves the predictor equations (1-4) for the xi(t+DT) at each integration step. This clearly involves more computation. But implicit integration rules often produce more stable solutions and may admit larger DT values without numerical instability, and thus still save computing time.

Variable-step integration adjusts integration step sizes to maintain accuracy estimates obtained by comparing various tentative updated solution values. This can save many steps. Figures 1.5, 8-7, and 8-8 show examples.

Figure 1-3b Phase-plane plot (xdot vs. x) for the linear oscillator in Fig. 1-3a.

Figure 1-4a Time histories and a phase-plane plot for the nonlinear oscillator modeled with

Figure 1-4b Simulation program for Duffing's differential-equation system. The experiment protocol first calls a simulation run demonstrating the initial transient, then a long run without display to obtain a steady state (TMAX=200, display 0, display 0), and finally, a third run showing the steady-state solution with the display turned on again (display 1). Phase-plane plots are shown as well. A plot of z=cos(t) is shown for comparison.

Figure 1-5 Space-vehicle-orbit simulation program, orbit display, and stripchart time histories of y and DT, showing the variable integration steps. For simplicity, the problem was scaled so that all coefficients equal unity.

Numerical integration normally assumes integrands fi that are continuous and differentiable within each integration step. Step-function inputs are acceptable only at t=t0 and thereafter at the end of integration steps. This problem is discussed in Sections 2-9 to 2-11 in connection with models involving sampled-data operations and switching functions.

1-8 Sampling Times and Integration Steps

The experiment protocol script selects the simulation-run time TMAX and the number of samples NN needed for display, listings, and/or sampled-data models. Desire returns an error message if you select an integration-step value DT value larger than ; Desire never samples data within integration steps.8 Sampled-data output to displays or sampled-data assignments is not well defined at such times. Sampled-data input within integration steps might make the numerical-integration routine invalid (see also Secs. 2-9 to 2-12).

Desire's variable-step integration routines automatically force the last integration step in each communication interval to end precisely on one of the user-selected communication points (1.2). An “illegal sampling rate” message warns you if the initial DT-value exceeds COMINT. Fixed-step integration routines, though, may have to add a fraction of DT to each sampling time (1.2) to make sure that sampling always occurs at the end of an integration step, as shown in Fig. 1-2b. This does not cause errors in displays or listings, for each x(t)-value is still associated with its correct t-value. But to produce output listings at exactly specified periodic sampling times (1.2) you must either use variable-step integration or set DT to a very small integral fraction of COMINT.

Figure 1-2b Desire output listings for variable-step integration and for fixed-step integration. Parameters were deliberately chosen to exaggerate the fixed-DT effect.

1-9 Sorting Defined-Variable Assignments

DYNAMIC-segment operations (1.1) preceding an OUT or SAMPLE m statement (if any) execute at every call of the differential-equation-solving integration routine. Each derivative or defined-variable assignment uses the time and state-variable values computed by the last derivative call. Derivative and defined-variable values for t=t0 are derived from the given initial state-variable values and t0 by an extra initial derivative call.

The state equations (1-1a) are normally programmed following the defined-variable assignments (1-1b). The defined-variable assignments may use yj-values already computed in the course of the current step. They must, therefore, execute in the correct procedural order to derive each yj-value from the current state-variable values and t. An out-of-order assignment might not find all its arguments, or try to use defined-variable values from an earlier derivative call. Legacy differential-equation solvers such as ACSL sort the defined-variable assignments automatically so that they use only yi-values already computed by the current derivative call. If that is impossible due to an algebraic loop, the program returns an error message (sort error).

Since unlike most legacy differential-equation solvers, Desire accommodates difference equations directly (Chapter 2), we do not sort defined-variable assignments automatically. As-yet-undefined variables are correctly identified with error messages, but users must inspect algebraic loops (if any) and re-sort the assignments if necessary.

Desire does not treat recursive assignments such as qi=Fi(t; qi) as algebraic loops but recognizes them automatically as difference equations (Sec. 2-2). In Secs. 2-16 to 2-21 we discuss significant applications of this technique.

SIMPLE APPLICATION PROGRAMS

1-10 Oscillators and Computer Displays

(a) Linear Oscillator

The complete small program in Fig. 1-3 illustrates the main features of a Desire simulation. The DYNAMIC program segment following the DYNAMIC statement in Fig. 1-3a defines a differential-equation model. We modeled a simple damped harmonic oscillator or mass–spring–dashpot system with the derivative assignments

Figure 1-3a Complete simulation program for a linear oscillator, producing five simulation runs with different values of the damping coefficient r.

We can add a display specification:

displays the variables x and xdot versus the simulation time t displays xdot versus x (phase-plane plot)

Model and display are exercised by the experiment-protocol script preceding the DYNAMIC statement. In Fig. 1-3a successive experiment-protocol lines specify

the runtime TMAX, the integration step DT, and the number NN of display pointsa model parameter wwthe initial value of the state variable x

Initial values of the time t and of the state variable xdot were not specified and default to 0. The integration routine defaults to a fixed-step second-order Runge–Kutta rule.9

A simple experiment-protocol loop next calls five simulation runs with five values of the oscillator damping parameter r. The display 2 statement keeps the display alive through multiple runs. The resulting displays are reproduced at the top of 1-3a. Figure 1-3b shows a phase-plane plot.

(b) Nonlinear Oscillator: Duffing's Differential Equation

The differential equations

model an oscillator with a nonlinear spring. Figure 1-4a and b show the resulting time histories and phase-plane plots obtained with a=0.02. These results are clearly different from the linear-oscillator response in Fig. 1-3.

If we drive the nonlinear oscillator with a sinusoidal voltage bcos(t), we obtain

Figure 1-4b shows solution displays and program. Note that the experiment-protocol script first calls a simulation run to exhibit the initial transient, then a long simulation run with the display turned off to establish steady-state conditions, and finally, a third run to display the steady-state solution.

Reference 2 has more Desire programs for small physics problems.

1-11 Space-Vehicle Orbit Simulation with Variable-Step Integration

The space-vehicle orbit simulation in Fig. 1-5 assumes a fixed Earth that exerts a simple inverse-square-law gravitational force on a satellite. Forces exerted by the Moon are neglected. With Earth at the coordinate origin, the inverse-square-law accelerations in the x and y directions are

The program is scaled so that the gravitational constant a equals 1, and we obtain a very simple differential-equation system:10

The orbit in Fig. 1-5 involves dramatic velocity changes, and the small integration steps required during the high-velocity portion of the trajectory would slow the rest of the simulation. For this reason such simulations employ an implicit variable-step/variable-order integration rule (irule15). The second display in Fig. 1-5 illustrates the integration-step changes.

1-12 Population-Dynamics Model