A First Course on Kinetics and Reaction Engineering Supplemental Unit S5. Solving Initial Value Differential Equations

Similar documents
A First Course on Kinetics and Reaction Engineering Supplemental Unit S4. Numerically Fitting Models to Data

A First Course on Kinetics and Reaction Engineering Example 26.3

A First Course on Kinetics and Reaction Engineering Unit 19. Analysis of Batch Reactors

A First Course on Kinetics and Reaction Engineering Example 23.1

A First Course on Kinetics and Reaction Engineering Example 30.1

A First Course on Kinetics and Reaction Engineering Example S5.1

A First Course on Kinetics and Reaction Engineering Example 38.2

Delay Differential Equations with Constant Lags

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

A First Course on Kinetics and Reaction Engineering Unit 33. Axial Dispersion Model

A First Course on Kinetics and Reaction Engineering Example S6.2

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

Computational Techniques Prof. Dr. Niket Kaisare Department of Chemical Engineering Indian Institute of Technology, Madras

A First Course on Kinetics and Reaction Engineering Example 29.3

NUMERICAL SOLUTION OF ODE IVPs. Overview

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Initial value problems for ordinary 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.

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

A First Course on Kinetics and Reaction Engineering Example 38.1

A First Course on Kinetics and Reaction Engineering Example 15.4

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Chapter 9 Implicit Methods for Linear and Nonlinear Systems of ODEs

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

A First Course on Kinetics and Reaction Engineering Unit 22. Analysis of Steady State CSTRs

Chapter 6 - Ordinary Differential Equations

A First Course on Kinetics and Reaction Engineering Example 33.1

Chapter 9b: Numerical Methods for Calculus and Differential Equations. Initial-Value Problems Euler Method Time-Step Independence MATLAB ODE Solvers

MECH : a Primer for Matlab s ode suite of functions

Computational Techniques Prof. Dr. Niket Kaisare Department of Chemical Engineering Indian Institute of Technology, Madras

Ordinary Differential Equations. Monday, October 10, 11

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

AMS 27L LAB #8 Winter 2009

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

A First Course on Kinetics and Reaction Engineering Example 33.2

Physics 584 Computational Methods

Excel for Scientists and Engineers Numerical Method s. E. Joseph Billo

Scientific Computing: An Introductory Survey

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

Numerical Integration of Ordinary Differential Equations for Initial Value Problems

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

Modeling and Experimentation: Compound Pendulum

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

Ph 22.1 Return of the ODEs: higher-order methods

Physically Based Modeling: Principles and Practice Differential Equation Basics

Computer lab for MAN460

Physically Based Modeling Differential Equation Basics

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

LECTURES 4/5: SYSTEMS OF LINEAR EQUATIONS

A First Course on Kinetics and Reaction Engineering Unit D and 3-D Tubular Reactor Models

Chap. 20: Initial-Value Problems

Fourth Order RK-Method

Numerical Methods for the Solution of Differential Equations

Solving systems of ODEs with Matlab

Manifesto on Numerical Integration of Equations of Motion Using Matlab

Remark on the Sensitivity of Simulated Solutions of the Nonlinear Dynamical System to the Used Numerical Method

Mechanics of Structures (CE130N) Lab 3

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

Modeling Basics: 4. Numerical ODE Solving In Excel 5. Solving ODEs in Mathematica

Section 7.4 Runge-Kutta Methods

2 Ordinary Differential Equations: Initial Value Problems

1 Overview of Simulink. 2 State-space equations

A First Course on Kinetics and Reaction Engineering Example S3.1

24, B = 59 24, A = 55

16.7 Multistep, Multivalue, and Predictor-Corrector Methods

Consistency and Convergence

Quantitative Understanding in Biology Module IV: ODEs Lecture I: Introduction to ODEs

Numerical Methods I Solving Nonlinear Equations

A First Course on Kinetics and Reaction Engineering Example 15.2

FORTRAN 77 Lesson 7. Reese Haywood Ayan Paul

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill

Mini project ODE, TANA22

Chapter 11 ORDINARY DIFFERENTIAL EQUATIONS

MATLAB Ordinary Differential Equation (ODE) solver for a simple example 1. Introduction

ODE Runge-Kutta methods

Multistep Methods for IVPs. t 0 < t < T

Numerical Solution of ODE IVPs

A First Course on Kinetics and Reaction Engineering Unit 4. Reaction Rates and Temperature Effects

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

Iterative Methods for Solving A x = b

ENGI9496 Lecture Notes State-Space Equation Generation

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

Multistage Methods I: Runge-Kutta Methods

Solution: (a) Before opening the parachute, the differential equation is given by: dv dt. = v. v(0) = 0

REVIEW: The Matching Method Algorithm

Quantitative Understanding in Biology Module IV: ODEs Lecture I: Introduction to ODEs

Lecture 17: Ordinary Differential Equation II. First Order (continued)

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

First In-Class Exam Solutions Math 246, Professor David Levermore Thursday, 20 September 2018

Differential Equations

ACM/CMS 107 Linear Analysis & Applications Fall 2016 Assignment 4: Linear ODEs and Control Theory Due: 5th December 2016

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

Math 252 Fall 2002 Supplement on Euler s Method

Part 1. The diffusion equation

University of Alberta ENGM 541: Modeling and Simulation of Engineering Systems Laboratory #5

Quantitative Techniques (Finance) 203. Polynomial Functions

Ordinary Differential Equation Introduction and Preliminaries

CDS 101 Precourse Phase Plane Analysis and Stability

INTRODUCTION TO COMPUTER METHODS FOR O.D.E.

Transcription:

Supplemental Unit S5. Solving Initial Value Differential Equations Defining the Problem This supplemental unit describes how to solve a set of initial value ordinary differential equations (ODEs) numerically. The equations must be of the form shown in equation (1), or using matrix notation as in equation (2). Notice, in particular that there are no partial derivatives in the equations, only ordinary first derivatives. All of the derivatives are taken with respect to the same independent variable, represented here as t. It is essential that the boundary conditions are specified at the same value of the independent variable, denoted here as t. The latter requirement is what distinguishes these as initial value ODEs, and in this situation, the boundary conditions are usually referred to as initial conditions. Often the value of t is zero, but this is not required. 1 = f t,z 1(,z,!,z 1 2 n ); z 1 t 2 ( ) = z 1 = f 2 ( t,z 1,z 2,!,z n ); z 2 ( t ) = z 2 " (1) n = f n ( t,z 1,z 2,!,z n ); z n ( t ) = z n = f t, z ( ) (2) Information and Data Required for Numerical Solution To numerically solve a system of initial value ODEs like those in equation (1) or (2), you will need to use mathematics software that provides an appropriate ODE solver. Irrespective of the particular brand of software you use, you typically will need to provide three things as input to that software: the initial values of the independent and dependent variables: t and z(t) the final value of either the independent variable or one of the dependent variables code that evaluates each of the derivatives given a value for the independent variable and values for each of the dependent variables At the minimum, the software will return the final values of the independent and dependent variables that were not specified. In many cases the software will return sets of values of the independent and dependent variables spanning the range from the initial values to the final values. The latter information is quite useful if you want to make a plot, for example of one or more dependent variables as a function of the independent variable. Copyright 214, Carl R. F. Lund

Overview of the Numerical Method Recall that when an ODE is solved analytically, the solution is an expression for the functional dependence of the dependent variable upon the independent variable. The analytical solution to a first order ODE always contains an unknown constant. For example, consider equation (3) where k is a known constant. The solution is given in equation (4), and equation (4) contains the additional constant C which did not appear in the original ODE. The value of this constant is determined using the initial condition. When a set of ODEs is solved numerically, the solution usually takes the form of a table of values of the independent variable and the corresponding values of the dependent variables. Thus, a numerical solution of equation (3) would consist of pairs of values of t and the corresponding value of z. = kz (3) z = C exp( kt) (4) ODEs like those considered here are solved numerically by starting at the initial value of the independent t because at this point the values of the dependent variables are known. A very small incremental change of t from t to t + h is then considered, where h is a small incremental change in the independent variable sometimes referred to as the step size. I will illustrate here using a single ODE, equation (5), but extending the approach to multiple ODEs is straightforward. Within the interval from t to t + h, the unknown z is approximated as some convenient mathematical function of t. Here I will illustrate by approximating z as a linear function of t, but other convenient mathematical forms can also be used. Approximating z as a linear function of t within the interval from t to t + h gives equation (5). The objective is to solve equation (6) to find the value of z at t = t + h. The value of z at t = t is known and the size of the incremental change, h, can be chosen (as long as it is small). However, a value for the slope, m, is also needed. If z truly was a linear function of t, the slope would be equal to the derivative of z with respect to t, equation (6), and that derivative would be a constant. In reality, however, the derivative of z with respect to t is not constant across the interval h, but it varies according to equation (7), which is the ODE being solved. In order to approximate z as a linear function of t in the interval of t from t to t + h a single value has to be chosen for the slope, m. z( t + h) = z( t ) + mh (5) m = (6) = f t,z ( ) (7) The easiest, and perhaps most obvious, choice for a value of m is to evaluate the derivative at t = t using equation (5). Since the value of z is known at t = t, the value of the derivative can be computed AFCoKaRE, Supplemental Unit S5 2

from equation (7) and substituted into equation (5) for the slope, m. Equation (5) can then be solved directly for the value of z at t = t + h. That approach is sometimes used; it is known as the explicit Euler method. The problem with the explicit Euler method is that it isn t very accurate unless the increment h is very, very small. Making the increment very, very small can lead to other problems. For that reason, it is preferable to approximate the slope m in a different way. An alternative choice for a value of m is to evaluate the derivative at t = t + h as shown in equation (8). Equation (8) cannot be solved directly for the value of the slope, m, however because the value of z at t = t + h is not known. Instead, it is necessary to solve equations (5) and (8) simultaneously. This approach is known as the implicit Euler method. It is more accurate than the explicit Euler method and eliminates many of its problems. There are situations, however, where the implicit Euler method is not accurate. These will be discussed later. The key point, for present purposes, is that the implicit Euler process allows solution of the ODEs numerically. Once the value of z at t = t + h has been found, the resulting point becomes the new initial condition. Thus, the process can be repeated over and over, producing pairs of values of t and z over any desired range. That is, the process can be repeated over and over until either t or z reaches some desired final value. m = t=t +h = f ( z( t + h),t + h) (8) There are many different variations of the approach described here. They differ with respect to the mathematical form of the function that is used to approximate z in the interval interval of t from t to t + h and in the way that the slope (or its equivalent when non-linear approximating functions are used) is estimated. A very popular method is the Runge-Kutta method. It gives an accuracy that is comparable to a fourth order polynomial approximating function by using a weighted average of several different approximations of the slope. Those who are interested in other numerical approaches are encouraged to take a course on the topic or consult a good textbook. The purpose here is just to provide a basic understanding of how these methods work. It was noted earlier that sometimes the implicit Euler method is not sufficiently accurate. The same can be true of the Runge-Kutta method. The problem arises when solving sets of ODEs. In essence it occurs when one of the functions changes very abruptly over a very small range of the independent variable and the changes in that function significantly affect the changes in other functions over a much larger range of the independent variable. Equations like this are called stiff ODEs, and they require special treatment of the interval size, h. A full discussion goes beyond the intended scope of this supplemental unit. When solving sets of ODEs, one should pay attention to whether any of the dependent variables change very abruptly as the independent variable changes, and if they do, it is probably advisable to check the solution obtained by repeating the solution using a different numerical method that is specifically tailored to stiff ODEs. AFCoKaRE, Supplemental Unit S5 3

MATLAB Template Files MATLAB includes a built in function named ode45 that implements the Runge-Kutta version of the approach described above, and it also includes a built in function named ode15s that is designed to handle stiff sets of ODEs. In both cases, the built in functions must be provided with the name of a subroutine (written by the user) that takes t and a vector z and uses them to compute and return the functions, f, in equation (1) as a column vector. The built in ODE solvers also must be given initial and final values of the independent variable and initial values of the dependent variables. There are many options that can be set when using these ODE solvers, and you should read the MATLAB documentation to learn what is available. One option that is commonly needed is to set a stopping criterion other than reaching the final value of the independent variable provided as an argument to the ODE solver. It is quite common to need to solve a set of initial value ODEs under conditions where you know the initial values of the independent and dependent variables, but instead of knowing the final value of the independent variable, you know the final value of one of the dependent variables and you want to calculate the corresponding value of the independent variable. For example, consider equation (3). Given the initial values of z and t, one might know the final value of t and be asked to calculate the corresponding final value of z, or, one might know the final value of z and be asked to calculate the value of t. When using the MATLAB ODE solvers, you always need to pass initial and final values for the independent variable, even if the final value is one of the quantities you are trying to solve for. What one does in this case is to provide a very large number for the final value of the independent variable, and then set an option to use a second termination criterion. The second termination criterion is set using a built in function named odeset, and when you do so, you must provide the name of a function (again written by the user) that takes t and z as arguments. I m not going to go into the details here, but one quantity that this function must return is a scalar, and when that scalar reaches zero, the ODE solver terminates. Thus, if you want the ODE solver to stop when z3 reaches some known final value, z3f, you would set this scalar equal to z3 - z3f. A critical aspect of this is that z3 must reach z3f before t reaches the final value passed to the ODE solver. That is why you give a very large number as the final value of the independent variable. When the ODE solver returns the results, you always need to check to see whether t reached the final value passed to the ODE solver. If it did, then you need to repeat the solution using a higher number for the final value of the independent variable until the solver stops without reaching that value. Using the MATLAB ODE solvers is not particularly difficult, but it does require care to set all the arguments and function calls properly. This can be distracting if you are required to do it every time you solve a set of initial value ODEs. Therefore, two MATLAB template files named SolvIVDifII.m and SolvIVDifD.m are provided with this supplemental unit. The names are intended as mnemonic for Solve Initial Value Differential equations. SolvIVDifI.m is used when you know the final value of the independent AFCoKaRE, Supplemental Unit S5 4

(hence the final I in the name) variable while SolvIVDifD.m is used when you know the final value of one of the dependent variables (and hence the final D in the name). These template files handle most of the programming details so that you can focus on the kinetics and reaction engineering aspects of the problems you solve, and not on computer programming. The template files do require some modifications each time they are used. Set of step-by-step instructions for making these modifications for each of the template files are provided with this supplemental unit. Example S5.1 illustrates how to modify and use the SolvIVDifI.m to solve a problem where the final value of the independent variable is known, and Example S5.2 illustrates how to modify and use SolvIVDifD.m when the final value of one of the dependent variables is known. AFCoKaRE, Supplemental Unit S5 5