Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)

Slides:



Advertisements
Similar presentations
Ordinary Differential Equations
Advertisements

Chapter 6 Differential Equations
Ordinary Differential Equations
PART 7 Ordinary Differential Equations ODEs
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Ordinary Differential Equations Equations which are.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 32 Ordinary Differential Equations.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 31 Ordinary Differential Equations.
Initial-Value Problems
Dr. Jie Zou PHY Chapter 9 Ordinary Differential Equations: Initial-Value Problems Lecture (II) 1 1 Besides the main textbook, also see Ref.: “Applied.
8-1 Chapter 8 Differential Equations An equation that defines a relationship between an unknown function and one or more of its derivatives is referred.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW III.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
CISE301_Topic8L31 SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2,
Differential Equations and Boundary Value Problems
Numerical solution of Differential and Integral Equations PSCi702 October 19, 2005.
Fin500J Topic 7Fall 2010 Olin Business School 1 Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential.
1 Chapter 6 Numerical Methods for Ordinary Differential Equations.
PART 7 Ordinary Differential Equations ODEs
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Boyce/DiPrima 9th ed, Ch 8.4: Multistep Methods Elementary Differential Equations and Boundary Value Problems, 9th edition, by William E. Boyce and Richard.
Chapters 5 and 6: Numerical Integration
EE3561_Unit 8Al-Dhaifallah14351 EE 3561 : Computational Methods Unit 8 Solution of Ordinary Differential Equations Lesson 3: Midpoint and Heun’s Predictor.
Simpson Rule For Integration.
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Integration of 3-body encounter. Figure taken from
Numerical Methods for Solving ODEs Euler Method. Ordinary Differential Equations  A differential equation is an equation in which includes derivatives.
Scientific Computing Multi-Step and Predictor-Corrector Methods.
© Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 7 - Chapter 25.
Numerical Analysis – Differential Equation
Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)
Introduction to the Runge-Kutta algorithm for approximating derivatives PHYS 361 Spring, 2011.
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,
PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler  Recall basic  Predictor-Corrector C. Runge-Kutta.
Dr. Mujahed AlDhaifallah ( Term 342)
Today’s class Ordinary Differential Equations Runge-Kutta Methods
ECE 576 – Power System Dynamics and Stability Prof. Tom Overbye Dept. of Electrical and Computer Engineering University of Illinois at Urbana-Champaign.
Ordinary Differential Equations
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
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.
This chapter is concerned with the problem in the form Chapter 6 focuses on how to find the numerical solutions of the given initial-value problems. Main.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
Assignment 1: due 1/19/16 Estimate all of the zero of x3-x2-2x+1 graphically. Write a MatLab code for Newton’s method. Use your code to refine the graphical.
Keywords (ordinary/partial) differencial equation ( 常 / 偏 ) 微分方程 difference equation 差分方程 initial-value problem 初值问题 convex 凸的 concave 凹的 perturbed problem.
Part 7 - Chapter 25.
Ordinary Differential Equations
525602:Advanced Numerical Methods for ME
Class Notes 18: Numerical Methods (1/2)
Numerical Solutions of Ordinary Differential Equations
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L4&5.
Class Notes 19: Numerical Methods (2/2)
Part 7 - Chapter 25.
Numerical Analysis Lecture 37.
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L2.
Numerical Analysis Lecture 38.
Numerical solution of first-order ordinary differential equations
Assignment 1: due 1/16/19 Estimate all of the zero of x3-x2-2x+1 graphically. Write a MatLab code for Newton’s method. Use your code to refine the graphical.
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L3 KFUPM.
Chapter 10 ordinary differential equations (ODEs)
Assignment 1: due 1/17/19 Estimate all of the zero of x3-x2-2x+1 graphically. Write a MatLab code for Newton’s method. Use your code to refine the graphical.
Numerical Analysis Lecture 36.
Numerical solution of first-order ordinary differential equations 1. First order Runge-Kutta method (Euler’s method) Let’s start with the Taylor series.
Presentation transcript:

Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)

System of ODEs

Initial value problems Regardless of problem statement, identify f(x,t), a, b, and x(a)

Initial-value problem: x’ = f(x,t); x(t 0 ) = x 0 Solved by “separation of variables”

Usually a “boot strap” method is required

Taylor-series method Given

Higher-order Taylor series methods x’(t) has both explicit and implicit time dependence given Given the value of x at t = t 0 evaluate x’(t 0 ), x’’(t 0 ), x’’’(t 0 ), etc. → x(t 0 +h) = x(t 0 )+hx’(t 0 )+h 2 x’’(t 0 )/2… then evaluate x’(t 0 +h), x’’(t 0 +h), x’’’(t 0 +h), etc. → x(t 0 +2h) = x(t 0 +h)+…

Solver: advances table X(t) → X(t+h), estimates local truncation error, controls propagation of error, etc. Is independent of a particular ODE Encoder: Tells solver how to calculate X’(t) for a particular ODE To solve a single ODE, encoder passed to solver as function handle For systems of ODEs, encoder passed to solver as an m-file Main: Defines initial conditions and domain of solution Sets solver parameters (number of points, error tolerance, etc. Calls solver for the particular ODE, analyze the results Exception: In higher-order Taylor method, encoder is part of solver Components of MatLab code to solve initial value problems main solver encoder

Solver: can be developed by criterion of table accuracy only, no concern for particular ODE or user objectives Encoder: only function is to tells the solver how to calculate X’(t) for all of the unknown functions in the problem. Encoder can be as simple as an inline function definition (one unknown) or as complex as an m-file describing a system being modeled by thousands of coupled ODEs Main: function restricted to problem setup (introduce encoder to solver) and downstream processing. Small changes for different problems Advantages of MatLab’s decomposition of problem: functions are specialized main solver encoder

Develop approach for Euler method x(t+h) = x(t) + hx’(t, x(t)) main solver encoder Start by developing the solver For singe ODE, encoder = inline function Write main to get results you need

MatLab code 4 th order Taylor-series method Command window function definition specific to problem derivatives calculated in order nested form saves operations No reason why driver and function should be separate See pseudo-code text p434 main solver encoder

Problems and p437 x’ = t 2 + x 3 5 equations needed for 4 th order Taylor x’ = x + e x 5 equations needed for 4 th order Taylor x’ = x 2 – cos(x) 6 equations needed for 5 th order

Runge-Kutta method: x’(t) = f(t, x(t))x(t 0 ) = x 0 Find method as accurate as Taylor series that does not involve higher order derivatives. 2nd order Runge-Kutta: Look for solution of the form x(t + h) = x(t) + w 1 F 1 + w 2 F 2 where F 1 = h f(t, x(t))F 2 = h f(t +  h, x +  F 1 ). Note: h in definition of F 1 and F 2 so they have the same units as x. All 4 parameters, w 1, w 2, , and  are dimensionless

Look for solution of the form x(t + h) = x(t) + w 1 F 1 + w 2 F 2 where F 1 = h f(t, x(t))F 2 = h f(t +  h, x +  F 1 ) Expanding f(t +  h, x +  F 1 ) to 1 st order in h give x(t+h) to 2 nd order in h

Note: F 1 alone is Euler’s method Pseudo-code text p443 This result also called “ extended Euler” method. In the 3 rd term on the RHS, Euler’s approximation to x(t+h) is used in calculating an estimate of the slope of x(t) between t and t+h. The 2 estimates of the slope between t and t+h are averaged with equal weight. RK2 derivation continued

4 th order Runge-Kutta The same method used for RK2 yields a result that is as accurate as Taylor 4 th order. See text p443 for pseudo code.

Runge-Kutta-Fehlberg Method Evaluate both 4 th and 5 th order Runge Kutta Use difference as estimate of error Adjust h to keep error in bounds

Estimate of the error in x(t)

Inside a loop to generate a table of values of X(t) Basic idea behind MatLabs ODE45

MatLab’s ODE45 solver Encoder is inline function. Specify domain of solution. ODE45 chooses points Plot results Display number of points Compare exact to last value in table to exact

ODE points vs exact X(10) correct to 4 significant figures t x(t)

main solver encoder Use the design above to implement Euler, RK2, RK4, and ODE45 methods to solve x’ = 1 + t 3 +x 2 for x(2) given x(1) = -4. Use the same number of points as ODE45 for Euler, RK2 and RK4. Like ODE45, design Euler, RK2 and RK4 so that {t(1),x(1)} are the initial conditions. Compare, by percent difference, your values with the accurate value on p434 of text. Hand in your solvers and copy of command window where solver is called. Assignment 6 due 3/3/15

Predictor-Corrector Methods: At every value of t, predict x p (t+h) Use x p (t+h) to get more accurate x(t+h) Example: Improved Euler (p p437) x p (t+h) = x(t) + hx’(t,x(t)) (normal Euler) x(t+h) = x(t) + h[x’(t,x(t))+x’(t+h, x p (t+h))]/2 Is this the same as RK2?

Higher-order predictor - corrector

Use same approach to derive a corrector

Systems of ODEs Solved by Taylor, Euler, RK and ODE45

Use the Taylor series method to solve the the system x’ = -3yy’ = x/3

Taylor series method applied to system x’ = -3yy’ = x/3

Compare Taylor solution to exact result

Euler, RK and ODE45 applied to systems of ODEs

Pseudo-code for Euler method applied to 1 ODE [t, x]=Euler(xp, t 0, x 0, h, npts) t(1)=t 0 ; x(1)=x 0 ; For k=2,npts x(k)=x(k-1)+h*xp(t(k-1),x(k-1)); t(k)=t(k-1)+h; end

Pseudo-code for vectorised Eulersys [t,XM]=Eulersys(xpsys, t0,x0,h,npts) t(1)=t0; XM(1,:)=x0; For k=2,npts x=XM(k-1,:); f1=h*xpsys(t(k-1),x); XM(k,:)=XM(k-1,:)+f1 t(k)=t(k-1)+h; end

xpsys pseudo code to solve x’ = -3yy’ = x/3 f=xpsys(t,x) f(1)=-3*x(2); f(2)=x(1)/3;

main pseudo code to compare solution of x’ = -3yy’ = x/3 with exact: x=3cos(t), y=sin(t) Set parameter t0,x0,h, and npts Call Eulersys Display last time point and corresponding values of unknowns Plot solutions for both unknowns on the same axes Select points where exact values will be shown Calculate exact values at selected points Plot exact values on same axes as numerical solutions

Eulersys solution of x’ = -3y, y’ = x/3 compared to exact As expected, Eulersys not as accurate as Taylor4sys2 (see slide 31)

Pseudo-code for RK2 method applied to 1 ODE [t, x]=RK2(xp, t 0, x 0, h, npts) t(1)=t 0 ; x(1)=x 0 ; For k=2,npts f1=h*xp(t(k-1),x(k-1)); f2=h*xp(t(k-1)+h,x(k-1)+f1); x(k)=x(k-1)+(f1+f2)/2; t(k)=t(k-1)+h;

Pseudo-code for vectorised RK2sys [t, XM]=RK2sys(xpsys, t 0, x 0, h, npts) t(1)=t 0 ; XM(1,:)=x 0 ; For k=2,npts x=XM(k-1,:) f1=h*xpsys(t(k-1),x); t(k)=t(k-1)+h; f2=h*xpsys(t(k),x+f1); XM(k)=XM(k-1)+(f1+f2)/2;

Vectorised RK2sys can use the same xpsys and similar main as vectorised Eulersys to solve x’ = -3yy’ = x/3 and compare with exact: x=3cos(t), y=sin(t)

Pseudo code for RK4 applied to 1 ODE; just more F’s

Pseudo-code for RK4 method applied to 1 ODE [t, x]=RK4(xp, t 0, x 0, h, npts) t(1)=t 0 ; x(1)=x 0 ; For k=2,npts f1=h*xp(t(k-1), x(k-1)); f2=h*xp(t(k-1)+h/2, x(k-1)+f1/2); f3=h*xp(t(k-1)+h/2, x(k-1)+f2/2); f4=h*xp(t(k-1)+h, x(k-1)+f3); x(k)=x(k-1)+(f1+2f2+2f3+f4)/6; t(k)=t(k-1)+h;

Vectorised RK4sys Pseudo code for vectorised RK4sys is similar to vectorised RK2sys; just more F’s

Pseudo-code for vectorised RK4sys [t, XM]=RK2sys(xpsys, t 0, x 0, h, npts) t(1)=t 0 ; XM(1,:)=x 0 ; For k=2,npts x=XM(k-1,:) f1=h*xpsys(t(k-1),x); f2=h*xpsys(t(k-1)+h/2, x+f1/2); f3=h*xpsys(t(k-1)+h/2, x+f2/2); f4=h*xpsys(t(k-1)+h, x+f3); XM(k,:)=XM(k-1,:)+(f1+2f2+2f3+f4)/6; t(k)=t(k-1)+h;

Vectorised RK4sys can use the same xpsys and similar main as vectorised Eulersys to solve x’ = -3yy’ = x/3 and compare with exact: x=3cos(t), y=sin(t)

ODE45 can use a similar main as vectorised Eulersys to solve x’ = -3yy’ = x/3 and compare with exact: x=3cos(t), y=sin(t) but needs a slightly modified xpsys f=xpsys(t,x) f1=-3*x(2); f2=x(1)/3; f=[f1;f2]; xpsys returns a column vector in this case

Sometimes ODE45 fails ODE applied to x’ = t +x 2 – y; y’ = t 2 – x+y 2 ; x(0) = 3; y(0) = 2

Very rapid change in solution → ODE45 solution for system x’ = t +x 2 – yy’ = t 2 – x+y 2 x(0) = 3, y(0) = 2

Assignment 7 Due 3/10/2015: Use Euler, RK4, and ode45 to solve the system of equations x’=x – y + 2t - t 2 - t 3 y’=x + y - 4t 2 + t 3 for 0 < t < 1 subject to the initial condition x(0)=1, y(0)=0 Design Euler and RK4 so that {t(1),XM(1,:)} are the initial conditions. Use the same number of points in all 3 methods. For each method, print out the values of x and y at t=1, there percent difference from the exact values at t=1, and make separate plots that compares your results to the exact solutions x(t)=exp(t)cos(t) + t 2 y(t)=exp(t)sin(t) - t 3 for 0 < t < 1. Each plot must distinguish numerical from exact solutions.

Suggested problems from the text on ODEs Chapter 10.1 p436: Taylor series Problems 1a, 1b, 1e, 2a, 2b, 5, 10, 11a Computer problems 1, 2, 8, 9, 10 Chapter 10.2 p445: RK4 single ODE Problems 1, 2, 5, 6 Computer problems 1, 2, 4, 6, 10, 12 Chapter 11.1 p475: RK4 system of ODEs Computer problems 3, 5, 6, 7

Write xpsys functions for the systems on pp CK 6 th edition: P(1) x’ = y, y’ = x P(2) x 1 ’ = x exp(t) - t 2, x 2 ’ = x 2 - cos(t) CP((4) x’ = x + 2t – t 2 – t 3, y’ = y - 4t 2 + t 3