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

Slides:



Advertisements
Similar presentations
Chapter 6 Differential Equations
Advertisements

MATLAB EXAMPLES Initial-value problems
Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton.
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.
王俊鑫 (Chun-Hsin Wang) 中華大學 資訊工程系 Fall 2002 Chap 2 Numerical Methods for First-Order Differential Equations.
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
Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)
Ordinary Differential Equations (ODEs)
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.
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.
Chapters 5 and 6: Numerical Integration
Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 8 Linear Algebraic Equations PowerPoint to accompany Copyright © 2010.
Interpolation. Interpolation is important concept in numerical analysis. Quite often functions may not be available explicitly but only the values of.
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.
Numerical Methods Part: Simpson Rule For Integration.
Integration of 3-body encounter. Figure taken from
Differential Equations 7. Direction Fields and Euler's Method 7.2.
Numerical Methods for Solving ODEs Euler Method. Ordinary Differential Equations  A differential equation is an equation in which includes derivatives.
Numerical Solutions of ODE
DIFFERENTIAL EQUATIONS 10. DIFFERENTIAL EQUATIONS Unfortunately, it’s impossible to solve most differential equations in the sense of obtaining an explicit.
© Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed.
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.
Numerical Analysis – Differential Equation
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,
Dr. Mujahed AlDhaifallah ( Term 342)
Today’s class Ordinary Differential Equations Runge-Kutta Methods
ENGR-25_Lec-21_Integ_Diff.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
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.
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.
Chapters 5 and 6: Numerical Integration Code development trapezoid rule Simpson’s rule Gauss quadrature Laguerre quadrature Analysis changing the variable.
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
Ordinary Differential Equations (ODEs). Objectives of Topic  Solve Ordinary Differential Equations (ODEs).  Appreciate the importance of numerical methods.
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
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.
Part 7 - Chapter 25.
Numerical Analysis Lecture 37.
Numerical Solutions of Ordinary Differential Equations
5.3 Higher-Order Taylor Methods
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.
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 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 methods Given Pseudo code for Euler’s method

Higher-order Taylor series methods x’(t) has both explicit and implicit time dependence given Pseudo code for high-order Taylor-series method 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)+…

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

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

Example of 4 th order Taylor-series method Main encoder-solver combination derivatives calculated in order nested form of Taylor series saves operations main solver encoder call encoder-solver

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 MatLab’s approach for Euler’s method main solver encoder Start by developing the solver For singe ODE, encoder = inline function in main example: x’ = 1 + x 2 + t 3 for x(2) given x(1) = -4. Write main to get results you need similar to 4 th order Taylor example on slide 10 compare to “exact” value x(2)= (text p434)

A solver for Euler’s method x(t+h) = x(t) + hx’(t, x(t)) function [t,x]=euler(fh,t0,x0,tmax,npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; x(1)=x0; for k=1:n t(k+1)=t(k)+h; x(k+1)=x(k)+h*fh(t(k),x(k)); end

Runge-Kutta method: Given x’(t) = f(t, x(t)) and x(t 0 ) = x 0 Find method as accurate as Taylor series that does not involve higher order derivatives. More accurate than Euler and still an independent solver 2 nd order Runge-Kutta: Look for solution of the form x(t + h) = x(t) + w 1 F 1 + w 2 F 2 that is as accurate as 2 nd order Taylor series method where F 1 = h f(t, x(t))F 2 = h f(t +  h, x +  F 1 ). Note: if w 2 = 0, reduces to Euler’s method Parameters w 1, w 2, , and  are independent of h

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 gives 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. constraints are satisfied by

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.

Pseudo code for RK4 text p443

A solver for Rk4 with same structure as solver for Euler’s method function [t,x]=RK4(fh,t0,x0,tmax,npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; x(1)=x0; for k=1:n K1=h*fh(t(k),x(k)); K2=h*fh(t(k)+h/2,x(k)+K1/2); K3=h*fh(t(k)+h/2,x(k)+K2/2); K4=h*fh(t(k)+h,x(k)+K3); t(k+1)=t(k)+h; x(k+1)=x(k)+(K1+2*K2+2*k3+k4)/6; end

Solve x’ = 1 + x 2 + t 3 for x(2) given x(1) = -4 by RK4 method with 100 points and compare to results with Euler method Start by developing the RK4 solver (done) For single ODE, encoder = inline function in main xp = inline(‘1 + x^2 + t^3’) for x(2) given x(1) = -4. Write main to get results you need call Euler solver call RK4 solver compare Euler to “exact” value x(2)= compare RK4 to exact value Euler % error RK x10 -5 % error

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)

Use ode45 to solve x’ = 1 + x 2 + t 3 for x(2) given x(1) = -4. Write a solver for extended Euler (slide 16) using the same structure as the solver for Euler (slide 13). Use the same number of points as ode45 to solve for x(t) by Euler and extended Euler methods. In all 3 cases calculate the percent difference from the exact value x(2) = on p434 of text. Hand in your Euler and extended Euler solvers and a copy of command window where all 3 methods were used. Assignment 4 due 11/19/15

Systems of ODEs Solved by Taylor, Euler, RK4 and ode45

Use the Taylor series method to solve the system x’ = -3y; y’ = x/3 with x(0)=3 and y(0)=0 to 4 th order in h for 0<t<4

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

Set parameter t0,x0,tmax, and npts Call Taylor4 encoder-solver Display last time point and corresponding values of unknowns Plot solutions for both unknowns on the same axes as curves Select points where exact values will be shown Calculate exact values at selected points Plot exact values as discrete points on same axes as numerical solutions pseudo code for main that compares solution of x’ = -3y, y’ = x/3 with exact, x=3cos(t), y=sin(t), for 0<t<4 when x(0)=3 and y(0)=0

Compare Taylor solution to exact result

Euler, RK and ode45 applied to systems of ODEs main solver encoder Same structure applies but solver generates a matrix and encoder is a.m file that returns a vector. Start by writing the encoder that return x’(t,x(t)) for all the unknowns in the system Pseudo code for x’=-3y, y’=x/3

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

[t,XM]=Eulersys(fh,t0,x0,tmax,neqs,npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; for i=1:neqs XM(1,i)=x0(i); %initial value all unknowns end for k=1:n for i=1:neqs x(i)=XM(k,i); %current value of all unknowns end f1=h*fh(t(k),x); %fh returns current slope of all unknowns for i=1:neqs XM(k+1,i)=XM(k,i)+f1(i); %new row added to solution matrix end t(k+1)=t(k)+h; end Solver for Eulersys using FOR loops

[t,XM]=Eulersys(fh, t0,x0,tmax,npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; XM(1,:)=x0; For k=1:n x=XM(k,:); f1=h*fh(t(k),x); XM(k+1,:)=XM(k,:)+f1 t(k+1)=t(k)+h; end Solver for Eulersys without FOR loop over neqs

Set parameter t0,x0,tmax, and npts Call Eulersys 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 Display last time point and corresponding values of unknowns Display exact values at tmax pseudo code for main that compares solution of x’ = -3y, y’ = x/3 with exact, x=3cos(t), y=sin(t), for 0<t<4 when x(0)=3 and y(0)=0

Find a numerical solution of x’ = -3y, y’ = x/3 for 0<t<4 by Euler’s method with 100 points when x(0)=3 and y(0)=0 Compare with exact solution, x=3cos(t), y=sin(t),

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

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

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 5, Due 12/3/2015: Write a solver for extended Euler applied to a system of equations. Use your extended Eulersys 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 < 3, subject to the initial condition x(0)=1, y(0)=0 Use the same number of points for both methods. Exact solutions are x(t)=exp(t)cos(t) + t 2 and y(t)=exp(t)sin(t) - t 3 For each method, print out the values of x and y at t=3, there percent difference from the exact values at t=3, and make separate plots that compares your results to the exact solutions for each method.

[t,XM]=Eulersys(fh, t0,x0,tmax,npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; XM(1,:)=x0; For k=1:n x=XM(k,:); k1=h*fh(t(k),x); XM(k+1,:)=XM(k,:)+k1 t(k+1)=t(k)+h; end function f=xpsys(t,x) f(1)=-3*x(2); f(2)=x(1)/3; Solver for Eulersys without FOR loop over neqs [t, x]=RK2(fh, t0, x0, tmax, npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; x(1)=x0; for k=1:n k1=h*fh(t(k),x(k)); k2=h*fh(t(k)+h,x(k)+k1); x(k+1)=x(k)+(k1+k2)/2; t(k+1)=t(k)+h; end

RK4 method

[t, x]=RK4(xp, t0,x0, tmax, npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; x(1)=x0; for k=1:n f1=h*xp(t(k), x(k)); f2=h*xp(t(k)+h/2, x(k)+f1/2); f3=h*xp(t(k)+h/2, x(k)+f2/2); f4=h*xp(t(k)+h, x(k)+f3); x(k+1)=x(k)+(f1+2*f2+2*f3+f4)/6; t(k+1)=t(k)+h; end RK4 solver for 1 ODE

[t, XM]=RK4sys(xpsys, t0,x0,tmax, npts) n=npts-1; h=(tmax-t0)/n; t(1)=t0; XM(1,:)=x0; For k=1:n x=XM(k,:) f1=h*xpsys(t(k),x); f2=h*xpsys(t(k)+h/2, x+f1/2); f3=h*xpsys(t(k)+h/2, x+f2/2); f4=h*xpsys(t(k)+h, x+f3); XM(k+1,:)=XM(k,:)+(f1+2*f2+2*f3+f4)/6; t(k+1)=t(k)+h; end Solver for RK4sys without FOR loop over neqs

RK4sys can use the same xpsys as Eulersys and RK2sys (i.e. returns a row vector) Only ode45 requires xpsys to return a column vector Write xpsys for the system of ODEs x’=tx+y’-t 2 y’=ty+3t z’=tz-y’+6t 3

Wirte xpsys encoder for ode45 x’=tx+y’-t 2 y’=ty+3t z’=tz-y’+6t 3 function f=xpsys(t,xvec) x=xvec(1); y=xvec(2); z=xvec(3); yp=t*y+3*t; xp=t*x+yp-t^2; zp=t*z-yp+6*t^3; f=[xp;yp;xp];

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: single ODE Problems 1, 2, 5, 6 Computer problems 1, 2, 4, 6, 10, 12 Chapter 11.1 p475: system of ODEs Computer problems 3, 5, 6, 7