Download ebooks file An Introduction to Python Programming for Scientists and Engineers Johnny Wei-Bing Lin all chapters
Download ebooks file An Introduction to Python Programming for Scientists and Engineers Johnny Wei-Bing Lin all chapters
com
https://ebookmeta.com/product/an-introduction-to-python-
programming-for-scientists-and-engineers-johnny-wei-bing-
lin/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmeta.com/product/introduction-to-scilab-for-engineers-
and-scientists-1st-edition-sandeep-nagar/
ebookmeta.com
https://ebookmeta.com/product/introduction-to-octave-for-engineers-
and-scientists-1st-edition-sandeep-nagar/
ebookmeta.com
https://ebookmeta.com/product/serial-sabotage-1st-edition-carolyn-
keene/
ebookmeta.com
Yard Birds The Lives and Times of America s Urban Chickens
First Edition Philip Levy
https://ebookmeta.com/product/yard-birds-the-lives-and-times-of-
america-s-urban-chickens-first-edition-philip-levy/
ebookmeta.com
https://ebookmeta.com/product/swaimans-pediatric-neurology-principles-
and-practice-6th-edition-kenneth-f-swaiman/
ebookmeta.com
https://ebookmeta.com/product/handbook-of-pediatric-epilepsy-case-
studies-2nd-edition-maria-augusta-montenegro/
ebookmeta.com
https://ebookmeta.com/product/electrophysiological-recording-
techniques-2nd-edition-robert-p-vertes-editor-timothy-allen-editor/
ebookmeta.com
https://ebookmeta.com/product/prince-musical-icon-1st-edition-
stephanie-watson/
ebookmeta.com
Joseph Portraits Through the Ages 1st Edition Alan T.
Levenson
https://ebookmeta.com/product/joseph-portraits-through-the-ages-1st-
edition-alan-t-levenson/
ebookmeta.com
An Introduction to Python Programming for
Scientists and Engineers
Python is one of the most popular programming languages, widely used for data analysis
and modelling, and is fast becoming the leading choice for scientists and engineers. Unlike
other textbooks introducing Python, typically organised by language syntax, this book uses
many examples from across Biology, Chemistry, Physics, Earth science, and Engineering to
teach and motivate students in science and engineering. The text is organised by the tasks
and workflows students undertake day-to-day, helping them see the connections between
programming tools and their disciplines. The pace of study is carefully developed for complete
beginners, and a spiral pedagogy is used so concepts are introduced across multiple chapters,
allowing readers to engage with topics more than once. “Try This!” exercises and online
Jupyter notebooks encourage students to test their new knowledge, and further develop their
programming skills. Online solutions are available for instructors, alongside discipline-specific
homework problems across the sciences and engineering.
Hannah Aizenman is a Ph.D. candidate in Computer Science at The Graduate Center, City
University of New York. She studies visualization and is a core developer of the Python
library Matplotlib.
Erin Manette Cartas Espinel graduated with a Ph.D. in physics from the University of
California, Irvine. After more than 10 years at the University of Washington Bothell, she
is now a software development engineer.
Joanne Liu received her Ph.D. in Bioinformatics and Systems Biology from the University of
California San Diego.
“This book provides an excellent introduction to the Python language especially targeted at those
interested in carrying out calculations in the physical sciences. I especially like the strong coverage of
graphics and of good coding practice.”
Raymond Pierrehumbert, University of Oxford
“An excellent introduction to Python for scientists and engineers. Much more than teaching you how to
program with Python, it teaches you how to do science with Python.”
Eric Shaffer, University of Illinois at Urbana-Champaign
“Python has achieved an essential role in many disciplines within science, engineering, and beyond.
Students and professionals are expected to be fluent in it, and (as I see in my daily job of helping users of a
high-performance computing facility) they often struggle to reach that fluency. The authors have succeeded
in the daunting task of writing a single book to help people reach a very advanced level of fluency, starting
very gently and assuming no background. Unlike other books on the subject, An Introduction to Python
Programming for Scientists and Engineers focuses on teaching for the intended end goal of scientists and
engineers – investigating their scientific problems – not writing software for its own sake. I am looking
forward to working with the generation who will learn how to program in Python using this book!”
Davide Del Vento, NCAR Computational & Information Services Laboratory
“An Introduction to Python Programming for Scientists and Engineers introduces programming in Python
using evidence-based approaches to active learning. The exercises help both students and instructors
identify misconceptions in programming, allowing students to build a strong foundation in Python
programming. The book streamlines content such that there is a focus on mastering immediately useful
concepts, normalizing errors, and demonstrating recovery.”
Kari L. Jordan, Executive Director, The Carpentries
An Introduction to Python
Programming for Scientists
and Engineers
Hannah Aizenman
City College of New York
Kim Gunnerson
University of Washington Bothell
Joanne Liu
Novozymes A/S
University Printing House, Cambridge CB2 8BS, United Kingdom
www.cambridge.org
Information on this title: www.cambridge.org/highereducation/isbn/9781108701129
DOI: 10.1017/9781108571531
A catalogue record for this publication is available from the British Library.
v
vi Contents
20 Recursion 633
Glossary 719
Acronyms and Abbreviations 726
Bibliography 727
Index 729
Detailed Contents
vii
viii Detailed Contents
20 Recursion 633
20.1 Example of Recursion 633
20.2 Python Programming Essentials 635
20.2.1 Using the walk Generator 635
20.2.2 Recursion and Writing Recursive Code 637
20.2.3 More Applications of Recursion 642
20.3 Try This! 645
20.4 More Discipline-Specific Practice 649
20.5 Chapter Review 649
20.5.1 Self-Test Questions 649
20.5.2 Chapter Summary 650
20.5.3 Self-Test Answers 651
The “Massachusetts.”
The mail route between England and India via the Cape was
admittedly slow; and it seemed possible to carry the mails by way of
Suez in a much shorter time. The eastern half of this service was
maintained in a very inefficient manner by the East India Company.
The British Government had inaugurated in February 1830 its mail
steam-packet service from Falmouth to the Mediterranean. Up to this
date the mails had been carried in sailing brigs, although steam
navigation with the Mediterranean had already been established and
the steamers beat the sailing brigs by many days. The first of these
Government steam packets was the Meteor, and the others
employed included the African, Messenger, Firebrand, Echo, Hermes,
Colombia, Confiance, and Carron.
The Dublin and London Steam Packet Company, under the
management of Messrs. Bourne, decided in 1834 upon establishing a
line of steamers between London and the Spanish peninsula. The
proposed line was to be called the Peninsular Steam Navigation
Company, and its first steamer was probably the Royal Tar. This
steamer, by the way, had previously been chartered in 1834 to Don
Pedro and then to the Queen Regent of Spain.
It is hardly correct, however, to describe these Admiralty vessels
as warships, for the Admiralty steam vessels at that time were
gunboats, or despatch vessels, steam for line-of-battle ships not
being used until some years later.
The Peninsular Company chartered a number of vessels for its
early service, but it was not until 1837 that it commenced to
despatch mail-packets regularly from London to Lisbon and Gibraltar
under contract with the British Government, which at that time and
for twenty years afterwards was represented by the Lords
Commissioners of the Admiralty. This contract was tendered for by
both the Peninsular Steam Navigation Company and a concern called
the British and Foreign Steam Navigation Company, but the latter
was unable to convince the Government that it possessed the
resources, both financial and shipping, which would enable it to
carry out the engagement. The Peninsular Company, on the other
hand, was able to give the required assurance. The company
undertook, in return for an annual subsidy of £29,600, to convey the
mails monthly to the Peninsula. The pioneer vessel of this service
was the Iberia, of 690 tons and 200 horse-power, which sailed in
September 1837. Altogether the company had ten vessels, two of
which were chartered from the City of Dublin Company.
The statement is often made that the steamer William Fawcett[71]
was the first boat of the company; she was built in 1829 by Caleb
Smith of Liverpool, and her engines were by Messrs. Fawcett and
Preston, also of Liverpool; and after being used for some years as a
ferry-boat on the Mersey she was placed on the Liverpool and Dublin
route and may have been “chartered for a short time to the
Peninsular Steam Navigation Company in 1835 or 1836, as she does
not appear in the company’s advertised sailing list for 1838.”[72]
[71] See the Frontispiece to this book.
[72] Kennedy’s “History of Steam Navigation.”
The East India Company’s service between Suez and Bombay was
as bad as that formerly maintained with Calcutta, owing to
indifferent management and unsuitable steamers, and as it cost
about 30s. per mile, whereas the P. & O. maintained its services to
India and China for 17s. per mile, there was a renewal of the
agitation for the service to be taken out of the control of the East
India Company and entrusted to a concern which could work it
better and more economically. Parliament in 1851 supported the
agitation, but the East India Company would not give way until the
fates were too strong for it; one lot of Bombay mails went to the
bottom in a native sailing vessel in which they had been placed at
Aden, as the company had no steamer ready for them at Suez. At
the request of the Government, the P. & O. Company agreed to take
over this service for a subvention of £24,000 per annum, as against
the £105,000, or thereabouts, which the old arrangement had cost.
The P. & O. Company opened its Australian service in 1852 as a
branch line, but this connection proved so beneficial to the company
and the Australian Colonies alike, that in course of time it was made
a main-line service, to the mutual advantage of the company and
the Colonies. So many of the company’s steamers were employed in
the Crimean War and during the Indian Mutiny for the Army, that the
Australian portion of the service was dropped for some time.
The Union Line was founded in 1853 as the Union Steam Collier
Company, and it made a start with five little steamers, the largest of
which were the Dane and Norman of 530 tons. The outbreak of the
Crimean War, and the consequent withdrawal of the P. & O.
steamers from the Southampton and Constantinople service for use
as transports, saw the Union vessels placed upon that service till
they also were engaged as transports, and a sixth vessel was
acquired. When the war was ended, the steamers were placed for a
time in the Southampton and Brazil trade, but it was not a very
profitable venture and they were diverted to the South African trade,
the company receiving a subsidy of £30,000 a year for five years for
carrying the mails to and from the Cape of Good Hope. The first
sailing was made by the Dane in September 1857, and the sailings
thereafter were monthly. The subsidy was increased by £3000 the
following year on condition that calls were made at St. Helena and
Ascension.
In 1857, Rennie’s “Aberdeen” Line, after having been for many
years in sail, went in for steam and despatched its first steamers,
Madagascar and Waldensian, from London to South Africa, carrying
the mails between Cape Town and Durban. These are stated to have
been the first steamers on the South African coast. The Madagascar,
of 500 tons, was commanded by Captain George Rennie. Like all the
long-distance steamers of her time, she carried a large spread of
sail, but her engines, like those of most of her contemporaries, were
calculated to be able to render her independent of the wind if it did
not happen to be suitable, and therein they marked a great
improvement upon those of an earlier type, which were merely
assistants to sail. The steamers built in the later ’fifties were
intended to place reliance principally on their engines, because of
the regularity of passage thereby secured, rather than upon their
sail-power; so that even by this time, although the vessels were
described as auxiliary steamers, a more correct description would
have been that they were steam-propelled vessels carrying a large
spread of canvas.
In March 1859, Messrs. J. and W. Dudgeon issued a circular on the
subject of steam navigation direct to Calcutta round the Cape,
pointing out that “steam hereafter will be almost exclusively
employed in the transport of goods between East India and Australia
and the United Kingdom may be taken for granted; this is merely a
matter of time.” The circular continued that the Cape route would
certainly be simple and safe, and therefore superior to the overland
route, especially if it could be rendered expeditious and profitable.
The conditions required that vessels of not less than 5500 tons,
builders’ measurement, be supplied at a total cost per vessel of
£150,000; the voyage, it was anticipated, would take thirty or thirty-
five days, or only a couple of days more than the overland route. As
a correct forecast of the size of vessels which until a few years ago
conveyed the great bulk of the merchandise between Britain and the
Far East, this statement is interesting and shows how accurately the
needs of the traffic were estimated.
The “Norman” (Union-Castle Line, 1894).
The Royal Mail Steam Packet Company in the seventy years of its
existence has played an eventful part in the history of the mercantile
marine. Its earliest steamers were wooden paddle-boats, and were
among the best, but in spite of their excellence they experienced an
extraordinary run of misfortunes, and losses by fire and wreck
marred the records of the company for several years after its
incorporation in 1839. Its charter has been revised and extended
from time to time, one clause being that the whole of the share
capital must be British owned, and the management British. In its
long career it has served almost every port in the West Indies with
the mails, and has had no less than fifty-three contracts. At one
stage its management was subjected to some strong criticism, but
under its present management the company has prospered by leaps
and bounds, affording an excellent illustration of the value of well-
directed energy and enterprise.
The history of the Royal Mail Steam Packet Company is the record
of the development of the steamship connection between this
country and the West Indian Colonies. In 1840 the original contract
was entered into with the Admiralty Commissioners for executing the
office of Lord High Admiral for the commencement of the mail
service to the West India Colonies, the Spanish Main, New York,
Halifax, Mexico, Cuba, &c.
The conditions under which the mail contract was to be carried
out were somewhat onerous. One was that the company should
receive on board every vessel a naval officer or other person and his
servant to take charge of the mails, and that every such person
should be recognised and considered by the company as the agent
of the Commissioners in charge of the mails. He was empowered to
require a strict observance of the contract and “to determine every
question whenever arising relative to proceeding to sea, or putting
into harbour, or to the necessity of stopping to assist any vessel in
distress, or to save human life.” A suitable first-class cabin was to be
furnished at the company’s expense, and appropriated to the
officer’s use; he was to be victualled by the company as a first-cabin
passenger without charge, and should he require a servant, such
servant, “and also any person appointed to take charge of the mails
on board,” should also be carried at the company’s cost. From which
it would appear that some very comfortable places were at the
disposal of the Admiralty. The Admiralty representative was also to
be allowed a properly manned four-oared boat to take him ashore
whenever he felt inclined to go. Various penalties were applicable for
breaches of the contract, the fines ranging from £100 for doing
something of which the official did not approve to £500 for a delay
of twelve hours, and a further £500 for every twelve hours “which
shall elapse until such vessel shall proceed direct on her voyage in
the performance of this contract,” so far as the Barbadoes mails
were concerned, and of £200 for mails for other places. Another
stipulation was that naval officers were to be charged only two-
thirds of the ordinary fares as passengers. The company’s subsidy
was to be £240,000 per annum.
The company’s first steamer, the Forth, was launched at Leith in
1841, and on January 1, 1842, the West Indian mail service was
established by the sailing of the steamer Thames from Falmouth. On
completion of her voyage she proceeded to Southampton, which has
been the terminal port of the company ever since. The company
organised transit by mules and canoes across the Isthmus of
Panama in 1846, opening up the route via Colon and Panama to the
Pacific ports.
In the same year the Admiralty, in order to make a through mail
communication between England and the West Coast of South
America, contracted with the Pacific Steam Navigation Company for
the carrying of mails from Panama in connection with the R.M.S.P.
service to Colon, and the next year the latter company made
through arrangements with the Pacific Steam Navigation Company
and the Panama Railroad Company for traffic from Southampton (via
Panama) to the South Pacific Ports.
Enough has been written to indicate in some detail the progress
made in steam-ship construction. Wood was the material chiefly
used until near the middle of the nineteenth century. Iron then
began to take its place and the screw-propeller to supersede the
paddle-wheel. Some iron screw steamers have already been
mentioned, but this was inevitable, as no hard and fast line can be
drawn across the history of invention and commercial enterprise, to
separate iron from wood and screw from paddle. The screw
propeller had actually been tried by Stevens in 1802, and iron boats
for inland waters were built as early as 1787.
But the general adoption of iron for building steam-ships and of
the screw for the propulsion of ocean-going ships marks a new era
in the history of steam-ship building.
CHAPTER VIII
EXPERIMENTAL IRON SHIPBUILDING
Another early form of marine engine was that in which the side
levers were arranged as levers of the third order, the fulcrum being
at one end and the steam cylinder placed between it and the
connecting-rod. The peculiar motion thereby given to the machinery
caused this type to be known as the grasshopper engine, from a
fancied resemblance to the long legs of a grasshopper. The direct-
acting engines were much more compact, more powerful, and lighter
than the old side levers. The necessity of providing a connecting-rod
of sufficient length was met by Messrs. Maudslay by the provision of
two cylinders. The cross-head was not unlike the letter T, the foot of
which passed down between the cylinders, and the lower end of this
was fitted with a journal from which the connecting-rod extended to
the crank in the axle. A still further improvement was made when