Ordinary Differential Equations (ODE)

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

Chap. 20: Initial-Value Problems

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

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

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

Ordinary Differential Equations (ode)

Fourth Order RK-Method

Ordinary Differential Equations. Monday, October 10, 11

Math 128A Spring 2003 Week 12 Solutions

Numerical Integration of Ordinary Differential Equations for Initial Value Problems

Solution. Your sketch should show both x and y axes marked from 5 to 5 and circles of radius 1, 3, and 5 centered at the origin.

Solutions of the Sample Problems for the First In-Class Exam Math 246, Fall 2017, Professor David Levermore

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

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

EAD 115. Numerical Solution of Engineering and Scientific Problems. David M. Rocke Department of Applied Science

Initial value problems for ordinary differential equations

Lesson 9: Predator-Prey and ode45

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Multistep Methods for IVPs. t 0 < t < T

First Order Linear Ordinary Differential Equations

Ordinary differential equations - Initial value problems

Numerical Methods for the Solution of Differential Equations

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

Ordinary Differential equations

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

Section 7.4 Runge-Kutta Methods

Ordinary Differential Equations: Initial Value problems (IVP)

9.6 Predictor-Corrector Methods

MTH 452/552 Homework 3

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

SME 3023 Applied Numerical Methods

Numerical Methods - Initial Value Problems for ODEs

Solving ODEs and PDEs in MATLAB. Sören Boettcher

Appendix 3B MATLAB Functions for Modeling and Time-domain analysis

COSC 3361 Numerical Analysis I Ordinary Differential Equations (II) - Multistep methods

Elementary Differential Equations

Syntax. Arguments. Solve m oderately stifo DEsand DAEs;trapezoidalrule. 1 of :34

x+ y = 50 Dividing both sides by 2 : ( ) dx By (7.2), x = 25m gives maximum area. Substituting this value into (*):

Vector Fields and Solutions to Ordinary Differential Equations using Octave

Finite Difference Method

SKMM 3023 Applied Numerical Methods

4.4 Computing π, ln 2 and e

Solution. It is evaluating the definite integral r 1 + r 4 dr. where you can replace r by any other variable.

DIFFERENTIAL EQUATIONS

DIFFERENTIATION RULES

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

Numerical Methods - Boundary Value Problems for ODEs

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

Chapter 8 Supplement: Deflection in Beams Double Integration Method

Chapter 8. Numerical Solution of Ordinary Differential Equations. Module No. 2. Predictor-Corrector Methods

Differential Equations

Civil Engineering Computation. Initial Meeting and Class Setup EXCEL Review Problems

Scientific Computing: An Introductory Survey

Ordinary Differential Equations (ODEs) Background. Video 17

What are Numerical Methods? (1/3)

Chapter 1: Introduction

First In-Class Exam Solutions Math 246, Professor David Levermore Tuesday, 21 February log(2)m 40, 000, M(0) = 250, 000.

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

10 Numerical Solutions of PDEs

Chapter 10. Initial value Ordinary Differential Equations

Fall 2003 Math 308/ Numerical Methods 3.6, 3.7, 5.3 Runge-Kutta Methods Mon, 27/Oct c 2003, Art Belmonte

Lesson 4: Population, Taylor and Runge-Kutta Methods

Solving Ordinary Differential Equations

Initial value problems for ordinary differential equations

MecE 390 Final examination, Winter 2014

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

Chapter 11 ORDINARY DIFFERENTIAL EQUATIONS

Chapter XI. Solution of Ordinary Differential Equations

Numerical Differential Equations: IVP

MECH : a Primer for Matlab s ode suite of functions

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.

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

ODE Runge-Kutta methods

Lecture 42 Determining Internal Node Values

Mathematical Models. MATH 365 Ordinary Differential Equations. J. Robert Buchanan. Spring Department of Mathematics

Mathematical Models. MATH 365 Ordinary Differential Equations. J. Robert Buchanan. Fall Department of Mathematics

Modeling and Experimentation: Compound Pendulum

Comparison of Numerical Ordinary Differential Equation Solvers

Old Math 330 Exams. David M. McClendon. Department of Mathematics Ferris State University

The Shooting Method for Boundary Value Problems

Differential Equation (DE): An equation relating an unknown function and one or more of its derivatives.

Math 23: Differential Equations (Winter 2017) Midterm Exam Solutions

Ordinary Differential Equations Initial and Boundary Value Problems

Lesson 14: Van der Pol Circuit and ode23s

Using Matlab to integrate Ordinary Differential Equations (ODEs)

Mechanics of Structures (CE130N) Lab 3

Physics 584 Computational Methods

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

Computers, Lies and the Fishing Season

ECE257 Numerical Methods and Scientific Computing. Ordinary Differential Equations

Lecture 4. Programming

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

Finite Differences for Differential Equations 28 PART II. Finite Difference Methods for Differential Equations

Numerical methods for solving ODEs

Pursuit Curves. Molly Severdia May 16, 2008

SMA 208: Ordinary differential equations I

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

Transcription:

Ordinary Differential Equations (ODE)

Why study Differential Equations? Many physical phenomena are best formulated mathematically in terms of their rate of change. Motion of a swinging pendulum Bungee-jumper Equation d dt g l sin 0 dv dt g c d m v CE 06: Engg. Computation Sessional

Euler s Method The first derivative provides a direct estimate of the slope at t i : dy dt ti f t i, y i Euler method uses that estimate as the increment function: f t i, y i y i1 y i f t i, y i h CE 06: Engg. Computation Sessional

MATLAB Code: Euler s Method function [t,y] = eulode(tspan,y0,h) % input: dydt = name of the M-file that evaluates the ODE % tspan = [ti, tf], ti and tf limits of independent variable % y0 = initial value of dependent variable h = step size % output:y = solution vector if nargin<3,error( less than 3 input arguments'),end ti = tspan(1); tf = tspan(); t = (ti:h:tf)'; n = length(t); % if necessary, add an additional value of t % so that range goes from t = ti to tf if t(n)<tf t(n+1) = tf; n = n+1; end y = y0*ones(n,1); %preallocate y to improve efficiency for i = 1:n-1 %implement Euler's method y(i+1) = y(i) + dydt(t(i),y(i))*(t(i+1)-t(i)); end yi 1 yi f ti, y i h CE 06: Engg. Computation Sessional

v (m/s) Exercise: Euler s method Solve the bungee jumper problem using Euler s method (use a step size of s). Compare the results with the analytical solution dv dt g cd m v Given, g = 9.81 m/s, c d = 0.5 kg/m, m = 68.1 kg 60 50 40 Analytical solution: v( t) gm c d tanh gc m d t 30 0 10 0 0 4 6 8 10 1 CE 06: Engg. Computation Sessional t (sec)

Heun s Method h y t f y t f y y h y t f y y i i i i i i i i i i ), ( ), ( ), ( 0 1 1 1 0 1 Predictor: Corrector: CE 06: Engg. Computation Sessional Exercise: Modify eulode.m to implement Heun s method. Solve the same bungee-jumper problem.

4 th order Runge-Kutta method where k 1 f t i, y i k f t i 1 h, y i 1 k 1h k 3 f t i 1 h, y 1 i k h k 4 f t i h, y i k 3 h y i1 y i 1 6 k k k k 1 3 4 h CE 06: Engg. Computation Sessional

MATLAB Code: Runge-Kutta Method function [tp,yp] = rk4(tspan,y0,h) % input: dydt = name of the M-file that evaluates the ODEs % tspan = [ti, tf]; initial and final times % y0 = initial values of dependent variables % h = step size % output: tp = vector of independent variable % yp = vector of solution for dependent variables if nargin<3,error( 3 input arguments required'), end ti = tspan(1); tf = tspan(); tp = (ti:h:tf)'; n = length(tp); % if necessary, add an additional value of t % so that range goes from tp = ti to tf if tp(n)<tf tp(n+1) = tf; n = n+1; end CE 06: Engg. Computation Sessional

MATLAB Code: Runge-Kutta Method y = y0*ones(n,1); %preallocate y to improve efficiency for i = 1:n-1 %implement RK method end hh = tp(i+1)-tp(i); tt = tp(i); yy = yp(i); k1 = dydt(tt,yy); k = dydt(tt + hh/, yy + 0.5*k1*hh); k3 = dydt(tt + hh/, yy + 0.5*k*hh); k4 = dydt(tt + hh, yy + k3*hh); yp(i+1) = yy + hh*(k1 + *k + *k3 + k4)/6; CE 06: Engg. Computation Sessional

Practice Problem Solve the following initial value problem over the interval from t = 0 to where y(0) = 1. Display all your results in the same graph dy dt yt 3 1.5y (a) Analytically (b) Euler s method with h = 0.5 and h = 0.5 (c) Heun s method with h = 0.5 (d) 4 th order RK method with h = 0.5 CE 06: Engg. Computation Sessional

MATLAB s common ODE solvers MATLAB s ode3 function uses second- and third-order RK functions to solve the ODE and adjust step sizes. MATLAB s ode45 function uses fourth- and fifth-order RK functions to solve the ODE and adjust step sizes. This is recommended as the first function to use to solve a problem. MATLAB s ode113 function is a multistep solver useful for computationally intensive ODE functions. CE 06: Engg. Computation Sessional

Example of ODE solver: ode45 The functions are generally called in the same way [t, y] = ode45(odefun, tspan, y0) y: solution array, where each column represents one of the variables and each row corresponds to a time in the t vector odefun: function returning a column vector of the righthand-sides of the ODEs tspan: time over which to solve the system If tspan has two entries, the results are reported for those times as well as several intermediate times based on the steps taken by the algorithm If tspan has more than two entries, the results are reported only for those specific times y0: vector of initial values CE 06: Engg. Computation Sessional

Solving a system of ODE using ode45 Predator-prey problem Solve dy 1 dt 1.y 1 0.6y 1 y dy dt 0.8y 0.3y 1 y with y 1 (0)= and y (0)=1 for 0 seconds function yp = predprey(t, y) yp = [1.*y(1)-0.6*y(1)*y(); -0.8*y()+0.3*y(1)*y()]; predprey.m file tspan = [0 0]; y0 = [, 1]; [t, y] = ode45(@predprey, tspan, y0); figure(1); plot(t,y); figure(); plot(y(:,1),y(:,)); CE 06: Engg. Computation Sessional

Example using ode45 Predator-prey problem Solve dy 1 dt 1.y 1 0.6y 1 y dy dt 0.8y 0.3y 1 y with y 1 (0)= and y (0)=1 for 0 seconds CE 06: Engg. Computation Sessional

Practice Problem: motion of a pendulum d dt g l sin Analytical solution (assuming θ = sinθ): 0 ( t) cos 0 g t l If l = ft, g = 3. ft/s and θ 0 = π/4, Solve for θ from t = 0 to 1.6 s using (a) Euler s method with h = 0.05 (b) Using ode45 function with h = 0.05 (c) Plot your results and compare with the analytical solution d dt g l sin 0 d v dt dv dt g l sin @t = 0, θ 0 = π/4 @t = 0, v = 0 CE 06: Engg. Computation Sessional

Boundary value problem: the shooting method the boundary-value problem is converted into an equivalent initial-value problem. d T dx h T T dt z 0 dx dz ht dx T Generally, the equivalent system will not have sufficient initial conditions -A guess is made for any undefined values. - The guesses are changed until the final solution satisfies all the B.C. For linear ODEs, only two shots are required - the proper initial condition can be obtained as a linear interpolation of the two guesses. CE 06: Engg. Comp. Sessional

Problem: shooting method Solve d T dx h T T T 4 T 4 0 with σ =.7x10-9 K -3 m -, L=10 m, h =0.05 m-, T =00 K, T(0) = 300 K, and T(10) = 400 K. First - break into two equations: d T dx h 4 4 T T T T 0 dt dx dz dx z 0.05 9 9 00 T.710 1.6 10 T CE 06: Engg. Computation Sessional

Problem: shooting method Code for derivatives: function dy=dydxn(x,y) dy=[y(); -0.05*(00-y(1))-.7e-9*(1.6e9-y(1)^4)]; Code for residual: function r=res(za) [x,y]=ode45(@dydxn, [0 10], [300 za]); r=y(length(x),1)-400; Code for finding root of residual: fzero(@res, -50) Code for solving system: [x,y]=ode45(@dydxn, [0 10], [300 fzero(@res, -50) ]); CE 06: Engg. Computation Sessional

Practice Problem: shooting method The basic differential equation of the elastic curve for a uniformly loaded beam is given as EI d y dx wlx wx If E = 30000 ksi, I = 800 in 4, w = 1 kip/ft, L = 10 ft, solve for the deflection of the beam using the shooting method and compare the numerical results with the analytical solution wlx y 1EI 3 4 wx 4EI 3 wl x 4EI CE 06: Engg. Computation Sessional

Numerical solution: finite difference finite differences are substituted for the derivatives in the original equation d T dx h T T 0 d T dx T i1 T i T i1 x T i1 T i T i1 x T i1 h x h T T i 0 T i T i1 h x T CE 06: Engg. Comp. Sessional

Numerical solution: finite difference The linear differential equation is transformed into a set of simultaneous algebraic equations. Since T 0 and T n are known (Drichlet boundary conditions), they will be on the right-hand-side of the linear algebra system h x 1 1 T h x 1 1 T 1 h x T n1 h x T T 0 h x T h x T T n CE 06: Engg. Comp. Sessional

Numerical solution: finite difference If there is a derivative boundary condition (Neumann B.C.), the centered difference equation is solved at the point and rewriting the system equation accordingly. For a Neumann condition at T 0 point: CE 06: Engg. Comp. Sessional dt T 1 T 1 dx 0 x T 1 h x T 1 x dt h x dx 0 T 1 T 1 x dt dx 0 T 0 T 1 h x T T 0 T 1 h x T h x T 0 T 1 h x T x dt dx 0

Practice Problem: Finite difference Solve the nondimensionalized ODE using finite difference methods that describe the temperature distribution in a circular rod with internal heat source S d T dr 1 r dt dr S Over the range 0 r 1, with boundary conditions dt T( r 1) 1 0 dr For S = 1, 10 and 0 K/m plot the temperature versus radius r0 0 CE 06: Engg. Computation Sessional