0% found this document useful (0 votes)
12 views20 pages

Numerical Analysis Using R Solutions To

The book 'Numerical Analysis Using R' by Graham W. Griffiths provides practical methods for solving initial and boundary value problems related to ordinary and partial differential equations using the R programming language. It covers standard techniques, high-resolution methods, and meshless approaches, along with detailed case studies to illustrate their application. This resource is aimed at students and practitioners in science and engineering, particularly those utilizing R for numerical analysis.

Uploaded by

Fernando Galvão
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views20 pages

Numerical Analysis Using R Solutions To

The book 'Numerical Analysis Using R' by Graham W. Griffiths provides practical methods for solving initial and boundary value problems related to ordinary and partial differential equations using the R programming language. It covers standard techniques, high-resolution methods, and meshless approaches, along with detailed case studies to illustrate their application. This resource is aimed at students and practitioners in science and engineering, particularly those utilizing R for numerical analysis.

Uploaded by

Fernando Galvão
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Cambridge University Press

978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs


Graham W. Griffiths
Frontmatter
More information

Numerical Analysis Using R

This book presents the latest numerical solutions to initial value problems and
boundary value problems described by ODEs and PDEs. The author offers
practical methods that can be adapted to solve wide ranges of problems and
illustrates them in the increasingly popular open source computer language R,
allowing integration with more statistically based methods.
The book begins with standard techniques, followed by an overview of
“high-resolution” flux limiters and WENO to solve problems with solutions
exhibiting high-gradient phenomena. Meshless methods using radial basis
functions are then discussed in the context of scattered data interpolation and
the solution of PDEs on irregular grids. Three detailed case studies demon-
strate how numerical methods can be used to tackle very different complex
problems.
With its focus on practical solutions to real-world problems, this book is
useful to students and practitioners in all areas of science and engineering,
especially those using R. R Code is available for download from the book’s
home page.

Graham W. Griffiths is a visiting professor in the School of Engineering and


Mathematical Sciences, City University London. His primary interests are in
numerical methods and climate modeling, on which he has previously pub-
lished four books. Griffiths was a founder of Special Analysis and Simulation
Technology Ltd. and later became vice president of operations and technology
with AspenTech. He is a Chartered Engineer and a Fellow of the Institute of
Measurement and Control and was granted Freedom of the City of London
in 1995.

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

NUMERICAL
ANALYSIS USING R
Solutions to ODEs and PDEs

Graham W. Griffiths
City University, United Kingdom

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

32 Avenue of the Americas, New York, NY 10013

Cambridge University Press is part of the University of Cambridge.


It furthers the University’s mission by disseminating knowledge in the pursuit of
education, learning, and research at the highest international levels of excellence.

www.cambridge.org
Information on this title: www.cambridge.org/9781107115613
© Graham W. Griffiths 2016
This publication is in copyright. Subject to statutory exception
and to the provisions of relevant collective licensing agreements,
no reproduction of any part may take place without the written
permission of Cambridge University Press.
First published 2016
Printed in the United States of America
A catalog record for this publication is available from the British Library.
Library of Congress Cataloging in Publication Data
Names: Griffiths, Graham W.
Title: Numerical analysis using R : solutions to ODEs and PDEs / Graham W. Griffiths,
City University, United Kingdom.
Description: New York, NY : Cambridge University Press, 2016. | Includes bibliographical
references and index.
Identifiers: LCCN 2015046150 | ISBN 9781107115613 (hardback : alk. paper)
Subjects: LCSH: Initial value problems – Data processing. | Boundary value problems –
Data processing. | Differential equations – Data processing. | Differential equations,
Partial – Data processing. | Numerical analysis. | R (Computer program language)
Classification: LCC QA378 .G76 2016 | DDC 518.0285/5133–dc23
LC record available at http://lccn.loc.gov/2015046150
ISBN 978-1-107-11561-3 Hardback
Cambridge University Press has no responsibility for the persistence or accuracy of URLs
for external or third-party Internet Web sites referred to in this publication and does not
guarantee that any content on such Web sites is, or will remain, accurate or appropriate.

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

To the memory of my dear son, Paul W. Griffiths (1977–2015).

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

Contents

Preface page xv

1 ODE Integration Methods . . . . . . . . . . . . . . . . . . . . . . . . . . 1


1.1 Introduction 1
1.2 Euler Methods 11
1.2.1 Forward Euler 11
1.2.2 Backward Euler 12
1.3 Runge–Kutta Methods 12
1.3.1 RK Coefficients 15
1.3.2 Variable Step Size Methods 19
1.3.3 SHK: Sommeijer, Van Der Houwen, and Kok Method 36
1.4 Linear Multistep Methods (LMMs) 37
1.4.1 General 37
1.4.2 Backward Differentiation Formulas (BDFs) 38
1.4.3 Numerical Differentiation Formulas (NDFs) 44
1.4.4 Convergence 46
1.4.5 Adams Methods 60
1.5 Truncation Error and Order of Integration 61
1.5.1 LMM Truncation Error 62
1.5.2 Verification of Integration Order 66
1.6 Stiffness 69
1.7 How to Choose a Numerical Integrator 69
1.A Installation of the R Package Ryacas 70
1.B Installation of the R Package rSymPy 71
References 72

2 Stability Analysis of ODE Integrators . . . . . . . . . . . . . . . . . . . . 74


2.1 General 74
2.1.1 Dahlquist Barrier Theorems 75
2.2 Dahlquist Test Problem 75
2.3 Euler Methods 76

vii

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

viii Contents

2.3.1 Forward Euler 76


2.3.2 Backward Euler 76
2.4 Runge–Kutta Methods 76
2.4.1 RK-1: First-Order Runge–Kutta 76
2.4.2 RK-2: Second-Order Runge–Kutta 79
2.4.3 RK-4: Fourth-Order Runge–Kutta 80
2.4.4 RKF-54: Fehlberg Runge–Kutta 83
2.4.5 SHK: Sommeijer, van der Houwen, and Kok 85
2.5 Linear Multistep Methods (LMMs) 87
2.5.1 General 87
2.5.2 Backward Differentiation Formulas (BDFs) 89
2.5.3 Numerical Differentiation Formulas (NDFs) 95
2.5.4 Adams Methods 97
References 101

3 Numerical Solution of PDEs . . . . . . . . . . . . . . . . . . . . . . . . 102


3.1 Some PDE Basics 102
3.2 Initial and Boundary Conditions 103
3.3 Types of PDE Solutions 105
3.4 PDE Subscript Notation 105
3.5 A General PDE System 106
3.6 Classification of PDEs 107
3.7 Discretization 109
3.7.1 General Finite Difference Terminology 109
3.7.2 The Mesh 111
3.7.3 Nonuniform Grid Spacing 112
3.7.4 The Courant–Friedrichs–Lewy Number 112
3.7.5 The Stencil 112
3.7.6 Upwinding 113
3.8 Method of Lines (MOL) 114
3.8.1 Introduction 114
3.8.2 Finite Difference Matrices 115
3.8.3 MOL 1D: Cartesian Coordinates 123
3.8.4 MOL 2D: Cartesian Coordinates 141
3.8.5 MOL 2D: Polar Coordinates 175
3.9 Fully Discrete Methods 194
3.9.1 Introduction 194
3.9.2 Overview of Some Common Schemes 194
3.9.3 Results from Simulating a Hyperbolic Equation 197
3.10 Finite Volume Method 207
3.10.1 General 207
3.10.2 Application to a 1D Conservative System 208
3.10.3 Application to a General Conservation Law 210
3.11 Interpretation of Results 210
3.11.1 Verification 210
3.11.2 Validation 211
3.11.3 Truncation Error 211

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

Contents ix

3.A Appendix: Derivative Matrix Coefficients 211


3.A.1 First Derivative Schemes 211
3.A.2 Second Derivative Schemes 213
3.A.3 Third Derivative Schemes 215
3.A.4 Fourth Derivative Schemes 216
3.B Appendix: Derivative Matrix Library 217
3.B.1 Example 220
References 222

4 PDE Stability Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 225


4.1 Introduction 225
4.2 The Well-Posed PDE Problem 226
4.3 Matrix Stability Method 231
4.3.1 Semi-Discrete Systems 231
4.4 Von Neumann Stability Method 242
4.4.1 General 242
4.4.2 Fully Discrete Systems 243
4.4.3 Semi-Discrete Systems 253
4.5 Unstructured Grids 260
4.A Fourier Transforms 261
References 262

5 Dissipation and Dispersion . . . . . . . . . . . . . . . . . . . . . . . . 264


5.1 Introduction 264
5.2 Dispersion Relation 264
5.3 Amplification Factor 265
5.4 Dissipation 266
5.5 Dispersion 267
5.6 Dissipation and Dispersion Errors 269
5.6.1 The 1D Advection Equation, Semi-Discrete Upwind 269
5.6.2 The 1D Advection Equation, Semi-Discrete Second-Order
Upwind 270
5.6.3 The 1D Advection Equation, Fully Discrete Upwind 275
5.6.4 The 1D Advection Equation, Fully Discrete Lax–Friedrichs
(LxF) 276
5.7 Group and Phase Velocities 277
5.7.1 Exact Relationships for the Basic PDE 278
5.7.2 Semi-Discrete, First-Order Upwind Discretization 278
5.7.3 Semi-Discrete Leapfrog Discretization 279
5.7.4 Fully Discrete Leapfrog Discretization 280
5.8 Modified PDEs 282
References 284

6 High-Resolution Schemes . . . . . . . . . . . . . . . . . . . . . . . . . 285


6.1 Introduction 285
6.2 The Riemann Problem 285
6.3 Total Variation Diminishing (TVD) Methods 286
6.3.1 TVD Numerical Integration 287

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

x Contents

6.4 Godunov Method 288


6.4.1 Godunov’s Theorem 290
6.5 Flux Limiter Method 292
6.5.1 How Limiters Work 293
6.5.2 Limiter Functions 294
6.6 Monotone Upstream-Centered Schemes for Conservation Laws
(MUSCL) 298
6.6.1 Linear Reconstruction 298
6.6.2 Kurganov and Tadmor Central Scheme 303
6.6.3 Piecewise Parabolic Reconstruction 312
6.6.4 Solutions to the Euler Equations 315
6.7 Weighted Essentially Nonoscillatory (WENO) Method 324
6.7.1 Polynomial Reconstruction: Finite Volume Approach 325
6.7.2 Polynomial Coefficients 327
6.7.3 Polynomial Reconstruction: Finite Difference Reconstruction 331
6.7.4 WENO Reconstruction 331
6.7.5 Alternative Calculation for Substencil Coefficients 332
6.7.6 Weights 335
6.7.7 Smoothness Indicators 336
6.7.8 Calculation of Smoothness Indicator Coefficients 336
6.7.9 Flux Splitting 337
6.7.10 Implementation of a WENO Finite Volume Scheme 337
6.7.11 Scalar Problems 342
6.7.12 Euler Equation Problems 343
6.7.13 2D Examples 347
6.8 Further Reading 351
6.A Eigenvalues of Euler Equations 351
6.B R Code for Simulating 1D Scalar Equation Problems 353
6.B.1 The Main Program 353
6.B.2 The Derivative Function 357
6.B.3 The MUSCL Function 358
6.B.4 Initialization 360
6.C R Code for Simulating 1D Euler Equations Problems 364
6.C.1 The Main Routine 364
6.C.2 Initialization 369
6.C.3 The Derivative Function 370
6.C.4 The MUSCL Function 373
6.C.5 Postsimulation Calculations 374
References 377

7 Meshless Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380


7.1 Introduction 380
7.2 Radial Basis Functions (RBF) 381
7.2.1 Positive Definite RBFs 382
7.2.2 RBF with Compact Support (CSRBF) 382
7.3 Interpolation 384
7.3.1 Interpolation Example: 1D 385

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

Contents xi

7.3.2 Interpolation Example: 2D 387


7.3.3 Larger Interpolation Example: 2D 389
7.3.4 Interpolation Example: 3D 393
7.3.5 Interpolation with Polynomial Precision 397
7.4 Differentiation 398
7.4.1 Derivative Example: 1D 399
7.5 Local RBFs 401
7.5.1 Allocating Stencil Nodes 403
7.5.2 Choosing the Right Shape Parameter Value 404
7.6 Application to Partial Differential Equations 406
7.6.1 Explicit Euler Integration 406
7.6.2 Weighted Average Integration 407
7.6.3 Method of Lines 408
7.6.4 With Nonlinear Terms 408
7.6.5 Initial Conditions (ICs) and Boundary Conditions (BCs) 409
7.6.6 Stability Considerations 410
7.6.7 Time-Dependent PDEs 410
7.6.8 Time-Independent PDEs 434
7.A Franke’s Function 452
7.B Halton Sequence 452
7.C RBF Definitions 454
References 455

8 Conservation Laws . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457


8.1 Introduction 457
8.2 Korteweg–de Vries (KdV) Equation 459
8.2.1 The First Conservation Law, u 459
8.2.2 The Second Conservation Law, u2 459
8.2.3 The Third Conservation Law, u3 + 21 u2x 460
8.2.4 Another Conservation Law 460
8.2.5 An Infinity of Conservation Laws 461
8.2.6 KdV Equation: 2D 463
8.2.7 KdV Equation with Variable Coefficients (vcKdV) 464
8.3 Conservation Laws for Other Evolutionary Equations 466
8.3.1 Nonlinear Schrödinger Equation 466
8.3.2 Boussinesq Equation 468
8.A Symbolic Algebra Computer Source Code 468
References 469

9 Case Study: Analysis of Golf Ball Flight . . . . . . . . . . . . . . . . . . 470


9.1 Introduction 470
9.2 Drag Force 472
9.3 Magnus Force 476
9.4 Gravitational Force 479
9.5 Golf Ball Construction 480
9.6 Ambient Conditions 480

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

xii Contents

9.7 The Shot 483


9.7.1 Golf Ball Compression 483
9.7.2 Spin 484
9.7.3 Launch Angle 484
9.7.4 Bounce and Roll 485
9.7.5 Shot Statistics 486
9.8 Completing the Mathematical Description 487
9.8.1 The Effect of Wind 488
9.9 Computer Simulation 489
9.9.1 Driver Shots 490
9.9.2 Wood Shots 491
9.9.3 Iron Shots 491
9.9.4 Effect of Wind 492
9.9.5 Effect of Differing Ambient Conditions 493
9.9.6 Effect of Push/Pull and Inclined Golf Ball Spin Axis 495
9.9.7 Drag/Lift Carry Test 497
9.9.8 Drag Effect at Ground Level 497
9.10 Computer Code 499
9.10.1 Main Program 499
9.10.2 Derivative Function 503
9.10.3 Initial Conditions 505
References 506

10 Case Study: Taylor–Sedov Blast Wave . . . . . . . . . . . . . . . . . . . 508


10.1 Brief Background to the Problem 508
10.2 System Analysis 508
10.3 Some Useful Gas Law Relations 512
10.4 Shock Wave Conditions 514
10.5 Energy 515
10.6 Photographic Evidence 516
10.7 Trinity Site Conditions 518
10.8 Numerical Solution 519
10.9 Integration of PDEs 529
10.A Appendix: Similarity Analysis 530
10.B Appendix: Analytical Solution 531
10.B.1 Closed-Form Solution 533
10.B.2 Additional Complexity 537
10.B.3 The Los Alamos Primer 537
References 537

11 Case Study: The Carbon Cycle . . . . . . . . . . . . . . . . . . . . . . 539


11.1 Introduction 539
11.2 The Model 539
11.2.1 Atmosphere 542
11.2.2 Oceans 543
11.2.3 Air–Ocean Exchange 544
11.2.4 Carbonate Chemistry 546

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

Contents xiii

11.2.5 Acidity of Surface Seawater 552


11.2.6 Ocean Circulation 553
11.2.7 Emission Profiles 554
11.2.8 Earth’s Radiant Energy Balance 557
11.2.9 How the Atmosphere is Affected by Radiation 562
11.3 Simulation Results 571
11.3.1 Carbon Buildup in the Atmosphere 571
11.3.2 Carbon Buildup in Surface Seawater and Accompanying
Acidification 572
11.3.3 Surface Temperature Changes 575
11.A Appendices 576
11.A.1 Model Differential Equations 576
11.A.2 Correlations for Chemical Equilibrium and Dissociation
Constants 576
11.A.3 Revelle and Uptake Factors 577
11.A.4 Residence Time 579
11.A.5 Mass Action 580
11.A.6 The Electromagnetic Spectrum 580
References 581

Appendix: A Mathematical Aide-Mémoire 585


Index 607

Color plates follow page 284

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

Preface

The language of science and engineering is largely mathematical, which, increasingly,


requires solving problems that are described by ordinary differential equations (ODEs)
and partial differential equations (PDEs). The primary focus of this book is numer-
ical solutions to initial value problems (IVPs) and boundary value problems (BVPs)
described by ODEs and PDEs. The solutions are implemented in computer code using
the open source R language system.
The intended readership is senior undergraduates and postgraduate students in the
subject areas of science, technology, engineering, and mathematics (STEM). The contents
should also appeal to engineers and scientists in industry who need practical solutions
to real-world problems. The emphasis is on understanding the basic principles of the
methods discussed and how they can be implemented in computer code.
The aim of this book is to provide a set of software tools that implement numerical
methods that can be applied to a broad spectrum of differential equation problems. Each
chapter includes a set of references that provide additional information and insight into
the methods and procedures employed. All chapters are more or less complete in them-
selves, except for a few references to other chapters. Thus each chapter can be studied
independently.
It is assumed that the reader has a basic understanding of the R language, although the
computer code is annotated to a level that should make understanding clear. Additional
discussion is included in the text for more advanced language constructs. Some basic
examples of the use of computer algebra systems are also included that make use of the
R interface packages Ryacas and rSymPy.
R is a free, high-level software programming language and software environment that
has traditionally been used for statistical computing and graphics. It has been widely
used for many years by statisticians for data analysis being particularly effective in han-
dling large data sets. However, recently, packages have been added to R to solve a wider
range of numerical problems. In particular, the addition of package deSolve [Soe-10]
opened up the language for solving differential equations by adding industrial strength
integrators. The package deSolve is used extensively in the R examples provided in this
book. For readers wishing to learn about R, The Art of R Programming [Mat-11] is a
good introductory text, and The R Book [Cra-11] is a comprehensive description of the

xv

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

xvi Preface

R language. Both are highly recommended. The R language can be downloaded from
http://cran.r-project.org/. To supplement the R installation, a free interactive develop-
ment environment (IDE), RStudio, can be downloaded from https://www.rstudio.com/.
RStudio provides a very user-friendly customizable user interface that greatly enhances
programming productivity and graphical display of simulation results. For users famil-
iar with Matlab, a comprehensive cross-reference between Matlab and R commands has
been compiled by Dr. David Hiebeler of the University of Maine and can be downloaded
from http://www.math.umaine.edu/~hiebeler.
We emphasize two areas of style usage that have been adopted in this book. The first
is that the symbol used for assignment is <- (also known as the gets symbol), which is the
R purist’s form. However, it is acknowledged that = is used extensively in the R literature
and that choosing between <- and = could be considered simply a matter of semantics,
as there are only a few special situations in which = does not work properly. The second
area of style usage relates to global variables, that is, those variables created outside of a
function but that can be used inside a function. Global variables created using the super-
assignment symbol <<- can also be changed within a lower environment function using
<<-. This means that, in general, they are allocated higher in the environment hierarchy
than where they are used. Now, like all modern programming languages, variables in R
are passed to functions by reference, but global variables are allowed. In this book, we
tend to make great use of global variables, as such use leads to cleaner and less cluttered
code. It also avoids having to process lists returned from functions where, in the rare situa-
tion, globals are actually changed within a function rather than just used. However, we do
not use global variables wherever possible and pass values through function arguments
where it is appropriate or where it makes the code clearer. For applications described in
this book, the scope for global variables is generally between adjacent levels in the envi-
ronment hierarchy and therefore is not readily prone to programming conflicts. A good
discussion relating to the use of global variables can be found in [Mat-11, chap. 7].

OVERVIEW OF CONTENTS
Chapter 1 introduces the subject of ordinary differential equations, and basic integration
methods are covered, including Euler, Runge–Kutta, variable step, extrapolation, BDFs,
NDFs, and Adams. The Newton and Levenberg–Marquardt convergence methods are
introduced in connection with implicit integration. A discussion relating to truncation
error and verification of integration order is presented with a number of examples that
use the concepts discussed. The chapter concludes with a brief discussion on stiffness.
Chapter 2 explores some of the theory and practical applications of ODE integrator
stability analysis. The discussion includes topics on global order of accuracy, A-stable
and zero-stable definitions, and the Dahlquist barrier theorems. Using the Dahlquist test
problem, we investigate the stability of various integration methods, including Runge–
Kutta, variable step, BDFs, NDFs, and Adams. For each method, the stability regions are
plotted in the complex plane to illustrate the associated stability margins.
Chapter 3 discusses Cauchy problems in the context of initial value and/or bound-
ary value problems. The basic concepts relating to PDEs and their classification are dis-
cussed, along with initial conditions (ICs) and the various types of boundary conditions
(BCs). General ideas relating to discretization methods, mesh grid, stencils, upwinding,

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

Preface xvii

and the Courant–Friedrichs–Lewy number are introduced. This leads into a discussion
on the method of lines (MOL), one of the major numerical schemes for solving PDEs.
A good selection of 1D and 2D example MOL problems are solved. These examples,
in both Cartesian and polar coordinates, have been chosen to bring out the main ideas
and to show the variety of problems that can be solved using this method. Then follows
a brief discussion of the following fully discrete methods: FTBS, implicit FTBS, FTCS,
implicit BTCS, leapfrog, Beam–Warming, Lax–Friedrichs, and Lax–Wendroff. Solutions
are compared for the different methods applied to sample problems. The ideas behind
the finite volume method are presented in preparation for their use in high-resolution
schemes, which are discussed subsequently in Chapter 6.
Chapter 4 discusses the concept of a system being well-posed and ways of using this
idea to investigate system stability. The matrix stability method is outlined, and detailed
stability calculations are included for semi-discrete PDE schemes. A number of exam-
ples are included that analyze PDEs, and results are presented in graphical form. The
von Neumann stability method is discussed with the fundamental ideas developed using
Fourier transforms. Various semi-discrete and fully discrete PDE systems are analyzed,
with results presented graphically.
Chapter 5 introduces the idea of the dispersion relation and its relationship to wave
number and wave frequency. The accuracy of numerical schemes is discussed in relation
to numerical amplification and exact amplification factors. Also discussed is how these
factors can be used to provide an indication of phase (dispersion) and amplitude (dissi-
pation) errors. The chapter concludes with a discussion on phase and group velocities.
Chapter 6 introduces the idea of high-resolution schemes for the solution of PDEs.
The Riemann problem is discussed, along with Godunov’s method of providing an
approximate solution. A discussion follows on the principle of total variation dimin-
ishing (TVD) and how Godunov’s order barrier theorem places constraints on mono-
tonic PDE solution methods. An introduction is then provided to two major methods
that are employed widely to solve these types of problems. The first is the flux lim-
iter method, whereby fifteen different flux limiter functions are presented. The second
is the weighted essentially nonoscilliatory (WENO) method, whereby the associated
weights and smoothness indicator calculations are presented. These methods are dis-
cussed within a finite volume and MOL framework. They are based on the monotone
upstream-centered schemes for conservation laws (MUSCL) method, with the particu-
lar implementation being the Kurganov and Tadmor central scheme. A variety of 1D and
2D problems are solved using these methods, and the results are presented graphically.
These include, advection, Burgers, Buckley–Everett, Euler equations, Sod’s shock tube,
Taylor–Sedov detonation, Woodward–Colella interacting blast wave, and frontogenesis:
all computationally demanding PDE evolution problems.
Chapter 7 introduces the concept of meshless methods using radial basis functions
(RBFs). These methods represent important tools for the numerical analyst and are
becoming very popular for solving otherwise difficult problems. One of the main advan-
tages of meshless methods is that they can be used on irregular grids and therefore
are applicable to problem geometries of any shape. The ideas are presented from an
introductory-basics level, with examples showing how the method is used to interpolate
scattered data and also for solving partial differential equations. For a number of exam-
ples, the results are compared to analytical solutions to demonstrate the accuracy of the

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

xviii Preface

results obtained. The Halton sequence, which produces pseudo-random data, is intro-
duced to demonstrate how the method readily handles irregular grids and/or scattered
data. A number of globally and compactly supported RBFs are defined and their use
illustrated with examples in 1D, 2D, and 3D. This chapter also includes discussion on the
use of local RBFs, which allow the method to be used on very large problems. Local RBFs
result in the system matrices becoming sparse, which facilitates the application of sparse
matrix methods, which are provided by the R package Matrix.
Chapter 8 introduces the concept of conservation laws in the context of evolution-
ary PDEs. Under the assumption of certain decay conditions, it is shown how conserved
quantities can be identified for particular PDEs. It is then shown that conserved quan-
tities can be used to calculate associated constants of motion or invariants. These con-
stants of motion are very useful in numerical analysis as they can be used to provide
an indication of calculation accuracy. The ideas are discussed mainly in terms of the 1D
Korteweg-de Vries (KdV) equation, where a number of the commonly known conserva-
tion laws applicable to this equation are derived. It is then shown using the Miura and
Gardener transformations that, actually, the KdV equation possesses an infinity of con-
servation laws. The discussion is then extended to the 2D KdV equation and then to the
KdV equation with variable coefficients (vcKdV). This chapter also includes conserva-
tion law discussions and example calculations in relation to the nonlinear Schrödinger
(NLS) equation and the Boussinesq equation.
Chapter 9 is a case study into the analysis of a golf ball in fight. It has been the subject
of many theoretical investigations, with some of the earliest being published in the late
1890s. This case study provides an in-depth study of this subject, with computer simula-
tion results presented and compared to published performance data. The various forces
acting on a golf ball in flight are discussed, namely, drag, Magnus, and gravitational. The
differential equations that describe the golf ball flight are then derived. The effects of
compression, spin, ambient conditions, wind, launch angle, bounce, and roll are all taken
into account in the simulation calculations. The latest coefficients from the literature for
drag and lift are used. The results are presented graphically and compared with measured
statistics for club head speed, carry, and trajectory height for various classes of player,
using different golf clubs. The effect of push, pull, fade, draw, slice, and hook shots are
investigated, and the results are discussed. The magnitude of wind shear at ground level
is calculated, and its effect on a static golf ball is investigated.
Chapter 10 is a case study into the problem of an intense explosion. In 1945, Sir Geof-
frey Ingram Taylor was asked by the British Military Application of Uranium Detona-
tion (MAUD) Committee to deduce information regarding the power of the first atomic
explosion at the Trinity site in the New Mexico desert. He was able to estimate, using
only public domain photographs of the blast, that the yield of the bomb was equivalent
to between 16.8 and 23.7 kilotons of TNT. This case study discusses the subsequent sem-
inal papers that Ingram published and traces the perceptive calculations that he made.
A systems analysis starts with a form of the Euler equations, from which, using similar-
ity analysis, certain important relationships are deduced. With the aid of a set of high-
speed photographs of the detonation, and assuming spherical symmetry, the underly-
ing characteristics of the blast are gradually revealed by a sequence of thermodynamic
calculations. The thermodynamic gas laws required to unravel this puzzle are discussed,
along with shock wave analysis using the Hugonoit–Rankine relations. Kinetic energy

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

Preface xix

and heat energy integrals are evaluated, leading to a full description of the blast. This
includes blast wave speed, pressure, and temperature over time. Closed-form analytical
solutions to the problem, subsequently published by Sedov in 1959, are presented that
provide a useful check on the accuracy of Ingram’s numerical calculations. A similarity
analysis is included, covering spherical, cylindrical, and planar blast situations.
Chapter 11 is a case study into the global carbon cycle and how increased concen-
trations in atmospheric carbon dioxide have implications for climate change. A simpli-
fied model is presented that considers four fossil-fuel emission scenarios based on the
work of Caldeira and Wickett and how the atmosphere and oceans respond. Air–ocean
interaction is modeled using the wind-driven gas–sea exchange relationship due to Wan-
2−
ninkhof, with the subsequent dispersion of gaseous CO2 into CO2 (aq), HCO− 3 , CO3 ,
and H in accordance with carbonate chemistry equilibria. It is shown how an increasing
+

concentration of positive hydrogen ions causes seawater acidity to rise, that is, a fall in
pH. Seawater buffering calculations are also introduced to demonstrate how the ocean’s
ability to absorb atmospheric CO2 is diminished as seawater concentration of dissolved
inorganic carbon increases. A discussion of solar and terrestrial radiation modeling is
also included, along with calculations that show how increasing CO2 concentrations in
the atmosphere can lead to increases in the Earth’s surface temperature, that is, to the
so-called greenhouse effect.
All chapters include worked examples, many of which generate animations, along
with annotated computer code, which is available for download. As an additional
resource for some chapters, computer code is provided with the downloads for symbolic
computer algebra analysis using Maple and Maxima/wxMaxima systems. Maxima is a
free open-source program available for different operating systems that can be down-
loaded from http://maxima.sourceforge.net/. A GUI-based version, wxMaxima, can be
downloaded from http://andrejv.github.io/wxmaxima/.
To maximize the benefit of studying numerical computing, the learning process should
not be regarded as a passive pursuit. Rather, it should be regarded as a hands-on experi-
mental activity. Because many problems are nonlinear, analytical or well-tried and tested
solutions may not exist. In these situations it may be necessary to try various different
options to find the most appropriate solution technique, with the best parameter values
being deduced by trial and error. This book includes many and varied solutions to a wide
range of problems, and it is hoped that the reader will find some that can be applied
directly, or adapted, to the particular problem of interest.
To conclude, the major focus of this book is the numerical solution of initial value
problems (IVPs) and boundary value problems (BVPs) described by ODEs and PDEs.
The general approach and content complement the author’s earlier books ([Gri-11] and
[Sch-09]) and also the excellent book Solving Differential Equations in R [Soe-12].

ACKNOWLEDGMENTS
I would like to thank Professor William (Bill) E. Schiesser of Lehigh University for col-
laboration in the area of numerical solutions to differential equations over many years
and for suggesting that I look into using the R language for solving ODEs and PDEs;
Professor Alan M. Nathan of the University of Illinois for useful discussions on the flight
of projectiles and for clarifying some concepts; and Professor Duncan Murdoch of the

© in this web service Cambridge University Press www.cambridge.org


Cambridge University Press
978-1-107-11561-3 - Numerical Analysis Using R: Solutions to ODEs and PDEs
Graham W. Griffiths
Frontmatter
More information

xx Preface

University of Western Ontario for advice on using the R package rgl and for respond-
ing positively to requests for changes to the 3D graphics function persp3d().

Graham W. Griffiths
Nayland, Suffolk, United Kingdom
June 2015
[email protected]
www.pdecomp.net

REFERENCES
[Cra-11] Crawley, M. J. (2011), The R Book, John Wiley.
[Gri-11] Griffiths, G. W. and W. E. Schiesser (2011), Traveling Wave Solutions of Partial Differential
Equations: Numerical and Analytical Methods with Matlab and Maple, Academic Press.
[Mat-11] Matloff, N. (2011), The Art of R Programming, No Starch Press.
[Sch-09] Schiesser, W. E. and G. W. Griffiths (2009), A Compendium of Partial Differential Equa-
tion Models: Method of Lines Analysis with Matlab, Cambridge University Press.
[Soe-10] Soetaert, K., T. Petzoldt and R. W. Setzer (2010), Solving Differential Equations in R:
Package deSolve, Journal of Statistical Software 33-9, 1–25.
[Soe-12] Soetaert, K., J. Cash and F. Mazzia (2012), Solving Differential Equations in R, Springer-
Verlag.

© in this web service Cambridge University Press www.cambridge.org

You might also like