ebook img

Difference Matrices for ODE and PDE. A MATLAB Companion PDF

212 Pages·2023·5.252 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Difference Matrices for ODE and PDE. A MATLAB Companion

John M. Neuberger Difference Matrices for ODE and PDE A MATLAB® Companion Difference Matrices for ODE and PDE John M. Neuberger Difference Matrices for ODE and PDE ® A MATLAB Companion 123 JohnM.Neuberger Department ofMathematics andStatistics Northern ArizonaUniversity Flagstaff, AZ,USA ISBN978-3-031-11999-6 ISBN978-3-031-12000-8 (eBook) https://doi.org/10.1007/978-3-031-12000-8 MATLABisaregisteredtrademarkofTheMathWorks,Inc.,Natick,MA,USA Mathematics Subject Classification: 65-01, 35-01, 34-01, 65L, 65M, 65M06, 65M20, 65N, 65N06, 65N25,35F,35G,35A24,35J20 ©SpringerNatureSwitzerlandAG2023 Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpart of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission orinformationstorageandretrieval,electronicadaptation,computersoftware,orbysimilarordissimilar methodologynowknownorhereafterdeveloped. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publicationdoesnotimply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfrom therelevantprotectivelawsandregulationsandthereforefreeforgeneraluse. The publisher, the authors, and the editorsare safeto assume that the adviceand informationin this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained hereinorforanyerrorsoromissionsthatmayhavebeenmade.Thepublisherremainsneutralwithregard tojurisdictionalclaimsinpublishedmapsandinstitutionalaffiliations. ThisSpringerimprintispublishedbytheregisteredcompanySpringerNatureSwitzerlandAG Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland Preface This text will be useful for the four different audiences listed below. It is expected that all readers will have knowledge of basic calculus, linear algebra, and ordinary differential equations, and that the successful student will either already know elementary partial differential equations, or be concurrently learning that subject. ThematerialisintendedtobeaccessibletothosewithoutexpertiseinMATLAB®, although a little prior experience with programming is probably required. 1. This text serves as a supplement for the student in an introductory partial dif- ferentialequationscourse.Aselectionoftheincludedexercisescanbeassigned asprojectsthroughoutthesemester.Throughtheuseofthistext,thestudentwill develop the skills to run simulations corresponding to the primarily theoretical course material covered by the instructor. 2. These notes work well as a standalone graduate course text in introductory scientific computing for partial differential equations. With prerequisite knowledge of ordinary and partial differential equations and elementary numerical analysis, most of the material can be covered and many of the exercisesassignedinaone-semestercourse.Someoftheharderexercisesmake substantial projects, and relate to topics from the other graduate mathematics coursesgraduatestudentstypicallytake,e.g.,differentialequationsandtopicsin nonlinear functional analysis. 3. Established researchers in theoretical partial differential equations may find thesenotesusefulaswell,particularlyasanintroductoryguidefortheirresearch students. Those unfamiliar with MATLAB can use the included material as a reference in quickly developing their own applications in that language. A mathematician who is new to the practical implementation of methods for scientific computation in general can with relative ease, by working through a selection of exercises, learn how to implement and execute numerical simula- tionsofdifferentialequationsinMATLAB.Thesenotescanserveasapractical guide in independent study, undergraduate or graduate research experiences, or for help simulating solutions to specific thesis- or dissertation-related v vi Preface experiments. The author hopes that the ease and brevity with which the notes provide solutions to fairly significant problems will serve as inspiration. 4. The text can serve as a supplement for the instructor teaching any course in differentialequations.Manyoftheexamplescanbeeasilyimplementedandthe resulting simulation demonstrated by the instructor. If the course has a numerical component, a few exercises of suitable difficulty can be assigned as student projects. Practical assistance in implementing algorithms in MATLAB can be found in this text. Scientist and engineers have valid motivations to become proficient at imple- menting numerical algorithms for solving PDE. The text’s emphasis on enforcing boundary conditions, eigenfunctions, and general regions will be useful as an introductiontotheiradvancedapplications.Forthemathematician,accomplishedor student,amorepowerfulbenefitcanbethetangible,visualrealizationoftheobjects of calculus, differential equations, and linear algebra. The high-level programs are developed by the reader from earlier programs and short fragments of relatable code. The resulting simulations are demonstrations of the properties of the under- lying mathematical objects, where vectors represent functions, matrix operations represent differentiation and integration, and calculations such as solving linear systemsorfindingeigenvaluesareeasilyaccomplishedwithonelineofcode.Even withoutmuchpriorknowledgeofprogrammingorMATLAB,byworkingthrough a selection of exercises in this text, the reader will be able to create working programs that simulate many of the classic problems from PDE, while gaining an understanding of the underlying fundamental mathematical principles. The approach of the text is to first review MATLAB and a small selection of techniques from elementary numerical analysis, and then introduce difference matricesinthecontextofordinarydifferentialequations.Wethenapplytheseideas to PDE, including topics from the heat, wave, and Laplace equations, eigenvalue problems, and semilinear boundary value problems. We enforce boundary condi- tions on regions including the interval, square, disk, and cube, and more general domains. We push the general notion that linear problems can be expressed as a single linear system, while many nonlinear problems can be solved via Newton’s method. Flagstaff, USA John M. Neuberger Acknowledgements I would first and foremost like to acknowledge my father J. W. Neuberger. He taught me much of what I know about differential equations and the numerical solution of them. His belief in my pedagogical approach and the practical useful- ness of my course notes was my main motivation in publishing them. IalsowouldliketothankmyPh.D.advisorAlfonsoCastrowhointroducedme to nonlinear functional analysis, particularly as it pertains to semilinear elliptic boundaryvalueproblems.Chapter5contentofthistextreflectsasmallsliceofmy lifetime pursuits to understand and computationally simulate the equations of that subject. Ihavebeenextremelyluckyinhavingawonderfullysupportivefamily.Mywife Dina has been the main source of inspiration over my career as a professor of mathematics. My son Nick has an interest in mathematics as well, and has been insistent that I refine the notes so that others could use them. I would also like to thank my 20-plus years of undergraduate and graduate partial differential equations and numerical analysis students. Their feedback was invaluableintheprocessofdevelopingandrefiningmynotes.Themuch-improved textcontainsnumerousclarificationsandhintsasadirectresultoftheirsuggestions, and the exercises are more robust and complete, thanks to their countless hours of coding and grinding out project reports. I learned a few MATLAB® tricks from them too. A special thanks goes to my former and current students Tyler Diggans, Ryan Kelly, and Ian Williams, who each took a turn at proofreading, and made some valuable editorial suggestions from the student perspective. vii Contents 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 A Summary of the Differential Equations We Will Consider. . . . 1 1.2 The Use of MATLAB® and the Student Exercises . . . . . . . . . . . 2 1.2.1 Using MATLAB®’s Debugger . . . . . . . . . . . . . . . . . . . 3 1.2.2 Line Numbering in MATLAB® Examples. . . . . . . . . . . 4 1.2.3 Reproducing Codes and Exercises. . . . . . . . . . . . . . . . . 4 1.2.4 Guidelines to the Homework Exercises . . . . . . . . . . . . . 5 1.3 The Organization of This Text . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 Review of Elementary Numerical Methods and MATLAB®. . . . . . . 11 2.1 Introduction to Basic MATLAB® at the Command Line. . . . . . . 12 2.1.1 MATLAB®:sum,prod,max,min,abs,norm,linspace, for loop, eigs, and sort . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2 Runge–Kutta Method for Initial Value Problems . . . . . . . . . . . . 17 2.2.1 The Shooting Method for ODE BVP—an IVP Approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.2.2 Comparison of Approximate Solutions to Exact Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.2.3 MATLAB®: Ones, Zeros, the ‘:’ Iterator, the @ Syntax for Defining Inline Functions, Subfunctions . . . . 23 2.2.4 Rows Versus Columns Part I, Diagnosing Dimension and Size Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.3 Numerical Differentiation and Integration. . . . . . . . . . . . . . . . . . 27 2.3.1 Higher Order Differences and Symbolic Computation. . . 32 2.3.2 MATLAB®: kron, spdiags, ‘backslash’ (mldivide), tic, and toc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.4 Newton’s Method for Vector Fields. . . . . . . . . . . . . . . . . . . . . . 36 2.4.1 MATLAB®: if, else, while, fprintf, meshgrid, surf, reshape, find, single indexing, and rows versus columns Part II . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 ix x Contents 2.5 Cubic Spline Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.5.1 Making Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.6 Theory: ODE, Systems, Newton’s Method, IVP Solvers, and Difference Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.6.1 Some ODE Theory and Techniques . . . . . . . . . . . . . . . 48 2.6.2 Convergence and Order of Newton’s Method . . . . . . . . 52 2.6.3 First-Order IVP Numerical Solvers: Euler’s and Runge–Kutta’s. . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.6.4 Difference Formulas and Orders of Approximation. . . . . 54 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 3 Ordinary Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.1 Second-Order Semilinear Elliptic Boundary Value Problems. . . . 64 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 3.2 Linear Ordinary Second-Order BVP. . . . . . . . . . . . . . . . . . . . . . 69 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 3.3 Eigenvalues of (cid:1)D and Fourier Series . . . . . . . . . . . . . . . . . . . 71 2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 3.4 Enforcing Zero Dirichlet, Zero Neumann, and Periodic Boundary Conditions Using Either Point or Cell Grid.... . . . . . . 77 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 3.5 First-Order Linear Solvers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 3.6 Systems of First-Order Linear Equations for Second-Order IVP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.7 First-Order Nonlinear IVP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 3.8 A Practical Guide to Fourier Series . . . . . . . . . . . . . . . . . . . . . . 89 4 Partial Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 4.1 The Laplacian on the Unit Square . . . . . . . . . . . . . . . . . . . . . . . 94 4.2 Creating the Sparse Laplacian Matrix D and Eigenvalues . . . . . 95 2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 4.3 Semilinear Elliptic BVP on the Square. . . . . . . . . . . . . . . . . . . . 100 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 4.4 Laplace’s Equation on the Square . . . . . . . . . . . . . . . . . . . . . . . 102 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 4.5 The Heat Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 4.5.1 Explicit Method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 4.5.2 Implicit Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 4.5.3 Explicit–Implicit Method . . . . . . . . . . . . . . . . . . . . . . . 111 Contents xi 4.5.4 The Method of Lines . . . . . . . . . . . . . . . . . . . . . . . . . . 112 4.5.5 Fourier Expansion with Numerical Integration . . . . . . . . 113 4.5.6 Block Matrix Systems . . . . . . . . . . . . . . . . . . . . . . . . . 117 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 4.6 The Wave Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 4.6.1 The Method of Lines . . . . . . . . . . . . . . . . . . . . . . . . . . 124 4.6.2 A Good Explicit Method . . . . . . . . . . . . . . . . . . . . . . . 124 4.6.3 Block Matrix Systems and D’Alembert Matrices . . . . . . 126 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 4.7 Tricomi’s Equation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 4.8 General Regions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 4.8.1 The Laplacian on the Cube. . . . . . . . . . . . . . . . . . . . . . 140 4.8.2 The Laplacian on the Disk . . . . . . . . . . . . . . . . . . . . . . 141 4.8.3 Accurate Eigenvalues of the Laplacian on Disk, Annulus, and Sections . . . . . . . . . . . . . . . . . . . . . . . . . 146 4.8.4 The Laplace–Beltrami Operator on a Spherical Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 4.8.5 A General Region Code . . . . . . . . . . . . . . . . . . . . . . . . 151 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 4.9 First-Order PDE and the Method of Characteristics. . . . . . . . . . . 161 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 4.10 Theory: Separation of Variables for PDE on Rectangular and Polar Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 4.10.1 Eigenfunctions of the Laplacian . . . . . . . . . . . . . . . . . . 164 4.10.2 Laplace’s Equation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 4.10.3 The Heat Equation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 4.10.4 The Wave Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 5 Advanced Topics in Semilinear Elliptic BVP . . . . . . . . . . . . . . . . . . 181 5.1 Branch Following and Bifurcation Detection . . . . . . . . . . . . . . . 181 5.1.1 The Tangent Newton Method for Branch Following. . . . 182 5.1.2 The Secant Method for Bifurcation Detection . . . . . . . . 183 5.1.3 Secondary Bifurcations and Branch Switching . . . . . . . . 186 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 5.2 Mountain Pass and Modified Mountain Pass Algorithms for Semilinear BVP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 5.2.1 The MPA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 5.2.2 The MMPA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 5.3 The p-Laplacian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 References.... .... .... .... ..... .... .... .... .... .... ..... .... 203

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.