Learning Scientific Programming With Python 2nd Edition Christian Hill Full Chapter Instant Download
Learning Scientific Programming With Python 2nd Edition Christian Hill Full Chapter Instant Download
Learning Scientific Programming With Python 2nd Edition Christian Hill Full Chapter Instant Download
https://ebookmass.com/product/learning-scientific-programming-
with-python-2nd-edition-christian-hill/
https://ebookmass.com/product/learning-scientific-programming-
with-python-hill/
https://ebookmass.com/product/python-for-chemists-christian-hill/
https://ebookmass.com/product/mastering-functional-programming-
with-python-brett-neutreon/
A Beginners Guide to Python 3 Programming 2nd Edition
John Hunt
https://ebookmass.com/product/a-beginners-guide-to-
python-3-programming-2nd-edition-john-hunt/
https://ebookmass.com/product/advanced-guide-to-
python-3-programming-2nd-2nd-edition-john-hunt/
https://ebookmass.com/product/programming-and-problem-solving-
with-python-ashok-namdev-kamthane/
https://ebookmass.com/product/python-programming-and-
sql-10-books-in-1-supercharge-your-career-with-python-
programming-and-sql-andrew-reed/
https://ebookmass.com/product/beginning-programming-with-python-
for-dummies-3rd-edition-john-paul-mueller/
Learning Scientific Programming with Python
Second Edition
Learn to master basic programming tasks from scratch with real-life, scientifically rel-
evant examples and solutions drawn from both science and engineering. Students and
researchers at all levels are increasingly turning to the powerful Python programming
language as an alternative to commercial packages and this fast-paced introduction
moves from the basics to advanced concepts in one complete volume, enabling readers
to gain proficiency quickly.
Beginning with general programming concepts such as loops and functions within
the core Python 3 language, and moving on to the NumPy, SciPy and Matplotlib
libraries for numerical programming and data visualization, this textbook also discusses
the use of Jupyter Notebooks to build rich-media, shareable documents for scientific
analysis. The second edition features a new chapter on data analysis with the pandas
library and comprehensive updates, new exercises and examples. A final chapter
introduces more advanced topics such as floating-point precision and algorithm stability,
and extensive online resources support further study. This textbook represents a targeted
package for students requiring a solid foundation in Python programming.
Christian Hill is a physicist and physical chemist currently working at the Interna-
tional Atomic Energy Agency. He has over 25 years’ experience of programming in the
physical sciences and has been programming in Python for 15 years. His research uses
Python to produce, analyze, process, curate and visualize large data sets in the area of
spectroscopy, plasma physics and material science.
Learning Scientific Programming
with Python
Second Edition
CHRISTIAN HILL
University Printing House, Cambridge CB2 8BS, United Kingdom
One Liberty Plaza, 20th Floor, New York, NY 10006, USA
477 Williamstown Road, Port Melbourne, VIC 3207, Australia
314–321, 3rd Floor, Plot 3, Splendor Forum, Jasola District Centre, New Delhi – 110025, India
79 Anson Road, #06–04/06, Singapore 079906
www.cambridge.org
Information on this title: www.cambridge.org/9781108745918
DOI: 10.1017/9781108778039
© Christian Hill 2015, 2020
This publication is in copyright. Subject to statutory exception
and to the provisions of relevant collective licensing agreements,
no reproduction of any part may take place without the written
permission of Cambridge University Press.
First published 2015
Second edition 2020
Printed in the United Kingdom by TJ International Ltd, Padstow Cornwall
A catalogue record for this publication is available from the British Library.
Library of Congress Cataloging-in-Publication Data
Names: Hill, Christian, 1974– author.
Title: Learning scientific programming with Python / Christian Hill.
Description: Second edition. | New York : Cambridge University Press, 2020.
| Includes bibliographical references and index.
Identifiers: LCCN 2020017917 (print) | LCCN 2020017918 (ebook)
| ISBN 9781108745918 (paperback) | ISBN 9781108778039 (epub)
Subjects: LCSH: Science–Data processing. | Science–Mathematics.
| Python (Computer program language)
Classification: LCC Q183.9 .H58 2020 (print) | LCC Q183.9 (ebook)
| DDC 005.13/3–dc23
LC record available at https://lccn.loc.gov/2020017917
LC ebook record available at https://lccn.loc.gov/2020017918
ISBN 978-1-108-74591-8 Paperback
Additional resources for this publication at www.cambridge.org/hill2 and https://scipython.com/
Cambridge University Press has no responsibility for the persistence or accuracy of
URLs for external or third-party internet websites referred to in this publication
and does not guarantee that any content on such websites is, or will remain,
accurate or appropriate.
Contents
1 Introduction 1
1.1 About This Book 1
1.2 About Python 2
1.3 Installing Python 5
1.4 The Command Line 6
v
vi Contents
6 NumPy 196
6.1 Basic Array Methods 196
6.2 Reading and Writing an Array to a File 228
6.3 Statistical Methods 239
6.4 Polynomials 246
6.5 Linear Algebra 261
6.6 Random Sampling 276
6.7 Discrete Fourier Transforms 287
7 Matplotlib 294
7.1 Line Plots and Scatter Plots 294
7.2 Plot Customization and Refinement 299
7.3 Bar Charts, Pie Charts and Polar Plots 314
7.4 Annotating Plots 323
7.5 Contour Plots and Heatmaps 336
7.6 Three-Dimensional Plots 348
7.7 Animation 352
8 SciPy 358
8.1 Physical Constants and Special Functions 358
8.2 Integration and Ordinary Differential Equations 381
8.3 Interpolation 408
8.4 Optimization, Data-Fitting and Root-Finding 414
Glossary 543
Index 549
Acknowledgments
Many people have helped directly or indirectly in the preparation of this book, in partic-
ular Jonathan Tennyson at UCL, and Laurence Rothman and Iouli Gordon for hosting
my sabbatical year at the Harvard-Smithsonian Center for Astrophysics.
Many of the errors and omissions in the first edition of this book were pointed out
by just a few people who were helpful enough to get in touch, notably Stafford Baines,
Matthew Gillman and Stuart Anderson. Those that remain are, of course, entirely my
own fault.
Special thanks are also due to Helen Reynolds, Chris Pickard, Alison Whiteley,
James Elliott, Lianna Ishihara and Milo Shaffer. As ever, I owe much to the support,
encouragement and friendship of Natalie Haynes.
viii
Code Listings
ix
x Code Listings
8.6 A comparison of the Lorentzian, Gaussian and Voigt line shapes 373
8.7 The spherical harmonic defined by l = 3, m = 2 377
8.8 Calculating the mass and center of mass of a tetrahedron given three differ-
ent densities 385
8.9 First-order reaction kinetics 387
8.10 Two coupled first-order reactions 390
8.11 Solution of the harmonic oscillator equation of motion 392
8.12 Calculating the motion of a sphere falling under the influence of gravity and
Stokes’ drag 394
8.13 Solution of the Robertson system of chemical reactions. 397
8.14 Calculating and plotting the trajectory of a spherical projectile including air
resistance. 400
8.15 A comparison of one-dimensional interpolation types using
scipy.interpolate.interp1d 408
8.16 Two-dimensional interpolation with scipy.interpolate.interp2d 410
8.17 Interpolation onto a regular two-dimensional grid with
scipy.interpolate.RectBivariateSpline 410
8.18 Interpolation from an unstructured array of two-dimensional points with
scipy.interpolate.griddata 412
8.19 Minimizing the drag on an airship envelope 423
8.20 Nonlinear least squares-fit to an ellipse 426
8.21 Weighted and unweighted least-squares fitting with curve_fit 428
8.22 Solution of the Euler–Lotka equation 432
8.23 Generating a Newton fractal image 433
9.1 Reading in a text table of vitamin data 454
9.2 The height of a projectile as a function of time 458
10.1 Comparison of different step sizes, h, in the numerical solution of y0 = −αy
by the forward Euler algorithm 499
R1
10.2 Comparison of algorithm stability in the calculation of I(n) = 0 xn e x dx 500
10.3 A function to calculate the volume of a tetrahedron 504
10.4 Code to simulate rolling two dice containing magic numbers 506
10.5 Code to simulate rolling two dice refactored to use named constants 506
10.6 A function for converting between different temperature units 510
10.7 Unit tests for the temperature conversion function 511
A.1 The structural formula of a straight-chain alkane 517
A.2 Least-squares fit to the function x = x0 + v0 t + 21 gt2 527
A.3 Calculating the probability of q or more misprints on a given page of a
book. 528
A.4 A comparison of the numerical behavior of f (x) = (1 − cos2 x)/x2 and
g(x) = sin2 x/x2 , close to x = 0. 534
1 Introduction
This book is intended to help scientists and engineers learn version 3 of the Python
programming language and its associated libraries: NumPy, SciPy, Matplotlib and pan-
das. No prior programming experience or scientific knowledge in any particular field is
assumed. However, familiarity with some mathematical concepts such as trigonometry,
complex numbers and basic calculus is helpful to follow the examples and exercises.
Python is a powerful language with many advanced features and supplementary pack-
ages; while the basic syntax of the language is straightforward to learn, it would be
impossible to teach it in depth in a book of this size. Therefore, we aim for a balanced,
broad introduction to the central features of the language and its important libraries. The
text is interspersed with examples relevant to scientific research, and at the end of most
sections there are questions (short problems designed to test knowledge) and exercises
(longer problems that usually require a short computer program to solve). Although it
is not necessary to complete all of the exercises, readers will find it useful to attempt
at least some of them. Where a section, example or exercise contains more advanced
material that may be skipped on first reading, this is indicated with the symbol ♦.
In Chapter 2 of this book, the basic syntax, data structures and flow control of a
Python program are introduced. Chapter 3 is a short interlude on the use of the pyplot
library for making graphical plots of data: this is useful to visualize the output of pro-
grams in subsequent chapters. Chapter 4 provides more advanced coverage of the core
Python language and a brief introduction to object-oriented programming. There fol-
lows another short chapter introducing the popular IPython and Jupyter Notebook envi-
ronments, before chapters on scientific programming with NumPy, Matplotlib, SciPy
and pandas. The final chapter covers more general topics in scientific programming,
including floating-point arithmetic, algorithm stability and programming style.
Readers who are already familiar with the Python programming language may wish
to skim Chapters 2 and 4.
Code examples and exercise solutions may be downloaded from the book’s web-
site at https://scipython.com . Note that while comments have been included in these
downloadable programs, they are not so extensive in the printed version of this book:
instead, the code is explained in the text itself through numbered annotations (such
as Ê). Readers typing in these programs for themselves may wish to add their own
explanatory comments to the code.
1
2 Introduction
names = ['Isaac Newton ', 'Marie Curie ', 'Albert Einstein ']
for name in names:
print(name)
Output:
Isaac Newton
Marie Curie
Albert Einstein
const char *names [] = {"Isaac Newton ", " Marie Curie ", " Albert Einstein "};
int main(void)
{
int i;
return EXIT_SUCCESS ;
}
Even if you are not familiar with the C language, you can see there is quite a lot
of overhead involved in coding even this simple task in C: two includes of libraries
not loaded by default, explicit declarations of variables to hold the list (“array”, in C)
of names, names, a counter, i, and explicit indexing of this array in a for loop; you
even need to add the line endings (“\n” is the “newline” character). This source code
then has to be compiled – converted into the machine code that the computer processor
understands – before it can be run (executed). Furthermore, there is plenty of scope for
errors (bugs): trying to print the name stored in name[10] will likely cause junk to be
output: the C compiler won’t stop you from accessing this non-existent name.
The same program written in three lines of Python is clean and expressive: we do
not have to explicitly declare that names is a list of strings, there is no need for a loop
counter like i and there are no separate libraries to include (import in Python). To
run the Python program, one simply needs to type python eg1-names.py which will
automatically invoke the Python “interpreter” to compile and then run the resulting
“bytecode” (a kind of intermediate representation of the program between its source
and the ultimate machine code that Python dispatches to the processor).
Python’s syntax aims to ensure that “There should be one – and preferably only one –
obvious way to do it.” This differs from some other popular high-level languages such as
Ruby and Perl, which take the opposite approach, encapsulated by the mantra “there’s
more than one way to do it.” For example, there are (at least) four obvious ways to
output the same list in Perl:2
Listing 1.3 Different ways to output a list of names using a program written in Perl
@names = ("Isaac Newton ", "Marie Curie", " Albert Einstein ");
# Method 1
print "$_\n" for @names ;
# Method 2
print join "\n", @names ;
print "\n";
# Method 3
print map { "$_\n" } @names ;
# Method 4
$" = "\n";
print " @names \n";
The official website of Python is www.python.org, and it contains full and easy-to-
follow instructions for downloading Python. However, there are several full distributions
which include the NumPy, SciPy and Matplotlib libraries (the “SciPy Stack”) to save
you from having to download and install these yourself:
• Anaconda is available for free (including for commerical use) from www.
anaconda.com/distribution. It installs both Python 2 and Python 3, but the default
version can be selected either before downloading as indicated on this web page,
or subsequently using the “conda” command.
• Enthought Deployment Manager (EDM) is a similar distribution with a free
version and various tiers of paid-for versions including technical support and
development software. It can be downloaded from https://assets.enthought.com/
downloads/.
In most cases, one of these distributions should be all you need. We provide some
platform-specific notes below.
The source code (and binaries for some platforms) for the NumPy, SciPy, Matplotlib
and IPython packages are available separately at:
• NumPy: https://github.com/numpy/numpy
• SciPy: https://github.com/scipy/scipy
• Matplotlib: https://matplotlib.org/users/installing.html
• IPython: https://github.com/ipython/ipython
6 Introduction
Windows
Windows users have a couple of further options for installing the full SciPy stack:
Python(x,y) (https://python-xy.github.io) and WinPython (https://winpython.github.io/).
Both are free.
macOS
macOS (formerly Mac OS X), being based on Unix, comes with Python, but it is
usually an older version of Python 2. You must not delete or modify this installation
(it’s needed by the operating system), but you can follow the instructions above for
obtaining Python 3 and the SciPy stack. macOS does not have a native package manager
(an application for managing and installing software), but the two popular third-party
package managers, Homebrew (https://brew.sh/) and MacPorts (www.macports.org),
can both supply Python 3 and its packages if you prefer this option.
Linux
Almost all Linux distributions come with Python 2, but usually not Python 3, so you
may need to install it from the links above: the Anaconda and Enthought distributions
both have versions for Linux. Most Linux distributions come with their own software
package managers (e.g. apt in Debian and rpm for RedHat). These can be used to
install Python 3 and its libraries, though finding the necessary package repositories may
take some research on the Internet. Be careful not to replace or modify your system
installation as other applications may depend on it.
Most of the code examples in this book are written as stand-alone programs which can
be run from the command line (or from within an integrated development environment
(IDE) if you use one: see Section 10.3.2). To access the command-line interface (also
known as a console or terminal) on different platforms, follow the instructions below.
• Windows 7 and earlier: Start > All Programs > Command Prompt; alternatively,
type cmd in the Start > Run input box.
• Windows 8: Preview (lower left of screen) > Windows System: All apps; alterna-
tively type cmd in the search box pulled down the top right corner of the screen.
• Windows 10: From the Start Menu (Windows icon, lower left of screen) >
Windows System > Command Prompt; alternatively type cmd in the search box
accessed from the bottom-left corner of the screen, next to the Windows icon.
• Mac OS X and macOS: Finder > Applications > Utilities > Terminal
• Linux: if you are not using a graphical interface you are already at the command
line; if you are, then locate the Terminal application (distributions vary, but it is
usually found within a System Utilities or System Tools subfolder).
1.4 The Command Line 7
Commands typed at the command line are interpreted by an application called a shell,
which allows the user to navigate the file system and is able to start other applications.
For example, the command
python myprog .py
instructs the shell to invoke the Python interpreter, sending it the file myprog.py as the
script to execute. Output from the program is then returned to the shell and displayed in
your console.
Another random document with
no related content on Scribd:
that fear God, and more especially to them that love as well as fear
him.
With regard to you, who are already engaged in this work, the
first advice I would give you is, calmly and deeply to consider, the
nature of your undertaking. Know what you are about; be throughly
acquainted with what you have in hand. Consider the objections
which are made to the whole of your undertaking. And before you
proceed, be satisfied that those objections have no real weight. Then
may every man act, as he is fully persuaded in his own mind.
4. I advise you, in the fourth place, see that you do every thing in
a right temper: with lowliness, and meekness, with patience and
gentleness, worthy the gospel of Christ. Take every step trusting in
God, and in the most tender, loving spirit you are able. Mean time
watch always, against all hurry and dissipation of spirit, and pray
always with all earnestness and perseverance, that your faith fail not.
And let nothing interrupt that spirit of sacrifice, which you make of all
you have and are, of all you suffer and do, that it may be an offering
of a sweet smelling savour to God through Jesus Christ.
6. I exhort all of you who fear God, as ever you hope to find
mercy at his hands, as you dread being found (tho’ you knew it not)
even to fight against God: do not on any account, reason, or
pretence whatsoever, either directly or indirectly, oppose or hinder so
merciful a design, and one so conducive to his glory. But this is not
all: if you are lovers of mankind, if you long to lessen the sins and
miseries of your fellow-creatures: can you satisfy yourselves, can
you be clear before God, by barely not opposing it? Are not you also
bound by the most sacred ties, as you have opportunity to do good
to all men? And is not here an opportunity of doing good to many,
even good of the highest kind? In the name of God then, embrace
the opportunity. Assist in doing this good, if no otherwise, yet by your
earnest prayers, for them who are immediately employed therein.
Assist them, according to your ability, to defray the expence which
necessarily attends it, and which without the assistance of charitable
persons, would be a burden they could not bear. Assist them, if you
can without inconvenience, by quarterly or yearly subscriptions. At
least, assist them now: use the present hour, doing what God puts
into your heart. Let it not be said, that you saw your brethren
labouring for God, and would not help them with one of your fingers.
In this way, however, come to the help of the Lord, to the help of the
Lord, against the mighty!
7. I have an higher demand upon you who love, as well as fear
God. He whom you fear, whom you love, has qualified you, for
promoting his work in a more excellent way. Because you love God,
you love your brother also: you love not only your friends, but your
enemies; not only the friends, but even the enemies of God. You
have put on, as the elect of God, lowliness, gentleness, long-
suffering. You have faith in God, and in Jesus Christ whom he hath
sent: faith which overcometh the world. And hereby you conquer
both evil shame, and that fear of man which bringeth a snare: so that
you can stand with boldness before them that despise you and make
no account of your labours. Qualified then as you are, and armed for
the fight, will you be like the children of Ephraim, who being
harnessed, and carrying bows, turned back in the day of battle? Will
you leave a few of your brethren to stand alone, against all the hosts
of the aliens? O say not, “This is too heavy a cross: I have not
strength or courage to bear it.” True; not of yourself. But you that
believe, can do all things through Christ strengthening you. If thou
canst believe, all things are possible to him that believeth. No cross
is too heavy for him to bear, knowing that they that suffer with him,
shall reign with him. Say not, “Nay, but I cannot bear to be singular.”
Then you cannot enter into the kingdom of heaven. No one enters
there but thro’ the narrow way. And all that walk in this, are singular.
Say not, “But I cannot endure the reproach, the odious name of an
informer.” And did any man ever save his soul, that was not a by-
word, and a proverb of reproach? Neither canst thou ever save thine,
unless thou art willing, that men should say all manner of evil of thee.
Say not, “But if I am active in this work, I shall lose not only my
reputation, but my friends, my customers, my business, my
livelihood, so that I shall be brought to poverty.” Thou shalt not: thou
canst not: it is absolutely impossible, unless God himself chuseth it.
For his kingdom ruleth over all, and the very hairs of thy head are all
numbered. But if the wise, the gracious God chuse it for thee, wilt
thou murmur or complain? Wilt thou not rather say, The cup which
my Father hath given me, shall I not drink it? If you suffer for Christ,
happy are you: the Spirit of glory and of Christ shall rest upon you.
Say not, “I would suffer all things, but my wife will not consent to it.
And certainly a man ought to leave father and mother and all, and
cleave to his wife.” True, all—but God; all—but Christ. But he ought
not to leave him for his wife. He is not to leave any duty undone, for
the dearest relative. Our Lord himself hath said in this very sense, If
any man loveth father, or mother, or wife, or children, more than me,
he is not worthy of me! Say not, “Well, I would forsake all for Christ.
But one duty must not hinder another. And this would frequently
hinder my attending public worship.” Sometimes it probably would.
Go then and learn what that meaneth, I will have mercy and not
sacrifice. And whatever is lost, by shewing this mercy, God will repay
sevenfold into thy bosom. Say not, “But I shall hurt my own soul. I
am a young man: and by taking up loose women, I should expose
my self to temptation.” Yes, if you did this in your own strength, or for
your own pleasure. But that is not the case. You trust in God: and
you aim at pleasing him only. And if he should call you even into the
midst of a burning fiery furnace, though thou walkest thro’ the fire
thou shalt not be burnt, neither shall the flames kindle upon thee.
“True; if he called me into the furnace. But I do not see that I am
called to this.” Perhaps thou art not willing to see it. However, if thou
wast not called before, I call thee now, in the name of Christ: take up
thy cross and follow him. Reason no more with flesh and blood, but
now resolve to cast in thy lot, with the most despised, the most
infamous of his followers, the filth and off-scouring of the world. I call
thee in particular, who didst once strengthen their hands, but since
art drawn back. Take courage! Be strong! Fulfil their joy, by returning
with heart and hand. Let it appear, thou departedst for a season, that
they might receive thee again for ever. O be not disobedient to the
heavenly calling! And as for all of you, who know whereunto ye are
called, count ye all things loss, so ye may save one soul, for which
Christ died. And therein take no thought for the morrow, but cast all
your care on him that careth for you. Commit your souls, bodies,
substance, all, to him, as unto a merciful and faithful Creator.
N. B. After this Society had subscribed several years, and done
unspeakable good, it was wholly destroyed, by a verdict given against it
in the King’s Bench, with three hundred pounds damages. I doubt a
severe account remains for the witnesses, the jury, and all who were
concerned in that dreadful affair.
¹
SERMON LIII.
¹ On the death of the Rev. Mr. George Whitefield. Preached at
the Chappel in Tottenham-Court-Road, and at the
Tabernacle near Moorfields, on Sunday, November 18,
1770.
Let me die the death of the righteous, and let my last end be like his!
LETPerhaps
1. my last end be like his! How many of you join in this wish?
there are few of you who do not, even in this numerous
congregation. And O that this wish may rest upon your minds! That it
may not die away, till your souls also are lodged where the wicked
cease from troubling, and where the weary are at rest!
3. He was soon tried as with fire. Not only his reputation was lost,
and some of his dearest friends forsook him; but he was exercised
with inward trials, and those of the severest kind. Many nights he lay
sleepless upon his bed; many days prostrate on the ground. But
after he had groaned several months under the Spirit of bondage,
God was pleased to remove the heavy load, by giving him the Spirit
of adoption, enabling him, through a living faith, to lay hold on the
Son of his love.
7. But he was quickly called from hence again to supply the cure
of Dummer in Hampshire. Here he read prayers twice a day, early in
the morning, and in the evening, after the people came from work.
He also daily catechized the children, and visited from house to
house. He now divided the day into three parts, alloting eight hours
for sleep and meals, eight for study and retirement, and eight for
reading prayers, catechizing, and visiting the people.—Is there a
more excellent way for a servant of Christ and his church? If not,
Who will go and do likewise?
8. Yet his mind still ran on going abroad. And being now fully
convinced he was called of God thereto, he set all things in order,
and in January 1737, went down to take leave of his friends in
Glocester. It was in this journey that God began to bless his ministry
in an uncommon manner. Wherever he preached, amazing
multitudes of hearers flocked together, in Glocester, in Stonehouse,
in Bath, in Bristol: so that the heat of the churches was scarce
supportable. And the impressions made on the minds of many, were
no less extraordinary. After his return to London, while he was
detained by General Oglethorpe, from week to week, and from
month to month, it pleased God to bless his word still more. And he
was indefatigable in his labour: generally on Sunday he preached
four times, to exceeding large auditories; beside reading prayers
twice or thrice, and walking to and fro, often ten or twelve miles.
10. From Sunday, May 7, 1738, till the latter end of August
following, he made full proof of his ministry in Georgia, particularly at
Savannah: he read prayers and expounded twice a day and visited
the sick daily. On Sunday he expounded at five in the morning; at ten
read prayers and preached, and at three in the afternoon: and at
seven in the evening expounded the church-catechism. How much
easier is it for our brethren in the ministry, either in England,
Scotland, or Ireland, to find fault with such a labourer in our Lord’s
vineyard, than to tread in his steps?
17. You may easily observe, that the preceding account is chiefly
extracted from his own journals, which, for their artless and
unaffected simplicity, may vie with any writings of the kind. And how
exact a specimen is this of his labours both in Europe and America,
for the honour of his beloved Master, during the thirty years that
followed! As well as of the uninterrupted shower of blessings
wherewith God was pleased to succeed his labours! Is it not much to
be lamented, that any thing should have prevented his continuing
this account, till at least near the time when he was called by his
Lord to enjoy the fruit of his labour?—If he has left any papers of this
kind, and his friends account me worthy of the honour, it would be
my glory and joy to methodize, transcribe, and prepare them for the
public view.
18. A particular account of the last scene of his life, is thus given
by a gentleman of Boston: “After being about a month with us in
Boston and its vicinity, and preaching every day, he went to Old-york,
preached on Thursday, September 27, there; proceeded to
Portsmouth, and preached there on Friday. On Saturday morning he
set out for Boston; but before he came to Newbury, where he had
engaged to preach the next morning, he was importuned to preach
by the way. The house not being large enough to contain the people,
he preached in an open field. But having been infirm for several
weeks, this so exhausted his strength, that when he came to
Newbury, he could not get out of the ferry-boat without the help of
two men. In the evening, however, he recovered his spirits, and
appeared with his usual chearfulness. He went to his chamber at
nine, his fixt time, which no company could divert him from: and slept
better than he had done for some weeks before. He rose at four in
the morning, September 30, and went into his closet; and his
companion observed he was unusually long in private. He left his
closet, returned to his companion, threw himself on the bed, and lay
about ten minutes. Then he fell upon his knees, and prayed most
fervently to God, ‘That if it was consistent with his will he might that
day finish his Master’s work.’ He then desired his man to call Mr.
Parsons, the clergyman, at whose house he was: but in a minute,
before Mr. Parsons could reach him died, without a sigh or groan. On
the news of his death, six gentlemen set out for Newbury, in order to
bring his remains hither, but he could not be moved, so that his
precious ashes must remain at Newbury. Hundreds would have
gone from this town to attend his funeral, had they not expected he
would have been interred here.—May this stroke be sanctified to the
church of God in general, and to this province in particular!”
III. But how shall we improve this awful providence? This is the
third thing which we have to consider. And the answer to this
important question is easy; (may God write it in all our hearts!) By
keeping close to the grand doctrines which he delivered: and by
drinking into his Spirit.
2. His fundamental point was, Give God all the glory of whatever
is good in man. And in the business of salvation, Set Christ as high,
and man as low as possible. With this point, he and his friends at
Oxford, the original Methodists (so called) set out. Their grand
principle was, There is no power (by nature) and no merit in man.
They insisted, all power to think, speak, or act right, is in and from
the Spirit of Christ: and all merit is (not in man, how high soever in
grace, but merely) in the blood of Christ. So he and they taught:
There is no power in man, till it is given him from above, to do one
good work, to speak one good word, or to form one good desire. For
it is not enough to say, all men are sick of sin: no, we are all dead in
trespasses and sins. It follows, that all the children of men are by
nature children of wrath. We are all guilty before God, liable to death
temporal and eternal.
3. And we are all helpless, both with regard to the power and to
the guilt of sin. For who can bring a clean thing out of an unclean?
None less than the Almighty. Who can raise those that are dead,
spiritually dead in sin? None but he who raised us from the dust of
the earth. But on what consideration will he do this? Not for works of
righteousness that we have done. The dead cannot praise thee, O
Lord! Nor do any thing for the sake of which they should be raised to
life. Whatever therefore God does, he does it merely for the sake of
his well beloved Son; he was wounded for our transgressions, he
was bruised for our iniquities. He himself bore all our sins in his own
body upon the tree. He was delivered for our offences, and rose
again for our justification. Here then is the sole meritorious cause of
every blessing we do or can enjoy: in particular of our pardon and
acceptance with God, of our full and free justification. But by what
means do we become interested in what Christ has done and
suffered? Not by works, lest any man should boast; but by faith
alone. We conclude, says the apostle, that a man is justified by faith,
without the works of the law. And to as many as thus receive him,
giveth he power to become the sons of God: even to those that
believe in his name, who are born, not of the will of man, but of God.
5. You are not ignorant, that these are the fundamental doctrines
which he every where insisted on. And may they not be summed up,
as it were, in two words, The new birth, and justification by faith?
These let us insist upon with all boldness, at all times, and in all
places: in public (those of us who are called thereto) and at all
opportunities, in private. Keep close to these good, old,
unfashionable doctrines, how many soever contradict and
blaspheme. Go on, my brethren, in the name of the Lord, and in the
power of his might. With all care and diligence, keep that safe which
is committed to your trust: knowing that heaven and earth shall pass
away; but this truth shall not pass away.
7. *Is there any other fruit of the grace of God, with which he was
eminently endowed, and the want of which among the children of
God he frequently and passionately lamented? There is one, that is,
Catholic love: that sincere and tender affection, which is due to all
those, who, we have reason to believe, are children of God by faith:
in other words, all those in every persuasion, who fear God and work
righteousness. He longed to see all who had tasted of the good
word, of a truly Catholic spirit, (a word little understood and still less
experienced by many, who have it frequently in their mouth.) Who is
he that answers this character? Who is a man of a Catholic spirit?
One who loves as friends, as brethren in the Lord, as joint partakers
of the present kingdom of heaven, and fellow-heirs of his eternal
kingdom, all of whatever opinion, mode of worship, or congregation,
who believe in the Lord Jesus; who love God and man: who rejoicing
to please, and fearing to offend God, are careful to abstain from evil,
and zealous of good works. He is a man of a truly Catholic spirit,
who bears all these continually upon his heart: who having an
unspeakable tenderness for their persons, and an earnest desire of
their welfare, does not cease to commend them to God in prayer, as
well as to plead their cause before men: who speaks comfortably to
them, and labours by all his words, to strengthen their hands in God.
He assists them to the uttermost of his power, in all things, spiritual
and temporal. He is ready to spend and to be spent for them; yea, to
lay down his life for his brethren.
8. How amiable a character is this? How desirable to every child
of God! But why is it then so rarely found? How is it, that there are so
few instances of it? Indeed, supposing we have tasted of the love of
God, how can any of us rest, ’till it is our own? Why, there is a
delicate device, whereby Satan persuades thousands, that they may
stop short of it, and yet be guiltless. It is well, if many here present
are not in this snare of the devil, taken captive at his will. “O yes,
says one, I have all this love for those I believe to be children of God.
But I will never believe, he is a child of God, who belongs to that vile
congregation! Can he, do you think, be a child of God, who holds
such detestable opinions? Or he that joins in such senseless and
superstitious, if not idolatrous worship?” So we justify ourselves in
one sin, by adding a second to it! We excuse the want of love in
ourselves, by laying the blame on others. To colour our own devilish
temper, we pronounce our brethren children of the devil. O beware of
this! And if you are already taken in the snare, escape out of it as
soon as possible. Go and learn that truly Catholic love, which is not
rash or hasty in judging: that love which thinketh no evil, which
believeth and hopeth all things: which makes all the allowances for
others, that we desire others should make for us. Then we shall take
knowledge of the grace of God, which is in every man, whatever be
his opinion or mode of worship. Then will all that fear God be near
and dear unto us, in the bowels of Jesus Christ.
9. Was not this the spirit of our dear friend? And why should it not
be ours? O thou God of love, how long shall thy people be a bye-
word among the Heathen? How long shall they laugh us to scorn,
and say, “See how these Christians love one another?” When wilt
thou roll away our reproach? Shall the sword devour for ever? How
long will it be, ere thou bid thy people return from following each
other? Now at least, let all the people stand still, and pursue after
their brethren no more! But whatever others do, let all of us, my
brethren, hear the voice of him that being dead, yet speaketh!
Suppose ye hear him say, “Now at least, be ye followers of me as I
was of Christ! Let brother no more lift up sword against brother,
neither know ye war any more! Rather put ye on, as the elect of God,
bowels of mercies, humbleness of mind, brotherly kindness,