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

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

Solving ODEs and PDEs in MATLAB. Sören Boettcher

S#ff ODEs and Systems of ODEs

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

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

sing matlab Farida Mosally Mathematics Department King Abdulaziz University

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

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

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

Products & Services Solutions Academia Support User Commu

Scientific Computing: An Introductory Survey

THE MATLAB ODE SUITE

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

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

MECH : a Primer for Matlab s ode suite of functions

Delay Differential Equations Part I: Constant Lags

MATH 350: Introduction to Computational Mathematics

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Ordinary differential equations - Initial value problems

24, B = 59 24, A = 55

Vector Fields and Solutions to Ordinary Differential Equations using Octave

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Ordinary Differential Equations (ODE)

Lesson 14: Van der Pol Circuit and ode23s

The Milne error estimator for stiff problems

AMS 27L LAB #8 Winter 2009

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

16.7 Multistep, Multivalue, and Predictor-Corrector Methods

NUMERICAL SOLUTION OF ODE IVPs. Overview

CS520: numerical ODEs (Ch.2)

Modeling & Simulation 2018 Lecture 12. Simulations

Consistency & Convergence

Chapter 9 Implicit Methods for Linear and Nonlinear Systems of ODEs

CHAPTER 5: Linear Multistep Methods

The Plan. Initial value problems (ivps) for ordinary differential equations (odes) Review of basic methods You are here: Hamiltonian systems

University of Alberta ENGM 541: Modeling and Simulation of Engineering Systems Laboratory #5

2 Solving Ordinary Differential Equations Using MATLAB

Solving Ordinary Differential Equations

Semi-implicit Krylov Deferred Correction Methods for Ordinary Differential Equations

Southern Methodist University.

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

Solving Ordinary Differential equations

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

Numerical Solution of ODE IVPs

MATH2071: LAB 3: Implicit ODE methods

Numerical Integration of Ordinary Differential Equations for Initial Value Problems

16.7 Multistep, Multivalue, and Predictor-Corrector Methods

Numerical Methods for the Solution of Differential Equations

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

(again assuming the integration goes left to right). Standard initial value techniques are not directly applicable to delay problems since evaluation

Applied Numerical Analysis

8.1 Introduction. Consider the initial value problem (IVP):

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

Lesson 9: Predator-Prey and ode45

MATH 100 Introduction to the Profession

A New Block Method and Their Application to Numerical Solution of Ordinary Differential Equations

Ordinary Differential Equations

The Chemical Kinetics Time Step a detailed lecture. Andrew Conley ACOM Division

Exponential Integrators

Parallel Methods for ODEs

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

Jim Lambers MAT 772 Fall Semester Lecture 21 Notes

Multistep Methods for IVPs. t 0 < t < T

Error Estimation and Control for ODEs

Numerical Differential Equations: IVP

Mathematics for chemical engineers. Numerical solution of ordinary differential equations

An initialization subroutine for DAEs solvers: DAEIS

Numerical Methods for Differential Equations

Applied Linear Algebra in Geoscience Using MATLAB

Ordinary Differential Equations

Initial-Value Problems for ODEs. Introduction to Linear Multistep Methods

Solving PDEs with PGI CUDA Fortran Part 4: Initial value problems for ordinary differential equations

Math Numerical Analysis Homework #4 Due End of term. y = 2y t 3y2 t 3, 1 t 2, y(1) = 1. n=(b-a)/h+1; % the number of steps we need to take

Part IB Numerical Analysis

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.

Non-negative solutions of ODEs

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

Fourth Order RK-Method

Linearized Equations of Motion!

MTH 452/552 Homework 3

Solving DDEs in Matlab

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

Numerical Integration of Equations of Motion

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

Rezolvarea ecuaţiilor şi sistemelor de ecuaţii diferenţiale ordinare (II)

Ordinary Differential Equations (ODEs) Background. Video 17

Faster Kinetics: Accelerate Your Finite-Rate Combustion Simulation with GPUs

Initial value problems for ordinary differential equations

Symbolic Solution of higher order equations

Physics 584 Computational Methods

Lecture Notes Multibody Dynamics B, wb1413

1. Introduction. Many dynamical systems in science and engineering are modeled by ordinary differential equations (ODEs)

Assignment on iterative solution methods and preconditioning

Computer lab for MAN460

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill

Lecture 4: Numerical solution of ordinary differential equations

A SYMBOLIC-NUMERIC APPROACH TO THE SOLUTION OF THE BUTCHER EQUATIONS

9.6 Predictor-Corrector Methods

Transcription:

1 of 8 09.01.2016 09:34 Solve m oderately stifo DEsand DAEs;trapezoidalrule Syntax [T,Y] = solver(odefun,tspan,y0) [T,Y] = solver(odefun,tspan,y0,options) [T,Y,TE,YE,IE] = solver(odefun,tspan,y0,options) sol = solver(odefun,[t0 tf],y0...) This page contains an overview of the solver functions: ode23, ode45, ode113, ode15s, ode23s, ode23t, and ode23tb. You can call any of these solvers by substituting the placeholder, solver, with any of the function names. Arguments The following table describes the input arguments to the solvers. odefun tspan A function handle that evaluates the right side of the differential equations. All solvers solve systems of equations in the form y = f(t,y) or problems that involve a mass matrix, M(t,y)y = f(t,y). The ode23s solver can solve only equations with constant mass matrices. ode15s and ode23t can solve problems with a mass matrix that is singular, i.e., differential-algebraic equations (DAEs). A vector specifying the interval of integration, [t0,tf]. The solver imposes the initial conditions at tspan(1), and integrates from tspan(1) to tspan(end). To obtain solutions at specific times (all increasing or all decreasing), use tspan = [t0,t1,...,tf]. 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 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 options A vector of initial conditions. Structure of optional parameters that change the default integration properties. This is the fourth input argument. [t,y] = solver(odefun,tspan,y0,options) You can create options using the odeset function. See odeset for details. The following table lists the output arguments for the solvers. T Y TE YE IE sol Column vector of time points. Solution array. Each row in Y corresponds to the solution at a time returned in the corresponding row of T. The time at which an event occurs. The solution at the time of the event. The index i of the event function that vanishes. Structure to evaluate the solution.

2 of 8 09.01.2016 09:34 Description [T,Y] = solver(odefun,tspan,y0) with tspan = [t0 tf] integrates the system of differential equations y = f(t,y) from time t0 to tf with initial conditions y0. The first input argument, odefun, is a function handle. The function, f = odefun(t,y), for a scalar t and a column vector y, must return a column vector f corresponding to f(t,y). Each row in the solution array Y corresponds to a time returned in column vector T. To obtain solutions at the specific times t0, t1,...,tf (all increasing or all decreasing), use tspan = [t0,t1,...,tf]. Parameterizing Functions explains how to provide additional parameters to the function fun, if necessary. [T,Y] = solver(odefun,tspan,y0,options) solves as above with default integration parameters replaced by property values specified in options, an argument created with the odeset function. Commonly used properties include a scalar relative error tolerance RelTol (1e 3 by default) and a vector of absolute error tolerances AbsTol (all components are 1e 6 by default). If certain components of the solution must be nonnegative, use the odeset function to set the NonNegative property to the indices of these components. See odeset for details. [T,Y,TE,YE,IE] = solver(odefun,tspan,y0,options) solves as above while also finding where functions of (t,y), called event functions, are zero. For each event function, you specify whether the integration is to terminate at a zero and whether the direction of the zero crossing matters. Do this by setting the 'Events' property to a function, e.g., events or @events, and creating a function [value,isterminal,direction] = events(t,y). For the ith event function in events, value(i) is the value of the function. isterminal(i) = 1, if the integration is to terminate at a zero of this event function and 0 otherwise. direction(i) = 0 if all zeros are to be computed (the default), +1 if only the zeros where the event function increases, and 1 if only the zeros where the event function decreases. Corresponding entries in TE, YE, and IE return, respectively, the time at which an event occurs, the solution at the time of the event, and the index i of the event function that vanishes. sol = solver(odefun,[t0 tf],y0...) returns a structure that you can use with deval to evaluate the solution at any point on the interval [t0,tf]. You must pass odefun as a function handle. The structure sol always includes these fields: sol.x sol.y sol.solver Steps chosen by the solver. Each column sol.y(:,i) contains the solution at sol.x(i). Solver name. If you specify the Events option and events are detected, sol also includes these fields: sol.xe sol.ye sol.ie Points at which events, if any, occurred. sol.xe(end) contains the exact point of a terminal event, if any. Solutions that correspond to events in sol.xe. Indices into the vector returned by the function specified in the Events option. The values indicate which event the solver detected. If you specify an output function as the value of the OutputFcn property, the solver calls it with the computed solution after each time step. Four output functions are provided: odeplot, odephas2, odephas3, odeprint. When you call the solver with no output arguments, it calls the default odeplot to plot the solution as it is computed. odephas2 and odephas3 produce twoand three-dimensional phase plane plots, respectively. odeprint displays the solution components on the screen. By default, the ODE solver passes all components of the solution to the output function. You can pass only specific components by providing a vector of indices as the value of the OutputSel property. For example, if you call the solver with no output arguments and set the value of OutputSel to [1,3], the solver plots solution components 1 and 3 as they are computed. For the stiff solvers ode15s, ode23s, ode23t, and ode23tb, the Jacobian matrix f/ y is critical to reliability and efficiency. Use odeset to set Jacobian to @FJAC if FJAC(T,Y) returns the Jacobian f/ y or to the matrix f/ y if the Jacobian is constant. If the Jacobian property is not set (the default), f/ y is approximated by finite differences. Set the Vectorized property 'on' if the ODE function is coded so that odefun(t,[y1,y2...]) returns [odefun(t,y1),odefun(t,y2),...]. If f/ y is a sparse matrix, set the JPattern property to the sparsity pattern of f/ y, i.e., a sparse matrix S with S(i,j) = 1 if the ith component of f(t,y) depends on the jth component of y, and 0 otherwise. The solvers of the ODE suite can solve problems of the form M(t,y)y = f(t,y), with time- and state-dependent mass matrix M. (The ode23s solver can solve only equations with constant mass matrices.) If a problem has a mass matrix, create a function

3 of 8 09.01.2016 09:34 M = MASS(t,y) that returns the value of the mass matrix, and use odeset to set the Mass property to @MASS. If the mass matrix is constant, the matrix should be used as the value of the Mass property. Problems with state-dependent mass matrices are more difficult: If the mass matrix does not depend on the state variable y and the function MASS is to be called with one input argument, t, set the MStateDependence property to 'none'. If the mass matrix depends weakly on y, set MStateDependence to 'weak' (the default); otherwise, set it to 'strong'. In either case, the function MASS is called with the two arguments (t,y). If there are many differential equations, it is important to exploit sparsity: Return a sparse M(t,y). Supply the sparsity pattern of f/ y using the JPattern property or a sparse f/ y using the Jacobian property. For strongly state-dependent M(t,y), set MvPattern to a sparse matrix S with S(i,j) = 1 if for any k, the (i,k) component of M(t,y) depends on component j of y, and 0 otherwise. If the mass matrix M is singular, then M(t,y)y = f(t,y) is a system of differential algebraic equations. DAEs have solutions only when y 0 is consistent, that is, if there is a vector yp 0 such that M(t 0,y 0)yp 0 = f(t 0,y 0). The ode15s and ode23t solvers can solve DAEs of index 1 provided that y0 is sufficiently close to being consistent. If there is a mass matrix, you can use odeset to set the MassSingular property to 'yes', 'no', or 'maybe'. The default value of 'maybe' causes the solver to test whether the problem is a DAE. You can provide yp0 as the value of the InitialSlope property. The default is the zero vector. If a problem is a DAE, and y0 and yp0 are not consistent, the solver treats them as guesses, attempts to compute consistent values that are close to the guesses, and continues to solve the problem. When solving DAEs, it is very advantageous to formulate the problem so that M is a diagonal matrix (a semi-explicit DAE). Solver Problem Type Order of Accuracy When to Use ode45 Nonstiff Medium Most of the time. This should be the first solver you try. ode23 Nonstiff Low For problems with crude error tolerances or for solving moderately stiff problems. ode113 Nonstiff Low to high For problems with stringent error tolerances or for solving computationally intensive problems. ode15s Stiff Low to medium If ode45 is slow because the problem is stiff. ode23s Stiff Low If using crude error tolerances to solve stiff systems and the mass matrix is constant. ode23t Moderately Stiff Low For moderately stiff problems if you need a solution without numerical damping. ode23tb Stiff Low If using crude error tolerances to solve stiff systems. The algorithms used in the ODE solvers vary according to order of accuracy [6] and the type of systems (stiff or nonstiff) they are designed to solve. See Algorithms for more details. Options Different solvers accept different parameters in the options list. For more information, see odeset and Integrator Options in the MATLAB Mathematics documentation. Parameters ode45 ode23 ode113 ode15s ode23s ode23t ode23tb RelTol, AbsTol, NormControl

olve moderately stiff ODEs and DAEs; trapezoidal rule - MATLAB o... of 8 09.01.2016 09:34 Parameters ode45 ode23 ode113 ode15s ode23s ode23t ode23tb OutputFcn, OutputSel, Refine, Stats NonNegative * * * Events MaxStep, InitialStep Jacobian, JPattern, Vectorized Mass MStateDependence MvPattern MassSingular InitialSlope MaxOrder, BDF Note You can use the NonNegative parameter with ode15s, ode23t, and ode23tb only for those problems for which there is no mass matrix. Examples Example 1 An example of a nonstiff system is the system of equations describing the motion of a rigid body without external forces. y 1 = y 2 y 3 y 2 = y 1 y 3 y 1 (0)= 0 y 2 (0)= 1 y 3 = 0.51y 1 y 2 y 3 (0)= 1 To simulate this system, create a function rigid containing the equations function dy = rigid(t,y) dy = zeros(3,1); % a column vector dy(1) = y(2) * y(3); dy(2) = y(1) * y(3); dy(3) = 0.51 * y(1) * y(2); In this example we change the error tolerances using the odeset command and solve on a time interval [0 12] with an initial condition vector [0 1 1] at time 0. options = odeset('reltol',1e 4,'AbsTol',[1e 4 1e 4 1e 5]); [T,Y] = ode45(@rigid,[0 12],[0 1 1],options); Plotting the columns of the returned array Y versus T shows the solution plot(t,y(:,1),' ',T,Y(:,2),'.',T,Y(:,3),'.')

olve moderately stiff ODEs and DAEs; trapezoidal rule - MATLAB o... of 8 09.01.2016 09:34 Example 2 An example of a stiff system is provided by the van der Pol equations in relaxation oscillation. The limit cycle has portions where the solution components change slowly and the problem is quite stiff, alternating with regions of very sharp change where it is not stiff. y 1 y 2 = y 2 =1000(1 y 2 1 )y 2 y 1 y 1 (0) =2 y 2 (0) =0 To simulate this system, create a function vdp1000 containing the equations function dy = vdp1000(t,y) dy = zeros(2,1); % a column vector dy(1) = y(2); dy(2) = 1000*(1 y(1)^2)*y(2) y(1); For this problem, we will use the default relative and absolute tolerances (1e 3 and 1e 6, respectively) and solve on a time interval of [0 3000] with initial condition vector [2 0] at time 0. [T,Y] = ode15s(@vdp1000,[0 3000],[2 0]); Plotting the first column of the returned matrix Y versus T shows the solution plot(t,y(:,1),' o')

6 of 8 09.01.2016 09:34 Example 3 This example solves an ordinary differential equation with time-dependent terms. Consider the following ODE, with time-dependent parameters defined only through the set of data points given in two vectors: y'(t) + f(t)y(t) = g(t) The initial condition is y(1) = 1, where the function f(t) is defined by the n-by-1 vector f evaluated at times ft, and the function g(t) is defined by the m-by-1 vector g evaluated at times gt. First, define the time-dependent parameters f(t) and g(t) as the following: ft = linspace(0,5,25); % Generate t for f f = ft.^2 ft 3; % Generate f(t) gt = linspace(1,6,25); % Generate t for g g = 3*sin(gt 0.25); % Generate g(t) Write a function to interpolate the data sets specified above to obtain the value of the time-dependent terms at the specified time: function dydt = myode(t,y,ft,f,gt,g) f = interp1(ft,f,t); % Interpolate the data set (ft,f) at time t g = interp1(gt,g,t); % Interpolate the data set (gt,g) at time t dydt = f.*y + g; % Evaluate ODE at time t Call the derivative function myode.m within the MATLAB ode45 function specifying time as the first input argument : Tspan = [1 5]; % Solve from t=1 to t=5 IC = 1; % y(t=1) = 1 [T Y] = ode45(@(t,y) myode(t,y,ft,f,gt,g),tspan,ic); % Solve ODE Plot the solution y(t) as a function of time: plot(t, Y); title('plot of y as a function of time'); xlabel('time'); ylabel('y(t)');

7 of 8 09.01.2016 09:34 More About expand all Algorithms ode45 is based on an explicit Runge-Kutta (4,5) formula, the Dormand-Prince pair. It is a one-step solver in computing y(t n), it needs only the solution at the immediately preceding time point, y(t n 1). In general, ode45 is the best function to apply as a first try for most problems. [3] ode23 is an implementation of an explicit Runge-Kutta (2,3) pair of Bogacki and Shampine. It may be more efficient than ode45 at crude tolerances and in the presence of moderate stiffness. Like ode45, ode23 is a one-step solver. [2] ode113 is a variable order Adams-Bashforth-Moulton PECE solver. It may be more efficient than ode45 at stringent tolerances and when the ODE file function is particularly expensive to evaluate. ode113 is a multistep solver it normally needs the solutions at several preceding time points to compute the current solution. [7] The above algorithms are intended to solve nonstiff systems. If they appear to be unduly slow, try using one of the stiff solvers below. ode15s is a variable order solver based on the numerical differentiation formulas (NDFs). Optionally, it uses the backward differentiation formulas (BDFs, also known as Gear's method) that are usually less efficient. Like ode113, ode15s is a multistep solver. Try ode15s when ode45 fails, or is very inefficient, and you suspect that the problem is stiff, or when solving a differential-algebraic problem. [9], [10] ode23s is based on a modified Rosenbrock formula of order 2. Because it is a one-step solver, it may be more efficient than ode15s at crude tolerances. It can solve some kinds of stiff problems for which ode15s is not effective. [9] ode23t is an implementation of the trapezoidal rule using a "free" interpolant. Use this solver if the problem is only moderately stiff and you need a solution without numerical damping. ode23t can solve DAEs. [10] ode23tb is an implementation of TR-BDF2, an implicit Runge-Kutta formula with a first stage that is a trapezoidal rule step and a second stage that is a backward differentiation formula of order two. By construction, the same iteration matrix is used in evaluating both stages. Like ode23s, this solver may be more efficient than ode15s at crude tolerances. [8], [1] Create Function Handle References

8 of 8 09.01.2016 09:34 [1] Bank, R. E., W. C. Coughran, Jr., W. Fichtner, E. Grosse, D. Rose, and R. Smith, "Transient Simulation of Silicon Devices and Circuits," IEEE Trans. CAD, 4 (1985), pp. 436 451. [2] Bogacki, P. and L. F. Shampine, "A 3(2) pair of Runge-Kutta formulas," Appl. Math. Letters, Vol. 2, 1989, pp. 321 325. [3] Dormand, J. R. and P. J. Prince, "A family of embedded Runge-Kutta formulae," J. Comp. Appl. Math., Vol. 6, 1980, pp. 19 26. [4] Forsythe, G., M. Malcolm, and C. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, New Jersey, 1977. [5] Kahaner, D., C. Moler, and S. Nash, Numerical Methods and Software, Prentice-Hall, New Jersey, 1989. [6] Shampine, L. F., Numerical Solution of Ordinary Differential Equations, Chapman & Hall, New York, 1994. [7] Shampine, L. F. and M. K. Gordon, Computer Solution of Ordinary Differential Equations: the Initial Value Problem, W. H. Freeman, San Francisco, 1975. [8] Shampine, L. F. and M. E. Hosea, "Analysis and Implementation of TR-BDF2," Applied Numerical Mathematics 20, 1996. [9] Shampine, L. F. and M. W. Reichelt, "The MATLAB ODE Suite," SIAM Journal on Scientific Computing, Vol. 18, 1997, pp. 1 22. [10] Shampine, L. F., M. W. Reichelt, and J.A. Kierzenka, "Solving Index-1 DAEs in MATLAB and Simulink," SIAM Review, Vol. 41, 1999, pp. 538 552. See Also deval ode15i odeget odeset Introduced before R2006a