ordinary and partial differential equation routines in matlab - h.j. lee & w.e. schiesser

515 548 0
ordinary and partial differential equation routines in matlab - h.j. lee & w.e. schiesser

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Ordinary and Partial Differential Equation Routines in C, C++, Fortran, Javađ, Mapleđ, and MATLABđ Copyright â Chapman & Hall/CRC Copyright (C) 2004 by 2004 Chapman by2004 Chapman &byHall/CRC & Hall/CRC Ordinary and Partial Differential Equation Routines in C, C++, Fortran, Java®, Maple®, and MATLAB® H.J Lee and W.E Schiesser CHAPMAN & HALL/CRC A CRC Press Company Boca Raton London New York Washington, D.C Copyright © Chapman & Hall/CRC Copyright (C) 2004 by 2004 Chapman by2004 Chapman &byHall/CRC & Hall/CRC C231 disclaimer.fm Page Friday, October 17, 2003 9:28 AM Java is a registered trademark of Sun Microsystems, Inc Maple is a registered trademark of Waterloo Maple, Inc MATLAB is a registered trademark of The MathWorks, Inc For product information, please contact: The MathWorks, Inc Apple Hill Drive Natick, MA 01760-2098 Tel.: 508-647-7000 Fax: 508-647-7001 e-mail: info@mathworks.com Web: www.mathworks.com http://www.mathworks.com/ Library of Congress Cataloging-in-Publication Data Lee, H J (Hyun Jin) Ordinary and partial differential equation routines in C, C++, Fortran, Java, Maple, and MATLAB / H.J Lee and W.E Schiesser p cm Includes bibliographical references and index ISBN 1-58488-423-1 (alk paper) Differential equations—Data processing Differential equations, Partial—Data processing I Schiesser, W E II Title QA371.5.D37L44 2003 515¢.352¢0285—dc22 2003055809 This book contains information obtained from authentic and highly regarded sources Reprinted material is quoted with permission, and sources are indicated A wide variety of references are listed Reasonable efforts have been made to publish reliable data and information, but the author and the publisher cannot assume responsibility for the validity of all materials or for the consequences of their use Neither this book nor any part may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, microfilming, and recording, or by any information storage or retrieval system, without prior permission in writing from the publisher The consent of CRC Press LLC does not extend to copying for general distribution, for promotion, for creating new works, or for resale Specific permission must be obtained in writing from CRC Press LLC for such copying Direct all inquiries to CRC Press LLC, 2000 N.W Corporate Blvd., Boca Raton, Florida 33431 Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation, without intent to infringe Visit the CRC Press Web site at www.crcpress.com © 2004 by Chapman & Hall/CRC No claim to original U.S Government works International Standard Book Number 1-58488-423-1 Library of Congress Card Number 2003055809 Printed in the United States of America Printed on acid-free paper Copyright © Chapman & Hall/CRC Copyright (C) 2004 by 2004 Chapman by2004 Chapman &byHall/CRC & Hall/CRC Preface Initial value ordinary differential equations (ODEs) and partial differential equations (PDEs) are among the most widely used forms of mathematics in science and engineering However, insights from ODE/PDE-based models are realized only when solutions to the equations are produced with acceptable accuracy and with reasonable effort Most ODE/PDE models are complicated enough (e.g., sets of simultaneous nonlinear equations) to preclude analytical methods of solution; instead, numerical methods must be used, which is the central topic of this book The calculation of a numerical solution usually requires that wellestablished numerical integration algorithms are implemented in quality library routines The library routines in turn can be coded (programmed) in a variety of programming languages Typically, for a scientist or engineer with an ODE/PDE- based mathematical model, finding routines written in a familiar language can be a demanding requirement, and perhaps even impossible (if such routines not exist) The purpose of this book, therefore, is to provide a set of ODE/PDE integration routines written in six widely accepted and used languages Our intention is to facilitate ODE/PDE-based analysis by using the library routines to compute reliable numerical solutions to the ODE/PDE system of interest However, the integration of ODE/PDEs is a large subject, and to keep this discussion to reasonable length, we have limited the selection of algorithms and the associated routines Specifically, we concentrate on explicit (nonstiff) Runge Kutta (RK) embedded pairs Within this setting, we have provided integrators that are both fixed step and variable step; the latter accept a userspecified error tolerance and attempt to compute a solution to this required accuracy The discussion of ODE integration includes truncation error monitoring and control, h and p refinement, stability and stiffness, and explicit and implicit algorithms Extensions to stiff systems are also discussed and illustrated through an ODE application; however, a detailed presentation of stiff (implicit) algorithms and associated software in six languages was judged impractical for a book of reasonable length Further, we have illustrated the application of the ODE integration routines to PDEs through the method of lines (MOL) Briefly, the spatial (boundary value) derivatives of the PDEs are approximated algebraically, typically by finite differences (FDs); the resulting system of initial-value ODEs is then solved numerically by one of the ODE routines Copyright © Chapman & Hall/CRC Copyright (C) 2004 by 2004 Chapman by2004 Chapman &by Hall/CRC & Hall/CRC Thus, we have attempted to provide the reader with a set of computational tools for the convenient solution of ODE/PDE models when programming in any of the six languages The discussion is introductory with limited mathematical details Rather, we rely on numerical results to illustrate some basic mathematical properties, and we avoid detailed mathematical analysis (e.g., theorems and proofs), which may not really provide much assistance in the actual calculation of numerical solutions to ODE/PDE problems Instead, we have attempted to provide useful computational tools in the form of software The use of the software is illustrated through a small number of ODE/PDE applications; in each case, the complete code is first presented, and then its components are discussed in detail, with particular reference to the concepts of integration, e.g., stability, error monitoring, and control Since the algorithms and the associated software have limitations (as all algorithms and software), we have tried to point out these limitations, and make suggestions for additional methods that could be effective Also, we have intentionally avoided using features specific to a particular language, e.g., sparse utilities, object-oriented programming Rather, we have emphasized the commonality of the programming in the six languages, and thereby illustrate how scientific computation can be done in any of the languages Of course, language-specific features can be added to the source code that is provided We hope this format will allow the reader to understand the basic elements of ODE/PDE integration, and then proceed expeditiously to a numerical solution of the ODE/PDE system of interest The applications discussed in detail, two in ODEs and two in PDEs, can be used as a starting point (i.e., as templates) for the development of a spectrum of new applications We welcome comments and questions about how we might be of assistance (directed to wes1@lehigh.edu) Information for acquiring (gratis) all the source code in this book is available from http://www.lehigh.edu/˜ wes1/ wes1.html Additional information about the book and software is available from the CRC Press Web site, http://www.crcpress.com Dr Fred Chapman provided expert assistance with the Maple programming We note with sadness the passing of Jaeson Lee, father of H J Lee, during the completion of H J Lee’s graduate studies at Lehigh University H J Lee W E Schiesser Bethlehem, PA Copyright © Chapman & Hall/CRC Copyright (C) 2004 by 2004 Chapman by2004 Chapman &by Hall/CRC & Hall/CRC Contents Some Basics of ODE Integration 1.1 General Initial Value ODE Problem 1.2 Origin of ODE Integrators in the Taylor Series 1.3 The Runge Kutta Method 1.4 Accuracy of RK Methods 1.5 Embedded RK Algorithms 1.6 Library ODE Integrators 1.7 Stability of RK Methods Solution of a 1x1 ODE System 2.1 Programming in MATLAB 2.2 Programming in C 2.3 Programming in C++ 2.4 Programming in Fortran 2.5 Programming in Java 2.6 Programming in Maple Solution of a 2x2 ODE System 3.1 Programming in MATLAB 3.2 Programming in C 3.3 Programming in C++ 3.4 Programming in Fortran 3.5 Programming in Java 3.6 Programming in Maple Solution of a Linear PDE 4.1 Programming in MATLAB 4.2 Programming in C 4.3 Programming in C++ 4.4 Programming in Fortran 4.5 Programming in Java 4.6 Programming in Maple Solution of a Nonlinear PDE 5.1 Programming in MATLAB 5.2 Programming in C 5.3 Programming in C++ 5.4 Programming in Fortran Copyright © Chapman & Hall/CRC Copyright (C) 2004 by 2004 Chapman by2004 Chapman &by Hall/CRC & Hall/CRC 5.5 Programming in Java 5.6 Programming in Maple Appendix A Embedded Runge Kutta Pairs Appendix B Integrals from ODEs Appendix C Stiff ODE Integration C.1 The BDF Formulas Applied to the 2x2 ODE System C.2 MATLAB Program for the Solution of the 2x2 ODE System C.3 MATLAB Program for the Solution of the 2x2 ODE System Using ode23s and ode15s Appendix D Alternative Forms of ODEs Appendix E Spatial p Refinement Appendix F Testing ODE/PDE Codes Copyright © Chapman & Hall/CRC Copyright (C) 2004 by 2004 Chapman by2004 Chapman &by Hall/CRC & Hall/CRC Some Basics of ODE Integration The central topic of this book is the programming and use of a set of library routines for the numerical solution (integration) of systems of initial value ordinary differential equations (ODEs) We start by reviewing some of the basic concepts of ODEs, including methods of integration, that are the mathematical foundation for an understanding of the ODE integration routines 1.1 General Initial Value ODE Problem The general problem for a single initial-value ODE is simply stated as dy = f (y, t), dt where y= t= f (y, t) = t0 = y0 = y(t0 ) = y0 (1.1)(1.2) dependent variable independent variable derivative function initial value of the independent variable initial value of the dependent variable Equations 1.1 and 1.2 will be termed a 1x1 problem (one equation in one unknown) The solution of this 1x1 problem is the dependent variable as a function of the independent variable, y(t) (this function when substituted into Equations 1.1 and 1.2 satisfies these equations) This solution may be a mathematical function, termed an analytical solution Copyright by Chapman & Hall/CRC Copyright 2004 © by2004 Chapman & Hall/CRC To illustrate these ideas, we consider the 1x1 problem, from Braun1 (which will be discussed subsequently in more detail) dy y(t0 ) = y0 (1.3)(1.4) = λe −αt y, dt where λ and α are positive constants Equation 1.3 is termed a first-order, linear, ordinary differential equation with variable coefficients These terms are explained below Term Differential equation Ordinary First-order Linear Variable coefficient Explanation Equation 1.3 has a derivative dy/dt = f (y, t) = λe −αt y Equation 1.3 has only one independent variable, t, so that the derivative dy/dt is a total or ordinary derivative The highest-order derivative is first order (dy/dt is first order) y and its derivative dy/dt are to the first power; thus, Equation 1.3 is also termed first degree (do not confuse order and degree) The coefficient e −αt is a function of the independent variable, t (if it were a function of the dependent variable, y, Equation 1.3 would be nonlinear or not first degree) The analytical solution to Equations 1.3 and 1.4 is from Braun:1   λ y(t) = y0 exp (1 − exp(−αt)) , y(0) = y0 α (1.5) where exp(x) = e x Equation 1.5 is easily verified as the solution to Equations 1.3 and 1.4 by substitution in these equations: Terms in Equations 1.3 and 1.4 dy dt −λe −αt y = y(0)  Substitution of Equation 1.5 in Equations 1.3 and 1.4   λ λ (1 − exp(−αt)) (−exp(−αt))(−α) α α   λ (1 − exp(−αt)) (exp(−αt)) = λy0 exp α   λ −λe −αt y0 exp (1 − exp(−αt)) α = y0 exp  λ (1 − exp(−α(0))) y0 exp α  thus confirming Equation 1.5 satisfies Equations 1.3 and 1.4 Copyright by Chapman & Hall/CRC Copyright 2004 © by2004 Chapman & Hall/CRC = y0 (e ) = y0 As an example of a nxn problem (n ODEs in n unknowns), we will also subsequently consider in detail the 2x2 system dy1 = a 11 y1 + a 12 y2 dt y1 (0) = y10 dy2 = a 21 y1 + a 22 y2 dt y2 (0) = y20 (1.6) The solution to Equations 1.6 is again the dependent variables, y1 , y2 , as a function of the independent variable, t Since Equations 1.6 are linear, constant coefficient ODEs, their solution is easily derived, e.g., by assuming exponential functions in t or by the Laplace transform If we assume exponential functions y1 (t) = c e λt y2 (t) = c e λt (1.7) where c 1, c , and λ are constants to be determined, substitution of Equations 1.7 in Equations 1.6 gives c λe λt = a 11 c e λt + a 12 c e λt c λe λt = a 21 c e λt + a 22 c e λt Cancellation of e λt gives a system of algebraic equations (this is the reason assuming exponential solutions works in the case of linear, constant coefficient ODEs) c λ = a 11 c + a 12 c c λ = a 21 c + a 22 c or (a 11 − λ)c + a 12 c = a 21 c + (a 22 − λ)c = (1.8) Equations 1.8 are the 2x2 case of the linear algebraic eigenvalue problem (A − λI)c = where  a 11  a 21  A=   a 12 a 22 a n1 a n2  0  I=   0 ··· ··· ··· ··· ···  a 1n a 2n     · · · a nn  0    Copyright by Chapman & Hall/CRC Copyright 2004 © by2004 Chapman & Hall/CRC (1.9) ... Ordinary and partial differential equation routines in C, C++, Fortran, Java, Maple, and MATLAB / H.J Lee and W.E Schiesser p cm Includes bibliographical references and index ISBN 1-5 848 8-4 2 3-1 .. .Ordinary and Partial Differential Equation Routines in C, C++, Fortran, Java®, Maple®, and MATLAB? ? H.J Lee and W.E Schiesser CHAPMAN & HALL/CRC A CRC Press Company... Programming in Maple Solution of a 2x2 ODE System 3.1 Programming in MATLAB 3.2 Programming in C 3.3 Programming in C++ 3.4 Programming in Fortran 3.5 Programming in Java 3.6 Programming in Maple

Ngày đăng: 08/04/2014, 10:27

Từ khóa liên quan

Mục lục

  • Ordinary and Partial Differential Equation Routines in C, C++, Fortran, Java®, Maple®, and MATLAB®

    • Preface

    • Contents

    • c231_c01.pdf

      • Ordinary and Partial Differential Equation Routines in C, C++, Fortran, Java®, Maple®, and MATLAB®

        • Contents

        • Chapter 1: Some Basics of ODE Integration

          • General Initial Value ODE Problem

          • Origin of ODE Integrators in the Taylor Series

          • The Runge Kutta Method

          • Accuracy of RK Methods

          • Embedded RK Algorithms

          • Library ODE Integrators

          • Stability of RK Methods

          • References

          • c231_c02.pdf

            • Ordinary and Partial Differential Equation Routines in C, C++, Fortran, Java®, Maple®, and MATLAB®

              • Contents

              • Chapter 2: Solution of a 1 x 1 ODE System

                • 2.1 Programming in MATLAB

                  • Program 2.1.1

                  • Program 2.1.2

                  • Program 2.1.3

                  • Program 2.1.4

                  • Program 2.1.5

                  • Program 2.1.6

                  • Program 2.1.7

                  • Program 2.1.8

Tài liệu cùng người dùng

Tài liệu liên quan