Modeling & Simulation 2018 Lecture 12. Simulations

Similar documents
Fourth Order RK-Method

Review Higher Order methods Multistep methods Summary HIGHER ORDER METHODS. P.V. Johnson. School of Mathematics. Semester

ECE257 Numerical Methods and Scientific Computing. Ordinary Differential Equations

Initial-Value Problems for ODEs. Introduction to Linear Multistep Methods

Ordinary differential equations - Initial value problems

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. by Michael T. Heath. Chapter 9

Differential Equations

Bindel, Fall 2011 Intro to Scientific Computing (CS 3220) Week 12: Monday, Apr 18. HW 7 is posted, and will be due in class on 4/25.

CS 450 Numerical Analysis. Chapter 9: Initial Value Problems for Ordinary Differential Equations

Scientific Computing: An Introductory Survey

Initial value problems for ordinary differential equations

10.34: Numerical Methods Applied to Chemical Engineering. Lecture 19: Differential Algebraic Equations

CHAPTER 10: Numerical Methods for DAEs

Solving Ordinary Differential equations

You may not use your books, notes; calculators are highly recommended.

Part IB Numerical Analysis

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit V Solution of

Consistency and Convergence

Numerical Methods for Differential Equations

Numerical Differential Equations: IVP

Applied Math for Engineers

Solving scalar IVP s : Runge-Kutta Methods

Numerical Methods - Initial Value Problems for ODEs

NUMERICAL SOLUTION OF ODE IVPs. Overview

Jim Lambers MAT 772 Fall Semester Lecture 21 Notes

Logistic Map, Euler & Runge-Kutta Method and Lotka-Volterra Equations

Ordinary Differential Equations

Math 660 Lecture 4: FDM for evolutionary equations: ODE solvers

Numerical Methods for the Solution of Differential Equations

Solving Ordinary Differential Equations

Numerical solution of ODEs

Section 7.4 Runge-Kutta Methods

Chapter 6 - Ordinary Differential Equations

Ordinary Differential Equations II

Ordinary differential equation II

MTH 452/552 Homework 3

AN OVERVIEW. Numerical Methods for ODE Initial Value Problems. 1. One-step methods (Taylor series, Runge-Kutta)

Ordinary Differential Equations II

Modeling and Experimentation: Compound Pendulum

COSC 3361 Numerical Analysis I Ordinary Differential Equations (II) - Multistep methods

The Chemical Kinetics Time Step a detailed lecture. Andrew Conley ACOM Division

Do not turn over until you are told to do so by the Invigilator.

CHAPTER 5: Linear Multistep Methods

Graded Project #1. Part 1. Explicit Runge Kutta methods. Goals Differential Equations FMN130 Gustaf Söderlind and Carmen Arévalo

Chapter 5 Exercises. (a) Determine the best possible Lipschitz constant for this function over 2 u <. u (t) = log(u(t)), u(0) = 2.

HIGHER ORDER METHODS. There are two principal means to derive higher order methods. b j f(x n j,y n j )

Astrodynamics (AERO0024)

Math 128A Spring 2003 Week 12 Solutions

Lecture 4: Numerical solution of ordinary differential equations

Mathematics for chemical engineers. Numerical solution of ordinary differential equations

4 Stability analysis of finite-difference methods for ODEs

Integration of Ordinary Differential Equations

Linear Multistep Methods I: Adams and BDF Methods

Dynamic Systems. Simulation of. with MATLAB and Simulink. Harold Klee. Randal Allen SECOND EDITION. CRC Press. Taylor & Francis Group

Lecture 5: Single Step Methods

Ordinary Differential Equations I

8.1 Introduction. Consider the initial value problem (IVP):

The family of Runge Kutta methods with two intermediate evaluations is defined by

CS520: numerical ODEs (Ch.2)

Module 4: Numerical Methods for ODE. Michael Bader. Winter 2007/2008

Euler s Method, cont d

Efficient Simulation of Physical System Models Using Inlined Implicit Runge Kutta Algorithms

Numerical Methods for Differential Equations

4.4 Computing π, ln 2 and e

16.7 Multistep, Multivalue, and Predictor-Corrector Methods

S#ff ODEs and Systems of ODEs

Research Article Diagonally Implicit Block Backward Differentiation Formulas for Solving Ordinary Differential Equations

Numerical Algorithms for ODEs/DAEs (Transient Analysis)

EECS 700: Exam # 1 Tuesday, October 21, 2014

Applied Numerical Analysis

Solving PDEs with PGI CUDA Fortran Part 4: Initial value problems for ordinary differential equations

Math Numerical Analysis Homework #4 Due End of term. y = 2y t 3y2 t 3, 1 t 2, y(1) = 1. n=(b-a)/h+1; % the number of steps we need to take

2.29 Numerical Fluid Mechanics Fall 2011 Lecture 20

1 Ordinary Differential Equations

AM205: Assignment 3 (due 5 PM, October 20)

MULTIPOINT BOUNDARY VALUE PROBLEMS FOR ORDINARY DIFFERENTIAL EQUATIONS. Katalin Károlyi Department of Applied Analysis, Eötvös Loránd University

A Brief Introduction to Numerical Methods for Differential Equations

Initial value problems for ordinary differential equations

Numerical Methods for Engineers. and Scientists. Applications using MATLAB. An Introduction with. Vish- Subramaniam. Third Edition. Amos Gilat.

Review. Numerical Methods Lecture 22. Prof. Jinbo Bi CSE, UConn

Higher Order Taylor Methods

Advanced methods for ODEs and DAEs

Numerical Analysis. A Comprehensive Introduction. H. R. Schwarz University of Zürich Switzerland. with a contribution by

Computational Methods CMSC/AMSC/MAPL 460. Ordinary differential equations

AMS 27L LAB #8 Winter 2009

Numerical Methods for Initial Value Problems; Harmonic Oscillators

2 Numerical Methods for Initial Value Problems

Ordinary Differential Equations I

MATH2071: LAB 3: Implicit ODE methods

Numerical Methods for Initial Value Problems; Harmonic Oscillators

Do not turn over until you are told to do so by the Invigilator.

Exam in TMA4215 December 7th 2012

MATH 350: Introduction to Computational Mathematics

Advanced methods for ODEs and DAEs. Lecture 9: Multistep methods/ Differential algebraic equations

Differential Equations FMNN10 Graded Project #1 c G Söderlind 2017

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Initial Value Problems

Review for Exam 2 Ben Wang and Mark Styczynski

Finite Difference and Finite Element Methods

Stability regions of Runge-Kutta methods. Stephan Houben Eindhoven University of Technology

Transcription:

Modeling & Simulation 2018 Lecture 12. Simulations Claudio Altafini Automatic Control, ISY Linköping University, Sweden

Summary of lecture 7-11 1 / 32 Models of complex systems physical interconnections, not block diagrams supporting theory: bond graphs implementing language: modelica associated technical difficulty: DAE (lecture 11) Differentiation index Index = 1 easy Index 2 difficult Linear DAE-models, standard form Nonlinear DAE-models

Lecture 12. Numerical methods and simulations 2 / 32 Summary of today Overview of the different numerical methods for simulations Properties Accuracy Stability Variable step length Stiffness Methods for DAE In the book: Swedish: chapter 15 English: chapter 14

Standard formulation of a simulation problem 3 / 32 Given an ODE or a DAE: ẋ = f(x) F (ẋ, x) = 0 Numerical solution: assume you want to compute approximations of x at times 0 < t 1 < t 2 < t 3 < < t f. then your algorithm has to compute the values x 1, x 2, x 3,..., x f that approximate x(t 1 ), x(t 2 ), x(t 3 ),..., x(t f )

Euler forward method 4 / 32 The simplest methods are based on approximating the derivative with a finite difference: ẋ(t n ) x n+1 x n h the step length h is given by h = t n+1 t n If forward-difference and state space description are used then we have the (forward) Euler method: x n+1 = x n + hf(x n ) Leonhard Euler 1770

x Euler forward method: example 5 / 32 ODE Euler forward approximation ẋ = 10x x n+1 = x n + h ( 10x n ) = (1 10h)x n 1.2 1 0.8 cont h=0.01 h=0.05 h=0.1 0.6 0.4 0.2 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 time

Euler backward differences 6 / 32 differences can be taken also backwards ẋ(t n ) x n x n 1, h = t n t n 1 h When backward differences and state space models are used then one gets the Euler backward method x n = x n 1 + hf(t n, x n ) Backwards differences and DAE give F ( x n x n 1, x n, t n ) = 0 h Notice that this method requires solving a system of equations in x n

x Euler backward method: example ODE Euler backward approximation ẋ = 10x x n = x n 1 + h ( 10x n ) = 1 1 + 10h x n 1 7 / 32 1.2 1 0.8 cont h=0.01 h=0.05 h=0.1 0.6 0.4 0.2 0 0 0.2 0.4 0.6 0.8 1 1.2 time

General simulation method 8 / 32 More generally, given a simulation method for a state model of the type x n+1 = G(t n, x n k+1, x n k+2,..., x n, x n+1 ) k -step method: the new value of x is calculated from the previous k values of x Explicit method: G does not contain x n+1 Implicit method: G containing x n+1 Euler forward: explicit one-step method Euler backward: implicit one-step method

Why are there different approaches? 9 / 32 in matlab: many ODE solvers: ode45, ode23, ode113, ode15s, ode23s, ode23t, ode23tb examples of properties that must be handled Accuracy Complexity Stability Dealing with discontinuities Dealing with stiff systems Dealing with DAE which method is best depends on which property is considered the most interesting in a certain context

Accuracy 10 / 32 Global error E n = x(t n ) x n Can only be calculated exactly if the true solution is known exactly Local error = one-step error (provided all information from previous steps is exact); can often be calculated directly from the Taylor expansion Local error is typically proportional to h p+1 for some integer p: O(h p+1 ) Global error is then typically proportional to h p : O(h p ) number p is the order of the method Example: Euler method has the order 1

Stability The stability of the numerical simulation need not correspond to the stability of the underlying differential equation Example: Test equation 11 / 32 ẋ = λx, λ complex Stability region: Re(λ) < 0 Euler forward approximation x n+1 = (1 + hλ)x n Stability region of the Euler forward approximation: 1 + hλ < 1 The step size that can be selected is determined by both the accuracy and stability considerations

x Stability of Euler forward method: example ODE ẋ = 10x Euler forward approximation 12 / 32 x n+1 = x n + h ( 10x n ) = (1 10h)x n 1.5 1 0.5 h=0.01 h=0.08 h=0.2 h=0.21 0-0.5-1 -1.5 0 0.2 0.4 0.6 0.8 1 1.2 time When h > 0.2 solution grows unlimited

Stability of Euler backward method 13 / 32 Euler backward approximation: x n+1 = x n + hf(x n+1 ) Example: Test equation ẋ = λx, λ complex Stability region of the Euler backward approximation 1 hλ > 1 Stable systems can be simulated with arbitrary long step size without incurring in stability problems

x Stability of Euler backward method: example 14 / 32 ODE Euler backward approximation x n+1 = ẋ = 10x 1 1 + 10h x n 1.2 1 0.8 h=0.01 h=0.08 h=0.2 h=0.5 0.6 0.4 0.2 0 0 0.2 0.4 0.6 0.8 1 1.2 time stability is not lost when when h increases

Runge-Kutta-method 15 / 32 Idea: compute f at intermediate points k 1 = f(t n, x n ) k 2 = f(t n + h/2, x n + hk 1 /2) order = 2 x n+1 = x n + hk 2 A classical Runge-Kutta-method k 1 = f(t n, x n ) k 2 = f(t n + h/2, x n + hk 1 /2) k 3 = f(t n + h/2, x n + hk 2 /2)) k 4 = f(t n + h, x n + hk 3 ) x n+1 = x n + h(k 1 + 2k 2 + 2k 3 + k 4 )/6 order = 4

Adam s methods 16 / 32 general formula k x n = x n 1 + β j f n j f i = f(t i, x i ) j=0 explicit k-step Adams method k = 1 : x n = x n 1 + hf n 1 k = 2 : x n = x n 1 + h (3f n 1 f n 2 ) /2 k = 3 : x n = x n 1 + h (23f n 1 16f n 2 + 5f n 3 ) /12 k = 4 : x n = x n 1 + h (55f n 1 59f n 2 + 37f n 3 9f n 4 ) /24 order = k

Adam s methods 17 / 32 Implicit k-step Adams method k = 0 : x n = x n 1 + hf n k = 1 : x n = x n 1 + h (f n + f n 1 ) /2 k = 2 : x n = x n 1 + h (5f n + 8f n 1 f n 2 ) /12 k = 3 : x n = x n 1 + h (9f n + 19f n 1 5f n 2 + f n 3 ) /24 order = k + 1

Stability region for explicit Adams method 18 / 32 1.5 1 0.5 Im 0 k=1 k=2 k=3 k=4-0.5-1 -1.5-2.5-2 -1.5-1 -0.5 0 0.5 Re

Stability region for implicit Adams method 19 / 32 4 k=1 3 2 Im 1 0 k=2 k=3-1 -2-3 -4-6 -5-4 -3-2 -1 0 Re

Variable step length 20 / 32 Many modern methods use variable step length, to obtain the desired accuracy with minimum calculation work The following principles are often used the user specifies the desired local error the algorithm has a method to estimate the local error if the estimated local error is large h is reduced if the estimated local error is unnecessarily small h is increased Computing a suitable step length at each step requires performing extra calculations per step. It can anyway reduce the total amount of calculations because it reduces the total number of steps

Stiff differential equations 21 / 32 Stiffness: fast and slow dynamics in the same model Problem: The stability requirement could limit the step length more than the accuracy requirement Consequence: simulation can become very slow Methods for stiff problems - often implicit

Stiff differential equations: example 22 / 32 Example: ẋ = [ ] [ ] 10001 10000 2 x, x(0) = 1 0 1.0001 2 2 1.5 1.5 1 1 0.5 0.5 x 0 x 0 0.5 0.5 1 1 1.5 0 2 4 6 8 10 time 1.5 0 0.05 0.1 0.15 0.2 time

Differential-algebraic problem 23 / 32 F (ż, z, t) = 0 Simple idea: replace ż with backward difference zn zn 1 h This gives the equation F ( z n z n 1, z n, t n ) = 0 h to be solved at each iteration (often using Newton s method) More generally: one can replace ż with a higher order backward difference formula: k ż α i z n i i=0 where the coefficients α i are chosen so that the approximation error gows as O(h k+1 )

Index = 1 24 / 32 Let z(t) = z(t) + w(t) and let F (ż, z, t) = 0 have the linear approximation If 1. A has constant rank 2. (A, B) has index = 1 Aẇ + Bw = g(t) with A = F ż ( z, z, t), B = F z ( z, z, t) for all z, ż in a neighborhood of the current solution, = so does the backward difference method F ( k α i z n i, z n, t n ) = 0 i=0 for k < 7, and provides an accuracy O(h k )

Other methods 25 / 32 For DAE there are other methods for example implicit Runge-Kutta methods Also these work in principle straightforwardly for problems with index = 1 For problems with higher index, the numerical methods or the DAE structure must be modified before the problem is solved

ODE solvers in matlab 26 / 32 ode45: explicit Runge-Kutta; one-step solver ode23: explicit Runge-Kutta; one-step solver ode113: variable order Adams-Bashforth-Moulton solver; multistep solver ode15s: based on the numerical differentiation (or backward differentiation) formulas; multistep solver ode23s: based on a modified Rosenbrock formula of order 2; one-step solver ode23t: implementation of the trapezoidal rule; can solve DAEs ode23tb: implicit Runge-Kutta formula with a first stage that is a trapezoidal rule step and a second stage that is a backward differentiation formula of order two

ODE solvers in matlab 27 / 32

Final slides: Summary 28 / 32

Final slides: Lab 29 / 32 Lab 1: all reports due: October 9 (passed) peer review due: October 16 (tomorrow) revised report due: October 23 (next Tuesday) Lab 2 & 3: should be completed this week

Final slides: Exam time: 2015-10-29, kl. 14-18 place: ISY datorsalen (Egypten, Asgård, Olympen, maybe Southfork) MAI datorsalen (Roxen, Boren, only if needed) 30 / 32 Meeting point: corridor in front of Egypten/Asgård

Final slides: Exam Tips for exam: see webpage 31 / 32 Be there a few minutes in advance Login in: use the exam account (tentamenxxx) you find in the exam sheet When printing out: write your AID number on the page (so that the guards know who is printing) Computer part of the exam: normally Matlab + System Identification Toolbox

One more final slide 32 / 32 Exjobb thesis in Complex Networks How to control complex (technological, social, biological) networks?? how to study dynamics over social networks Exjobb thesis in Systems Biology Structure and organization of biological networks (metabolic networks, gene networks, drug-target network) Modeling signaling pathways For details, contact me (claudio.altafini@liu.se)

Thank you!! www.liu.se