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

Slides:



Advertisements
Similar presentations
Lecture on Numerical Analysis Dr.-Ing. Michael Dumbser
Advertisements

Formal Computational Skills
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
Differential Equations Math Review with Matlab: Finding Solutions to Differential Equations S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department.
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,
Mechatronics 1 Weeks 5,6, & 7. Learning Outcomes By the end of week 5-7 session, students will understand the dynamics of industrial robots.
Integration Techniques
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.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 2 : Dynamics & Numerical Methods Goal : To write a simple physics simulation Topics: Intro.
Linear Systems of Equations Ax = b Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und Bioingenieurwissenschaften ETH Hönggerberg/
Manipulator Dynamics Amirkabir University of Technology Computer Engineering & Information Technology Department.
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)
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.
Numerical Solution of Ordinary Differential Equation
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.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
In the previous two sections, we focused on finding solutions to differential equations. However, most differential equations cannot be solved explicitly.
Numerical Solutions to ODEs Nancy Griffeth January 14, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis.
Ch 8.1 Numerical Methods: The Euler or Tangent Line Method
Lecture 35 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
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.
Boundary Value Problems and Least Squares Minimization
Numerical Integration and Rigid Body Dynamics for Potential Field Planners David Johnson.
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Integration of 3-body encounter. Figure taken from
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 12.
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)
BEH.420 Matlab Tutorial Bambang Adiwijaya 09/20/01.
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.
© Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed.
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.
Intro to Simulink April 15, Copyright , Andy Packard. This work is licensed under the Creative Commons.
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,
Part 6 Chapter 21 Adaptive Methods and Stiff Systems PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
ME451 Kinematics and Dynamics of Machine Systems Numerical Integration. Stiffness: Implicit Methods. October 30, 2013 Radu Serban University of Wisconsin-Madison.
ME451 Kinematics and Dynamics of Machine Systems Dealing with Differential Equations ~ A Numerical Approach ~ March 12, 2009 © Dan Negrut, 2009 ME451,
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.
Intro to Simulink Modified by Gary Balas 20 Feb 2011 Copyright , Andy Packard. This work is licensed under.
Lecture 39 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
Sec 232: The coefficient tableau 2ed order RK method Expand all f around (x,y) using Taylor expansion in 2d and then choose constants such that the equation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Nonlinear Regression 1Michael Sokolov / Numerical Methods for Chemical Engineers / Nonlinear Regression Michael Sokolov ETH Zurich, Institut für Chemie-
Engineering Problem Solution
Numerical Methods by Dr. Laila Fouad.
Sec:25.3 RUNGE-KUTTA METHODS.
Sec:5.4 RUNGE-KUTTA METHODS.
Numerical Analysis Lecture 37.
Numerical Analysis Lecture 38.
Presentation transcript:

Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F135 – 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 2Michael Sokolov / 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  Example: 3Michael Sokolov / 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) 4Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Some Nomenclature  On the next slides, the following notation will be used 5Michael Sokolov / 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 forward / explicite Euler method, named after Leonhard Euler (Basel, 18 th century) 6Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Definition of an implicit algorithm  In an implicit algorithm, the function value at the next step appears on the right hand side of the step equation:  A simple example is the backward / implicit Euler method:  A system of equations has to be solved at every iteration step; Why even use implicit algorithms? 7Daniel Baur / Numerical Methods for Chemical Engineers / Implicit 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 8Michael Sokolov / 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) 9Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Matlab Syntax Hints [T, Y] = ode45(ode_fun, tspan, y0, …);  All ODE-solvers use the syntax [T, Y] = ode45(ode_fun, 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); 10Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Assigment 1: Radioactive decay  A decaying radioactive element changes its concentration according to the ODE where k is the decay constant  The analytical solution to this problem reads 11Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Assignment 1 1.Plot the behavior of the radioactive decay problem as a vector field in the y vs t plane  Find online the function vector_field.m. It plots the solutions and derivatives of first order IVPs for different initial conditions  Plot the vector field for different initial values between 0 and 1, time between 0 and 2 and k = 1. Can you see what a solver has to do?  Is it possible to switch from one trajectory in the vector field to another? What follows for the uniqueness of the solutions? 2.The forward Euler method reads for this problem ynp = Forward_stepper(k, yn, h)  First define a function defining the successor of y n with a header like function ynp = Forward_stepper(k, yn, h) function [T,Y] =  Use the conditions y0 = 1, k = 1 and h = 0.1 to solve the radioactive decay problem from t0 = 0 to tEnd = 10 by defining an integrating function of the form function [T,Y] = 12Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

13Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers 3.The backward Euler algorithm uses the following step formula  Rearrange this equation so that you can define a function defining the successor of y n with a header like function ynp = Backward_stepper(k, yn, h) ynp = Backward_stepper(k, yn, h)  Use the prior defined integration function to solve the problem with the backward method. 4.Plot the obtained solutions comparing them to the analytical solution. Use the subplot method to produce two subplots in a single figure. What happens if you increase the step size h? What happens if you increase the step size above 2? 5.Plot the global error (error at tEnd) for both methods as a function of the stepsize with h = logspace(-4,0,10) in a double logarithmic plot ( loglog ). Assignment 1 (cont’d)

Assigment 2: System of ODEs Problem: The analytical solution to this problem reads 14Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers

Assigment 2: System of ODEs 15Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers 1.Solve the problem numerically using  x = 0:1/N:1 with a reasonably large N  y0 = [4;13;1]  A function using the matrix A with a header like function dy = func(x,y,A)  A forward Euler method suitable for vectors y with a header like function [t,y] = eulerForward(f, x0, xEnd, y0, N) 2.Determine and plot the global error using  N = 2.^(0:12)  The built-in function expm in Matlab to determine the analytical solution  The function norm to calculate the error and a double logarithmic plot ( loglog )

Assigment 3: Dampened harmonic oscillator  A mass on a spring is subject to a force when out of equilibrium  According to Newton’s second law (including friction), the resulting movement follows the solution to an ODE: 16Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers m y F Spring force Friction

Assignment 3 1.Rewrite the motion equation for the dampened harmonic oscillator as an explicit, first order ODE system 2.Use ode45 to solve the problem  Set up a function file to calculate the derivatives, its header should read something like function dy = harm_osc(t, y, m, k, a)  Use m = 1; k = 10; a = 0.5; y0 = 1; dy/dt0 = 0; tSpan = [0, 20];  Plot against time : (1) the position of the mass y, (2) the speed of the mass, (3) the kinetic energy of the mass, (4) the potential energy of the mass 17Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers