Solving ODEs and PDEs in MATLAB. Sören Boettcher

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

Differential Equations (Mathematics) Evaluate the numerical solution using output of ODE solvers.

ODE solvers in Julia. Gabriel Ingesson. October 2, 2015

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

MATH 350: Introduction to Computational Mathematics

Introduction to MATLAB

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Lecture 42 Determining Internal Node Values

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

sing matlab Farida Mosally Mathematics Department King Abdulaziz University

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.

Initial value problems for ordinary differential equations

Products & Services Solutions Academia Support User Commu

Mechanics of Structures (CE130N) Lab 3

Delay Differential Equations Part I: Constant Lags

AMS 27L LAB #8 Winter 2009

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

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

2 Solving Ordinary Differential Equations Using MATLAB

Ordinary Differential Equations: Initial Value problems (IVP)

S#ff ODEs and Systems of ODEs

Numerical Methods - Boundary Value Problems for ODEs

Solving optimal control problems with MATLAB Indirect methods

Ordinary Differential Equations (ODE)

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

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

Butcher tableau Can summarize an s + 1 stage Runge Kutta method using a triangular grid of coefficients

AM 205: lecture 14. Last time: Boundary value problems Today: Numerical solution of PDEs

Scientific Computing: An Introductory Survey

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

Vector Fields and Solutions to Ordinary Differential Equations using Octave

Lecture 5: Single Step Methods

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

Numerical Integration of Ordinary Differential Equations for Initial Value Problems

Selected HW Solutions

Numerical Methods for the Solution of Differential Equations

MECH : a Primer for Matlab s ode suite of functions

Fourth Order RK-Method

MB4018 Differential equations

THE MATLAB ODE SUITE

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

(6.1) -The Linear Shooting Method

24, B = 59 24, A = 55

Chapter 1: Introduction

Southern Methodist University.

Manifesto on Numerical Integration of Equations of Motion Using Matlab

Ordinary Differential Equations (ode)

Matlab Course. Anna Kristine Wåhlin. Department of Geophysics, University of Oslo. January Matlab Course p.1/??

multistep methods Last modified: November 28, 2017 Recall that we are interested in the numerical solution of the initial value problem (IVP):

Ordinary Differential Equations

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

Lecture 4. Programming

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

Mathematical Computing

Ordinary Differential Equations. Monday, October 10, 11

Applied Numerical Analysis

Consistency & Convergence

FDM for parabolic equations

The Milne error estimator for stiff problems

Computation Fluid Dynamics

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

An Introduction to Numerical Methods for Differential Equations. Janet Peterson

MTH 452/552 Homework 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.

Lecture 2. Introduction to Differential Equations. Roman Kitsela. October 1, Roman Kitsela Lecture 2 October 1, / 25

2 Ordinary Differential Equations: Initial Value Problems

Initial Value Problems

Solving Ordinary Differential Equations

1 Error Analysis for Solving IVP

INTRODUCTION TO PDEs

10.34 Numerical Methods Applied to Chemical Engineering Fall Homework #4: IVP

NUMERICAL SOLUTION OF ODE IVPs. Overview

MA3232 Summary 5. d y1 dy1. MATLAB has a number of built-in functions for solving stiff systems of ODEs. There are ode15s, ode23s, ode23t, ode23tb.

Research Computing with Python, Lecture 7, Numerical Integration and Solving Ordinary Differential Equations

Lesson 9: Predator-Prey and ode45

Exponential Integrators

CS520: numerical ODEs (Ch.2)

Numerical Differential Equations: IVP

Chapter 2: First Order DE 2.4 Linear vs. Nonlinear DEs

MAT 275 Laboratory 6 Forced Equations and Resonance

Multistep Methods for IVPs. t 0 < t < T

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

Error Estimation and Control for ODEs

The One Dimensional Heat Equation

Ordinary Differential Equations

MATH2071: LAB 1(b): Using Matlab ODE solvers. This version of the first lab is intended only for students who have already taken Math 2070.

Delay Differential Equations Part II: Time and State dependent Lags

MATH2071: LAB 3: Implicit ODE methods

Astrodynamics (AERO0024)

4. Numerical analysis II

(1 + 2y)y = x. ( x. The right-hand side is a standard integral, so in the end we have the implicit solution. y(x) + y 2 (x) = x2 2 +C.

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

Ordinary differential equations - Initial value problems

Ordinary Differential Equation Theory

The Linear Shooting Method -(8.4)

Applied Math for Engineers

Review for Exam 2 Ben Wang and Mark Styczynski

Math 128A Spring 2003 Week 12 Solutions

Solving DDEs in MATLAB

Transcription:

16.02.2009

Introduction Quick introduction to syntax ODE in the form of Initial Value Problems (IVP) what equations can handle how to code into how to choose the right solver how to get the solver to do what you want how to see the result(s) several examples Boundary Value Problems (BVP) Delay Differential Equations (DDE) Partial Differential Equations (PDE) NOT todays topic: numerical methods, ODE, BVP, DDE, PDE or

Problem DEs are functions of one or several variables that relate the values of the function itself and of its derivatives of various orders An ODE is a DE in which the unknown function is a function of a single independent variable y = f (t, y) (1) In many cases, a solution exists, but the ODE may not necessarily be directly solvable. Instead, the solution may be numerically approximated using computers There are many numerical methods in use to solve (??), but one has to use the right solver in order to obtain good solutions

The ODE Solvers Explicit methods for nonstiff problems: ode45 - Runge-Kutta pair of Dormand-Prince ode23 - Runge-Kutta pair of Bogacki-Shampine ode113 - Adams predictor-corrector pairs of orders 1 to 13 ode15i - BDF Implicit methods for stiff problems: ode23s - Runge-Kutta pair of Rosenbrock ode23t - Trapezoidal rule ode23tb - TR-BDF2 ode15s - NDF of orders 1 to 5 All these methods have built-in local error estimate to control the step size; codes are found in the /toolbox/matlab/funfun folder

Basic usage for s solvers Apply a solver: [t,y] = solver(@odefun, time interval, y0, options) odefun - a function handle that evaluates the right side of the differential equations. time interval - a vector specifying the interval of integration. [t0,tf] - initial and final value [t0,t1,...,tn] - evaluation of the method at certain points y0 - a vector of initial conditions. options - structure of optional parameters that change the default integration properties.

Approach Consider the IVP: y + y = 0, y(0) = 2, y (0) = 0 Rewrite the problem as a system of first-order ODEs: y 1 = y 2 y 2 = y 1 Code the system of first-order ODEs: function dy dt = odefun(t,y) dy dt = [y(2); -y(1)]; Apply a solver to the problem: [t,y] = ode45(@odefun, [0,20], [2,0]); The algorithm selects a certain partition of the time interval and returns the value at each point of the partition.

Solution of harmonic oscillation View the solver output: plot(t, y(:,1), r,t,y(:,2), b ) title( Solution of van der Pol Equation); xlabel( time t ); ylabel( solution y ); legend( y 1, y 2 )

Options Several options are available for solvers. The odeset function lets you adjust the integration parameters of the following ODE solvers. Save options in opts opts=odeset( name1, value1, name2, value2,... ) Expand opts opts=odeset(old opts, name, value ) If no options are specified, the default values are used.

The ODESET Options name meaning default value RelTol relative error tolerance 10 3 AbsTol absolute error tolerance 10 6 Refine output refinement factor 1 (4) MaxStep upper bound on step size Stats display computational cost statistics off The estimated error in each integration step satiesfies e k max{reltol y k, AbsTol} whereas y k the approximation of y(x k ) at step k

Example of efficiency differences Van der Pol oscillator as a system of first-order ODEs: y 1 = y 2 y 2 = µ(1 y1 2 y 2 y 1 ) as a function with µ = 1000: function dy dt = vdp(t,y,mu) dy dt = [y(2); mu*(1-y(1).^2).*y(2)-y(1)]; Apply a solver (takes 123 seconds) [t,y]=ode23(@(t,y)vdp(t,y,1000),[0,3000],[2,0]); Different solver (takes 56 milliseconds) [t,y]=ode15s(@(t,y)vdp(t,y,1000),[0,3000],[2,0]);

Example of efficiency differences Although the above function is stiff for large µ, ode23 has almost achieved the same result as ode15s

Example for false solver Simple ODE: Analytic solution: y = sin(1000t), y(0) = 1.2 y(t) = cos(1000t) + 1201 1000 2 different solvers, one for stiff ODEs: [t,y]=ode23(@(t,y)sin(1000*t),[0,3],1.2); [t,y]=ode23s(@(t,y)sin(1000*t),[0,3],1.2);

Example for false solver ode23 is totally wrong, ode23s makes it well

Solving BVPs with BVPs can have multiple solutions and one purpose of the initial guess is to indicate which solution you want. The 2nd order DE y + y = 0 has exactly two solutions that satisfy the boundary conditions y(0) = 0, y(4) = 2 DE for boundary value function dy dx = bvpex(x,y) dy dx = [y(2); -abs(y(1))]; Evaluate residual of boundary condition function res = bc(ya,yb) res = [ ya(1); yb(1) + 2]; Apply a solver: solinit = bvpinit(linspace(0,4,5),[-1 0]); sol = bvp4c(@bvpex,@bc,solinit);

Solving DDEs with A DDE is a DE in which the derivative of the unknown function at a certain time is given in terms of the values of the function at previous times. Consider the problem y (t) = 2y(t 2) y(t), t [0, 100], y(t) = 0.5 for t < 0 1 + y(t 2) 9.65 Code the function: function dy dt = ddes(t,y,z) dy dt = 2*z/(1+z^9.65)-y; Apply a solver: sol=dde23(@ddes,2,0.5,[0,100]) plot(sol.x,sol.y)

Numerical Solution of PDEs with A PDE is a DE in which the unknown function is a function of multiple independent variables and their partial derivatives. solver nonlinear system 1D pdepe 2D pdenonlin (elliptic) parabolic hyperbolic 3D

Specifying an IVBP pdepe solves PDEs of the form µ(x, t, u, u x )u t = x m (x m f (x, t, u, u x )) x + s(x, t, u, u x ) x (a, b), a > 0, t [t 0, t f ], m = 0, 1, 2, µ 0 The problem has an initial condition of the form u(x, t 0 ) = Φ(x), x [a, b] The boundary conditions are p(a, t, u(a, t)) + q(a, t)f (a, t, u(a, t), u x (a, t)) = 0, t t 0 p(b, t, u(b, t)) + q(b, t)f (b, t, u(b, t), u x (b, t)) = 0, t t 0

Example Consider the PDE π 2 u t = u xx, x (0, 1), t (0, 2] with boundary conditions u(0, t) = 0, u x (1, t) = π exp( t) and initial conditions u(x, 0) = sin(πx) The exact solution for this problem is u(x, t) = exp( t) sin(πx)

Example The specification of the problem for solution by pdepe is m = 0, a = 0, b = 1, t 0 = 0, t f = 2, µ(x, t, u, u x ) = π 2, f (x, t, u, u x ) = u x, s(x, t, u, u x ) = 0, p(a, t, u(a, t)) = u(a, t), q(a, t) = 0, p(b, t, u(b, t)) = π exp( t), q(b, t) = 1, Φ(x) = sin(πx)

Solving an IBVP The syntax of the PDE solver is sol=pdepe(m,pdefun,icfun,bcfun,xmesh,tspan) pdefun is a function handle that computes µ, f and s [mu,f,s]=pdefun(x,t,u,ux) icfun is a function handle that computes Φ phi=icfun(x) bcfun is a function handle that computes the BC [pa,qa,pb,qb]=bcfun(a,ua,b,ub,t) xmesh is a vector of points in [a, b] where the solution is approximated tspan is a vector of time values where the solution is approximated sol is a 3D array where sol(i,j,1) is the solution at tspan(i) and xmesh(j)

References Books Papers Coombes et al.; Differential Equations with Cooper; Introduction to PDEs with Fansett; Applied Numerical Analysis using Moler; Numerical Computing with Shampine et al.; with Stanoyevitch; Introduction to ODEs and PDEs using Shampine, Reichelt; The ODE Suite Shampine et al.; Solving BVPs for ODEs in with bvp4c Help

Exercises y + 2y = sin(t) + exp( 5t), y(0) = 0 y + y cot(t) = 5 exp(cos(t)), y(0) = 0 y 4y + 5y = exp( 2t) tan(t), y(0) = 0, y (0) = 0 2y + y = 2 tan(t), y(0) = 0, y (0) = 1

Thank you for your attention.