ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab

Similar documents
Euler s Methods (a family of Runge- Ku9a methods)

Module1: Numerical Solution of Ordinary Differential Equations. Lecture 6. Higher order Runge Kutta Methods

over The idea is to construct an algorithm to solve the IVP ODE (9.1)

over The idea is to construct an algorithm to solve the IVP ODE (8.1)

LAB #8 Numerical Methods

MATH2071: LAB 2: Explicit ODE methods

A Study on Numerical Exact Solution of Euler, Improved Euler and Runge - Kutta Method

Ordinary differential equations solving methods

=.1( sin(2πx/24) y) y(0) = 70.

Module 2: Single Step Methods Lecture 4: The Euler Method. The Lecture Contains: The Euler Method. Euler's Method (Analytical Interpretations)

Workpackage 5 - Ordinary Differential Equations

Review Initial Value Problems Euler s Method Summary

4 Visualization and. Approximation

ODEs occur quite often in physics and astrophysics: Wave Equation in 1-D stellar structure equations hydrostatic equation in atmospheres orbits

Mathematical Methods and Modeling Laboratory class. Numerical Integration of Ordinary Differential Equations

Application 2.4 Implementing Euler's Method

Euler s Method for Approximating Solution Curves

ODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable:

dy = dx y dx Project 1 Consider the following differential equations: I. xy II. III.

Homework Set 5 (Sections )

METU Mechanical Engineering Department ME 582 Finite Element Analysis in Thermofluids Spring 2018 (Dr. C. Sert) Handout 12 COMSOL 1 Tutorial 3

Homework Set #2-3, Math 475B

Ordinary Differential Equations

Application 7.6A The Runge-Kutta Method for 2-Dimensional Systems

Basic MATLAB. Getting MATLAB (for MIT students) Creating matrices and vectors. Some operation of matrices/vectors.

37 Self-Assessment. 38 Two-stage Runge-Kutta Methods. Chapter 10 Runge Kutta Methods

A parameter corresponding to the symmetry of the problem. m can be slab = 0, cylindrical = 1, or spherical = 2.

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

Post Processing, Visualization, and Sample Output

Direction Fields; Euler s Method

Simulation in Computer Graphics. Particles. Matthias Teschner. Computer Science Department University of Freiburg

Data Visualization. Fall 2017

Lecture 8: Euler s Methods

Numerical Modelling in Fortran: day 3. Paul Tackley, 2017

2.9 Linear Approximations and Differentials

Differential Equations (92.236) Listing of Matlab Lab Exercises

Approximate Solutions to Differential Equations Slope Fields (graphical) and Euler s Method (numeric) by Dave Slomer

Finite difference methods

The listing says y(1) = How did the computer know this?

Runge Kutta Methods Optimized For Advection Problems

CS205b/CME306. Lecture 9

Jason Yalim. Here we perform a few tasks to ensure a clean working environment for our script.

Introduction to Simulink

RK4. Version 3.0. (updated 12/1/2006) 2001, 2005, 2006 Tomas Co. Michigan Technological University Houghton, MI 49931

Physics Tutorial 2: Numerical Integration Methods

CODE-GENERATION FOR DIFFERENTIAL EQUATION SOLVERS

Vector Field Visualization: Introduction

Exercises for a Numerical Methods Course

During the timed portion for Part A, you may work only on the problems in Part A.

Exact equations are first order DEs of the form M(x, y) + N(x, y) y' = 0 for which we can find a function f(x, φ(x)) so that

Goals for This Lecture:

A First Course on Kinetics and Reaction Engineering Example S4.5

An Introduction to Flow Visualization (1) Christoph Garth

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Math 104: Euler s Method and Applications of ODEs

Introduction to Scientific Computing Lecture 8

P1 REVISION EXERCISE: 1

Modelling and Simulation for Engineers


COMPUTING AND DATA ANALYSIS WITH EXCEL. Numerical integration techniques

Mathematics for chemical engineers

Lecture 10: Simulink. What is Simulink?

THE TANGENT PLANE 6.1 INTRODUCTION TO THE TANGENT PLANE CHAPTER 6:

User-Defined Function

Numerical Solutions of Differential Equations (1)

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

Lectures & Excercises

Chapter 3 Limits and Derivative Concepts

The Jello Cube Assignment 1, CSCI 520. Jernej Barbic, USC

Math 225 Scientific Computing II Outline of Lectures

Good luck! First name Legi number Computer slabhg Points

Teaching Engineering Analysis Using VBA for Excel. Abstract. Introduction

Numerical Methods in Engineering Sciences

Computer Simulations

4.7 Approximate Integration

Introduction to Matlab. SAMSI Undergraduate Workshop May 15, 2006

x n x n stepnumber k order r error constant C r+1 1/2 5/12 3/8 251/720 abs. stab. interval (α,0) /11-3/10

MATLAB Examples. Simulink. Hans-Petter Halvorsen, M.Sc.

(Part - 1) P. Sam Johnson. April 14, Numerical Solution of. Ordinary Differential Equations. (Part - 1) Sam Johnson. NIT Karnataka.

Surname. Other Names. Centre Number. Candidate Number. Candidate Signature. General Certificate of Education Advanced Level Examination June 2014

Thursday 1/8 1 * syllabus, Introduction * preview reading assgt., chapter 1 (modeling) * HW review chapters 1, 2, & 3

Num. #1: Recalls on Numerical Methods for Linear Systems and Ordinary differential equations (ODEs) - CORRECTION

Matlab Handout Nancy Chen Math 19 Fall 2004

Computers in Engineering Root Finding Michael A. Hawker

Bucknell University Using ODE45 MATLAB Help

7.1 First-order initial-value problems

Vector Field Visualization: Introduction

Mass-Spring Systems. Last Time?

Questions Q1. (a) Find the values of the constants A, B and C. (4) b) Hence find

Accuracy Analysis of Charged Particle Trajectory CAE Software

the Simulation of Dynamics Using Simulink

PA2 Introduction to Tracking. Connected Components. Moving Object Detection. Pixel Grouping. After Pixel Grouping 2/19/17. Any questions?

16.1 Runge-Kutta Method

Functions. Edexcel GCE. Core Mathematics C3

RK4. Version 2.0 (updated 5/30/2005) 2001, 2005 Tomas Co. Michigan Technological University Houghton, MI 49931

Numerical Integration

Chapter 3 Path Optimization

Department of Chemical Engineering University of Texas at Austin

Transcription:

ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab Tutorial 6: Numerical Solution of ODE Gerardine G. Botte This handout contains information about: How to solve ODEs using Euler s method and Runge Kutta s method using Excel How to solve systems of ODEs using Euler s method and Runge Kutta s method using Excel How to solve ODEs and systems of ODEs using build up subroutines available in Matlab 1. Solve the following differential equation using Euler s method: dy 3 2x 12x 20x 8.5 dx = + + with the initial value y = 1 @ x = 0. Stop your solution when x = 1. Compare your solution with the exact solution. Discretize your function for Δx=0.1. Is your solution stable for Δx = 0.1? What is the Δx for a stable solution if you want to be accurate for 2 decimals? Solution: 1. The analytical solution is given by: 4 x 3 2 y= + 4x 10x + 8.5x+ 1 2 2. The value of the dependent variable can be calculated using Euler s method by: y = i 1 y +Δ + i x f i(x,y) 3. The solution is given by: node x Exact sol. Numerical 1 0.000 1.00 1.00 2 0.100 1.75 1.85 3 0.200 2.33 2.51 4 0.300 2.75 3.01 5 0.400 3.04 3.36 6 0.500 3.22 3.59 7 0.600 3.30 3.72 8 0.700 3.30 3.75 9 0.800 3.24 3.72 10 0.900 3.14 3.64 11 1.000 3.00 3.52 The solution is stable for Δx = 0.01, see results given below 1

Solution Example 1 Using Euler's method Y 4.5 4.0 3.5 3.0 2.5 2.0 1.5 1.0 0.5 0.0 Analytical Solution The numerical solution seems to be stable for Δx = 0.01 Δx = 0.2 Δx = 0.1 Δx = 0.05 Δx = 0.01, 0.005 0 0.2 0.4 0.6 0.8 1 1.2 X 2. Solve exercise 1 using second order Runge-Kutta method (midpoint method). Solution: 1. The solution using second order RK method is given by: 1 i i ( ) yi+ 1= yi+ a1k1+ a2k2 Δx where k = f(x,y ) Δx k1 2. For the midpoint method a1 = 0, a2 = 1, k2 = f(x i +,yi + Δ x). The solution is given 2 2 below: Midpoint Method: Δx=0.1 node x k1 k2 y numerical y exact Error 1 0 1 2 0.100 8.500 7.530 1.753 1.754 0.001 3 0.200 6.618 5.763 2.329 2.331 0.002 4 0.300 4.964 4.219 2.751 2.754 0.003 5 0.400 3.526 2.884 3.040 3.043 0.004 6 0.500 2.292 1.748 3.214 3.219 0.004 7 0.600 1.250 0.797 3.294 3.299 0.005 8 0.700 0.388 0.021 3.296 3.302 0.006 9 0.800-0.306-0.594 3.237 3.243 0.006 10 0.900-0.844-1.058 3.131 3.138 0.007 11 1.000-1.238-1.385 2.993 3.000 0.007 2

3. Solve the following system of ODE using Euler s method, second order R-K (midpoint): dy1 = 0.5y1 dx dy2 = 4 0.3y 0.1y dx 2 1 Initial conditions: y 1 = 4, y 2 = 6 @ x = 0. Use Δx = 0.5 Solution: 1. Euler s method (Δx=0.5): 2. R-K Midpoint (Δx=0.5): node x y1 y2 1 0.000 4.000 6.000 2 0.500 3.000 6.900 3 1.000 2.250 7.715 4 1.500 1.688 8.445 5 2.000 1.266 9.094 In this problem the constants were found as follow: k1,1 = 0.5yi,1 k1,2 = 4 0.3yi,2 0.1yi,1 Δx k2,1 = 0.5 yi,1 + k1,1 2 Δx Δx k2,2 = 4 0.3 yi,2 + k1,2 0.1 yi,1 + k1,1 2 2 Therefore, the solutions are obtained by: ( ) ( ) y = y + Δx k y = y + Δx k i+ 1,1 i,1 2,1 i+ 1,2 i,2 2,2 node x k1,1 k1,2 k2,1 k2,2 y1 y2 0 0 4.00 6.00 1 0.5-2 1.8-1.75 1.715 3.13 6.86 2 1-1.5625 1.63025-1.367188 1.547044 2.44 7.63 3 1.5-1.220703 1.466553-1.068115 1.387079 1.91 8.32 4 2-0.953674 1.311897-0.834465 1.237346 1.49 8.94 3

4. Solving an ODE or system of ODEs using Matlab: ODE Solver Basic Syntax: All of the ODE solver functions share a syntax that makes it easy to try any of the different numerical methods if it is not apparent which is the most appropriate. To apply a different method to the same problem, simply change the ODE solver function name. The simplest syntax, common to all the solver functions, is: [t,y] = solver(odefun,tspan,y0) where solver is one of the ODE solver functions listed below: ODE45, ODE23, etc. See Matlab help for more details about each of them. The ODE solvers are based on Runge Kutta method. ODE23 uses a second order Runge-Kutta type, while ODE45 uses a fourth order R-K type. The basic input arguments are: odefun: Function that evaluates the system of ODEs. It has the form dydt = odefun(t,y) where t is a scalar, and dydt and y are column vectors. tspan: Vector specifying the interval of integration. The solver imposes the initial conditions at tspan(1), and integrates from tspan(1) to tspan(end). For tspan vectors with two elements [t0 tf], the solver returns the solution evaluated at every integration step. For tspan vectors with more than two elements, the solver returns solutions evaluated at the given time points. The time values must be in order, either increasing or decreasing. Specifying tspan with more than two elements does not affect the internal time steps that the solver uses to traverse the interval from tspan(1) to tspan(end). All solvers in the MATLAB ODE suite obtain output values by means of continuous extensions of the basic formulas. Although a solver does not necessarily step precisely to a time point specified in tspan, the solutions produced at the specified time points are of the same order of accuracy as the solutions computed at the internal time points. Specifying tspan with more than two elements has little effect on the efficiency of computation, but for large systems, affects memory management. y0: Vector of initial conditions for the problem The output arguments are: t: Column vector of time points y: Solution array. Each row in y corresponds to the solution at a time returned in the corresponding row of t. Additional ODE Solver Arguments For more advanced applications, you can also specify as input arguments solver options and additional problem parameters. Options: Structure of optional parameters that change the default integration properties. This is the fourth input argument. [t,y] = solver(odefun,tspan,y0,options) 4

Improving ODE Solver Performance tells you how to create the structure and describes the properties you can specify. p1,p2...: Parameters that the solver passes to odefun. [t,y] = solver(odefun,tspan,y0,options,p1,p2...) IMPORTANT: It is recommended to define your function odefun in a separate file. When the function is called by the solver the symbol @ should be used as: @odefun, instead of the regular odefun used in the past. 5. Solve the system of ODE given in exercise 3 using Matlab. Use ODE23 for the solution. The first step is to define the function file that contains the system of ODEs: The second step is to build the program using the function defined above: 5

Solutions: 6

7