Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.

Slides:



Advertisements
Similar presentations
Formal Computational Skills
Advertisements

Programming Tips: While Loops and Comparisons 1Daniel Baur / Numerical Methods for Chemical Engineerse Daniel Baur ETH Zurich, Institut für Chemie- und.
Boundary Value Problems and Partial Differential Equations (PDEs)
Chapter 6 Differential Equations
MATLAB EXAMPLES Initial-value problems
Fixed point iterations and solution of non-linear functions
Partial Differential Equations (PDEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / BVP and PDE Daniel Baur ETH Zurich, Institut für Chemie-
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Linear Regression 1Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Computational Methods in Physics PHYS 3437
Ordinary Differential Equations
Systems of Linear Equations
1cs542g-term Notes  Notes for last part of Oct 11 and all of Oct 12 lecture online now  Another extra class this Friday 1-2pm.
1cs542g-term Notes  Even if you’re not registered (not handing in assignment 1) send me an to be added to a class list.
Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE.
Constrained Fitting Calculation the rate constants for a consecutive reaction with known spectrum of the reactant A = (A A + A B + A C ) + R = C E T =
Initial-Value Problems
Dynamical Systems Analysis II: Evaluating Stability, Eigenvalues By Peter Woolf University of Michigan Michigan Chemical Process Dynamics.
Efficient Simulation of Physical System Models Using Inlined Implicit Runge-Kutta Algorithms Vicha Treeaporn Department of Electrical & Computer Engineering.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Chapter 16 Integration of Ordinary Differential Equations.
Ordinary Differential Equations (ODEs)
Differential Equations and Boundary Value Problems
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Solving ODEs UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
MATH 685/ CSI 700/ OR 682 Lecture Notes Lecture 10. Ordinary differential equations. Initial value problems.
Fin500J Topic 7Fall 2010 Olin Business School 1 Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential.
Numerical Solutions to ODEs Nancy Griffeth January 14, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis.
Professor Walter W. Olson Department of Mechanical, Industrial and Manufacturing Engineering University of Toledo Solving ODE.
Ch 8.1 Numerical Methods: The Euler or Tangent Line Method
Boyce/DiPrima 9th ed, Ch 8.4: Multistep Methods Elementary Differential Equations and Boundary Value Problems, 9th edition, by William E. Boyce and Richard.
Systems of Linear Equations Iterative Methods
Erin Catto Blizzard Entertainment Numerical Integration.
EE3561_Unit 8Al-Dhaifallah14351 EE 3561 : Computational Methods Unit 8 Solution of Ordinary Differential Equations Lesson 3: Midpoint and Heun’s Predictor.
ME451 Kinematics and Dynamics of Machine Systems
Boundary Value Problems and Least Squares Minimization
1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Integration of 3-body encounter. Figure taken from
6. Introduction to Spectral method. Finite difference method – approximate a function locally using lower order interpolating polynomials. Spectral method.
Numerical Methods for Solving ODEs Euler Method. Ordinary Differential Equations  A differential equation is an equation in which includes derivatives.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Beginning Programming for Engineers
Numerical Differentiation and Quadrature (Integration)
Solution of Nonlinear Functions
Large Timestep Issues Lecture 12 Alessandra Nardi Thanks to Prof. Sangiovanni, Prof. Newton, Prof. White, Deepak Ramaswamy, Michal Rewienski, and Karen.
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 7 - Chapter 25.
Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Please remember: When you me, do it to Please type “numerical-15” at the beginning of the subject line Do not reply to my gmail,
ME451 Kinematics and Dynamics of Machine Systems Numerical Integration. Stiffness: Implicit Methods. October 30, 2013 Radu Serban University of Wisconsin-Madison.
Dr. Mujahed AlDhaifallah ( Term 342)
Lecture 40 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
ECE 576 – Power System Dynamics and Stability Prof. Tom Overbye Dept. of Electrical and Computer Engineering University of Illinois at Urbana-Champaign.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
1/14  5.2 Euler’s Method Compute the approximations of y(t) at a set of ( usually equally-spaced ) mesh points a = t 0 < t 1
Lecture 39 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Ordinary Differential Equations
ECE 576 – Power System Dynamics and Stability
Class Notes 18: Numerical Methods (1/2)
Class Notes 19: Numerical Methods (2/2)
Sec:25.3 RUNGE-KUTTA METHODS.
Sec:5.4 RUNGE-KUTTA METHODS.
Numerical Analysis Lecture 37.
MATH 175: Numerical Analysis II
Chapter 2 A Survey of Simple Methods and Tools
Presentation transcript:

Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F128 – Zürich

Problem Definition  We are going to look at initial value problems of explicit ODE systems, which means that they can be cast in the following form 2Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Higher Order ODEs  Higher order explicit ODEs can be cast into the first order form by using the following «trick»  Therefore, a system of ODEs of order n can be reduced to first order by adding n-1 variables and equations 3Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Autonomous Systems  A system is called autonomous if the independent variable (t) does not explicitly appear in the system  It is always possible to transform a non-autonomous system into an autonomous one 4Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Example: A 1-D First Order ODE  Consider the following initial value problem  This ODE and its solution follow a general form (Johann Bernoulli, Basel, 17 th – 18 th century) 5Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Numerical Solution of a 1-D First Order ODE  Since we know the first derivative, Taylor expansion suggests itself as a first approach  This is known as the Euler method, named after Leonhard Euler (Basel, 18 th century) 6Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Some Nomenclature  On the next slides, the following notation will be used 7Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Categorization of Algorithms  One step integration algorithms:  Multi-step integration algorithms:  Explicit integration algorithms:  Implicit integration algorithms: 8Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Accuracy of Integration Algorithms  The local error is always proportional to a known power of the integration step  An algorithm is of order p if it can correctly integrate a polynomial of order p  An algorithm of order p always has a local error in the order of h p+1  An algorithm is called convergent if for h  0 the global error decreases (assuming there are no rounding errors) 9Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Examples  Forward Euler Algorithm  Explicit Runge-Kutta (p = 2) 10Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers h = 0.01 h = 0.1 h = 0.2 Error at t = 1 (h = 0.01) Euler Forward: 1.72% RK (p=2): 0.01% h = 0.01 h = 0.2

Conditioning of the Problem  A system of ODEs is called well conditioned if a small error in the function (e.g. parameters) and/or in the initial conditions generate a small error in the solution (without rounding errors!)  Example of perturbations / errors: 11Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers The conditioning of a problem has nothing to do with the stability of an algorithm!

Example of Bad Conditioning  Consider the ODE  The general solution reads  If the initial condition y(0) = 1 applies, the constant is 0  On the other hand, if y(0) = , the solution reads 12Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Examples for Conditioning  Consider these initial value problems  They all have the same solution  But if we perturb the initial condition (y(0) = ) 13Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Measuring the Conditioning  We can tell a priori if a system is ill conditioned: If all the eigenvalues of the Jacobian of a system of ODEs have a positive real part, then the system is ill conditioned. 14Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Stability of the Algorithms  The Forward Euler algorithm is stable only if where κ is the amplification factor  Therefore 1.If f y > 0 (the ODE is ill conditioned)  |κ| > 1 for h > 0 2.If f y < 0 (the ODE is well conditioned)  |κ| < 1 but only if 15Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Stability and Precision  When dealing with ODE systems, it is common practice to reduce the problem of stability to the ODE where λ max is the largest eigenvalue of the Jacobian of the system. Note that eigenvalues are typically complex.  For example, take a look at the Forward Euler method  The method is stable if  The local error of the method is  With the maximum step size 16Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Explicit Runge-Kutta Methods  A very commonly used method is RK with p = 4  Advantages  RK is typically efficient and requires small memory  It is easy to change the integration step  Disadvantages  Efficiency is lower than multi-step methods  It is difficult to evaluate the local error 17Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Multi-Step Algorithms  Multi-step methods use not only the current function value y n to compute the next value y n+1, but also function values at previous times (y n-1,...)  One example are the Adams-Bashforth methods (here p = 3)  At the start of the integration, only y 0 is known, therefore we have to use some other method to calculate y 1 and y 2 to get the algorithm started (for example the Euler method) 18Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Multi-Step Algorithms (Continued)  Advatanges  Typically very efficient  Integration step is easy to change  Error estimation is simple  Order of the method is easily changed  It is easy to compute y(t) outside the grid points  Usually, fewer function evaluations are required  ODEs with a non-identity mass matrix A are easily solved 19Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Stiff Problems  A problem is considered stiff if e.g. the following apply:  A linear constant coefficient system is stiff if all of its eigenvalues have a negative real part and the stiffness ratio is large  Stability requirements, rather than accuracy considerations, constrain the step length  Some components of the solution show much faster dynamics than others  Explicit solvers require an impracticably small h to insure stability, therefore implicit solvers are preferred  This requires solving large (non-)linear algebraic systems, which will be addressed in a later excercise 20Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

How does Matlab do it? Non-Stiff Solvers  ode45  ode45 : Most general solver, best to try first; Uses an explicit Runge-Kutta pair (Dormand-Prince, p = 4 and 5)  ode23ode45  ode23 : More efficient than ode45 at crude tolerances, better with moderate stiffness; Uses an explicit Runge- Kutta pair (Bogacki-Shampine, p = 2 and 3).  ode113  ode113 : Better at stringent tolerances and when the ODE function file is very expensive to evaluate; Uses a variable order Adams-Bashforth-Moulton method 21Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

How does Matlab do it? Stiff Solvers  ode15sode45  ode15s : Use this if ode45 fails or is very inefficient and you suspect that the problem is stiff; Uses multi-step numerical differentiation formulas (approximates the derivative in the next point by extrapolation from the previous points)  ode23sode15s  ode23s may be more efficient than ode15s at crude tolerances and for some problems (especially if there are largely different time-scales / dynamics involved); Uses a modified Rosenbrock formula of order 2 (one-step method) 22Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Matlab Syntax Hints [T, Y] = tspan, y0, …);  All ODE-solvers use the syntax [T, Y] = tspan, y0, …);  ode_fun is a function handle taking two inputs, a scalar t (current time point) and a vector y (current function values), and returning as output a vector of the derivatives dy/dt in these points  tspan is either a two component vector [tstart, tend] or a vector of time points where the solution is needed [tstart, t1, t2,...]  y0 are the values of y at tstart f_new y, k, p);  Use parametrizing functions to pass more arguments to ode_fun if needed f_new y, k, p);  This can be done directly in the solver call  [T, Y] = y, k, p), tspan, y0); 23Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Exercise  Consider a batch reactor where these reactions take place 24Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Assignment 1.Using the following values  k 1 = 1; k 2 = 10; A 0 = 1; B 0 = 0  Find the Jacobian of the system. Which are the eigenvalues of the Jacobian? Is the system well conditioned? ode45  Use ode45 to solve system. Find the time where 99% of A has been consumed and use this as the final integration time. Plot the results. 2.Find online templates for the Forward Euler method and the RK method of order 4. ode45 ode45  Add the necessary lines to calculate a step, using the formulas on slides 10 (Euler) and 17 (RK4). Which step size h is needed to have a maximum error of 1% compared to ode45 at the end of the integration? What stepsize was used by ode45 ? ode45 3.Now change A 0 = 0.9; B 0 = 0.2; k 2 = 1e5 and try ode45 again. What happened? What can you do to resolve this issue? Plot the resulting concentration profiles. 25Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers