You are on page 1of 53

Finite Difference Computing with PDEs

A Modern Software Approach 1st


Edition Hans Petter Langtangen
Visit to download the full and correct content document:
https://textbookfull.com/product/finite-difference-computing-with-pdes-a-modern-softw
are-approach-1st-edition-hans-petter-langtangen/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Pricing Derivatives Under Lévy Models Modern Finite


Difference and Pseudo Differential Operators Approach
1st Edition Andrey Itkin (Auth.)

https://textbookfull.com/product/pricing-derivatives-under-levy-
models-modern-finite-difference-and-pseudo-differential-
operators-approach-1st-edition-andrey-itkin-auth/

Software for Exascale Computing SPPEXA 2016 2019 Hans-


Joachim Bungartz

https://textbookfull.com/product/software-for-exascale-computing-
sppexa-2016-2019-hans-joachim-bungartz/

Automating with SIMATIC Controllers Software


Programming Data Communication 6th Edition Hans Berger

https://textbookfull.com/product/automating-with-simatic-
controllers-software-programming-data-communication-6th-edition-
hans-berger/

Numerical Solution of Differential Equations:


Introduction to Finite Difference and Finite Element
Methods 1st Edition Zhilin Li

https://textbookfull.com/product/numerical-solution-of-
differential-equations-introduction-to-finite-difference-and-
finite-element-methods-1st-edition-zhilin-li/
Finite Difference Methods in Heat Transfer, Second
Edition M. Necati Özi■ik

https://textbookfull.com/product/finite-difference-methods-in-
heat-transfer-second-edition-m-necati-ozisik/

Finite Element Computations in Mechanics with R: A


Problem-Centered Programming Approach 1st Edition
Khameel Bayo Mustapha

https://textbookfull.com/product/finite-element-computations-in-
mechanics-with-r-a-problem-centered-programming-approach-1st-
edition-khameel-bayo-mustapha/

Engineering Software as a Service An Agile Approach


Using Cloud Computing First Edition, 1.2.1 Edition Fox

https://textbookfull.com/product/engineering-software-as-a-
service-an-agile-approach-using-cloud-computing-first-
edition-1-2-1-edition-fox/

Finite Element Computations in Mechanics with R A


Problem Centered Programming Approach First Edition
Bayo Mustapha

https://textbookfull.com/product/finite-element-computations-in-
mechanics-with-r-a-problem-centered-programming-approach-first-
edition-bayo-mustapha/

A Philosophical Approach to Quantum Field Theory 1st


Edition Hans Christian Öttinger

https://textbookfull.com/product/a-philosophical-approach-to-
quantum-field-theory-1st-edition-hans-christian-ottinger/
0 u1
u

2
u5
u
u3
u4

16

Hans Petter Langtangen · Svein Linge

Finite Difference
Computing
with PDEs
A Modern Software Approach Editorial Board
T. J.Barth
M.Griebel
D.E.Keyes
R.M.Nieminen
D.Roose
T.Schlick
Texts in Computational
Science and Engineering
16

Editors
Timothy J. Barth
Michael Griebel
David E. Keyes
Risto M. Nieminen
Dirk Roose
Tamar Schlick
More information about this series at
http://www.springer.com/series/5151
Hans Petter Langtangen  Svein Linge

Finite Difference
Computing with PDEs
A Modern Software Approach
Hans Petter Langtangen Svein Linge
Lysaker, Norway Process, Energy & Environmental
Technology
University College of Southeast Norway
Porsgrunn, Norway

ISSN 1611-0994
Texts in Computational Science and Engineering
ISBN 978-3-319-55455-6 ISBN 978-3-319-55456-3 (eBook)
DOI 10.1007/978-3-319-55456-3

Library of Congress Control Number: 2017942747

Mathematic Subject Classification (2010): 34, 35, 65, 68

© The Editor(s) (if applicable) and The Author(s) 2017 This book is an open access publication
Open Access This book is distributed under the terms of the Creative Commons Attribution 4.0 Interna-
tional License (http://creativecommons.org/licenses/by/4.0/), which permits use, duplication, adaptation,
distribution and reproduction in any medium or format, as long as you give appropriate credit to the orig-
inal author(s) and the source, provide a link to the Creative Commons license and indicate if changes
were made.
The images or other third party material in this book are included in the work’s Creative Commons li-
cense, unless indicated otherwise in the credit line; if such material is not included in the work’s Creative
Commons license and the respective action is not permitted by statutory regulation, users will need to
obtain permission from the license holder to duplicate, adapt or reproduce the material.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publica-
tion does not imply, even in the absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in 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, express or implied, with respect to the material contained herein or for any
errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

Printed on acid-free paper

This Springer imprint is published by Springer Nature


The registered company is Springer International Publishing AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
Preface

There are so many excellent books on finite difference methods for ordinary and
partial differential equations that writing yet another one requires a different view
on the topic. The present book is not so concerned with the traditional academic
presentation of the topic, but is focused at teaching the practitioner how to obtain
reliable computations involving finite difference methods. This focus is based on a
set of learning outcomes:

1. understanding of the ideas behind finite difference methods,


2. understanding how to transform an algorithm to a well-designed computer code,
3. understanding how to test (verify) the code,
4. understanding potential artifacts in simulation results.

Compared to other textbooks, the present one has a particularly strong emphasis
on computer implementation and verification. It also has a strong emphasis on an
intuitive understanding of constructing finite difference methods. To learn about
the potential non-physical artifacts of various methods, we study exact solutions
of finite difference schemes as these give deeper insight into the physical behavior
of the numerical methods than the traditional (and more general) asymptotic error
analysis. However, asymptotic results regarding convergence rates, typically trun-
cation errors, are crucial for testing implementations, so an extensive appendix is
devoted to the computation of truncation errors.

Why finite differences? One may ask why we do finite differences when finite
element and finite volume methods have been developed to greater generality and
sophistication than finite differences and can cover more problems. The finite ele-
ment and finite volume methods are also the industry standard nowadays. Why not
just those methods? The reason for finite differences is the method’s simplicity, both
from a mathematical and coding perspective. Especially in academia, where simple
model problems are used a lot for teaching and in research (e.g., for verification of
advanced implementations), there is a constant need to solve the model problems
from scratch with easy-to-verify computer codes. Here, finite differences are ideal.
A simple 1D heat equation can of course be solved by a finite element package, but
a 20-line code with a difference scheme is just right to the point and provides an

v
vi Preface

understanding of all details involved in the model and the solution method. Every-
body nowadays has a laptop and the natural method to attack a 1D heat equation is
a simple Python or Matlab program with a difference scheme. The conclusion goes
for other fundamental PDEs like the wave equation and Poisson equation as long
as the geometry of the domain is a hypercube. The present book contains all the
practical information needed to use the finite difference tool in a safe way.
Various pedagogical elements are utilized to reach the learning outcomes, and
these are commented upon next.

Simplify, understand, generalize The book’s overall pedagogical philosophy is


the three-step process of first simplifying the problem to something we can under-
stand in detail, and when that understanding is in place, we can generalize and
hopefully address real-world applications with a sound scientific problem-solving
approach. For example, in the chapter on a particular family of equations we first
simplify the problem in question to a 1D, constant-coefficient equation with simple
boundary conditions. We learn how to construct a finite difference method, how to
implement it, and how to understand the behavior of the numerical solution. Then
we can generalize to higher dimensions, variable coefficients, a source term, and
more complicated boundary conditions. The solution of a compound problem is in
this way an assembly of elements that are well understood in simpler settings.

Constructive mathematics This text favors a constructive approach to mathemat-


ics. Instead of a set of definitions followed by popping up a method, we emphasize
how to think about the construction of a method. The aim is to obtain a good intu-
itive understanding of the mathematical methods.
The text is written in an easy-to-read style much inspired by the following quote.

Some people think that stiff challenges are the best device to induce learning, but I am not
one of them. The natural way to learn something is by spending vast amounts of easy,
enjoyable time at it. This goes whether you want to speak German, sight-read at the piano,
type, or do mathematics. Give me the German storybook for fifth graders that I feel like
reading in bed, not Goethe and a dictionary. The latter will bring rapid progress at first,
then exhaustion and failure to resolve.
The main thing to be said for stiff challenges is that inevitably we will encounter them,
so we had better learn to face them boldly. Putting them in the curriculum can help teach
us to do so. But for teaching the skill or subject matter itself, they are overrated. [18, p. 86]
Lloyd N. Trefethen, Applied Mathematician, 1955-.

This book assumes some basic knowledge of finite difference approximations,


differential equations, and scientific Python or MATLAB programming, as often
met in an introductory numerical methods course. Readers without this background
may start with the light companion book “Finite Difference Computing with Expo-
nential Decay Models” [9]. That book will in particular be a useful resource for the
programming parts of the present book. Since the present book deals with partial
differential equations, the reader is assumed to master multi-variable calculus and
linear algebra.
Fundamental ideas and their associated scientific details are first introduced in
the simplest possible differential equation setting, often an ordinary differential
equation, but in a way that easily allows reuse in more complex settings with par-
tial differential equations. With this approach, new concepts are introduced with a
Preface vii

minimum of mathematical details. The text should therefore have a potential for
use early in undergraduate student programs.

All nuts and bolts Many have experienced that “vast amounts of easy, enjoyable
time”, as stated in the quote above, arises when mathematics is implemented on
a computer. The implementation process triggers understanding, creativity, and
curiosity, but many students find the transition from a mathematical algorithm to a
working code difficult and spend a lot of time on “programming issues”.
Most books on numerical methods concentrate on the mathematics of the subject
while details on going from the mathematics to a computer implementation are
less in focus. A major purpose of this text is therefore to help the practitioner by
providing all nuts and bolts necessary for safely going from the mathematics to a
well-designed and well-tested computer code. A significant portion of the text is
consequently devoted to programming details.

Python as programming language While MATLAB enjoys widespread popular-


ity in books on numerical methods, we have chosen to use the Python programming
language. Python is very similar to MATLAB, but contains a lot of modern soft-
ware engineering tools that have become standard in the software industry and that
should be adopted also for numerical computing projects. Python is at present also
experiencing an exponential growth in popularity within the scientific computing
community. One of the book’s goals is to present an up-to-date Python eco system
for implementing finite difference methods.

Program verification Program testing, called verification, is a key topic of the


book. Good verification techniques are indispensable when debugging computer
code, but also fundamental for achieving reliable simulations. Two verification
techniques saturate the book: exact solution of discrete equations (where the ap-
proximation error vanishes) and empirical estimation of convergence rates in prob-
lems with exact (analytical or manufactured) solutions of the differential equa-
tion(s).

Vectorized code Finite difference methods lead to code with loops over large ar-
rays. Such code in plain Python is known to run slowly. We demonstrate, especially
in Appendix C, how to port loops to fast, compiled code in C or Fortran. However,
an alternative is to vectorize the code to get rid of explicit Python loops, and this
technique is met throughout the book. Vectorization becomes closely connected to
the underlying array library, here numpy, and is often thought of as a difficult sub-
ject by students. Through numerous examples in different contexts, we hope that
the present book provides a substantial contribution to explaining how algorithms
can be vectorized. Not only will this speed up serial code, but with a library that can
produce parallel code from numpy commands (such as Numba1 ), vectorized code
can be automatically turned into parallel code and utilize multi-core processors and
GPUs. Also when creating tailored parallel code for today’s supercomputers, vec-
torization is useful as it emphasizes splitting up an algorithm into plain and simple

1
http://numba.pydata.org
viii Preface

array operations, where each operation is trivial to parallelize efficiently, rather than
trying to develop a “smart” overall parallelization strategy.

Analysis via exact solutions of discrete equations Traditional asymptotic analy-


sis of errors is important for verification of code using convergence rates, but gives a
limited understanding of how and why a correctly implemented numerical method
may give non-physical results. By developing exact solutions, usually based on
Fourier methods, of the discrete equations, one can obtain a physical understanding
of the behavior of a numerical method. This approach is favored for analysis of
methods in this book.

Code-inspired mathematical notation Our primary aim is to have a clean and


easy-to-read computer code, and we want a close one-to-one relationship between
the computer code and mathematical description of the algorithm. This principle
calls for a mathematical notation that is governed by the natural notation in the
computer code. The unknown is mostly called u, but the meaning of the symbol u
in the mathematical description changes as we go from the exact solution fulfilling
the differential equation to the symbol u that is naturally used for the associated
data structure in the code.

Limited scope The aim of this book is not to give an overview of a lot of methods
for a wide range of mathematical models. Such information can be found in numer-
ous existing, more advanced books. The aim is rather to introduce basic concepts
and a thorough understanding of how to think about computing with finite differ-
ence methods. We therefore go in depth with only the most fundamental methods
and equations. However, we have a multi-disciplinary scope and address the inter-
play of mathematics, numerics, computer science, and physics.

Focus on wave phenomena Most books on finite difference methods, or books


on theory with computer examples, have their emphasis on diffusion phenomena.
Half of this book (Chap. 1, 2, and Appendix C) is devoted to wave phenomena.
Extended material on this topic is not so easy find in the literature, so the book
should be a valuable contribution in this respect. Wave phenomena is also a good
topic in general for choosing the finite difference method over other discretization
methods since one quickly needs fine resolution over the entire mesh and uniform
meshes are most natural.
Instead of introducing the finite difference method for diffusion problems, where
one soon ends up with matrix systems, we do the introduction in a wave phenomena
setting where explicit schemes are most relevant. This slows down the learning
curve since we can introduce a lot of theory for differences and for software aspects
in a context with simple, explicit stencils for updating the solution.

Independent chapters Most book authors are careful with avoiding repetitions of
material. The chapters in this book, however, contain some overlap, because we
want the chapters to appear meaningful on their own. Modern publishing technol-
ogy makes it easy to take selected chapters from different books to make a new book
tailored to a specific course. The more a chapter builds on details in other chapters,
the more difficult it is to reuse chapters in new contexts. Also, most readers find it
Preface ix

convenient that important information is explicitly stated, even if it was already met
in another chapter.

Supplementary materials All program and data files referred to in this book are
available from the book’s primary web site: URL: http://github.com/hplgit/fdm-
book/.

Acknowledgments Professor Kent-Andre Mardal at the University of Oslo has


kindly contributed to enlightening discussions on several issues. Many students
have provided lots of useful feedback on the exposition and found many errors in
the text. Special efforts in this regard were made by Imran Ali, Shirin Fallahi,
Anders Hafreager, Daniel Alexander Mo Søreide Houshmand, Kristian Gregorius
Hustad, Mathilde Nygaard Kamperud, and Fatemeh Miri. The collaboration with
the Springer team, with Dr. Martin Peters, Thanh-Ha Le Thi, and their production
staff has always been a great pleasure and a very efficient process.
Finally, want really appreciate the strong push from the COE of Simula Research
Laboratory, Aslak Tveito, for publishing and financing books in open access format,
including this one. We are grateful for the laboratory’s financial contribution as
well as to the financial contribution from the Department of Process, Energy and
Environmental Technology at the University College of Southeast Norway.

Oslo, July 2016 Hans Petter Langtangen, Svein Linge


Contents

1 Vibration ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Finite Difference Discretization . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 A Basic Model for Vibrations . . . . . . . . . . . . . . . . . 1
1.1.2 A Centered Finite Difference Scheme . . . . . . . . . . . . 2
1.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.1 Making a Solver Function . . . . . . . . . . . . . . . . . . . . 4
1.2.2 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.3 Scaled Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 Visualization of Long Time Simulations . . . . . . . . . . . . . . . . 11
1.3.1 Using a Moving Plot Window . . . . . . . . . . . . . . . . . 11
1.3.2 Making Animations . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.3 Using Bokeh to Compare Graphs . . . . . . . . . . . . . . . 15
1.3.4 Using a Line-by-Line Ascii Plotter . . . . . . . . . . . . . . 18
1.3.5 Empirical Analysis of the Solution . . . . . . . . . . . . . . 19
1.4 Analysis of the Numerical Scheme . . . . . . . . . . . . . . . . . . . . 21
1.4.1 Deriving a Solution of the Numerical Scheme . . . . . . . 21
1.4.2 The Error in the Numerical Frequency . . . . . . . . . . . . 22
1.4.3 Empirical Convergence Rates and Adjusted ! . . . . . . . 24
1.4.4 Exact Discrete Solution . . . . . . . . . . . . . . . . . . . . . 24
1.4.5 Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.4.6 The Global Error . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.4.7 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.4.8 About the Accuracy at the Stability Limit . . . . . . . . . . 27
1.5 Alternative Schemes Based on 1st-Order Equations . . . . . . . . . 29
1.5.1 The Forward Euler Scheme . . . . . . . . . . . . . . . . . . . 29
1.5.2 The Backward Euler Scheme . . . . . . . . . . . . . . . . . . 30
1.5.3 The Crank-Nicolson Scheme . . . . . . . . . . . . . . . . . . 30
1.5.4 Comparison of Schemes . . . . . . . . . . . . . . . . . . . . . 32
1.5.5 Runge-Kutta Methods . . . . . . . . . . . . . . . . . . . . . . 33
1.5.6 Analysis of the Forward Euler Scheme . . . . . . . . . . . . 34
1.6 Energy Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1.6.1 Derivation of the Energy Expression . . . . . . . . . . . . . 36
1.6.2 An Error Measure Based on Energy . . . . . . . . . . . . . . 38

xi
xii Contents

1.7 The Euler-Cromer Method . . . . . . . . . . . . . . . . . . . . . . . . . 40


1.7.1 Forward-Backward Discretization . . . . . . . . . . . . . . . 40
1.7.2 Equivalence with the Scheme for the Second-Order ODE 42
1.7.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.7.4 The Störmer-Verlet Algorithm . . . . . . . . . . . . . . . . . 45
1.8 Staggered Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
1.8.1 The Euler-Cromer Scheme on a Staggered Mesh . . . . . . 46
1.8.2 Implementation of the Scheme on a Staggered Mesh . . . 48
1.9 Exercises and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 50
1.10 Generalization: Damping, Nonlinearities, and Excitation . . . . . . 57
1.10.1 A Centered Scheme for Linear Damping . . . . . . . . . . . 57
1.10.2 A Centered Scheme for Quadratic Damping . . . . . . . . . 58
1.10.3 A Forward-Backward Discretization of the Quadratic
Damping Term . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
1.10.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 59
1.10.5 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
1.10.6 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
1.10.7 User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
1.10.8 The Euler-Cromer Scheme for the Generalized Model . . 63
1.10.9 The Störmer-Verlet Algorithm for the Generalized Model 64
1.10.10 A Staggered Euler-Cromer Scheme for a Generalized
Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
1.10.11 The PEFRL 4th-Order Accurate Algorithm . . . . . . . . . 65
1.11 Exercises and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 66
1.12 Applications of Vibration Models . . . . . . . . . . . . . . . . . . . . 67
1.12.1 Oscillating Mass Attached to a Spring . . . . . . . . . . . . 67
1.12.2 General Mechanical Vibrating System . . . . . . . . . . . . 69
1.12.3 A Sliding Mass Attached to a Spring . . . . . . . . . . . . . 70
1.12.4 A Jumping Washing Machine . . . . . . . . . . . . . . . . . 71
1.12.5 Motion of a Pendulum . . . . . . . . . . . . . . . . . . . . . . 71
1.12.6 Dynamic Free Body Diagram During Pendulum Motion . 74
1.12.7 Motion of an Elastic Pendulum . . . . . . . . . . . . . . . . . 79
1.12.8 Vehicle on a Bumpy Road . . . . . . . . . . . . . . . . . . . . 83
1.12.9 Bouncing Ball . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
1.12.10 Two-Body Gravitational Problem . . . . . . . . . . . . . . . 85
1.12.11 Electric Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . 88
1.13 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

2 Wave Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
2.1 Simulation of Waves on a String . . . . . . . . . . . . . . . . . . . . . 93
2.1.1 Discretizing the Domain . . . . . . . . . . . . . . . . . . . . . 94
2.1.2 The Discrete Solution . . . . . . . . . . . . . . . . . . . . . . 94
2.1.3 Fulfilling the Equation at the Mesh Points . . . . . . . . . . 94
2.1.4 Replacing Derivatives by Finite Differences . . . . . . . . . 95
2.1.5 Formulating a Recursive Algorithm . . . . . . . . . . . . . . 96
2.1.6 Sketch of an Implementation . . . . . . . . . . . . . . . . . . 98
2.2 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
2.2.1 A Slightly Generalized Model Problem . . . . . . . . . . . 99
2.2.2 Using an Analytical Solution of Physical Significance . . 99
Contents xiii

2.2.3 Manufactured Solution and Estimation of Convergence


Rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
2.2.4 Constructing an Exact Solution of the Discrete Equations 102
2.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
2.3.1 Callback Function for User-Specific Actions . . . . . . . . 104
2.3.2 The Solver Function . . . . . . . . . . . . . . . . . . . . . . . 105
2.3.3 Verification: Exact Quadratic Solution . . . . . . . . . . . . 106
2.3.4 Verification: Convergence Rates . . . . . . . . . . . . . . . . 107
2.3.5 Visualization: Animating the Solution . . . . . . . . . . . . 108
2.3.6 Running a Case . . . . . . . . . . . . . . . . . . . . . . . . . . 112
2.3.7 Working with a Scaled PDE Model . . . . . . . . . . . . . . 113
2.4 Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
2.4.1 Operations on Slices of Arrays . . . . . . . . . . . . . . . . . 115
2.4.2 Finite Difference Schemes Expressed as Slices . . . . . . . 117
2.4.3 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
2.4.4 Efficiency Measurements . . . . . . . . . . . . . . . . . . . . 119
2.4.5 Remark on the Updating of Arrays . . . . . . . . . . . . . . 121
2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
2.6 Generalization: Reflecting Boundaries . . . . . . . . . . . . . . . . . 125
2.6.1 Neumann Boundary Condition . . . . . . . . . . . . . . . . . 126
2.6.2 Discretization of Derivatives at the Boundary . . . . . . . . 126
2.6.3 Implementation of Neumann Conditions . . . . . . . . . . . 127
2.6.4 Index Set Notation . . . . . . . . . . . . . . . . . . . . . . . . 128
2.6.5 Verifying the Implementation of Neumann Conditions . . 130
2.6.6 Alternative Implementation via Ghost Cells . . . . . . . . . 132
2.7 Generalization: Variable Wave Velocity . . . . . . . . . . . . . . . . . 135
2.7.1 The Model PDE with a Variable Coefficient . . . . . . . . . 135
2.7.2 Discretizing the Variable Coefficient . . . . . . . . . . . . . 136
2.7.3 Computing the Coefficient Between Mesh Points . . . . . 137
2.7.4 How a Variable Coefficient Affects the Stability . . . . . . 138
2.7.5 Neumann Condition and a Variable Coefficient . . . . . . . 138
2.7.6 Implementation of Variable Coefficients . . . . . . . . . . . 139
2.7.7 A More General PDE Model with Variable Coefficients . 140
2.7.8 Generalization: Damping . . . . . . . . . . . . . . . . . . . . 140
2.8 Building a General 1D Wave Equation Solver . . . . . . . . . . . . . 141
2.8.1 User Action Function as a Class . . . . . . . . . . . . . . . . 142
2.8.2 Pulse Propagation in Two Media . . . . . . . . . . . . . . . . 144
2.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
2.10 Analysis of the Difference Equations . . . . . . . . . . . . . . . . . . 155
2.10.1 Properties of the Solution of the Wave Equation . . . . . . 155
2.10.2 More Precise Definition of Fourier Representations . . . . 157
2.10.3 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
2.10.4 Numerical Dispersion Relation . . . . . . . . . . . . . . . . . 160
2.10.5 Extending the Analysis to 2D and 3D . . . . . . . . . . . . . 163
2.11 Finite Difference Methods for 2D and 3D Wave Equations . . . . . 167
2.11.1 Multi-Dimensional Wave Equations . . . . . . . . . . . . . . 167
2.11.2 Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
2.11.3 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
xiv Contents

2.12 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171


2.12.1 Scalar Computations . . . . . . . . . . . . . . . . . . . . . . . 172
2.12.2 Vectorized Computations . . . . . . . . . . . . . . . . . . . . 174
2.12.3 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
2.12.4 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
2.13 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
2.14 Applications of Wave Equations . . . . . . . . . . . . . . . . . . . . . 183
2.14.1 Waves on a String . . . . . . . . . . . . . . . . . . . . . . . . . 183
2.14.2 Elastic Waves in a Rod . . . . . . . . . . . . . . . . . . . . . . 186
2.14.3 Waves on a Membrane . . . . . . . . . . . . . . . . . . . . . . 186
2.14.4 The Acoustic Model for Seismic Waves . . . . . . . . . . . 186
2.14.5 Sound Waves in Liquids and Gases . . . . . . . . . . . . . . 188
2.14.6 Spherical Waves . . . . . . . . . . . . . . . . . . . . . . . . . . 189
2.14.7 The Linear Shallow Water Equations . . . . . . . . . . . . . 190
2.14.8 Waves in Blood Vessels . . . . . . . . . . . . . . . . . . . . . 192
2.14.9 Electromagnetic Waves . . . . . . . . . . . . . . . . . . . . . 194
2.15 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

3 Diffusion Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207


3.1 An Explicit Method for the 1D Diffusion Equation . . . . . . . . . . 208
3.1.1 The Initial-Boundary Value Problem for 1D Diffusion . . 208
3.1.2 Forward Euler Scheme . . . . . . . . . . . . . . . . . . . . . . 208
3.1.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 210
3.1.4 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
3.1.5 Numerical Experiments . . . . . . . . . . . . . . . . . . . . . 215
3.2 Implicit Methods for the 1D Diffusion Equation . . . . . . . . . . . 218
3.2.1 Backward Euler Scheme . . . . . . . . . . . . . . . . . . . . . 219
3.2.2 Sparse Matrix Implementation . . . . . . . . . . . . . . . . . 223
3.2.3 Crank-Nicolson Scheme . . . . . . . . . . . . . . . . . . . . . 224
3.2.4 The Unifying  Rule . . . . . . . . . . . . . . . . . . . . . . . 226
3.2.5 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
3.2.6 The Laplace and Poisson Equation . . . . . . . . . . . . . . 227
3.3 Analysis of Schemes for the Diffusion Equation . . . . . . . . . . . 229
3.3.1 Properties of the Solution . . . . . . . . . . . . . . . . . . . . 229
3.3.2 Analysis of Discrete Equations . . . . . . . . . . . . . . . . . 233
3.3.3 Analysis of the Finite Difference Schemes . . . . . . . . . . 233
3.3.4 Analysis of the Forward Euler Scheme . . . . . . . . . . . . 234
3.3.5 Analysis of the Backward Euler Scheme . . . . . . . . . . . 236
3.3.6 Analysis of the Crank-Nicolson Scheme . . . . . . . . . . . 237
3.3.7 Analysis of the Leapfrog Scheme . . . . . . . . . . . . . . . 237
3.3.8 Summary of Accuracy of Amplification Factors . . . . . . 238
3.3.9 Analysis of the 2D Diffusion Equation . . . . . . . . . . . . 239
3.3.10 Explanation of Numerical Artifacts . . . . . . . . . . . . . . 241
3.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
3.5 Diffusion in Heterogeneous Media . . . . . . . . . . . . . . . . . . . . 245
3.5.1 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
3.5.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 246
3.5.3 Stationary Solution . . . . . . . . . . . . . . . . . . . . . . . . 247
Contents xv

3.5.4 Piecewise Constant Medium . . . . . . . . . . . . . . . . . . 247


3.5.5 Implementation of Diffusion in a Piecewise Constant
Medium . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
3.5.6 Axi-Symmetric Diffusion . . . . . . . . . . . . . . . . . . . . 251
3.5.7 Spherically-Symmetric Diffusion . . . . . . . . . . . . . . . 252
3.6 Diffusion in 2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
3.6.1 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
3.6.2 Numbering of Mesh Points Versus Equations and
Unknowns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
3.6.3 Algorithm for Setting Up the Coefficient Matrix . . . . . . 259
3.6.4 Implementation with a Dense Coefficient Matrix . . . . . . 260
3.6.5 Verification: Exact Numerical Solution . . . . . . . . . . . . 264
3.6.6 Verification: Convergence Rates . . . . . . . . . . . . . . . . 265
3.6.7 Implementation with a Sparse Coefficient Matrix . . . . . 266
3.6.8 The Jacobi Iterative Method . . . . . . . . . . . . . . . . . . 270
3.6.9 Implementation of the Jacobi Method . . . . . . . . . . . . . 273
3.6.10 Test Problem: Diffusion of a Sine Hill . . . . . . . . . . . . 274
3.6.11 The Relaxed Jacobi Method and Its Relation to the
Forward Euler Method . . . . . . . . . . . . . . . . . . . . . . 276
3.6.12 The Gauss-Seidel and SOR Methods . . . . . . . . . . . . . 277
3.6.13 Scalar Implementation of the SOR Method . . . . . . . . . 277
3.6.14 Vectorized Implementation of the SOR Method . . . . . . 278
3.6.15 Direct Versus Iterative Methods . . . . . . . . . . . . . . . . 282
3.6.16 The Conjugate Gradient Method . . . . . . . . . . . . . . . . 285
3.6.17 What Is the Recommended Method for Solving Linear
Systems? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
3.7 Random Walk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
3.7.1 Random Walk in 1D . . . . . . . . . . . . . . . . . . . . . . . 288
3.7.2 Statistical Considerations . . . . . . . . . . . . . . . . . . . . 288
3.7.3 Playing Around with Some Code . . . . . . . . . . . . . . . 290
3.7.4 Equivalence with Diffusion . . . . . . . . . . . . . . . . . . . 293
3.7.5 Implementation of Multiple Walks . . . . . . . . . . . . . . 294
3.7.6 Demonstration of Multiple Walks . . . . . . . . . . . . . . . 300
3.7.7 Ascii Visualization of 1D Random Walk . . . . . . . . . . . 300
3.7.8 Random Walk as a Stochastic Equation . . . . . . . . . . . 303
3.7.9 Random Walk in 2D . . . . . . . . . . . . . . . . . . . . . . . 304
3.7.10 Random Walk in Any Number of Space Dimensions . . . 305
3.7.11 Multiple Random Walks in Any Number of Space
Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
3.8 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
3.8.1 Diffusion of a Substance . . . . . . . . . . . . . . . . . . . . . 308
3.8.2 Heat Conduction . . . . . . . . . . . . . . . . . . . . . . . . . 309
3.8.3 Porous Media Flow . . . . . . . . . . . . . . . . . . . . . . . . 312
3.8.4 Potential Fluid Flow . . . . . . . . . . . . . . . . . . . . . . . 312
3.8.5 Streamlines for 2D Fluid Flow . . . . . . . . . . . . . . . . . 313
3.8.6 The Potential of an Electric Field . . . . . . . . . . . . . . . 313
3.8.7 Development of Flow Between Two Flat Plates . . . . . . 313
3.8.8 Flow in a Straight Tube . . . . . . . . . . . . . . . . . . . . . 314
xvi Contents

3.8.9 Tribology: Thin Film Fluid Flow . . . . . . . . . . . . . . . 315


3.8.10 Propagation of Electrical Signals in the Brain . . . . . . . . 316
3.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316

4 Advection-Dominated Equations . . . . . . . . . . . . . . . . . . . . . . . 323


4.1 One-Dimensional Time-Dependent Advection Equations . . . . . . 323
4.1.1 Simplest Scheme: Forward in Time, Centered in Space . . 324
4.1.2 Analysis of the Scheme . . . . . . . . . . . . . . . . . . . . . 327
4.1.3 Leapfrog in Time, Centered Differences in Space . . . . . 328
4.1.4 Upwind Differences in Space . . . . . . . . . . . . . . . . . . 331
4.1.5 Periodic Boundary Conditions . . . . . . . . . . . . . . . . . 333
4.1.6 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 333
4.1.7 A Crank-Nicolson Discretization in Time and Centered
Differences in Space . . . . . . . . . . . . . . . . . . . . . . . 337
4.1.8 The Lax-Wendroff Method . . . . . . . . . . . . . . . . . . . 339
4.1.9 Analysis of Dispersion Relations . . . . . . . . . . . . . . . 340
4.2 One-Dimensional Stationary Advection-Diffusion Equation . . . . 344
4.2.1 A Simple Model Problem . . . . . . . . . . . . . . . . . . . . 344
4.2.2 A Centered Finite Difference Scheme . . . . . . . . . . . . 345
4.2.3 Remedy: Upwind Finite Difference Scheme . . . . . . . . 347
4.3 Time-dependent Convection-Diffusion Equations . . . . . . . . . . . 349
4.3.1 Forward in Time, Centered in Space Scheme . . . . . . . . 349
4.3.2 Forward in Time, Upwind in Space Scheme . . . . . . . . . 349
4.4 Applications of Advection Equations . . . . . . . . . . . . . . . . . . 350
4.4.1 Transport of a Substance . . . . . . . . . . . . . . . . . . . . . 350
4.4.2 Transport of Heat in Fluids . . . . . . . . . . . . . . . . . . . 350
4.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351

5 Nonlinear Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353


5.1 Introduction of Basic Concepts . . . . . . . . . . . . . . . . . . . . . . 353
5.1.1 Linear Versus Nonlinear Equations . . . . . . . . . . . . . . 353
5.1.2 A Simple Model Problem . . . . . . . . . . . . . . . . . . . . 354
5.1.3 Linearization by Explicit Time Discretization . . . . . . . . 355
5.1.4 Exact Solution of Nonlinear Algebraic Equations . . . . . 356
5.1.5 Linearization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
5.1.6 Picard Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . 357
5.1.7 Linearization by a Geometric Mean . . . . . . . . . . . . . . 359
5.1.8 Newton’s Method . . . . . . . . . . . . . . . . . . . . . . . . . 360
5.1.9 Relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
5.1.10 Implementation and Experiments . . . . . . . . . . . . . . . 362
5.1.11 Generalization to a General Nonlinear ODE . . . . . . . . . 365
5.1.12 Systems of ODEs . . . . . . . . . . . . . . . . . . . . . . . . . 367
5.2 Systems of Nonlinear Algebraic Equations . . . . . . . . . . . . . . . 368
5.2.1 Picard Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . 369
5.2.2 Newton’s Method . . . . . . . . . . . . . . . . . . . . . . . . . 369
5.2.3 Stopping Criteria . . . . . . . . . . . . . . . . . . . . . . . . . 371
5.2.4 Example: A Nonlinear ODE Model from Epidemiology . 372
Contents xvii

5.3 Linearization at the Differential Equation Level . . . . . . . . . . . . 373


5.3.1 Explicit Time Integration . . . . . . . . . . . . . . . . . . . . 373
5.3.2 Backward Euler Scheme and Picard Iteration . . . . . . . . 374
5.3.3 Backward Euler Scheme and Newton’s Method . . . . . . 375
5.3.4 Crank-Nicolson Discretization . . . . . . . . . . . . . . . . . 377
5.4 1D Stationary Nonlinear Differential Equations . . . . . . . . . . . . 378
5.4.1 Finite Difference Discretization . . . . . . . . . . . . . . . . 378
5.4.2 Solution of Algebraic Equations . . . . . . . . . . . . . . . . 379
5.5 Multi-Dimensional Nonlinear PDE Problems . . . . . . . . . . . . . 384
5.5.1 Finite Difference Discretization . . . . . . . . . . . . . . . . 384
5.5.2 Continuation Methods . . . . . . . . . . . . . . . . . . . . . . 386
5.6 Operator Splitting Methods . . . . . . . . . . . . . . . . . . . . . . . . 387
5.6.1 Ordinary Operator Splitting for ODEs . . . . . . . . . . . . 387
5.6.2 Strang Splitting for ODEs . . . . . . . . . . . . . . . . . . . . 388
5.6.3 Example: Logistic Growth . . . . . . . . . . . . . . . . . . . 388
5.6.4 Reaction-Diffusion Equation . . . . . . . . . . . . . . . . . . 391
5.6.5 Example: Reaction-Diffusion with Linear Reaction Term 392
5.6.6 Analysis of the Splitting Method . . . . . . . . . . . . . . . . 400
5.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401

A Useful Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409


A.1 Finite Difference Operator Notation . . . . . . . . . . . . . . . . . . . 409
A.2 Truncation Errors of Finite Difference Approximations . . . . . . . 410
A.3 Finite Differences of Exponential Functions . . . . . . . . . . . . . . 411
A.4 Finite Differences of t n . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
A.4.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412

B Truncation Error Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 415


B.1 Overview of Truncation Error Analysis . . . . . . . . . . . . . . . . . 415
B.1.1 Abstract Problem Setting . . . . . . . . . . . . . . . . . . . . 415
B.1.2 Error Measures . . . . . . . . . . . . . . . . . . . . . . . . . . 416
B.2 Truncation Errors in Finite Difference Formulas . . . . . . . . . . . 417
B.2.1 Example: The Backward Difference for u0 .t/ . . . . . . . . 417
B.2.2 Example: The Forward Difference for u0 .t/ . . . . . . . . . 418
B.2.3 Example: The Central Difference for u0 .t/ . . . . . . . . . 419
B.2.4 Overview of Leading-Order Error Terms in Finite
Difference Formulas . . . . . . . . . . . . . . . . . . . . . . . 420
B.2.5 Software for Computing Truncation Errors . . . . . . . . . 421
B.3 Exponential Decay ODEs . . . . . . . . . . . . . . . . . . . . . . . . . 422
B.3.1 Forward Euler Scheme . . . . . . . . . . . . . . . . . . . . . . 422
B.3.2 Crank-Nicolson Scheme . . . . . . . . . . . . . . . . . . . . . 423
B.3.3 The -Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
B.3.4 Using Symbolic Software . . . . . . . . . . . . . . . . . . . . 424
B.3.5 Empirical Verification of the Truncation Error . . . . . . . 425
B.3.6 Increasing the Accuracy by Adding Correction Terms . . 430
B.3.7 Extension to Variable Coefficients . . . . . . . . . . . . . . . 432
B.3.8 Exact Solutions of the Finite Difference Equations . . . . 433
B.3.9 Computing Truncation Errors in Nonlinear Problems . . . 434
xviii Contents

B.4 Vibration ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434


B.4.1 Linear Model Without Damping . . . . . . . . . . . . . . . . 434
B.4.2 Model with Damping and Nonlinearity . . . . . . . . . . . . 437
B.4.3 Extension to Quadratic Damping . . . . . . . . . . . . . . . 438
B.4.4 The General Model Formulated as First-Order ODEs . . . 439
B.5 Wave Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
B.5.1 Linear Wave Equation in 1D . . . . . . . . . . . . . . . . . . 440
B.5.2 Finding Correction Terms . . . . . . . . . . . . . . . . . . . . 441
B.5.3 Extension to Variable Coefficients . . . . . . . . . . . . . . . 442
B.5.4 Linear Wave Equation in 2D/3D . . . . . . . . . . . . . . . . 444
B.6 Diffusion Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
B.6.1 Linear Diffusion Equation in 1D . . . . . . . . . . . . . . . . 445
B.6.2 Nonlinear Diffusion Equation in 1D . . . . . . . . . . . . . . 446
B.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447

C Software Engineering; Wave Equation Model . . . . . . . . . . . . . . . 451


C.1 A 1D Wave Equation Simulator . . . . . . . . . . . . . . . . . . . . . 451
C.1.1 Mathematical Model . . . . . . . . . . . . . . . . . . . . . . . 451
C.1.2 Numerical Discretization . . . . . . . . . . . . . . . . . . . . 451
C.1.3 A Solver Function . . . . . . . . . . . . . . . . . . . . . . . . . 452
C.2 Saving Large Arrays in Files . . . . . . . . . . . . . . . . . . . . . . . 455
C.2.1 Using savez to Store Arrays in Files . . . . . . . . . . . . . 455
C.2.2 Using joblib to Store Arrays in Files . . . . . . . . . . . . 457
C.2.3 Using a Hash to Create a File or Directory Name . . . . . 458
C.3 Software for the 1D Wave Equation . . . . . . . . . . . . . . . . . . . 459
C.3.1 Making Hash Strings from Input Data . . . . . . . . . . . . 460
C.3.2 Avoiding Rerunning Previously Run Cases . . . . . . . . . 460
C.3.3 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
C.4 Programming the Solver with Classes . . . . . . . . . . . . . . . . . . 462
C.4.1 Class Parameters . . . . . . . . . . . . . . . . . . . . . . . . . 463
C.4.2 Class Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
C.4.3 Class Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
C.4.4 Class Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
C.4.5 Class Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
C.5 Migrating Loops to Cython . . . . . . . . . . . . . . . . . . . . . . . . 475
C.5.1 Declaring Variables and Annotating the Code . . . . . . . . 476
C.5.2 Visual Inspection of the C Translation . . . . . . . . . . . . 478
C.5.3 Building the Extension Module . . . . . . . . . . . . . . . . 479
C.5.4 Calling the Cython Function from Python . . . . . . . . . . 480
C.6 Migrating Loops to Fortran . . . . . . . . . . . . . . . . . . . . . . . . 480
C.6.1 The Fortran Subroutine . . . . . . . . . . . . . . . . . . . . . 481
C.6.2 Building the Fortran Module with f2py . . . . . . . . . . . . 482
C.6.3 How to Avoid Array Copying . . . . . . . . . . . . . . . . . . 483
C.7 Migrating Loops to C via Cython . . . . . . . . . . . . . . . . . . . . 485
C.7.1 Translating Index Pairs to Single Indices . . . . . . . . . . . 485
C.7.2 The Complete C Code . . . . . . . . . . . . . . . . . . . . . . 486
C.7.3 The Cython Interface File . . . . . . . . . . . . . . . . . . . . 486
C.7.4 Building the Extension Module . . . . . . . . . . . . . . . . 487
Contents xix

C.8 Migrating Loops to C via f2py . . . . . . . . . . . . . . . . . . . . . . 488


C.8.1 Migrating Loops to C++ via f2py . . . . . . . . . . . . . . . 489
C.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
List of Exercises, Problems and Projects

Problem 1.1: Use linear/quadratic functions for verification . . . . . . . . . . . 50


Exercise 1.2: Show linear growth of the phase with time . . . . . . . . . . . . . 51
Exercise 1.3: Improve the accuracy by adjusting the frequency . . . . . . . . . 51
Exercise 1.4: See if adaptive methods improve the phase error . . . . . . . . . . 52
Exercise 1.5: Use a Taylor polynomial to compute u1 . . . . . . . . . . . . . . . 52
Problem 1.6: Derive and investigate the velocity Verlet method . . . . . . . . . 52
Problem 1.7: Find the minimal resolution of an oscillatory function . . . . . . 52
Exercise 1.8: Visualize the accuracy of finite differences for a cosine function 53
Exercise 1.9: Verify convergence rates of the error in energy . . . . . . . . . . . 53
Exercise 1.10: Use linear/quadratic functions for verification . . . . . . . . . . . 53
Exercise 1.11: Use an exact discrete solution for verification . . . . . . . . . . . 53
Exercise 1.12: Use analytical solution for convergence rate tests . . . . . . . . 53
Exercise 1.13: Investigate the amplitude errors of many solvers . . . . . . . . . 54
Problem 1.14: Minimize memory usage of a simple vibration solver . . . . . . 54
Problem 1.15: Minimize memory usage of a general vibration solver . . . . . 56
Exercise 1.16: Implement the Euler-Cromer scheme for the generalized model 56
Problem 1.17: Interpret ŒD t D t un as a forward-backward difference . . . . . . 56
Exercise 1.18: Analysis of the Euler-Cromer scheme . . . . . . . . . . . . . . . 56
Exercise 1.19: Implement the solver via classes . . . . . . . . . . . . . . . . . . . 66
Problem 1.20: Use a backward difference for the damping term . . . . . . . . . 66
Exercise 1.21: Use the forward-backward scheme with quadratic damping . . 67
Exercise 1.22: Simulate resonance . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Exercise 1.23: Simulate oscillations of a sliding box . . . . . . . . . . . . . . . . 88
Exercise 1.24: Simulate a bouncing ball . . . . . . . . . . . . . . . . . . . . . . . 88
Exercise 1.25: Simulate a simple pendulum . . . . . . . . . . . . . . . . . . . . . 89
Exercise 1.26: Simulate an elastic pendulum . . . . . . . . . . . . . . . . . . . . . 89
Exercise 1.27: Simulate an elastic pendulum with air resistance . . . . . . . . . 90
Exercise 1.28: Implement the PEFRL algorithm . . . . . . . . . . . . . . . . . . 91
Exercise 2.1: Simulate a standing wave . . . . . . . . . . . . . . . . . . . . . . . . 122
Exercise 2.2: Add storage of solution in a user action function . . . . . . . . . . 123
Exercise 2.3: Use a class for the user action function . . . . . . . . . . . . . . . . 123
Exercise 2.4: Compare several Courant numbers in one movie . . . . . . . . . . 123
Exercise 2.5: Implementing the solver function as a generator . . . . . . . . . . 124
Project 2.6: Calculus with 1D mesh functions . . . . . . . . . . . . . . . . . . . . 124

xxi
xxii List of Exercises, Problems and Projects

Exercise 2.7: Find the analytical solution to a damped wave equation . . . . . 148
Problem 2.8: Explore symmetry boundary conditions . . . . . . . . . . . . . . . 148
Exercise 2.9: Send pulse waves through a layered medium . . . . . . . . . . . . 148
Exercise 2.10: Explain why numerical noise occurs . . . . . . . . . . . . . . . . 149
Exercise 2.11: Investigate harmonic averaging in a 1D model . . . . . . . . . . 149
Problem 2.12: Implement open boundary conditions . . . . . . . . . . . . . . . . 149
Exercise 2.13: Implement periodic boundary conditions . . . . . . . . . . . . . . 151
Exercise 2.14: Compare discretizations of a Neumann condition . . . . . . . . 151
Exercise 2.15: Verification by a cubic polynomial in space . . . . . . . . . . . . 152
Exercise 2.16: Check that a solution fulfills the discrete model . . . . . . . . . 181
Project 2.17: Calculus with 2D mesh functions . . . . . . . . . . . . . . . . . . . 181
Exercise 2.18: Implement Neumann conditions in 2D . . . . . . . . . . . . . . . 182
Exercise 2.19: Test the efficiency of compiled loops in 3D . . . . . . . . . . . . 182
Exercise 2.20: Simulate waves on a non-homogeneous string . . . . . . . . . . 195
Exercise 2.21: Simulate damped waves on a string . . . . . . . . . . . . . . . . . 195
Exercise 2.22: Simulate elastic waves in a rod . . . . . . . . . . . . . . . . . . . . 195
Exercise 2.23: Simulate spherical waves . . . . . . . . . . . . . . . . . . . . . . . 195
Problem 2.24: Earthquake-generated tsunami over a subsea hill . . . . . . . . . 196
Problem 2.25: Earthquake-generated tsunami over a 3D hill . . . . . . . . . . . 198
Problem 2.26: Investigate Mayavi for visualization . . . . . . . . . . . . . . . . . 199
Problem 2.27: Investigate visualization packages . . . . . . . . . . . . . . . . . . 199
Problem 2.28: Implement loops in compiled languages . . . . . . . . . . . . . . 199
Exercise 2.29: Simulate seismic waves in 2D . . . . . . . . . . . . . . . . . . . . 200
Project 2.30: Model 3D acoustic waves in a room . . . . . . . . . . . . . . . . . 200
Project 2.31: Solve a 1D transport equation . . . . . . . . . . . . . . . . . . . . . 201
Problem 2.32: General analytical solution of a 1D damped wave equation . . 204
Problem 2.33: General analytical solution of a 2D damped wave equation . . 205
Exercise 3.1: Explore symmetry in a 1D problem . . . . . . . . . . . . . . . . . . 242
Exercise 3.2: Investigate approximation errors from a ux D 0 boundary
condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Exercise 3.3: Experiment with open boundary conditions in 1D . . . . . . . . . 243
Exercise 3.4: Simulate a diffused Gaussian peak in 2D/3D . . . . . . . . . . . . 244
Exercise 3.5: Examine stability of a diffusion model with a source term . . . . 245
Exercise 3.6: Stabilizing the Crank-Nicolson method by Rannacher time
stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Project 3.7: Energy estimates for diffusion problems . . . . . . . . . . . . . . . . 316
Exercise 3.8: Splitting methods and preconditioning . . . . . . . . . . . . . . . . 318
Problem 3.9: Oscillating surface temperature of the earth . . . . . . . . . . . . . 319
Problem 3.10: Oscillating and pulsating flow in tubes . . . . . . . . . . . . . . . 320
Problem 3.11: Scaling a welding problem . . . . . . . . . . . . . . . . . . . . . . 320
Exercise 3.12: Implement a Forward Euler scheme for axi-symmetric diffusion 322
Exercise 4.1: Analyze 1D stationary convection-diffusion problem . . . . . . . 351
Exercise 4.2: Interpret upwind difference as artificial diffusion . . . . . . . . . 351
Problem 5.1: Determine if equations are nonlinear or not . . . . . . . . . . . . . 401
Problem 5.2: Derive and investigate a generalized logistic model . . . . . . . . 401
Problem 5.3: Experience the behavior of Newton’s method . . . . . . . . . . . . 402
Exercise 5.4: Compute the Jacobian of a 2  2 system . . . . . . . . . . . . . . . 402
Problem 5.5: Solve nonlinear equations arising from a vibration ODE . . . . . 402
List of Exercises, Problems and Projects xxiii

Exercise 5.6: Find the truncation error of arithmetic mean of products . . . . . 402
Problem 5.7: Newton’s method for linear problems . . . . . . . . . . . . . . . . 404
Problem 5.8: Discretize a 1D problem with a nonlinear coefficient . . . . . . . 404
Problem 5.9: Linearize a 1D problem with a nonlinear coefficient . . . . . . . 404
Problem 5.10: Finite differences for the 1D Bratu problem . . . . . . . . . . . . 404
Problem 5.11: Discretize a nonlinear 1D heat conduction PDE by finite
differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Problem 5.12: Differentiate a highly nonlinear term . . . . . . . . . . . . . . . . 405
Exercise 5.13: Crank-Nicolson for a nonlinear 3D diffusion equation . . . . . 406
Problem 5.14: Find the sparsity of the Jacobian . . . . . . . . . . . . . . . . . . . 406
Problem 5.15: Investigate a 1D problem with a continuation method . . . . . . 406
Exercise B.1: Truncation error of a weighted mean . . . . . . . . . . . . . . . . . 447
Exercise B.2: Simulate the error of a weighted mean . . . . . . . . . . . . . . . . 447
Exercise B.3: Verify a truncation error formula . . . . . . . . . . . . . . . . . . . 447
Problem B.4: Truncation error of the Backward Euler scheme . . . . . . . . . . 447
Exercise B.5: Empirical estimation of truncation errors . . . . . . . . . . . . . . 448
Exercise B.6: Correction term for a Backward Euler scheme . . . . . . . . . . . 448
Problem B.7: Verify the effect of correction terms . . . . . . . . . . . . . . . . . 448
Problem B.8: Truncation error of the Crank-Nicolson scheme . . . . . . . . . . 448
Problem B.9: Truncation error of u0 D f .u; t/ . . . . . . . . . . . . . . . . . . . 448
Exercise B.10: Truncation error of ŒD t D t un . . . . . . . . . . . . . . . . . . . . 449
Exercise B.11: Investigate the impact of approximating u0 .0/ . . . . . . . . . . 449
Problem B.12: Investigate the accuracy of a simplified scheme . . . . . . . . . 449
Exercise C.1: Explore computational efficiency of numpy.sum versus built-in
sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Exercise C.2: Make an improved numpy.savez function . . . . . . . . . . . . . 490
Exercise C.3: Visualize the impact of the Courant number . . . . . . . . . . . . 491
Exercise C.4: Visualize the impact of the resolution . . . . . . . . . . . . . . . . 491
Vibration ODEs
1

Vibration problems lead to differential equations with solutions that oscillate in


time, typically in a damped or undamped sinusoidal fashion. Such solutions put
certain demands on the numerical methods compared to other phenomena whose
solutions are monotone or very smooth. Both the frequency and amplitude of the
oscillations need to be accurately handled by the numerical schemes. The forthcom-
ing text presents a range of different methods, from classical ones (Runge-Kutta and
midpoint/Crank-Nicolson methods), to more modern and popular symplectic (ge-
ometric) integration schemes (Leapfrog, Euler-Cromer, and Störmer-Verlet meth-
ods), but with a clear emphasis on the latter. Vibration problems occur throughout
mechanics and physics, but the methods discussed in this text are also fundamen-
tal for constructing successful algorithms for partial differential equations of wave
nature in multiple spatial dimensions.

1.1 Finite Difference Discretization

Many of the numerical challenges faced when computing oscillatory solutions to


ODEs and PDEs can be captured by the very simple ODE u00 C u D 0. This ODE
is thus chosen as our starting point for method development, implementation, and
analysis.

1.1.1 A Basic Model for Vibrations

The simplest model of a vibrating mechanical system has the following form:

u00 C ! 2 u D 0; u.0/ D I; u0 .0/ D 0; t 2 .0; T  : (1.1)

Here, ! and I are given constants. Section 1.12.1 derives (1.1) from physical prin-
ciples and explains what the constants mean.
The exact solution of (1.1) is

u.t/ D I cos.!t/ : (1.2)

© The Author(s) 2017 1


H.P. Langtangen, S. Linge, Finite Difference Computing with PDEs,
Texts in Computational Science and Engineering 16, DOI 10.1007/978-3-319-55456-3_1
2 1 Vibration ODEs

That is, u oscillates with constant amplitude I and angular frequency !. The corre-
sponding period of oscillations (i.e., the time between two neighboring peaks in the
cosine function) is P D 2=!. The number of periods per second is f D !=.2/
and measured in the unit Hz. Both f and ! are referred to as frequency, but ! is
more precisely named angular frequency, measured in rad/s.
In vibrating mechanical systems modeled by (1.1), u.t/ very often represents
a position or a displacement of a particular point in the system. The derivative
u0 .t/ then has the interpretation of velocity, and u00 .t/ is the associated acceleration.
The model (1.1) is not only applicable to vibrating mechanical systems, but also to
oscillations in electrical circuits.

1.1.2 A Centered Finite Difference Scheme

To formulate a finite difference method for the model problem (1.1), we follow the
four steps explained in Section 1.1.2 in [9].

Step 1: Discretizing the domain The domain is discretized by introducing a


uniformly partitioned time mesh. The points in the mesh are tn D nt, n D
0; 1; : : : ; N t , where t D T =N t is the constant length of the time steps. We in-
troduce a mesh function un for n D 0; 1; : : : ; N t , which approximates the exact
solution at the mesh points. (Note that n D 0 is the known initial condition, so
un is identical to the mathematical u at this point.) The mesh function un will be
computed from algebraic equations derived from the differential equation problem.

Step 2: Fulfilling the equation at discrete time points The ODE is to be satisfied
at each mesh point where the solution must be found:

u00 .tn / C ! 2 u.tn / D 0; n D 1; : : : ; N t : (1.3)

Step 3: Replacing derivatives by finite differences The derivative u00 .tn / is to be


replaced by a finite difference approximation. A common second-order accurate
approximation to the second-order derivative is

unC1  2un C un1


u00 .tn /  : (1.4)
t 2
Inserting (1.4) in (1.3) yields

unC1  2un C un1


D ! 2 un : (1.5)
t 2
We also need to replace the derivative in the initial condition by a finite dif-
ference. Here we choose a centered difference, whose accuracy is similar to the
centered difference we used for u00 :

u1  u1
D 0: (1.6)
2t
1.1 Finite Difference Discretization 3

Step 4: Formulating a recursive algorithm To formulate the computational al-


gorithm, we assume that we have already computed un1 and un , such that unC1 is
the unknown value to be solved for:

unC1 D 2un  un1  t 2 ! 2 un : (1.7)

The computational algorithm is simply to apply (1.7) successively for n D


1; 2; : : : ; N t  1. This numerical scheme sometimes goes under the name Störmer’s
method, Verlet integration1 , or the Leapfrog method (one should note that Leapfrog
is used for many quite different methods for quite different differential equations!).

Computing the first step We observe that (1.7) cannot be used for n D 0 since
the computation of u1 then involves the undefined value u1 at t D t. The
discretization of the initial condition then comes to our rescue: (1.6) implies u1 D
u1 and this relation can be combined with (1.7) for n D 0 to yield a value for u1 :

u1 D 2u0  u1  t 2 ! 2 u0 ;

which reduces to
1
u1 D u0  t 2 ! 2 u0 : (1.8)
2
Exercise 1.5 asks you to perform an alternative derivation and also to generalize the
initial condition to u0 .0/ D V ¤ 0.

The computational algorithm The steps for solving (1.1) become

1. u0 D I
2. compute u1 from (1.8)
3. for n D 1; 2; : : : ; N t  1: compute unC1 from (1.7)

The algorithm is more precisely expressed directly in Python:

t = linspace(0, T, Nt+1) # mesh points in time


dt = t[1] - t[0] # constant time step
u = zeros(Nt+1) # solution

u[0] = I
u[1] = u[0] - 0.5*dt**2*w**2*u[0]
for n in range(1, Nt):
u[n+1] = 2*u[n] - u[n-1] - dt**2*w**2*u[n]

Remark on using w for ! in computer code


In the code, we use w as the symbol for !. The reason is that the authors prefer w
for readability and comparison with the mathematical ! instead of the full word
omega as variable name.

1
http://en.wikipedia.org/wiki/Verlet_integration
4 1 Vibration ODEs

Operator notation We may write the scheme using a compact difference notation
listed in Appendix A.1 (see also Section 1.1.8 in [9]). The difference (1.4) has the
operator notation ŒD t D t un such that we can write:

ŒD t D t u C ! 2 u D 0n : (1.9)

Note that ŒD t D t un means applying a central difference with step t=2 twice:
1 1
ŒD t unC 2  ŒD t un 2
ŒD t .D t u/n D
t
which is written out as
 
1 unC1  un un  un1 unC1  2un C un1
 D :
t t t t 2

The discretization of initial conditions can in the operator notation be expressed


as
Œu D I 0 ; ŒD2t u D 00 ; (1.10)
where the operator ŒD2t un is defined as

unC1  un1
ŒD2t un D : (1.11)
2t

1.2 Implementation

1.2.1 Making a Solver Function

The algorithm from the previous section is readily translated to a complete Python
function for computing and returning u0 ; u1 ; : : : ; uN t and t0 ; t1 ; : : : ; tN t , given the
input I , !, t, and T :

import numpy as np
import matplotlib.pyplot as plt

def solver(I, w, dt, T):


"""
Solve u’’ + w**2*u = 0 for t in (0,T], u(0)=I and u’(0)=0,
by a central finite difference method with time step dt.
"""
dt = float(dt)
Nt = int(round(T/dt))
u = np.zeros(Nt+1)
t = np.linspace(0, Nt*dt, Nt+1)

u[0] = I
u[1] = u[0] - 0.5*dt**2*w**2*u[0]
for n in range(1, Nt):
u[n+1] = 2*u[n] - u[n-1] - dt**2*w**2*u[n]
return u, t
1.2 Implementation 5

We have imported numpy and matplotlib under the names np and plt, respec-
tively, as this is very common in the Python scientific computing community and
a good programming habit (since we explicitly see where the different functions
come from). An alternative is to do from numpy import * and a similar “import
all” for Matplotlib to avoid the np and plt prefixes and make the code as close as
possible to MATLAB. (See Section 5.1.4 in [9] for a discussion of the two types of
import in Python.)
A function for plotting the numerical and the exact solution is also convenient to
have:

def u_exact(t, I, w):


return I*np.cos(w*t)

def visualize(u, t, I, w):


plt.plot(t, u, ’r--o’)
t_fine = np.linspace(0, t[-1], 1001) # very fine mesh for u_e
u_e = u_exact(t_fine, I, w)
plt.hold(’on’)
plt.plot(t_fine, u_e, ’b-’)
plt.legend([’numerical’, ’exact’], loc=’upper left’)
plt.xlabel(’t’)
plt.ylabel(’u’)
dt = t[1] - t[0]
plt.title(’dt=%g’ % dt)
umin = 1.2*u.min(); umax = -umin
plt.axis([t[0], t[-1], umin, umax])
plt.savefig(’tmp1.png’); plt.savefig(’tmp1.pdf’)

A corresponding main program calling these functions to simulate a given number


of periods (num_periods) may take the form

I = 1
w = 2*pi
dt = 0.05
num_periods = 5
P = 2*pi/w # one period
T = P*num_periods
u, t = solver(I, w, dt, T)
visualize(u, t, I, w, dt)

Adjusting some of the input parameters via the command line can be handy.
Here is a code segment using the ArgumentParser tool in the argparse module
to define option value (–option value) pairs on the command line:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument(’--I’, type=float, default=1.0)
parser.add_argument(’--w’, type=float, default=2*pi)
parser.add_argument(’--dt’, type=float, default=0.05)
parser.add_argument(’--num_periods’, type=int, default=5)
a = parser.parse_args()
I, w, dt, num_periods = a.I, a.w, a.dt, a.num_periods
6 1 Vibration ODEs

Such parsing of the command line is explained in more detail in Section 5.2.3 in
[9].
A typical execution goes like

Terminal

Terminal> python vib_undamped.py --num_periods 20 --dt 0.1

Computing u0 In mechanical vibration applications one is often interested in com-


puting the velocity v.t/ D u0 .t/ after u.t/ has been computed. This can be done by
a central difference,

unC1  un1
v.tn / D u0 .tn /  v n D D ŒD2t un : (1.12)
2t
This formula applies for all inner mesh points, n D 1; : : : ; N t  1. For n D 0, v.0/
is given by the initial condition on u0 .0/, and for n D N t we can use a one-sided,
backward difference:
un  un1
v n D ŒD t un D :
t
Typical (scalar) code is

v = np.zeros_like(u) # or v = np.zeros(len(u))
# Use central difference for internal points
for i in range(1, len(u)-1):
v[i] = (u[i+1] - u[i-1])/(2*dt)
# Use initial condition for u’(0) when i=0
v[0] = 0
# Use backward difference at the final mesh point
v[-1] = (u[-1] - u[-2])/dt

Since the loop is slow for large N t , we can get rid of the loop by vectorizing the
central difference. The above code segment goes as follows in its vectorized version
(see Problem 1.2 in [9] for explanation of details):

v = np.zeros_like(u)
v[1:-1] = (u[2:] - u[:-2])/(2*dt) # central difference
v[0] = 0 # boundary condition u’(0)
v[-1] = (u[-1] - u[-2])/dt # backward difference

1.2.2 Verification

Manual calculation The simplest type of verification, which is also instructive


for understanding the algorithm, is to compute u1 , u2 , and u3 with the aid of a
calculator and make a function for comparing these results with those from the
solver function. The test_three_steps function in the file vib_undamped.py
shows the details of how we use the hand calculations to test the code:
1.2 Implementation 7

def test_three_steps():
from math import pi
I = 1; w = 2*pi; dt = 0.1; T = 1
u_by_hand = np.array([1.000000000000000,
0.802607911978213,
0.288358920740053])
u, t = solver(I, w, dt, T)
diff = np.abs(u_by_hand - u[:3]).max()
tol = 1E-14
assert diff < tol

This function is a proper test function, compliant with the pytest and nose testing
framework for Python code, because

 the function name begins with test_


 the function takes no arguments
 the test is formulated as a boolean condition and executed by assert

We shall in this book implement all software verification via such proper test func-
tions, also known as unit testing. See Section 5.3.2 in [9] for more details on how to
construct test functions and utilize nose or pytest for automatic execution of tests.
Our recommendation is to use pytest. With this choice, you can run all test functions
in vib_undamped.py by

Terminal

Terminal> py.test -s -v vib_undamped.py


============================= test session starts ======...
platform linux2 -- Python 2.7.9 -- ...
collected 2 items

vib_undamped.py::test_three_steps PASSED
vib_undamped.py::test_convergence_rates PASSED

=========================== 2 passed in 0.19 seconds ===...

Testing very simple polynomial solutions Constructing test problems where the
exact solution is constant or linear helps initial debugging and verification as one
expects any reasonable numerical method to reproduce such solutions to machine
precision. Second-order accurate methods will often also reproduce a quadratic
solution. Here ŒD t D t t 2 n D 2, which is the exact result. A solution u D t 2
leads to u00 C ! 2 u D 2 C .!t/2 ¤ 0. We must therefore add a source in the
equation: u00 C ! 2 u D f to allow a solution u D t 2 for f D 2 C .!t/2 . By
simple insertion we can show that the mesh function un D tn2 is also a solution of
the discrete equations. Problem 1.1 asks you to carry out all details to show that
linear and quadratic solutions are solutions of the discrete equations. Such results
are very useful for debugging and verification. You are strongly encouraged to do
this problem now!

Checking convergence rates Empirical computation of convergence rates yields


a good method for verification. The method and its computational details are ex-
Another random document with
no related content on Scribd:
“For forms of government let fools contest;
Whate’er is best administer’d, is best.”[369]
Pope’s Essay on Man.

Dr. Rittenhouse was, undoubtedly, among those who entertained


the most sanguine expectations, that the political institutions in the
United States, formed as they are according to the republican model,
would tend to meliorate the condition of the people, and “promote the
general welfare.” He may at some time have even “believed political,
as well as moral evil, to be intruders into the society of men.”[370] But
some passages in his Oration plainly shew, that, as has been
already observed, he had no faith in the perfectibility of human
reason,[371] in this life. He was also too sound a philosopher not to
know, that if, by the best rules of philosophical ratiocination, many
well known phænomena in the natural world could not be reached,
with respect to their nature and causes, in such manner as to render
these susceptible of demonstrative proof,—nothing like certainty in
the result, much less perfection, could be calculated on, in putting
the theories of a science, such as government, to the test of
experiment.

If it be asked: ‘Where are the Works of Rittenhouse?’ a ready and


satisfactory answer to the question is at hand. Although he published
no ponderous volumes, he has left behind him great and honourable
memorials of his genius, his science and his skill; such as will long
remain, as Monuments of the extraordinary extent of his practical
usefulness in his day, and of his well-earned fame. “He has not
indeed made a world,” as Mr. Jefferson, in speaking of his Orrery,
emphatically expresses himself; “but he has, by imitation,
approached nearer its Maker, than any man who has lived from the
creation to this day.”[372] As long, too, as the geographical boundaries
of Pennsylvania, connected in part with those of the neighbouring
states, shall continue to define the respective jurisdictions of their
local sovereignties and rights, considered as members of a great
confederated nation; so long will they serve to distinguish the name
of Rittenhouse.[373] Nay, some of the rivers and canals, even some
principal roads, in the country of his nativity, bear testimony to his
talents, his public spirit and his industry. His inventions and
improvements, in various specimens of mechanism, conceived and
executed by himself, fully manifest, that, “as an artist, he has
exhibited as great a proof of mechanical genius as the world has
ever produced.”[374] And, as a man of extensive and profound
science, his various philosophical papers, but more especially those
relating to his astronomical observations, justify Mr. Jefferson’s
remark, that he was “second to no Astronomer living,”—that he was,
“in genius the first, because self-taught.”[375]

Such, then, were the “Works” of this truly great man. And it
appears that they were, in general, not only arduous in their
execution, and highly beneficial in their uses and effects; but that
they were likewise the productions of a lofty, penetrating and active
genius, great knowledge and skill, and the most indefatigable
perseverance.[376]

But though Dr. Rittenhouse published no great systematic literary


work, he communicated to others by his conversation, and by such
of his writings as have been given to the world, much valuable
philosophical information. He instructed, liberally, such persons as
were desirous of acquiring knowledge from a social intercourse with
him. The elevated station his character maintained, both for wisdom
and integrity, exhibited him to his cotemporaries as an example
worthy of being imitated:[377] and thus, in reality, his high reputation
operated as a powerful incitement upon many of his countrymen, to
pursue similar objects of science, inspiring them with a taste to
cultivate the true philosophy.

The reputation of this distinguished man, as a mathematician and


astronomer, was pre-eminently great, in every civilized part of the
western world. Perhaps no man’s philosophical talents were ever
held in higher estimation, nor more deservedly so, by those qualified
to form a proper judgment of them, wherever his name was known;
not excepting those of Newton himself. His celebrity was far from
being confined within the limits of his native country: his Orrery, with
the proceedings and results of the Observation of that phænomenon
which so greatly interested the principal astronomers of both
hemispheres, the Transit of Venus in 1769, had rendered him justly
celebrated in Europe as well as America, as a philosopher of the
highest grade, at the age of thirty-seven years.

The peculiar circumstances of his Life, which have been amply


detailed in these Memoirs, were of such a nature as to preclude him,
in a great measure, from opportunities of carrying on a
correspondence with men of science and letters, abroad: the
extremely delicate, and oftentimes infirm state of his general health,
in addition to his numerous avocations, his long continued, various,
and important employments in the public service, left him little leisure
for literary pursuits of any kind. Indeed, nothing less than the
wonderful energy of his mind, and his extraordinary industry, could
have enabled him to write as much as he has done.[378]

Dr. Rittenhouse never attempted to amuse the world with any


hypothetical system of philosophy, or with opinions, merely
speculative, on any subject. The great objects of his pursuits,
through life, were Certainty and Truth: hence, he never advanced an
opinion, concerning any thing whatever, which he did not consider as
being either susceptible of verification by experiment and the
evidence of our senses, or, where the nature of the subject did not
admit of such proof, capable of being tested by the soundest
principles of human reason. Yet, though this profound investigator of
nature viewed “sober certainty” as the great desideratum in
philosophy, he was by no means a dogmatist; even with respect to
that portion of natural science which is capable of demonstration.
Notwithstanding the opinion he entertained of the vast extent to
which the faculties of the mind may be enlarged by a proper
improvement of them, he was fully aware that its powers are limited.
Like his great predecessor, Maclaurin, “the farther he advanced in
the knowledge of geometry and of nature, the greater his aversion
grew to perfect systems, hypotheses, and dogmatizing: without
peevishly despising the attainments we can arrive at, or the uses to
which they serve, he saw there lay infinitely more beyond our reach.”
Like him, also, he considered “our highest discoveries as being but a
dawn of knowledge, suited to our circumstances and wants in this
life; which, however, we ought thankfully to acquiesce in, for the
present, in hopes that it will be improved in a happier and more
perfect state.”[379] Rittenhouse never supposed, that, (to use the
words of Maclaurin’s biographer[380]), “because demonstrative
evidence is the most perfect, it should be—as, by some, it has been
—taken for granted, there is no other.” On the contrary, our
philosopher believed that there are many truths, natural as well as
moral, which are beyond the reach of demonstration; consequently,
not to be rejected, solely by reason of their insusceptibility of this
kind of proof. Hence, in his Oration he says, “Our Religion teaches
us what Philosophy could not have taught; and we ought to admire,
with reverence, the great things it has pleased Divine Providence to
perform, beyond the ordinary course of nature, for man, who is
undoubtedly the most noble inhabitant of this globe. But,” continues
this truly good man, “neither Religion nor Philosophy forbid us to
believe, that infinite Wisdom and Power, prompted by infinite
Goodness, may, throughout the vast extent of creation and duration,
have frequently interposed in a manner quite incomprehensible to
us, when it became necessary to the happiness of created beings of
some other rank or degree.”

Such were the pious reflections of a Christian Philosopher; the


sublime sentiments of an eminently distinguished Astronomer.

Should it be enquired: What was the system of Philosophy, to


which Dr. Rittenhouse adhered? though such a question can
scarcely be anticipated, after what has been already said; the
answer may be furnished in a few words: He was a thorough and
zealous disciple of the Newtonian school. He early embraced, and
perseveringly cultivated, “the Philosophy of Newton;” which “disdains
to make use of subterfuges,” which “is not reduced to the necessity
of using them, because it pretends not to be of nature’s privy
council;” while “other systems of philosophy have ever found it
necessary to conceal their weakness and inconsistency, under the
veil of unintelligible terms and phrases, to which no two mortals
perhaps ever affixed the same meaning.”[381]
With Newton, too, our Philosopher entertained the most exalted
conceptions of the Deity. He did not imagine, as his illustrious
predecessor was unjustly charged with having done, that infinite
space is an attribute of the Deity; that He is present in all parts of
space, by diffusion;[382] but, like that great man, he did believe, that
the Deity endures from eternity to eternity, and is present from infinity
to infinity; yet that He is not eternity or infinity, space or duration. For,
says Dr. Rittenhouse, “Nothing can better demonstrate the
immediate presence of the Deity in every part of space, whether
vacant or occupied by matter, than Astronomy does. It was from an
Astronomer St. Paul quoted that exalted expression, so often since
repeated, ‘In God we live, and move, and have our being.’”[383]

The terms of profound veneration, in which our Philosopher spoke,


on all occasions, of the character of Newton, demonstrate most
clearly his complete and undeviating attachment to the Principles of
that astonishing man.[384] Indeed, he appears to have taken him as
his model; and, certainly, he resembled him much, in many points of
character. Parallels have often been drawn between distinguished
men; and in comparatively a few instances, a strong resemblance
has been discovered, in some prominent features of character,
between two or more persons. Yet the infinite variety of talent, that
appears throughout the human race; the almost incredible difference
in the grades of intellectual endowment, distinguishing the sons of
men from each other; and the adventitious circumstances peculiar to
each individual, which either direct or controul his conduct, and seem
to mark his destiny in life; all these, taken together, produce such an
endless diversity of character in the species, as to render it
impracticable, if not absolutely impossible, to find any two men who
greatly resemble each other in many particulars.

There are, nevertheless, so many circumstances founded on


natural causes, that indicate an extraordinary similitude in the
genius, disposition and principles of Rittenhouse, and his great
Prototype; so many, moreover, of a singular nature, connected with
events purely adventitious, wherein the condition, occupations and
pursuits of these philosophers, with other eventual relations
depending wholly on accident, resembled each other; that an
interesting parallel, between them, might be attempted with no
inconsiderable share of success.

In the course of these Memoirs, the Biographer of Rittenhouse


has endeavoured to furnish a faithful representation of the
Philosopher and of the Man. He was desirous of delineating his true
character, in both points of view; that the world may be enabled to
make a just estimate of the genius, the principles, and the conduct of
a person, so celebrated in name. But, in order that the more correct
judgment might be formed of his virtues and talents, and of the
services he has rendered to society, it became necessary to
describe the sphere in which he moved; so far, at least, as to present
to view occasional sketches of the complexion of the Times in which
he lived, and of some of the more prominent Characters who were
his compatriots. The Memorialist has therefore conveyed to the mind
of his reader some idea of the moral, political, and literary state of
society, more particularly in the country of our Philosopher’s
residence, within the same period. This rendered it proper to notice
the rise, nature, and progress of certain Institutions, upon which
science and the arts, with many of the benefits of civil polity, greatly
depend; such as tend to diffuse useful knowledge throughout the
community, to promote the general weal, and to meliorate the
condition of the great family of mankind.

It has been already observed, that every individual in society is


more or less closely connected with it, in various ways: and it is
obvious, that an eminent citizen, one, especially, standing in
relations of a public nature in the community of which he is a
member, usually has his history and character so interwoven with
those of his own times, that it is difficult to understand the former
thoroughly, without possessing a competent knowledge of the latter.
The Life of such a man as Rittenhouse could not, therefore, in
many respects, be either well comprehended or duly estimated,
unless there had been connected with it some account of men and
things, to which his private pursuits and public employments were,
directly or indirectly, related.
In whatever light, then, a retrospective view of Dr. Rittenhouse’s
character may be taken, it will be found to present a model worthy of
imitation. The mild and amiable virtues of domestic life, and similar
dispositions in the intercourses of private society, decorated his
whole deportment, as a man and as a citizen; the more stern
qualities of the patriot equally distinguished him as the friend of his
native country, in all his public relations; while the principles of
genuine philanthrophy impressed his heart with feelings of the most
extended benevolence. In all these respects, nevertheless, some
have equalled, though few, if any, have surpassed him. But when,
united to virtues and dispositions, such as these, the powerful
genius, the extensive philosophical talents and attainments, the self-
acquired and extraordinary mechanical skill of Dr. Rittenhouse,
shall also have been considered; it will be acknowledged, that the
Memoirs of his Life, commemorate a Man truly great. They recal to
his surviving countrymen, and to their posterity, a remembrance of
his excellence and usefulness; presenting to them such a specimen
of worth and abilities, as is highly deserving of being emulated. At
the same time, they exhibit to the world a faithful portrait of a Man,
whose character had early acquired the well-earned respect of the
wise and good in other nations. During his life, the name of
Rittenhouse received due homage from some of the most
illustrious Philosophers of Europe. In his own country, that name
cannot cease to be venerated, so long as genius, science, and
virtue, shall be held in the high estimation to which they are entitled.

It has been observed by a noble author[385] of the present day, “that


the decline of public spirit in matters of Taste, is a certain indication
of political decay.” To whatever degree the justness of this
observation may extend, it will apply still more forcibly to any country,
wherein a disregard, consequently a declension of learning, science
and moral virtue, is perceived. Rittenhouse lived in an eventful age.
During a long period of his life, he witnessed a comparative simplicity
of manners and much integrity of character, among his countrymen.
He beheld a progressive course of useful knowledge, and an
advance in those arts and refinements of polished society, which
minister as well to the rational enjoyments as to the conveniences of
human life; and these he saw accompanied by almost every species
of public improvements, promoted by the liberal spirit of the people
and fostered by the benign genius of the government. Our
Philosopher himself, one-and-twenty years before his death, in
speaking of the rapid progress his countrymen had then made in
almost every species of social refinements, made this remark: “We
have made most surprising, I had almost said unnatural, advances
towards the meridian of glory.”[386] But this good man dreaded even
at that time, what he always most earnestly deprecated, that Luxury
would, ere long, follow in the train of an highly cultivated state of
manners and too sumptuous a style of living: for, he considered an
excess of such refinements as leading to that depravity of morals
which often accompanies “Luxury,” and, as he has expressed it, “her
constant follower, Tyranny.”

The gloomy anticipations, which he sometimes entertained, of a


future depression of the interests of learning in his native country,
from such causes, he lived not to see realized. There is, indeed,
ground on which a reasonable hope may be founded, that,
notwithstanding the operation of some inauspicious circumstances,
in these times, occasioned by the present distracted state of the
political world, literature, science and the arts, will yet be
successfully cultivated in the United States of America. Dr.
Rittenhouse had the good fortune to live in an age when virtue and
talents were honoured; when abilities to serve the country, and an
honest attachment to its best interests, were the surest passports to
the public confidence and esteem. In the latter years of his life, it was
a source of great gratification to him to know that his country was
prosperous; it being then in the full enjoyment of all the arts of
peace, and other blessings of a well-ordered society. He was greatly
respected and esteemed by his illustrious compatriot, Washington;
whose magnanimity taught him to spurn with disdain all petty
considerations, arising from such mere difference of opinion in the
speculations of politics, as could neither undermine the principles of
a Patriot, nor affect the fidelity of an honest Man. Very many
distinguished men, besides, were his contemporaries; and by
persons of this description, almost universally, as well as by all his
countrymen of every class, to whom his person or character was
known, he was held in the highest estimation: indeed, few men ever
enjoyed a larger share of the public regard.

Some years after the decease of Dr. Rittenhouse, it was judged


expedient to transfer his perishable remains from their first place of
sepulture, to another: they were accordingly removed; and interred in
the cemetery adjoining the Presbyterian church in Pine-street,
Philadelphia, near the body of his son-in-law, Mr. Sergeant. The
grave of the celebrated American Astronomer is enclosed, under a
plain slab of marble, thus inscribed:

IN MEMORY OF

DAVID RITTENHOUSE,
BORN APRIL 8th, 1732,

DIED JUNE 26th; 1796;

AND

HANNAH RITTENHOUSE,

HIS WIFE,

Who died October 15th,

1799,

Aged 64 years.

But, although no costly tomb contains the ashes of this eminently-


distinguished Man; although no sculptured cenotaph, in any part of
his country, blazons his genius or records his fame; and
notwithstanding the chisel of the statuary has never been employed
in obedience to the public voice, to produce a permanent
resemblance of his countenance and figure; yet a monument of more
durable nature than any of these, consecrates his virtues, his talents,
and his usefulness. A grateful remembrance of his modest worth is
enshrined in the hearts of the wise and the good of his own age and
country; and the name of David Rittenhouse will be every where
perpetuated with veneration and renown, among the sons of science
and the benefactors of mankind.

302. Rush’s Eulog. on Ritt.

303. “Astronomy, like the Christian religion, if you will allow me the
comparison,” said our philosopher, “has a much greater influence on
our knowledge in general, and perhaps on our manners too, than is
commonly imagined. Though but few men are its particular votaries,
yet the Light it affords is universally diffused among us; and it is
difficult for us to divest ourselves of its influence so far, as to frame
any competent idea of what would be our situation without it.” See
Ritt. Orat.

In another part of his Oration is this passage—“Our Religion


teaches us what Philosophy could not have taught: and we ought to
admire, with reverence, the great things it has pleased Divine
Providence to perform, beyond the ordinary course of nature, for
man, who is, undoubtedly, the most noble inhabitant of this globe,”
&c.

And in addition to these sentiments, uttered and published by our


philosopher himself, let the testimony of Dr. Rush, who had long and
intimately known him, be quoted, from the learned professor’s
Eulogium: “He believed in the Christian Revelation,” says the Doctor;
and then subjoins—“Of this he gave many proofs; not only in the
conformity of his life to the precepts of the Gospel, but in his letters
and conversation.”

304. Equivalent to 36,066⅔ American or Spanish dollars.

305. The elder of these ladies became, in the year 1788, the
second wife of Jonathan Dickinson Sergeant, Esq. late an eminent
lawyer in Philadelphia, and sometime attorney-general of
Pennsylvania. This gentleman was one of the five persons
delegated, on the 20th of February, 1776, by the convention of New-
Jersey (where he then resided,) to represent that colony in congress:
his colleagues were, the late governor Livingston, and John de Hart,
Richard Smith, and John Cooper, Esquires. Mr. Sergeant died of the
yellow fever in Philadelphia, on the 8th of October, 1793; after having
been many weeks actively and benevolently employed, with a few
other gentlemen of humanity, in the prosecution of such measures,
as the sufferings of those of the citizens who had not fled, and the
general welfare of the city required, at that calamitous period. He left
issue a son and two daughters, by this marriage, besides several
children by his first wife.

The other daughter of Dr. Rittenhouse was married in the year


1790, to Nicholas Baker Waters, M. D. of Philadelphia, a young
physician of respectable talents and amiable disposition. Dr. Waters
died of a pulmonary disease, in August, 1794, at a very early age,
leaving one son, an only child.

Dr. Rittenhouse named his second daughter, Esther, in


compliment to his sister Barton. In a letter to the Rev. Mr. Barton,
written on the occasion of the birth of this younger child, he says
—“To me, it is a matter of indifference, but to my Eleanor it was a
great disappointment, to have a girl, having promised herself a boy;
and it had long since been resolved that this child, if a son, should be
called Thomas, after yourself.” The eldest daughter was named
Elizabeth, after his own mother.

306. Dr. Rush has very beautifully expressed the same sentiment,
in a passage of his Eulogium on our philosopher. After remarking,
that his bodily infirmities “contributed much to the perfection of his
virtue, by producing habitual patience and resignation to the will of
heaven, and a constant eye to the hour of his dissolution,” he says:
“It was a window through which he often looked with pleasure
towards a place of existence, where, from the increase and
perfection of his intuitive faculties, he would probably acquire more
knowledge in an hour, than he had acquired in his whole life, by the
slow operations of reason; and where, from the greater magnitude
and extent of the objects of his contemplation, his native globe would
appear like his cradle, and all the events of time, like the
amusements of his infant years.” Such, too, must have been the
ideas, impressed on the mind of Rittenhouse himself, when, in the
morning of his life, he imagined the angel Gabriel looking down from
the seat of perfect knowledge, and viewing, benignly, far from
beholding with a smile of contempt, the efforts of Newton, to
demonstrate the actual motion of our earth. W. B.

307. See Eulog. on Ritt.

308. About twenty-six years and an half.—Dr. Franklin was


President from the institution of the society, in Jan. 1769, until his
death, on the 17th of April, 1790; and Dr. Rittenhouse, who
succeeded him in Jan. 1791, continued in the office until he died, the
26th of June, 1796. W. B.

309. See Mr. Malone’s Account of the Life and Writings of Sir
Joshua Reynolds, prefixed to the works of Sir Joshua.

310. See Rush’s Eulog. on Ritt.

311. “His manners were civil and engaging, to such a degree, that
he seldom passed an hour, even in a public house in travelling
through our country, without being followed by the good wishes of all
who attended upon him.” Rush’s Eulogium on Ritt.

312. Dr. Rittenhouse’s brother Benjamin, in a written


communication made to the writer of these memoirs in the year
1796, observes, that the Doctor, “when in health, was cheerful; and
his passions, unless they were excited by the abuses and knavery of
men, either in public or private life, were moderate: but where he
conceived that the interest or liberties of his country were
endangered, he would, on those occasions, express himself with
great warmth and asperity.”
313. See his Oration.

314. It was publicly declared by the same acrimonious writer who


charged Dr. Rittenhouse with being an atheist, (namely, Mr. William
Cobbett,) and with an equal disregard of truth, as has been already
shewn, that the Doctor signed “the inflammatory Resolutions” of the
Democratic Society against the Excise-law, which, as he alleged,
produced the Western Insurrection in Pennsylvania, in the year
1794. Dr. Rittenhouse, it is well known, did not even attend the
meetings of that society. This is admitted by Mr. Cobbett himself, in
the following invidious paragraph, extracted from a pamphlet written
and published by the late William L. Smith, Esq. of South-Carolina,
and republished by Cobbett in his own works: it is in these words
—“Rittenhouse was a great philosopher; but the only proof we have
had of his political talents, was, his suffering himself to be wheedled
into the presidency of the democratic society of Philadelphia; a
society with which he was even ashamed to associate, though
cajoled and flattered into the loan of his name.”

315. The memorialist cannot deprive himself of the gratification of


introducing, on the present occasion, a little anecdote communicated
to him by his friend, Francis Johnston, Esq. characteristic of our
philosopher’s amiable simplicity and benevolent disposition.
Circumstances as unimportant in themselves, as the one here
related, sometimes make us acquainted with the true character of
individuals.

Colonel Johnston, who was bred a scholar, and held with


reputation the rank of a colonel in the American service in the war of
the revolution, was, at an early period of his life, a zealous admirer of
the character of Rittenhouse. But long afterwards, and while the
Doctor officiated as state-treasurer, that gentleman held the next
great office in the financial department of the state. The connexion of
those offices occasioned almost daily visits from the colonel to the
state-treasury, and intercourse with the treasurer himself; and this
produced a reciprocal friendship between the two gentlemen. “For a
time,” says Col. Johnston, “Dr. Rittenhouse managed the business of
his office with the utmost attention and assiduity: but his all-
capacious mind could no longer be restrained from its native
pursuits; his money and his counter, therefore, he resigned into the
hands of his beloved wife, who, although possessed of all the
feminine virtues, performed the arduous duties of the office with a
masculine understanding, with accuracy and unwearied attention.”

“My intimacy with Dr. Rittenhouse,” continues the colonel,


“introduced between us a concern in some property, in the western
part of the city, which often induced us to walk out together, to visit it.
That part of the property which laid on the main street, belonged to
me; and being more exposed to the depredations of the disorderly
people who then inhabited that neighbourhood, was consequently
often injured in the fences or board-inclosures. More than once, I
have seen this philosopher, who never thought it any degradation of
philosophy, to bow at the shrine of friendship, marching along my
line of fence, and most industriously, and in a most masterly manner,
with his own hammer and nails, mending or repairing the same.”

“This anecdote I mention thus particularly,” adds the worthy


colonel, “with a view of shewing, that in addition to Dr. Rittenhouse’s
other virtues, humanity and friendship were leading traits in his
excellent character.”

316. In expressing his admiration of “that dispositions of lands and


seas, which affords a communication between distant regions, and a
mutual exchange of benefits,” Dr. Rittenhouse unquestionably had in
view a commercial, as well as social, intercourse between the
inhabitants of different climes: he was too enlightened a man, not to
have been aware of its “benefits.” “A civilized nation, without
commerce,” (as the writer of these memoirs had occasion to observe
in a former publication,[316a]) “is a solecism in politics. It is in the
rudest state of mankind, only, that a people can exist, without any
communication with other societies or commercial intercourse
among themselves, every one supporting himself by his own labour.
Indeed, so absolute a state of nature can only be conceived; but has
scarcely existed in reality. The wants, the fears, the weakness, nay
the very nature of man, constitute him a social animal: and, in the
very origin of society, their mutual necessities, with the various
talents, means, and opportunities of individuals for supporting them,
must have produced a reciprocity of services, and an occasional
interchange with one another of that property, which each had
acquired by his own exertions.”
316a. The true interest of the United States, and particularly of Pennsylvania,
considered: published in 1786.

317. See his Oration.

318. In the year 1756, he made an eight-day clock, for his brother-
in-law, Mr. Barton; over the dial-plate of which, was engraven this
mementory motto—Tempus fugit; and underneath, this blunt but too
often necessary precept—Go about your business.

On one description of the continental bills of credit, issued by


congress during the American war, were represented a sundial and a
meridian sun over it: above, the word “Fugio;” and beneath, these
words—“Mind your Business.” And on the reverse of a copper one
cent piece, struck in the year 1787, in pursuance of a resolve of
congress of the 6th of July in that year, are impressed the same
device and mottoes as those last mentioned; corresponding with
those adopted by our Philosopher, when only twenty-four years of
age: a circumstance that shews, how early in life he had formed a
just estimate of the value of time.

It may not be improper here to observe, that the various devices


affixed to the continental money, as it was called, were much
admired for their appropriate significancy; and that they were
generally supposed to be the production of the late ingenious Judge
Hopkinson, an intimate friend of Mr. Rittenhouse.

319. See Eulog. on Ritt.

320. An eulogy of this great astronomer, celebrated for his


discovery of the aberration and nutation, will be found in the History
of the French Academy, for the year 1762. He was born in 1692; and
died at Greenwich, in 1762, at the age of seventy years.

321. See the Memorial of the Society to the General Assembly,


dated the 6th of March, 1775; introduced in the foregoing pages.

322. Observatories are indispensably necessary to the cultivation


of astronomical science. There are many celebrated institutions of
this kind, in various parts of Europe; and of these, the British isles
may justly boast of possessing a large proportion in number,
admirably fitted up with all the necessary apparatus. Some account
of these will be found in other parts of this work.

Besides the liberal and honourable provision made for eminent


astronomers in Great-Britain, many of the most distinguished men of
the same class, on the continent of Europe, have experienced the
bounty of their respective princes and states. Such, among others,
were the celebrated C. Mayer, Astronomer to the Elector Palatine
and duke of Bavaria, at Manheim; Zach, Astronomer to the Duke of
Saxe-Gotha, at Gotha; and Lalande, Professor of Astronomy and
Inspector of the College of France, at Paris. These great
philosophers have had splendid astronomical establishments
provided for them, by their sovereigns; as is more particularly noticed
in other parts of these memoirs. And the extensive work of Mr. de
Zach, entitled, Tabulæ Motuum Solis novæ et correctæ, &c. (a large
quarto volume in the Latin language,) was printed under the
patronage and at the expense of the Duke of Saxe-Gotha, in the
year 1792, and distributed gratis among many of the learned of the
old and new world; an example of munificence worthy of imitation by
all sovereign princes and states, who know how to estimate, as they
deserve, such importantly useful productions of men eminent in
science.

The time, in which the transcendent talents of such philosophers


as have been here named, was employed, together with the
products of their labours, were rightfully, under such patronage, the
property of the public; while the time of our astronomer was with
equal justice his own, and consequently the fruits of his time, genius,
and labour, were, at least primarily, due to himself and his family.

323. The famous English Observatory near Greenwich Hospital,


and in the immediate vicinity of the town of Greenwich in Kent,
(erected, on a commanding eminence one hundred and sixty feet
above the level of the river Thames, in the year 1676, by order of
King Charles II.) is still called Flamstead-House; Mr. Flamstead
having been the first person appointed Regius Professor there.

324. It is said of the celebrated Roger Cotes, by his friend and


patron, the learned Dr. Richard Bentley, in his inscription upon the
tomb of that great philosopher, at Cambridge, that—

“Pauca quidem Ingenii sui pignora reliquit,


Sed egregia, sed admiranda:”

In like manner, though the writings of Dr. Rittenhouse are neither


numerous nor extensive, some of his works are, nevertheless, so
excellent and admirable in their nature, they exhibit such proofs of
transcendent genius, that they will immortalize his name. And, as
Cotes was prematurely taken away by death, or, as expressed in his
epitaph,

“Immaturâ Morte præreptus;”—

so, the actual term of Rittenhouse’s life may be considered as having


been much shortened by sickness. Franklin, who lived twenty years
longer than our astronomer, published little in philosophy; yet this
circumstance does not derogate from his claims to the character of a
philosopher.

325. A second edition of the first volume was published in the year
1789, in consequence of the extraordinary demand for that book, by
reason of the very important papers respecting the Transit of Venus,
contained in it.
326. Some further remarks respecting this comet, than those
contained in Dr. Rittenhouse’s communication, here referred to, will
be found in an extract which has already been given, of his letter to
the Rev. Mr. Barton, under the date of July 30, 1770.

327. Mr. Francis de Zach (Astronomer to the duke of Saxe-Gotha,)


in the explanation and use of his table, No. 38, entitled, “Correctio
horæ meridianæ prodeuntis ex altitudinibus correspondentibus
Solis,” says—“Tradit Clarissimus Dav. Rittenhouse, in
Transactionibus Americanis (vol. 1. p. 155. edit. 2.), Methodum
novum correctionis horæ meridianæ, absque tabulis, ex solâ
observatione deducendæ; sed requiruntur, ad hoc, duorum dierum
subsequentium altitudines quatuor æquales: id est, sub eadem
altitudine manè et vesperi factæ, ad assequendam ex his,
correctiones meridiei, Regulæ Clariss. Authoris sunt sequentes:” Mr.
de Zach then lays down Dr. Rittenhouse’s Rules, which will be found
in the Transactions of the American Philosophical Society, already
referred to; and adds—“Exempla hoc perspicuum reddent:” he next
states two examples, from which he deduces proofs of the accuracy
of Dr. Rittenhouse’s method. See “Tabulæ Motuum Solis, novæ et
correctæ, ex Theoriâ Gravitatis et Observationibus recentissimis
erutæ, &c. auctore Francisco de Zach:” printed at Gotha, in 1792.

328. This Comet was observed by John Lukens, Esq. of


Philadelphia, on the 20th of January, 1784. This respectable
practical astronomer communicated his discovery of it to Dr.
Rittenhouse the next day, on the evening of which, (“assisted by Mr.
Lukens and Mr. Prior,”) he ascertained the then apparent place of
this comet. Dr. Rittenhouse’s communication to the society, on this
subject, gives also the apparent place of the comet on the 17th of
February, being the last time the weather permitted him to see it: the
result of his intermediate observations is also stated.

329. These observations were made in Philadelphia, by Dr.


Rittenhouse, at sundry times in the years 1784, 1785, and 1786, on
the new planet, or Georgium Sidus; and on the Transit of Mercury
over the Sun’s disk, on the 12th of November, 1782. The same
communication also states the geocentric places of the Georgium
Sidus, at several different dates between the 1st of April, 1762, and
the 14th of March, 1784, both included; as observed by Mr. James
Six, at the city of Canterbury in England.

330. This eclipse was observed by Andrew Ellicott, Esq. at the city
of Washington, as follows; viz.

6.h 39′. 1″,25 Annulus


completed
April 6. 43. 15,25 Do. broken M.
3d. Time.
7. 55. 37,75 End of Eclipse.

A letter from the celebrated French Astronomer, Lalande, to Dr.


Rittenhouse, on the same subject, has been already given.

331. In this letter, Dr. Rittenhouse merely informs Mr. Patterson, in


general terms, of the time when he first observed this comet, its then
place, and its course through several of the constellations, until the
8th of February; on the evening of which day, he saw it for the last
time. It is presumed that Dr. Rittenhouse’s state of health, at that
period, would not admit of his making more definite observations on
this comet.

332. This desideratum in astronomical science had long engaged


Dr. Rittenhouse’s attention; and it is confidently said by one of his
intimate friends, that, in the latter part of his life, he had actually
written much on the subject of Pendulums; intended, probably, for
publication. But, unfortunately, the manuscript-book, which contained
what he had thus written, can not now be found.

In the paper mentioned in the text, he remarks, that “the invention


and construction of time-keepers may be reckoned among the most
successful exertions of human genius. Pendulum-clocks especially,”
says he, “have been made to measure time with astonishing
accuracy; and, if there are still some causes of inequality in their
motions, the united efforts of mechanism, philosophy and
mathematics, will probably, in time, remove them.”

Indeed no man has done more, none perhaps so much, towards


removing the imperfections in chronometers, to which he alludes, as
this great mechanician himself. His admirable time-piece, now in the
possession of the Philosophical Society at Philadelphia, constructed
by him, on an improved plan of his own, affords ample proof of the
“astonishing accuracy” (as he expresses it) to which the pendulum-
chronometer may be brought. A description of the mechanism of this
extremely accurate time-piece, as well as of the principles on which
its superior correctness depends, is inserted in the Appendix.

333. The appropriate location of “The American Philosophical


Society” is the city of “Philadelphia,” where their meetings must be
held in conformity to their charter. Monticello, Mr. Jefferson’s
residence in Virginia, is situated at the distance of about two hundred
and seventy miles from the capital of Pennsylvania.

334. It is difficult for a sound and contemplative mind to form any


conception of the character of a philosopher, according to the true
meaning of the term, more especially of an astronomer, of a man
observant of the works of nature and acquainted with her laws; and
yet wanting in a due sense of religion. And hence Dr. Young has
declared, that—

“An undevout Philosopher is mad.”

Instances, however, of this kind of mania, are known to have existed;


produced by that presumptuous pride, which is too often engendered
by a sophistication of true philosophy with the wild fantasies of some
modern metaphysical sects, affecting extraordinary illumination. By
thus engrafting a bad scion upon a good stock, pernicious fruit is
propagated: or, to drop metaphorical allusions, by attempting to
blend into one system, principles so discordant in their nature, as
those of the experimental philosopher and the visionary theorist who
deals in abstract speculations and reasonings â priori, the

You might also like