100% found this document useful (2 votes)
190 views

Python Programming and Numerical Methods: A Guide for Engineers and Scientist 1st Edition Qingkai Kong - Download the ebook now and read anytime, anywhere

The document provides information about various eBooks available for download on textbookfull.com, focusing on programming and numerical methods for engineers and scientists. It highlights titles such as 'Python Programming and Numerical Methods' by Qingkai Kong and 'Numerical Methods for Engineers and Scientists Using MATLAB' by Esfandiari. Additionally, it includes details about the contents and structure of the books, along with links to access them.

Uploaded by

asefunastua43
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
190 views

Python Programming and Numerical Methods: A Guide for Engineers and Scientist 1st Edition Qingkai Kong - Download the ebook now and read anytime, anywhere

The document provides information about various eBooks available for download on textbookfull.com, focusing on programming and numerical methods for engineers and scientists. It highlights titles such as 'Python Programming and Numerical Methods' by Qingkai Kong and 'Numerical Methods for Engineers and Scientists Using MATLAB' by Esfandiari. Additionally, it includes details about the contents and structure of the books, along with links to access them.

Uploaded by

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

Explore the full ebook collection and download it now at textbookfull.

com

Python Programming and Numerical Methods: A Guide


for Engineers and Scientist 1st Edition Qingkai
Kong

https://textbookfull.com/product/python-programming-and-
numerical-methods-a-guide-for-engineers-and-scientist-1st-
edition-qingkai-kong/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Numerical Methods for Engineers and Scientists Using


MATLAB Second Edition Esfandiari

https://textbookfull.com/product/numerical-methods-for-engineers-and-
scientists-using-matlab-second-edition-esfandiari/

textbookfull.com

Programming For Computations - Python: A Gentle


Introduction To Numerical Simulations With Python 3.6
Svein Linge
https://textbookfull.com/product/programming-for-computations-python-
a-gentle-introduction-to-numerical-simulations-with-python-3-6-svein-
linge/
textbookfull.com

Numerical Methods for Engineers 8ed 2021 8th Edition


Chapra S

https://textbookfull.com/product/numerical-methods-for-
engineers-8ed-2021-8th-edition-chapra-s/

textbookfull.com

Numerical Methods for Engineers and Scientists Using


MATLAB® Ramin S. Esfandiari

https://textbookfull.com/product/numerical-methods-for-engineers-and-
scientists-using-matlab-ramin-s-esfandiari/

textbookfull.com
Applied Numerical Methods with MATLAB for Engineers and
Scientists Fourth Edition Steven C. Chapra Dr.

https://textbookfull.com/product/applied-numerical-methods-with-
matlab-for-engineers-and-scientists-fourth-edition-steven-c-chapra-dr/

textbookfull.com

Numerical Methods in Physics with Python 1st Edition Alex


Gezerlis

https://textbookfull.com/product/numerical-methods-in-physics-with-
python-1st-edition-alex-gezerlis/

textbookfull.com

NUMERICAL METHODS IN ENGINEERING WITH PYTHON 1st Edition


Kiusalaas Jaan

https://textbookfull.com/product/numerical-methods-in-engineering-
with-python-1st-edition-kiusalaas-jaan/

textbookfull.com

Prototyping Python Dashboards for Scientists and


Engineers: Build and Deploy a Complete Dashboard with
Python 1st Edition Houlahan
https://textbookfull.com/product/prototyping-python-dashboards-for-
scientists-and-engineers-build-and-deploy-a-complete-dashboard-with-
python-1st-edition-houlahan/
textbookfull.com

Beginning Julia Programming: For Engineers and Scientists


1st Edition Sandeep Nagar

https://textbookfull.com/product/beginning-julia-programming-for-
engineers-and-scientists-1st-edition-sandeep-nagar/

textbookfull.com
Python Programming and
Numerical Methods
A Guide for Engineers and Scientists

Qingkai Kong
Timmy Siauw
Alexandre M. Bayen
Python Programming and
Numerical Methods
A Guide for Engineers and Scientists
Academic Press is an imprint of Elsevier
125 London Wall, London EC2Y 5AS, United Kingdom
525 B Street, Suite 1650, San Diego, CA 92101, United States
50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States
The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom
Copyright © 2021 Elsevier Inc. All rights reserved.

MATLAB® is a trademark of The MathWorks, Inc. and is used with permission.


The MathWorks does not warrant the accuracy of the text or exercises in this book.
This book’s use or discussion of MATLAB® software or related products does not constitute endorsement or sponsorship by
The MathWorks of a particular pedagogical approach or particular use of the MATLAB® software.
No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical,
including photocopying, recording, or any information storage and retrieval system, without permission in writing from the
publisher. Details on how to seek permission, further information about the Publisher’s permissions policies and our
arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found
at our website: www.elsevier.com/permissions.
This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may
be noted herein).
Notices
Knowledge and best practice in this field are constantly changing. As new research and experience broaden our
understanding, changes in research methods, professional practices, or medical treatment may become necessary.
Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any
information, methods, compounds, or experiments described herein. In using such information or methods they should be
mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any
injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or
operation of any methods, products, instructions, or ideas contained in the material herein.

Library of Congress Cataloging-in-Publication Data


A catalog record for this book is available from the Library of Congress

British Library Cataloguing-in-Publication Data


A catalogue record for this book is available from the British Library

ISBN: 978-0-12-819549-9

For information on all Academic Press publications


visit our website at https://www.elsevier.com/books-and-journals

Publisher: Katey Birtcher


Acquisitions Editor: Steve Merken
Editorial Project Manager: Alice Grant
Production Project Manager: Kamesh Ramajogi
Designer: Miles Hitchen
Typeset by VTeX
To Fanyu, Fanqi, and Fan without whom this book would have been finished
¨ To Xianzhong, and Ping!
earlier 
To the students of UC Berkeley’s E7 class: past, present, and future.
To my daughter Myriam,
who is discovering the world of programming.
Contents

List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

PART 1 INTRODUCTION TO PYTHON PROGRAMMING


CHAPTER 1 Python Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 Getting Started With Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.1 Setting Up Your Working Environment . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.2 Three Ways to Run Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 Python as a Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Managing Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.1 Managing Packages Using Package Managers . . . . . . . . . . . . . . . . . . . 15
1.3.2 Install Packages From Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4 Introduction to Jupyter Notebook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.1 Starting the Jupyter Notebook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.2 Within the Notebook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.4.3 How Do I Close a Notebook? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.4.4 Shutting Down the Jupyter Notebook Server . . . . . . . . . . . . . . . . . . . . 20
1.5 Logical Expressions and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
CHAPTER 2 Variables and Basic Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1 Variables and Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2 Data Structure – String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.3 Data Structure – List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.4 Data Structure – Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.5 Data Structure – Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.6 Data Structure – Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.7 Introducing NumPy Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.8 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.8.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.8.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
CHAPTER 3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.1 Function Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.1.1 Built-In Functions in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.1.2 Define Your Own Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.2 Local Variables and Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
vii
viii Contents

3.3 Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67


3.4 Lambda Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.5 Functions as Arguments to Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
CHAPTER 4 Branching Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
4.1 If-Else Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
4.2 Ternary Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.3 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.3.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.3.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
CHAPTER 5 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.1 For-Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.2 While Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.3 Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
5.3.1 List Comprehension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
5.3.2 Dictionary Comprehension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5.4 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5.4.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5.4.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
CHAPTER 6 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
6.1 Recursive Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
6.2 Divide-and-Conquer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
6.2.1 Tower of Hanoi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
6.2.2 Quicksort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6.3 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
6.3.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
6.3.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
CHAPTER 7 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
7.1 Introduction to OOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
7.2 Class and Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
7.2.1 Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
7.2.2 Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
7.2.3 Class vs Instance Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.3 Inheritance, Encapsulation, and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . 127
7.3.1 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
7.3.2 Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
7.3.3 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
7.4 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
7.4.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
7.4.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Contents ix

CHAPTER 8 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135


8.1 Complexity and Big-O Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
8.2 Complexity Matters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
8.3 The Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.3.1 Using the Magic Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.3.2 Use Python Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
8.3.3 Use Line Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.4 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
8.4.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
8.4.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
CHAPTER 9 Representation of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
9.1 Base-N and Binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
9.2 Floating Point Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
9.3 Round-Off Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
9.3.1 Representation Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
9.3.2 Round-Off Error by Floating-Point Arithmetic . . . . . . . . . . . . . . . . . . 152
9.3.3 Accumulation of Round-Off Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
9.4 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
9.4.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
9.4.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
CHAPTER 10 Errors, Good Programming Practices, and Debugging . . . . . . . . . . . . . . . . 157
10.1 Error Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
10.2 Avoiding Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
10.2.1 Plan Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
10.2.2 Test Everything Often . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
10.2.3 Keep Your Code Clean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
10.3 Try/Except . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
10.4 Type Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
10.5 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
10.5.1 Activating Debugger After Running Into an Exception . . . . . . . . . . . 168
10.5.2 Activating Debugger Before Running the Code . . . . . . . . . . . . . . . . 171
10.5.3 Add a Breakpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
10.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
CHAPTER 11 Reading and Writing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
11.1 TXT Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
11.1.1 Writing to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
11.1.2 Appending a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
11.1.3 Reading a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
11.1.4 Dealing With Numbers and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . 178
11.2 CSV Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
11.2.1 Writing and Opening a CSV File . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
x Contents

11.2.2 Reading a CSV File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180


11.2.3 Beyond NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.3 Pickle Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.3.1 Writing to a Pickle File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.3.2 Reading a Pickle File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.3.3 Reading in Python 2 Pickle File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.4 JSON Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.4.1 JSON Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.4.2 Writing a JSON File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.4.3 Reading a JSON File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.5 HDF5 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.5.1 Reading an HDF5 File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
CHAPTER 12 Visualization and Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
12.1 2D Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
12.2 3D Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
12.3 Working With Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
12.4 Animations and Movies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
12.5 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
12.5.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
12.5.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
CHAPTER 13 Parallelize Your Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
13.1 Parallel Computing Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
13.1.1 Process and Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
13.1.2 Python’s GIL Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
13.1.3 Disadvantages of Using Parallel Computing . . . . . . . . . . . . . . . . . . . 227
13.2 Multiprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
13.2.1 Visualize the Execution Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
13.3 Using Joblib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
13.4 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
13.4.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
13.4.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

PART 2 INTRODUCTION TO NUMERICAL METHODS


CHAPTER 14 Linear Algebra and Systems of Linear Equations . . . . . . . . . . . . . . . . . . . 235
14.1 Basics of Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
14.1.1 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
14.1.2 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
14.1.3 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
14.2 Linear Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
14.3 Systems of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Contents xi

14.4 Solutions to Systems of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . 246


14.4.1 Gauss Elimination Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
14.4.2 Gauss–Jordan Elimination Method . . . . . . . . . . . . . . . . . . . . . . . . . 250
14.4.3 LU Decomposition Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
14.4.4 Iterative Methods – Gauss–Seidel Method . . . . . . . . . . . . . . . . . . . . 253
14.5 Solving Systems of Linear Equations in Python . . . . . . . . . . . . . . . . . . . . . . 256
14.6 Matrix Inversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
14.7 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
14.7.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
14.7.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
CHAPTER 15 Eigenvalues and Eigenvectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
15.1 Eigenvalues and Eigenvectors Problem Statement . . . . . . . . . . . . . . . . . . . . 265
15.1.1 Eigenvalues and Eigenvectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
15.1.2 The Motivation Behind Eigenvalues and Eigenvectors . . . . . . . . . . . 265
15.1.3 The Characteristic Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
15.2 The Power Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
15.2.1 Finding the Largest Eigenvalue . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
15.2.2 The Inverse Power Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
15.2.3 The Shifted Power Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.3 The QR Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.4 Eigenvalues and Eigenvectors in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
15.5 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
15.5.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
15.5.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
CHAPTER 16 Least Squares Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
16.1 Least Squares Regression Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . 279
16.2 Least Squares Regression Derivation (Linear Algebra) . . . . . . . . . . . . . . . . . 280
16.3 Least Squares Regression Derivation (Multivariate Calculus) . . . . . . . . . . . . 281
16.4 Least Squares Regression in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
16.4.1 Using the Direct Inverse Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
16.4.2 Using the Pseudo-Inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
16.4.3 Using numpy.linalg.lstsq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
16.4.4 Using optimize.curve_fit From SciPy . . . . . . . . . . . . . . . . . . . . . 285
16.5 Least Squares Regression for Nonlinear Functions . . . . . . . . . . . . . . . . . . . . 286
16.5.1 Log Tricks for Exponential Functions . . . . . . . . . . . . . . . . . . . . . . . 286
16.5.2 Log Tricks for Power Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
16.5.3 Polynomial Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
16.5.4 Using optimize.curve_fit From SciPy . . . . . . . . . . . . . . . . . . . . . 289
16.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
16.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
16.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
CHAPTER 17 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
17.1 Interpolation Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
xii Contents

17.2 Linear Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296


17.3 Cubic Spline Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
17.4 Lagrange Polynomial Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
17.4.1 Using the Lagrange Function From SciPy . . . . . . . . . . . . . . . . . . . . 304
17.5 Newton’s Polynomial Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
17.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
17.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
17.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
CHAPTER 18 Taylor Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
18.1 Expressing Functions Using a Taylor Series . . . . . . . . . . . . . . . . . . . . . . . . . 315
18.2 Approximations Using Taylor Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
18.3 Discussion About Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
18.3.1 Truncation Errors for Taylor Series . . . . . . . . . . . . . . . . . . . . . . . . . 320
18.3.2 Estimating Truncation Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
18.3.3 Round-Off Errors for Taylor Series . . . . . . . . . . . . . . . . . . . . . . . . . 322
18.4 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
18.4.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
18.4.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
CHAPTER 19 Root Finding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
19.1 Root Finding Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
19.2 Tolerance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
19.3 Bisection Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
19.4 Newton–Raphson Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
19.5 Root Finding in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
19.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
19.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
19.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
CHAPTER 20 Numerical Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
20.1 Numerical Differentiation Problem Statement . . . . . . . . . . . . . . . . . . . . . . . 337
20.2 Using Finite Difference to Approximate Derivatives . . . . . . . . . . . . . . . . . . . 338
20.2.1 Using Finite Difference to Approximate Derivatives With Taylor
Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
20.3 Approximating of Higher Order Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . 344
20.4 Numerical Differentiation With Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
20.5 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
20.5.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
20.5.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
CHAPTER 21 Numerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
21.1 Numerical Integration Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 353
21.2 Riemann Integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
21.3 Trapezoid Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
21.4 Simpson’s Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
21.5 Computing Integrals in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Contents xiii

21.6 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365


21.6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
21.6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
CHAPTER 22 Ordinary Differential Equations (ODEs) Initial-Value Problems . . . . . . . . . . 371
22.1 ODE Initial Value Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
22.2 Reduction of Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
22.3 The Euler Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
22.4 Numerical Error and Instability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
22.5 Predictor–Corrector and Runge–Kutta Methods . . . . . . . . . . . . . . . . . . . . . . 382
22.5.1 Predictor–Corrector Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
22.5.2 Runge–Kutta Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
22.6 Python ODE Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
22.7 Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
22.7.1 Multistep Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
22.7.2 Stiffness ODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
22.8 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
22.8.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
22.8.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
CHAPTER 23 Boundary-Value Problems for Ordinary Differential Equations (ODEs) . . . . . 399
23.1 ODE Boundary Value Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 399
23.2 The Shooting Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
23.3 The Finite Difference Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
23.4 Numerical Error and Instability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
23.5 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
23.5.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
23.5.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
CHAPTER 24 Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
24.1 The Basics of Waves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
24.1.1 Modeling a Wave Using Mathematical Tools . . . . . . . . . . . . . . . . . . 415
24.1.2 Characteristics of a Wave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
24.2 Discrete Fourier Transform (DFT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
24.2.1 DFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
24.2.2 The Inverse DFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
24.2.3 The Limit of DFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
24.3 Fast Fourier Transform (FFT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
24.3.1 Symmetries in the DFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
24.3.2 Tricks in FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
24.4 FFT in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
24.4.1 FFT in NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
24.4.2 FFT in SciPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
24.4.3 More Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
24.5 Summary and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
24.5.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
xiv Contents

24.5.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441


Appendix A Getting Started With Python in Windows . . . . . . . . . . . . . . . . . . . . . . . . . . 445
A.1 Getting Started With Python in Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
A.1.1 Setting Up Your Working Environment in Windows . . . . . . . . . . . . . . 445
A.1.2 Three Ways to Run Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
List of Figures

Fig. 1.1 The Miniconda download page; choose the installer based on your operating system. 4
Fig. 1.2 Screen shot of running the installer in a terminal. 5
Fig. 1.3 The default installation location of your file system. 5
Fig. 1.4 Quick way to check if Miniconda was installed successfully and the programs are run properly. 6
Fig. 1.5 Installation process for the packages that will be used in the rest of the book. 6
Fig. 1.6 Run “Hello World” in IPython shell by typing the command. “print” is a function that is
discussed later in the book that will print out anything within the parentheses. 7
Fig. 1.7 Example of a Python script file example using Visual Studio Code. Type in the commands you
want to execute and save the file with a proper name. 8
Fig. 1.8 To run the Python script from command line, type “python hello_world.py”. This line tells
Python to execute the commands that saved in this file. 8
Fig. 1.9 To launch a Jupyter notebook server, type jupyter notebook in the command line, which
will open a browser page as shown here. Click the “New” button on the top right and choose
“Python3”. This will create a Python notebook from which to run Python code. 9
Fig. 1.10 To run the Hello World example within Jupyter notebook, type the command in the code cell
(the grey boxes) and press Shift + Enter to execute it. 10
Fig. 1.11 An example demonstrating the interactive search for functions within IPython by typing TAB
after the dot. The grey box shown all available functions. 12
Fig. 1.12 The help document of pip after executing pip help. 16
Fig. 1.13 Using pip list to show all the packages installed on your machine. 17
Fig. 1.14 Using pip show to get detailed information about a installed package. 17
Fig. 1.15 The Jupyter notebook dashboard after launching the server. Red arrows (light grey arrows in
print version) are pointing to you the most common features in the dashboard. 19
Fig. 1.16 A quick view of a notebook. The Header of the notebook shows the name of the notebook. The
menu has various drop-down lists that let you access to all the functionalities of the notebook.
The tool bar provides you some shortcuts for the commonly used functionalities. 20
Fig. 1.17 Truth tables for the logical and/or. 22
Fig. 1.18 Truth tables for the logical XOR. 25
Fig. 2.1 String index for the example of "Hello World". 31
Fig. 2.2 Example of list index. 36
Fig. 5.1 Interrupt the kernel by pressing the little square. 99
Fig. 6.1 Recursion tree for factorial(3). 107
Fig. 6.2 Recursion tree for factorial(5). 108
Fig. 6.3 Illustration of the Tower of Hanoi: In eight steps, all disks are transported from pole 1 to pole 3,
one at a time, by moving only the disk at the top of the current stack, and placing only smaller
disks on top of larger disks. 111
Fig. 6.4 Breakdown of one iteration of the recursive solution of the Tower of Hanoi problem. 111
Fig. 6.5 Pascal’s triangle. 118
Fig. 8.1 Illustration of running time for complexity log(n), n, and n2 . 138
xv
xvi List of Figures

Fig. 8.2 The profiling result from prun. 141


Fig. 8.3 The line by line profiling result from line_profiler. 142
Fig. 9.1 Binary addition. 146
Fig. 9.2 Binary multiplication. 147
Fig. 9.3 Illustration of −12.0 that is represented in computer with 64-bit. Each square is one bit, with the
green square representing 1 and grey square as zero. 148
Fig. 11.1 The content in the text file we write. 177
Fig. 11.2 Append a line to the end of an existing file. 177
Fig. 11.3 The NumPy array we saved in the file. 179
Fig. 11.4 Open the csv file using Microsoft Excel. 181
Fig. 11.5 Open the csv file using a text editor. 181
Fig. 12.1 Plot of x versus y. 190
Fig. 12.2 Plot of the function f (x) = x 2 for −5 ≤ x ≤ 5. 191
Fig. 12.3 Plot of the function f (x) = x 2 for −5 ≤ x ≤ 5 using dashed line. 192
Fig. 12.4 Using different colors and markers. 192
Fig. 12.5 Adding title and axis labels to a figure. 193
Fig. 12.6 Using seaborn-poster style. 194
Fig. 12.7 Using a legend in the figure. 195
Fig. 12.8 Changing limits of the figure and turning on grid. 196
Fig. 12.9 Different type of plots. 198
Fig. 12.10 Saving a figure. 199
Fig. 12.11 3D axes. 200
Fig. 12.12 3D scatter plot. 202
Fig. 12.13 3D surface plot. 204
Fig. 12.14 3D wireframe and surface plot. 205
Fig. 12.15 Simple world map. 206
Fig. 12.16 World map with background. 207
Fig. 12.17 Simple US map. 208
Fig. 12.18 US map with various features. 209
Fig. 12.19 Bay area map with higher resolution. 210
Fig. 12.20 Add more entities on the map. 211
Fig. 13.1 Parallel computing vs. serial computing. 226
Fig. 13.2 The hardware on the author’s laptop with multicore processor. 226
Fig. 14.1 Graph for Problem 12. 263
Fig. 16.1 Illustration of the L2 projection of Y on the range of A. 281
Fig. 17.1 Illustration of the interpolation problem: estimate the value of a function in-between data
points. 295
Fig. 19.1 Illustration of the intermediate value theorem. If sign(f (a)) and sign(f (b)) are not equal, then
there exists a c in (a, b) such that f (c) = 0. 327
Fig. 19.2 Illustration of the bisection method. The sign of f (m) is checked to determine if the root is
contained in the interval (a, m) or (m, b). This new interval is used in the next iteration of the
bisection method; in the case depicted in the figure, the root is in the interval (m, b). 328
Fig. 19.3 Illustration of Newton step for a smooth function, g(x). 330
Fig. 20.1 Numerical grid used to approximate functions. 337
List of Figures xvii

Fig. 20.2 Finite difference approximation of the derivative. 339


Fig. 20.3 Illustration of the forward difference, the backward difference, and the central difference. Note
the difference in slopes depending on the method used. 341
Fig. 21.1 Illustration of the integral. The integral from a to b of the function f is the area below the curve
(shaded in grey). 353
Fig. 21.2 Illustration of the trapezoid integral procedure. The area below the curve is approximated by a
sum of areas of trapezoids that approximate the function. 357
Fig. 21.3 Illustration of the Simpson integral formula. Discretization points are grouped by three, and a
parabola is fit between the three points. This can be done by a typical interpolation polynomial.
The area under the curve is approximated by the area under the parabola. 360
Fig. 21.4 Illustration of the accounting procedure to approximate the function f by the Simpson rule for
the entire interval [a, b]. 361
Fig. 22.1 Pendulum system. 372
Fig. 22.2 The illustration of the explicit Euler method. 376
Fig. 22.3 The illustration of the stiffness equation. 390
Fig. 23.1 Heat flow in a pin fin. The variable L is the length of the pin fin, which starts at x = 0 and
finishes at x = L. The temperatures at two ends are T0 and TL , with Ts being the surrounding
environment temperature. 400
Fig. 23.2 Target shooting analogy to the shooting method. 401
Fig. 23.3 Illustration of the finite difference method. 406
Fig. 24.1 Period and amplitude of a sine wave. 418
Fig. 24.2 Wavelength and amplitude of a sine wave. 418
Fig. 24.3 More general wave form. 422
Fig. 24.4 Illustration of Fourier transform with time and frequency domain signal. 422
Fig. 24.5 Signal generated before with 3 frequencies. 433
Fig. A.1 The Miniconda download page, choose the installer based on your operating system. 446
Fig. A.2 Screen shot of running the installer in Anaconda prompt. 446
Fig. A.3 The default installation location of your file system. 447
Fig. A.4 Open the Anaconda prompt from the start menu. 448
Fig. A.5 A quick way to check if your installed Miniconda runs properly. 449
Fig. A.6 Installation process for the packages that will be used in the rest of the book. 449
Fig. A.7 Run "Hello World" in IPython shell by typing the command, “print” is a function that we will
learn to print out anything within the parentheses. 450
Fig. A.8 A Python script file example using Visual Studio Code. You type in the commands you want to
execute and save the file with a proper name. 450
Fig. A.9 To run the Python script from command line, we can type “python hello_world.py”. This line
tells Python that we will execute the commands that were saved in this file. 451
Fig. A.10 To launch a Jupyter notebook server, type jupyter notebook in the command line, which
will open a browser page as shown here. Click “New” button at the top right corner, and choose
“Python3” which will create a Python notebook to run Python code. 451
Fig. A.11 Run the Hello World example within Jupyter notebook. Type the command in the code cell
(the grey boxes) and press Shift + Enter to execute it. 452
Preface

PURPOSE
Because programming has become an essential component of engineering, science, medicine, media,
business, finance, and many other fields, it is important for scientists and engineers to have a basic
foundation in computer programming to be competitive. This book introduces programming to students
from a wide range of backgrounds and gives them programming and mathematical tools that will be
useful throughout their careers.
For the most part, this book follows the standard material taught at the University of California,
Berkeley, in the class E7: Introduction to computer programming for scientists and engineers. This
class is taken by most science and engineering freshmen in the College of Engineering, and by un-
dergraduate students from other disciplines, including physics, biology, Earth, and cognitive sciences.
The course was originally taught in Matlab, but with the recent trend of the data science movement at
Berkeley, the Division of Data Sciences agreed on and supported the transform of this course into a
Python-oriented course to prepare students from different fields for further data science courses. The
course has two fundamental goals:

• Teach Python programming to science and engineering students who do not have prior exposure to
programming.
• Introduce a variety of numerical analysis tools that are useful for solving science and engineering
problems.

These two goals are reflected in the two parts of this book:

• Introduction to Programming for Scientists and Engineers


• Introduction to Numerical Methods

This book is written based on the book An Introduction to MATLAB® Programming and Numerical
Methods for Engineers by Timmy Siauw and Alexandre Bayen. The current book was first written in
Jupyter Notebook for interactive purposes, and then converted to LaTeX. Most of the codes showing
in this book are from the Jupyter Notebook code cells, which can be run directly in the notebook cell.
All the Jupyter Notebook codes can be found at pythonnumericalmethods.berkeley.edu.
Because this book covers such a wide range of topics, no topic is covered in great depth. Each
chapter has been designed to be covered in at most two lecture hours, even though there are entire
semester courses dedicated to these same chapters. Rather than an in-depth treatment, this book is
intended to give students a wide breadth of programming knowledge and mathematical vocabulary on
which they can expand.
We believe that just like learning a new foreign language, learning to program can be fun and
illuminating. We hope that as you journey through this book, you will agree.
xix
xx Preface

PREREQUISITES
This book is designed to introduce programming and numerical methods to students who have abso-
lutely no prior experience with computer programming. We hope this underlying concept is reflected
in the pace, tone, and content of the text. For the purpose of programming, we assume the reader has
the following prerequisite knowledge:
• Understanding of the computer monitor and keyboard/mouse input devices
• Understanding of the folder structure used to store files in most operating systems
For the mathematical portions of the text, we assume the reader has the following prerequisite
knowledge:
• High school level algebra and trigonometry
• Introductory, college-level calculus
That’s it! Anything in the text that assumes more than this level of knowledge is our mistake, and
we apologize in advance for any confusion of instances where concepts are unclear.

ORGANIZATION
Part 1 teaches the fundamental concepts of programming. Chapter 1 introduces the reader to Python
and Jupyter Notebook. Chapters 2 through 7 teach the fundamentals of programming. Proficiency in
the material from these chapters should provide enough background to enable you to program almost
anything you imagine. Chapter 8 provides the theory that characterizes computer programs based on
how fast they run, and Chapter 9 gives insights into how computers represent numbers and their effect
on arithmetic. Chapter 10 provides useful tips on good programming practices to limit mistakes from
popping up in computer code, and tells the user how to find them when they do. Chapter 11 explains
how to store data over the long term and how to make results from Python useful outside of Python
(i.e., for other programs). Chapter 12 introduces Python’s graphical features that allow you to produce
plots and charts, which is a really useful feature for engineers and scientists to visualize results. Fi-
nally, Chapter 13 introduces basics about the parallel programming in Python to take advantage of the
multicore design of today’s computers.
Part 2 gives an overview of a variety of numerical methods that are useful for engineers. Chapter 14
gives a crash course in linear algebra. Although theoretical in nature, linear algebra is the single most
critical concept for understanding many advanced engineering topics. Chapter 15 discusses eigenval-
ues and eigenvectors, which are important tools in engineering and science, and the ways we can utilize
them. Chapter 16 is about regression, a mathematical term that is simply a method of fitting theoretical
models to observed data. Chapter 17 is about inferring the value of a function between data points, a
framework known as “interpolation.” Chapter 18 introduces the idea of approximating functions with
polynomials, which can be useful for simplifying complicated functions. Chapter 19 teaches two algo-
rithms for finding roots of functions, that is, finding an x such that f (x) = 0, where f is a function.
Chapters 20 and 21 cover methods of approximating the derivative and integral of a function, respec-
tively. Chapters 22 and Chapter 23 introduce a mathematical model type called “ordinary differential
equations.” These two chapters focus on different problems, i.e., initial value problems and bound-
How to Read This Book? xxi

ary value problems, and present several methods for finding their solutions. Chapter 24 introduces the
concepts of “discrete Fourier transform” and “fast Fourier transform” and their use in digital signal
processing.

HOW TO READ THIS BOOK?


Learning to program is all about practice, practice, and practice. Just like learning a new language,
there is no way to master computer programming without engaging with the material, internalizing it,
and putting it into constant use.
We suggest that as you go through the text, you should ideally have Jupyter Notebook open or
the interactive website in front of you, and run all of the numerous examples that are provided. Go
slowly. Taking the time to understand what Python is doing in every example will pay large dividends
compared to “powering through” the text like a novel.
In terms of the text itself, Chapters 1 through 5 should be read and understood first since they cover
the fundamentals of programming. Chapters 6 through 11 can be covered in any order. Chapter 12
and 13 on plotting and parallel programming are must-read chapters if you wish to improve your
problem-solving skills. In Part 2, Chapter 14 should be read first since subsequent chapters rely on
linear algebraic concepts. The remaining chapters can be read in any order. We do suggest reading
Chapters 17 and 18 before Chapters 19 and 20.
Throughout the text, there are words written in boldface. When you encounter one of them, you
should take the time to commit the word to memory and understand its meaning in the context of the
material being presented.
To keep the text from running on and overwhelming the reader, we have punctuated the material
with smaller blocks of text. Different blocks of text have different functions. For example,
TRY IT! This is the most common block in the text. It will usually have a short description of a
problem and/or an activity. We strongly recommend that you actually “try” all of these in Python.
TIP! This block gives some advice that we believe will make programming easier. Note that the
blocks do not contain any new material that is essential for understanding the key concepts of the text.
EXAMPLE: These sections are concrete examples of new concepts. They are designed to help you
think about new concepts; however, they do not necessarily need to be tried.
WARNING! Learning to program can have many pitfalls. These sections contain information that
will help you avoid confusion, developing bad habits, or misunderstanding key concepts.
WHAT IS HAPPENING? These sections follow Python in scrutinizing detail to help you under-
stand what goes on when Python executes programs.
CONSTRUCTION: In programming there are standard architectures that are reserved to perform
common and important tasks. These sections outline these architectures and how to use them.
There are two sections that end every chapter. The Summary section lists the main take-aways of
the chapter. These points should be intuitive to you by the end of the chapter. The Problems section
gives exercises that will reinforce concepts from the chapter.
As one final note, there are many ways of doing the same thing in Python. Although at first this
can seem like a useful feature, it can make learning Python confusing or overload the programming
novice with possibilities when the task is actually straightforward. This book presents a single way of
performing a task to provide structure for the new user’s learning experience and to keep that user on
xxii Preface

track and from being inundated by extraneous information. You may discover solutions that differ from
the text’s solutions but solve the problem just the same or even better! We encourage you to find these
alternative methods, and use your own judgment to given the tools we have provided herein to decide
which way is better.
We hope you enjoy the book!

WHY PYTHON?
Python is a high-level and general-purpose computer language that lends itself to many applications.
As it is beginner friendly, we hope that you will find it easy to learn and that it is fun to play with it.
The language itself is very flexible, which means that there are no hard rules on how to build features,
and you will find that there are several ways to solve the same problem. Perhaps its great strength is
that it has a great user community that supports it, with lots of packages to essentially plug in and go
with very little efforts. With the ongoing popular trend, Python suits the goals of data science today.
Python is free (open source), and most of the packages are also free for use. The idea of an open source
programming language makes a huge difference in the learning curve. Not only you can use these
packages for free, but also you can learn many advanced skills from the source code of these packages
developed by other users. We hope you can enjoy your learning of Python presented here and use it in
your work and life.

PYTHON AND PACKAGE VERSIONS


This book was written using Python 3. Here is a list of packages with their versions that used in this
book. As these packages are constantly under development, some features may be added, removed, or
changed in the versions on your computer:
• jupyter – 1.0.0
• IPython – 7.5.0
• NumPy – 1.16.4
• SciPy – 1.2.1
• h5py – 2.9.0
• matplotlib – 3.1.0
• cartopy – 0.17.0
• joblib – 0.13.2
Acknowledgements

The first version of this book was written at a time when the standard generalist language taught in
engineering (and beyond) at UC Berkeley was Matlab. Its genesis goes back to the mid-2000s, which
precede the current era of data science, machine learning, in which Python emerged as a commonly
used language across the engineering profession. The first version was thus written as part of the E7
class at UC Berkeley, which introduces many students to programming and numerical analysis. It
would never have been written without the help of colleagues, teams of Graduate Student Instructors
(GSI), graders, and administrative staff members who helped us through the challenging process of
teaching E7 to several hundreds of students each semester at UC Berkeley. Furthermore, the first edi-
tion of this book would never have reached completion without the help of the students who had the
patience to read the book and give us their feedback. In the process of teaching E7 numerous times,
we have interacted with thousands of students, dozens of GSIs and graders, and a dozen colleagues
and administrators, and we apologize to those we will inevitably forget given the number of people
involved. We are extremely grateful for guidance from our colleagues Professors Panos Papadopou-
los, Roberto Horowitz, Michael Frenklach, Andy Packard, Tad Patzek, Jamie Rector, Raja Sengupta,
Mike Cassidy, and Samer Madanat. We owe thanks particularly to Professors Roberto Horowitz, Andy
Packard, Sanjay Govindjee, and Tad Patzek for sharing the material they used for the class, which
contributed to the material in this book. We also thank Professors Rob Harley and Sanjay Govindjee
for using a draft of this book during the semesters they taught E7 and giving us feedback that helped
improve the manuscript. The smooth running of the semester course gave the authors the time and
energy to produce this book. Managing the course was greatly facilitated by numerous administrative
staff members who bore much of the logistic load. We are particularly grateful to Joan Chamberlain,
Shelley Okimoto, Jenna Tower, and Donna Craig. Civil and Environmental Engineering Vice Chair
Bill Nazaroff deserves particular recognition for assigning the second author to teach the class in 2011.
Without this assignment the two authors of this book would not have had an opportunity to work to-
gether and write this book. E7 is notoriously the hardest class to teach at UC Berkeley in the College
of Engineering. However, it continued to run smoothly over the many semesters we learned to teach
this class, mainly due to the help of the talented GSIs we had the pleasure of working with. During the
years the coauthors taught the class, a series of legendary head GSIs have contributed to shaping the
class and making it a meaningful experience for students. In particular, Scott Payne, James Lew, Claire
Saint-Pierre, Kristen Parish, Brian McDonald, and Travis Walter have in their respective roles led a
team of dedicated GSI to exceed expectations. The GSI and grader team during the Spring of 2011
greatly influenced the material of this book. For their contribution during that critical semester, we
thank Jon Beard, Leah Anderson, Marc Lipoff, Sebastien Blandin, Sam Chiu, Rob Hansen, Jiangchuan
Huang, Brad Adams, Ryan Swick, Pranthik Samal, Matthieu Lewandowski, and Romain Bourcier. We
are also grateful to Claire Johnson and Katherine Mellis for finding errors in the text and helping us
incorporate edits into the manuscript. We are indebted to the E7 students for their patience with us
and their thorough reading of the material. Having seen thousands of them through the years, we are
sorry to only be able to mention a few for their extraordinary feedback and performance: Gursham-
njot Singh, Sabrina Nicolle Atienza, Yi Lu, Nicole Schauser, Harrison Lee, Don Mai, Robin Parrish,
xxiii
xxiv Acknowledgements

and Mara Minner. In 2018, as the UC Berkeley campus was already deeply engaged in the transition
leading to the birth of the Division of Computing, Data Science, and Society, numerous conversations
started on the need for UC Berkeley students to learn Python, which in the mean time had become
a commodity of choice for employment in most tech companies. Thus, this book started with the in-
tention of preparing engineering and science students with basic data science tools. The UC Berkeley
Division of Computing, Data Science, and Society played an active role in creating this book for a lower
division course to prepare students for further study. We thank Cathryn Carson and David Culler for
their support in writing this book and for the discussions on how to make it better. Their help happened
in parallel to the herculean efforts they led to build the Division of Computing, Data Science, and So-
ciety. It is one of the many expressions of their scientific generosity and dedication to building a rich
and innovative data science environment at UC Berkeley. Finally, we also appreciate the care and help
from Eric Van Dusen and Keeley Takimoto. About two thirds of the book are adapted from the original
Matlab version – An Introduction to MATLAB® Programming and Numerical Methods for Engineers
by the two last authors. We thank Jennifer Grannen, Brian Mickel, Nick Bourlier, and Austin Chang
for their help to convert some of the Matlab code to Python. We are (again!) grateful to Claire Johnson
for her help with the second version of the book, and to Jennifer Taggart for finding errors in the text
and helping us incorporate edits into the manuscript. We also thank the Berkeley Seismsology Lab for
the support of writing this book and the Python training over the years.

Qingkai Kong
Timmy Siauw
Alexandre M. Bayen
June 2020
CHAPTER

PYTHON BASICS
1
CONTENTS
1.1 Getting Started With Python ......................................................................................... 3
1.1.1 Setting Up Your Working Environment ............................................................. 3
1.1.2 Three Ways to Run Python Code .................................................................... 7
1.2 Python as a Calculator ............................................................................................... 9
1.3 Managing Packages .................................................................................................. 15
1.3.1 Managing Packages Using Package Managers .................................................... 15
Install a Package ............................................................................................. 15
Upgrade a Package.......................................................................................... 16
Uninstall a Package.......................................................................................... 16
Other Useful Commands ................................................................................... 16
1.3.2 Install Packages From Source ....................................................................... 18
1.4 Introduction to Jupyter Notebook ................................................................................... 18
1.4.1 Starting the Jupyter Notebook....................................................................... 18
1.4.2 Within the Notebook .................................................................................. 19
1.4.3 How Do I Close a Notebook?......................................................................... 20
1.4.4 Shutting Down the Jupyter Notebook Server ...................................................... 20
1.5 Logical Expressions and Operators ................................................................................ 20
1.6 Summary and Problems .............................................................................................. 23
1.6.1 Summary ............................................................................................... 23
1.6.2 Problems ............................................................................................... 23

1.1 GETTING STARTED WITH PYTHON


1.1.1 SETTING UP YOUR WORKING ENVIRONMENT
The first step in using Python is to set up the working environment on the computer. This section
introduces the initial processes to get it started.
There are different ways to install Python and related packages, and we recommend using Ana-
conda1 or Miniconda2 to install and manage your packages. Depending on the operating system (OS)
you are using (i.e., Windows, Mac OS X, or Linux), you will need to download a specific installer for
your machine. Both Anaconda and Miniconda are aimed at providing easy ways to manage the Python
work environment in scientific computing and data sciences.

1 https://www.anaconda.com/download/.
2 https://conda.io/miniconda.html.

Python Programming and Numerical Methods. https://doi.org/10.1016/B978-0-12-819549-9.00010-5


Copyright © 2021 Elsevier Inc. All rights reserved.
3
4 CHAPTER 1 PYTHON BASICS

FIGURE 1.1
The Miniconda download page; choose the installer based on your operating system.

In this example, we will use Mac OS X to show you how to install Miniconda (the process of which
is very similar to installing on Linux). For Windows users, please skip the rest of this section and read
Appendix A on the installation instructions. The main differences between Anaconda and Miniconda
are as follows:
• Anaconda is a complete distribution framework that includes the Python interpreter, package man-
ager, and the commonly used packages in scientific computing.
• Miniconda is a “light” version of Anaconda that does not include the commonly used packages.
You need to install all the different packages yourself, but it does include the Python interpreter and
package manager.
The option we’ve chosen here is Miniconda, and we will install only those packages that we will
need. The Miniconda install process is described below:
Step 1. Download the Miniconda installer from the website.3 The download page is shown in
Fig. 1.1. Here you can choose a different installer based on your OS. In this example, we choose Mac
OS X and Python 3.7.
Step 2. Open a terminal (on a Mac, you can search for “terminal” in Spotlight search). Run the
installer from the terminal using the commands showing in Fig. 1.2. After you run the installer, follow
the guide to finish the installation.
Note that although you can change the installation location by giving it an alternative location on
your machine, the default is your home directory (Fig. 1.3).
After installation, you can check the installed packages by typing the commands shown in Fig. 1.4.

3 https://conda.io/miniconda.html.
1.1 GETTING STARTED WITH PYTHON 5

FIGURE 1.2
Screen shot of running the installer in a terminal.

FIGURE 1.3
The default installation location of your file system.
6 CHAPTER 1 PYTHON BASICS

FIGURE 1.4
Quick way to check if Miniconda was installed successfully and the programs are run properly.

FIGURE 1.5
Installation process for the packages that will be used in the rest of the book.
1.1 GETTING STARTED WITH PYTHON 7

Step 3. As shown in Fig. 1.5, install the basic packages used in this book: ipython, numpy, scipy,
pandas, matplotlib, and jupyter notebook. In a later section, we will talk about the management of
the packages using pip and conda.

1.1.2 THREE WAYS TO RUN PYTHON CODE


There are different ways to run Python code and they all have different usages. This section will intro-
duce the three different ways to get you started.
Using the Python shell or IPython shell. The easiest way to run Python code is through the Python
shell or IPython shell (which stands for Interactive Python). The IPython shell is more powerful than
the Python shell, including features such as Tab autocompletion, color-highlighted error messages, ba-
sic UNIX shell integration, and so on. Since we’ve just installed IPython, let us try to run the “Hello
World” example using it. To launch the IPython shell, we begin by typing ipython in a terminal (see
Fig. 1.6). Then we run a Python command by typing it into the shell and pressing Enter. We imme-
diately see the results from the command. For example, we can print out “Hello World” by using the
print function in Python, as shown in Fig. 1.6.
Run a Python script/file from the command line. The second way to run Python code is to put all
the commands into a file and save it as a file with the extension .py; the extension of the file can be
anything, but by convention, it is usually .py. For example, use your favorite text editor (here we used

FIGURE 1.6
Run “Hello World” in IPython shell by typing the command. “print” is a function that is discussed later in the book
that will print out anything within the parentheses.
8 CHAPTER 1 PYTHON BASICS

FIGURE 1.7
Example of a Python script file example using Visual Studio Code. Type in the commands you want to execute and
save the file with a proper name.

FIGURE 1.8
To run the Python script from command line, type “python hello_world.py”. This line tells Python to execute the
commands that saved in this file.

Visual Studio Code4 ) to type the commands you wish to execute in a file called hello_world.py, as
shown in Fig. 1.7, which is then run from terminal (see Fig. 1.8).

4 https://code.visualstudio.com.
1.2 PYTHON AS A CALCULATOR 9

FIGURE 1.9
To launch a Jupyter notebook server, type jupyter notebook in the command line, which will open a browser
page as shown here. Click the “New” button on the top right and choose “Python3”. This will create a Python
notebook from which to run Python code.

Using Jupyter Notebook. The third way to run Python is through Jupyter Notebook, which is a very
powerful browser-based Python environment. We will discuss this in details later in this chapter. The
example presented here is to demonstrate how quickly we can run the code using Jupyter notebook.
If you type jupyter notebook in the terminal, a local web page will pop up; use the upper right button
to create a new Python3 notebook, as shown in Fig. 1.9.
Running code in Jupyter notebook is easy. Type your code in the cell and press Shift + Enter
to run the cell; the results will be shown below the code (Fig. 1.10).

1.2 PYTHON AS A CALCULATOR


Python contains functions found in any standard graphing calculator. An arithmetic operation is either
addition, subtraction, multiplication, division, or powers between two numbers. An arithmetic opera-
tor is a symbol that Python has reserved to mean one of the aforementioned operations. These symbols
are + for addition, - for subtraction, * for multiplication, / for division, and ** for exponentiation.
An instruction or operation is executed when it is resolved by the computer. An instruction is
executed at the command prompt by typing it where you see the >>> symbol appears in the Python
shell (or the In [1]: sign in IPython) and then pressing Enter. In the case of the Jupyter notebook,
type the operation in the code cell and Shift + Enter. Since we will use Jupyter notebook for the
rest of the book, to familiarize yourself with all the different options, all examples in this section will
be shown in the IPython shell – see the previous section for how to begin working in IPython. For
Windows users, you will use the Anaconda prompt shown in the Appendix A instead of using the
terminal.
Discovering Diverse Content Through
Random Scribd Documents
The Project Gutenberg eBook of The
Philippine Islands, 1493-1898; Volume
50
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: The Philippine Islands, 1493-1898; Volume 50

Editor: Emma Helen Blair

Contributor: Edward Gaylord Bourne

Editor: James Alexander Robertson

Release date: May 20, 2018 [eBook #57189]

Language: English

Credits: Produced by Jeroen Hellingman and the Online


Distributed
Proofreading Team at http://www.pgdp.net/ for Project
Gutenberg (This file was partially produced from
images
generously made available by The Internet
Archive/American
Libraries.)

*** START OF THE PROJECT GUTENBERG EBOOK THE PHILIPPINE


ISLANDS, 1493-1898; VOLUME 50 ***
The Philippine Islands,
1493–1898; Volume L

Explorations by early navigators,

descriptions of the islands and

their peoples, their history and

records of the catholic missions,

as related in contemporaneous

books and manuscripts, showing

the political, economic,


commercial and religious

conditions of those islands from

their earliest relations with

European nations to the close of

the nineteenth century,

Volume L, 1764–1800

Edited and annotated by Emma


Helen Blair and James Alexander
Robertson with historical
introduction and additional notes by
Edward Gaylord Bourne.
The Arthur H. Clark Company
Cleveland, Ohio
MCMVII
CONTENTS OF VOLUME L
Preface 9
Document of 1764–1800
Events in Filipinas, 1764–1800. [Compiled from Montero y Vidal’s
Historia de Filipinas.] 23
Miscellaneous Documents, 1766–1771
Financial affairs of the islands, 1766. Francisco Leandro de Viana;
Manila, July 10, 1766. 77
Letter from Viana to Carlos III. F. L. de Viana; Manila, May 1,
1767. 118
Anda’s Memorial to the Spanish government. Simon de Anda y
Salazar; Madrid, April 12, 1768. 137
Ordinances of good government. [Compiled by Governors Corcuera
(1642), Cruzat y Góngora (1696), and Raón (1768).] 191
Instructions to the secular clergy. Basilio Sancho de Santa Justa y
Rufina; Manila, October 25, 1771. 265
The expulsion of the Jesuits, 1768–69. [Compiled from various
sources.] 269
The council of 1771. [Letter by a Franciscan friar]; Manila,
December 13, 1771. 317
Bibliographical Data. 323
ILLUSTRATIONS
Plan of the city of Manila and its environs and suburbs on the other
side of the river, by the pilot Francisco Xavier Estorgo y Gallegos,
1770; photographic facsimile from original MS. map (in colors) in
Archivo general de Indias, Sevilla 35
Plan of the present condition of Manila and its environs, drawn by
the engineer Feliciano Márquez, Manila, September 30, 1767;
photographic facsimile from original MS. map (in colors) in
Archivo general de Indias, Sevilla 83
Map of the river of Cagayan, showing town sites along its banks,
1720(?); drawn by Juan Luis de Acosta; photographic facsimile 182,
from original MS map in Archivo general de Indias, Sevilla 183
Map of Manila Bay, port of Cavite, and Lake of Bay, showing
depths of various parts of the bay, drawn by the engineer Feliciano
Márquez, September 28, 1767; from original MS. map (in colors) in
Archivo general de Indias, Sevilla 201
Map of Guam, one of the Marianas Islands, in Concepción’s
Historia general (Sampaloc, 1788–1792), vii, facing p. 145;
photographic facsimile from copy in library of Harvard University 291
PREFACE
In this volume is a brief outline of events from the restoration of Manila by
the English (1764) to 1800; and a group of documents relating to the more
important topics in the first decade of that period. The condition of the
islands and their people at that time is well described by the able and
patriotic officials Viana and Anda; and the “ordinances of good
government” are an important addition to our sources of information
regarding the administration of justice in Filipinas. The most important
event of that time was the expulsion of the Jesuits from the Spanish
dominions, although its great significance in Europe was but feebly
reflected in those remote colonies.

In a brief summary are noted the leading events in Filipinas from 1764 to
1800. Manila is restored to the Spanish authorities by the English on March
31, 1764; a few months before, Archbishop Rojo had died, in captivity. The
brief term of the temporary governor, Torre, contains little that is
noteworthy, outside of a controversy between the civil government and the
religious orders, occasioned by the imprudent utterances of a Jesuit
preacher. In July, 1765, arrives the new governor, José Raón, in whose term
occurs the expulsion of the Jesuits from the islands, a matter treated more
fully in a later document; he also publishes a revision of the laws compiled
earlier by Arandia. The city of Manila first coins small copper money about
this time. The old controversy regarding episcopal visitation of the regular
curas is revived (1767) by Archbishop Santa Justa y Rufina, and it is
complicated by Raón’s attempt to enforce the royal rights of patronage;
bitter controversies arise, and are carried to the Madrid court.

After the capture of Manila by the English, the Moros had renewed their
piracies, and ravaged the entire archipelago, year after year—even
entrenching themselves and opening a slave market on Mindoró Island.
Later, an expedition is sent to drive them out of this stronghold, which is
successful. In 1770, the patriot Anda returns to Filipinas as its governor; he
brings suit against Raón and other officials for misconduct in office, which
is proved against them; but they and their friends rouse bitter opposition
against him, and hinder his labors for the country. Incited by reports of
another English invasion, he strengthens the fortifications of Manila Bay.
His appointment was unwelcome to the friars, and he makes official
remonstrance against the abuses prevalent among them, and calls for
corrections of these. Attempting to enforce the royal rights of patronage, all
the orders save the Dominicans refuse to obey; but later royal orders (1776)
make provision for more gradual secularization of the curacies in Filipinas,
and somewhat modify the enforcement of the episcopal visitation—to
secure which Santa Justa had convened a provincial council at Manila in
1771, which was afterward disapproved by the king. Difficulties arise with
the Moros of Joló through the imprudence of an envoy sent thither by Anda,
and through the military establishment made by the English on an islet near
Joló. The Moros seize this fort by treachery (1775) and kill most of the
Englishmen in it; this success emboldens the Moros to ravage the Spanish
islands again. In the following year the king sends 50,000 pesos to Filipinas
for building light vessels to follow up those pirates. The weight of Anda’s
official responsibility, and the constant attacks of his enemies, cause his
death, October 30, 1776. He is succeeded by Basco y Vargas, an energetic,
able, and conscientious officer. The auditors conspire against him, but he
arrests them and ships them to Spain; he then devotes himself to the welfare
of the country and the development of its resources. He makes all possible
efforts to promote agriculture, industries, and commerce; founds the
celebrated “Economic Society;” improves the schools, punishes
highwaymen, reorganizes the army, and repairs the forts; visits the
provinces in person, and informs himself of their condition; places the
public revenues on a sound basis; and checks the Moro piracies for a time.
Nevertheless, he is disliked and opposed by some of the citizens, and
resigns his post as governor (1787); his temporary successor is Pedro
Sarrio, who finds it necessary to allow the regular curas to resume their
parish charges.

The next proprietary governor, Félix Berenguer de Marquina, assumes his


office on July 1, 1788. After becoming acquainted with the condition of the
islands, he sends to the home government proposals for the reforms which
seem desirable for Filipinas. Various events in his term of office are related,
but there is little in them of unusual importance. In 1793 he is succeeded by
Aguilar. New alarms of another English invasion oblige him to give
attention first to the defenses of Manila and the improvement of the army.
In the last days of 1796, a powerful Spanish fleet, commanded by Álava,
arrives at Manila, sent thither for the defense of the islands in the war with
Great Britain, which began in that year. Sailing to attack the English
trading-fleet from China, Álava encounters a fierce hurricane, which drives
him back to Manila. Endeavoring to improve the navy of the islands, and to
reorganize the arsenals, he encounters official corruption and other
difficulties, and is involved in long controversies with Aguilar and the royal
officials at Manila. In 1797, the Acapulco galleon is wrecked soon after
leaving Cavite, through “its commander’s complete ignorance of nautical
affairs,” occasioning heavy loss to the citizens of Manila. Álava is
compelled, by the continual danger of an attack by the English, to remain
near the city for its defense; but he does all in his power to protect its
commerce and improve the administration of its navy, and finally returns to
Spain in 1803. On August 8, 1806, Aguilar dies, having held his office
longer than any other governor before or since.

A detailed statement of the financial affairs of the islands in 1766 is


furnished by the royal fiscal at Manila, Francisco Leandro de Viana. He
aims to show how the Philippines can be made self-supporting, and even
more, by proper retrenchments of expense and by increasing the revenues
of government through the abolition of certain privileges and exemptions,
the establishment of various monopolies, and, if necessary, the increase of
the tributes paid by the natives. This last item produces 250,000 pesos
annually; but nearly all of this is paid out for “the spiritual administration”
of the Indians, so that, according to Viana, “the religious orders profit by
and receive almost all the proceeds from the tributes.” Hence the need of
the royal situado each year from Mexico, to pay the civil and military
expenses of the government. Viana enumerates the other profits derived
from the Indians by the religious who are charged with their spiritual care,
and mentions numerous other sources of income which they possess. In
short, “all the profit of the islands accrues to the ecclesiastical estate;” the
royal treasury is heavily indebted, and cannot meet the enormous expenses;
“the provinces are at the mercy of the Moros, and everything is in danger of
total ruin, unless suitable remedies are applied in time.”

For this purpose Viana advocates various retrenchments of expenses,


especially of those now incurred for the support of the ecclesiastical estate
in the islands. He recommends that the exemptions of certain Indian chiefs
and church servants from tribute-paying be abolished; that the “barangays”
be suppressed, and the native villages reduced to parishes; that changes and
reforms be made in the dealings of the provincial alcaldes with the crown;
that offices be not sold, but granted as rewards of merit; that certain royal
imposts be increased; that some privileges be sold at auction; and that
monopolies be established on playing-cards, cock-fighting, and tobacco, not
only in Manila but throughout the provinces and islands—to all of which
the monopolies on wine and buyo might profitably be extended, which
“would produce for the royal treasury enormous sums.” From all these
sources, the royal treasury will obtain enough income “to maintain the
islands with respectable forces, and to make good the expenses hitherto
caused to the royal revenue,” without the necessity of increasing the tribute
paid by the natives. But, if this last expedient be deemed necessary, he
shows what will be the proceeds from increasing the tribute from ten reals
to two, three, and four pesos respectively. The fiscal Viana shows himself to
be a capable and honest official; but he evidently must contend with forces
and conditions—greed for gain, official corruption, fraud, negligence and
waste—that cannot be overcome without entire reform and reorganization
of the colonial administration. With all his ability, he nevertheless regards
the native peoples, as so many other European officials have done, as
legitimate subjects for reckless exploitation; but in the light of modern
thought and investigation his proposed expedients seem both short-sighted
and ruinous. In some cases they would be diabolical, if their author could
have realized what their effects would be, as with the proposed extension of
the vicious monopolies (gambling, and the use of tobacco and wine)
throughout the islands. He himself says, “Even the boys and girls use the
said tobacco before they are old enough to exercise their reason.”

Another document of especial interest is a report by Viana (May 1, 1767) to


the king and the Council of the Indias, apparently the final one sent by him
as fiscal. The subjects which it chiefly discusses are, the necessity of
rendering trade free between the Spaniards and the Indians in the provinces,
and that of instructing the natives in the Spanish language. As it is, the
Indians seldom understand that language, outside of Manila, and dare not
use it in presence of the religious. The latter, Viana says, are absolute
despots in the islands, and, to conceal this from the authorities, they keep
the natives in ignorance of the Spanish language; and they allow no
Spaniard to enter their villages except by special permission of the cura, and
for the time of three days only. He complains of their insolence, greed for
dominion, disregard of all laws that do not suit their convenience, intrigues
to prevent the enforcement of law, and oppression of the natives. These
evils are incurable so long as the present mode of secular government
continues. The interests of the king and his exchequer, and the government
of the provinces, are shamefully neglected; the governor is indolent and
covetous, seeks his own profit, and leaves business affairs to his secretary—
who in turn neglects those which do not yield him gain. Viana urges that the
superintendency of the exchequer be separated from the governor’s office,
as a partial remedy for the disorder and neglect which it has suffered; also
the surrender of civil government in the provinces to the sole charge of the
Audiencia, and the reduction of all the natives into parishes. He describes
the intrigues within the orders which attend the appointments therein to the
parishes under their charge, and claims that the missions are in consequence
rapidly decaying. He renews his complaint of the despotic rule practiced by
the friar curas, over both natives and alcaldes; and declares that the only
cure for this will be, to subject the curas to episcopal visitation. Viana
closes by urging that better governors be sent to the islands.

Further light on the condition of the islands after the English invasion is
furnished by a notable memorial to the Spanish government, written by the
patriot Anda (April 12, 1768). Far the greater part of this is devoted to the
abuses resulting from the arrogance and lawlessness of the friars, with
Anda’s recommendations for measures to counteract those abuses; and to
his text we add the helpful annotations made thereon by Dr. Pardo de
Tavera. The inadequate and defective education furnished by the Manila
universities leads Anda to recommend that they be abolished, and replaced
by a secular foundation. He complains of the tyranny exerted by the
regulars over the secular clergy and over the Indians, their refusal to
acknowledge the episcopal authority, their defiance of the secular
government, their greed for gain (extorting all they can get from the
Indians, although they receive large stipends and contributions from the
government, and acquiring large estates, besides engaging in a lucrative
trade), their persecutions of any Spaniards who attempt to visit or trade in
the Indian villages, their protection of the infidel Chinese, their persistent
neglect to teach the Spanish language to the Indians and their holding the
latter in ignorance in order to retain their domination over them. The
regulars also neglect their spiritual work, do nothing to check the vagrant
life of many Indians, tyrannize over the alcaldes, and incite the Indians to
hate the Spaniards. Anda urges that they be compelled to submit to
episcopal visitation, to give up trade, to cease from meddling with all affairs
of secular government, and to teach the Spanish language to the natives;
and, if they prove contumacious, that they be expelled from the islands. At
the end of the memorial, Anda touches on some other abuses which need
correction: the choice of friars as bishops, the mismanagement of the royal
storehouses, the undue expense of the Acapulco galleon, the failure to tax
the production of gold, and the neglect to subdue the inland tribes of Luzón.
He advocates the operation of the Philippine mines, revision of the
commercial regulations, recoinage of money, reorganization of the colonial
government, and more care in selecting the governors of the islands, with
the grant to them of more power to correct abuses.

Of decided importance in this series are the ordinances of good government


of Corcuera and Cruzat (with later additions), and those of Raón (revising
those of Arandía, of 1768), which were intended for the guidance of
alcaldes, corregidors, and other judicial officials. While in actual use they
were never of the transcendental importance in executive, legislative, and
judicial matters that might be imagined from their context, because they are
for the most part merely a record on paper (especially those of Raón), and
were almost entirely disregarded; yet they are valuable, as they show the
Spanish treatment of natives, and reveal social and economic conditions.
Although the source from which we translate and synopsize presents first
the ordinances of Raón, we have preferred to follow the more chronological
arrangement, and hence begin with those of Corcuera and Cruzat. The
ordinances of Corcuera, which were formulated in 1642, are revised by
Cruzat, because such revision is demanded by the changed conditions that
have come with the lapse of time. The first thirty-eight are the more
valuable portion of these first ordinances, and are the result of the revision
of those of Corcuera. They are much more clear-cut than most of the
remaining twenty-three ordinances, some of which are vague and full of
loopholes. As a whole, these first sixty-one ordinances regulate the conduct
of the alcaldes-mayor in their official and private life in all lines—moral,
religious, judicial, economic, etc. From them one obtains almost a full
glimpse of the life of the times; he sees the canker of graft which was
working in and through everything; gains a knowledge of the Spanish
treatment of their wards, the natives, from the different standpoints of
government paternalism, and individual rapacity, half-contempt, and cruelty
of subordinate officials and others; notes the corrective measures that were
taken, often halting and inadequate; and above all, is conscious of that
peculiar method of Spanish legislation which, while apparently giving
subordinate officials a free hand, drew them back to the center by threats of
the residencia. The ordinances of Raón are ninety-four in number, many of
which are repetitions of the foregoing, while some contain amendments and
additions, and some again, are new. There is, for instance, considerably
more legislation relating to the ecclesiastical estate in these later ordinances,
which touch upon certain abuses common among them in their treatment of
the natives and in their relations with the government. Less drastic, in many
ways, than those of Arandía (of which no known copy is extant), they are
more drastic than those of Corcuera and Cruzat, in the treatment of both
religious and natives. The scheme of government outlined in both sets of
ordinances is a simple and in some ways effective one, but its effects were
never fully seen, because of the almost total disregard of the measures
contained therein.

In 1771, Archbishop de Santa Justa issued instructions to the secular clergy


which forcibly indicate the need of many reforms among them, in both their
official and their private conduct.

One of the most important events in the history of Filipinas was the
expulsion of the Jesuit order therefrom in 1768, an account of which is here
presented, prefaced by a brief statement of the expulsion of that order from
Spain and its domains, and the causes of that measure; it proves to be the
final stroke in the long conflict between the Spanish crown and the popes of
Rome over the prerogatives of authority claimed by the former in
ecclesiastical matters. The Jesuits had always upheld the principle of
authority, as exercised by the Holy See, and were therefore opposed to the
claims of the Spanish monarchs; moreover, the ideas of freedom brought
from France in that period were already fermenting in Spain, and had great
influence in the minds of Carlos III and his ministers; and they saw that the
expulsion of the Jesuits from the Spanish dominions would remove the
chief obstacles to their designs for governmental reforms and independence
of papal interference. In Filipinas this expulsion does not proceed as desired
by the Spanish court, with secrecy and promptness; the venal governor
(Raón) warns the Jesuits of their fate, enabling them to make all
preparations for their departure. Legal proceedings are therefore brought
against Raón and his associates in their residencias, but some of them die
before the suits are ended; and Anda, who instituted these by royal order, is
nevertheless impeded in every way, and afterward sentenced to heavy fines,
through the machinations of his enemies. A decree by the archbishop
(November 1, 1769) censures the officious proceeding of an auditor, who
seized and prohibited certain books hostile to the Jesuits.

A letter (December 13, 1771) from a Franciscan friar at Manila, relates


various ecclesiastical disputes in connection with the diocesan council of
1771.

The Editors

April, 1907.
DOCUMENT OF 1764–1800
Events in Filipinas, 1764–1800. Compiled from Montero y Vidal.

Source: Compiled from Montero y Vidal’s Historia de Filipinas, ii, pp. 66–70, 115–140,
229–382.

Translation: This is made by Emma Helen Blair.


EVENTS IN FILIPINAS, 1764–1800
Archbishop Rojo, ad interim governor of the islands at the time of the English attack
on Manila, died on January 30, 1764, a prisoner in the hands of the conquerors.1 A
few days later, Anda received despatches from Spain notifying him of the treaty of
peace made with England, and he immediately entered into negotiations with the
English for the surrender of Manila, which was accomplished on March 31
following. There was a dispute over the question of who should succeed Rojo in the
government of the islands, an honor which was certainly due to the patriot Anda,
who was, however, opposed by some of the citizens; but this was settled by the
arrival of Colonel Francisco de la Torre, appointed governor ad interim of the
islands, to whom Anda surrendered his command on March 17. The revolts and other
disturbances in the provinces, consequent on the English occupancy, and their
suppression, are noted in VOL. XLIX; cf. Montero y Vidal, Hist. de Filipinas, ii,
chap. iii, and Ferrando, Hist. PP. dominicos, v, pp. 640–644, 651–740, for fuller
accounts of these, and of the Chinese insurrection which then occurred. Ferrando
makes (p. 739) the following interesting citation from an unnamed but “reliable”
writer: “There died in this war some seventy Spaniards and two hundred and fifty
natives, who, as good subjects, fought even unto death for their king. Before the
insurrection there were in the province [of Pangasinan] 60,383 souls; and according
to the computation which was made on May 13, 1766, there were in it only 33,456;
consequently the loss for the entire province was 26,927 souls. Many of these
inhabitants emigrated, others perished from their privations, and no small number
were killed by the barbarians.”2 During Torre’s temporary command the most
important occurrence was a noisy controversy which was called forth by the
imprudent and meddlesome utterances of a Jesuit preacher in Manila, Francisco
Javier Puch, attacking government officials.3 The governor with the aid of the fiscal
Viana, attempted to secure the punishment or rebuke of Puch, but the Dominican
theologians took sides against them with the Jesuits;4 the dispute was carried to the
court at Madrid, and produced long and bitter controversies and dissensions, and
probably was one of the motives which influenced the king, some years later, to
expel the Jesuits from his dominions.

On July 6, 1765, the new proprietary governor, José Raon, a military officer of high
rank, relieved Torre; he appears to have been able but unscrupulous.5 He is most
conspicuous for his revision of the “Ordinances of good government” drawn up by
Arandía (see post, pp. 191–264), the revision being dated February 26, 1768; and for
the expulsion of the Jesuits from the islands (1768), in pursuance of the orders
received from Madrid dated March 1, 1767—which matter is related in detail in the
last document of this volume. In 1769 he also decreed the expulsion of the Chinese
from Filipinas, although this was not fully enforced. Early in October, 1766, the
French astronomer Le Gentil, whose Voyage (Paris, 1781) is a valuable contribution
at once to science and to the history of Filipinas at that time, arrived at Manila,
commissioned by the French government to make observations on the approaching
transit of Venus. “On account of the scarcity of copper money in Manila, the senior
regidor of the municipal council, Domingo Gómez de la Sierra, in 17666 requested
authorization to make the said coins, with the name of barrillas, because their shape
was that of a parallelogram. The government complied with this request, ordaining
that only [the amount of] 5,000 pesos should be coined, to be used only in Tondo and
Cavite. From that time, the Indians gave the name barrilla to copper coins.” “The
municipal council again asked for authority to make the barrillas, for use in various
provinces; and by royal decree of December 19, 1769, order was given to send from
Mexico 6,000 pesos in cuartillos (that is, fourths of silver reals)—with the provision
that the coin [previously] made should be gathered in, and that what should be
necessary should be made with the royal arms, within the limits allowed to San
Domingo, as appears in ley 8, tit. xxiv, [book iv,] of the Recopilación de Indias.” In
1766 there were two very fierce eruptions of the volcano Mayón, in Albay, occurring
on July 20 and October 23; in the second, vast quantities of water were ejected,
forming rivers and torrents, which destroyed some villages and many lives, and
ruined many homes and farms.7

On July 22, 1767, the new archbishop, Basilio Sancho de Santa Justa y Rufina,8 took
possession of the see of Manila, and immediately undertook to subject the regular
curas to his diocesan visitation, thus reviving the Camacho controversy of 1697–
1700 (see VOL. XLII, pp. 25–116) with the religious orders; but Santa Justa had the
support of the civil authority, which had orders to enforce the royal rights of
patronage. “The governor of the islands, on his side, communicated to the
provincials of the religious orders rigorous commands that they must submit to the
royal rights of patronage: that within a short time-limit they should present their lists
of three names each [sus ternas] for appointments to all the curacies; and that in
future they might not remove any religious from his post without informing the
viceregal patron of the causes, whether public or private, for such action.” The
Dominican province, in a provincial council of August 5, 1767, yielded to the
archbishop’s claims, and during the following year he visited all the parishes
administered by them; but some individuals refused to obey the council. The other
orders obstinately resisted the episcopal visitation, declaring that they would
abandon their curacies if it were enforced. Thereupon, the archbishop appointed
secular priests to the vacant curacies, including those of the Parián, Binondo, and
Bataan, which were in charge of the Dominicans.9 As the number of Spanish priests
was so small, the archbishop made up the deficiency by ordaining natives from the
seminaries; but this measure caused great resentment among the regulars and their
supporters, and Santa Justa himself was disappointed in its effects, as the native
clergy were generally so unfit for the office of priest in both education and morals.10
Complaints to the king were made by both the religious orders and the archbishop,
filled with mutual accusations and recriminations; and Raon withdrew his support
from the latter, ceasing to press the claims of the royal patronage—influenced
thereto, according to Montero y Vidal, by the intrigues of the Jesuits, who were
enemies to Santa Justa. The support given by the Dominicans to the Jesuits in the
Puch affair was censured by the Dominican general (Fray Tomás de Bojadors), who
punished the Philippine provincial, Fray Joaquín del Rosario, and two of his brethren
by depriving them of office and recalling them to Madrid. They availed themselves
of various technicalities to delay their return for a long time; but finally two of them
were sent from Manila late in December, 1778. Fray Joaquín del Rosario (his
companion having died on the voyage) was captured by the English, but afterward
regained his liberty and proceeded to Madrid, where the dispute was finally settled in
an amicable manner.

After the capture of Manila by the English, the Moros renewed their piratical
incursions, the Spanish authorities being so burdened with the insurrections of the
natives and the Chinese, the lack of revenues, and the general disturbance of the
colony’s affairs, that they could do nothing to curb the insolence of the Moros. Those
cruel pirates therefore ravaged the entire archipelago, even capturing fishing-boats in
Manila Bay; and everywhere the coast villages were destroyed or depopulated, and
the native population kept in continual terror of this inhuman foe. Bishop Ezpeleta,
while temporary governor, had disbanded the little fleet at Iligan commanded by the
Jesuits Ducós, which had been some check on the enemy, but Governor Rojo
reëstablished the Pintados fleet, with headquarters at Cebú; nevertheless, this could
do little to restrain them. There was a general attack by the Joloans and
Mindanaos,11 well aided by the Tirones and Malanaos; and so insolent did they
become that they captured two richly-laden champans on the Mariveles coast, and
entrenched themselves at Mamburao, on Mindoro Island, and sold their Filipino
captives to the Macasar traders who resorted thither. A small squadron was collected
at Cavite, which conveyed over 1,200 men to attack this Moro fort;12 after several
days of skirmishing, the enemy fled, and the Spaniards seized their stronghold,
finding therein sufficient rice and other property to more than pay the expenses of
the expedition. Another Moro band, however, made amends for this loss by gaining
possession of the fort at Cateel, with all its contents; but on going to besiege that at
Tandag they were repulsed and defeated, leaving behind all their arms and supplies.

Plan of the city of Manila and its environs and suburbs on the other side of the river, by the pilot
Francisco Xavier Estorgo y Gallegos, 1770

[From original MS. map (in colors) in Archivo general de Indias, Sevilla]

In 1767 Anda went to Madrid, where he was praised and richly rewarded for his
brave conduct during the English invasion; and the king made him a member of the
Council of Castilla. Later, the post of governor of Filipinas was offered to him; he
several times refused the honor, but finally yielded to the urgent request of the
government, and in July, 1770 made his entry into Manila, where he was received
with unbounded enthusiasm. His instructions made it necessary for him to institute
legal proceedings against his predecessor Raon, who was accused of having warned
the Jesuits of their intended expulsion, and of having secreted important official
documents. Raon was held a prisoner in his house, but died before the suit could be
tried in court. In this suit were also included two auditors and the royal fiscal, and
they and their friends attacked Anda bitterly, causing him numberless vexations in
his efforts to fix on them the responsibility for misconduct in the affair of the Jesuit
expulsion. It was reported in Spain that the English intended to make another attack
on Manila; Anda therefore repaired the walls of the city13 and constructed ships, and
within eight months had built and equipped twelve armed vessels of various sizes,
besides several smaller craft. Notwithstanding this enterprise, the public revenues
were greatly increased during the first year,14 and thus Anda was able to send several
expeditions against the Moro pirates. An earthquake15 occurred on the night of
February 1, which fortunately did no great damage.

“The religious corporations, notwithstanding the support which they generally lent to
Anda during the war with the English, regarded with displeasure his appointment as
governor of Filipinas. That strict magistrate, obeying the dictates of his conscience
(which some persons attribute, but without sufficient grounds, to feelings of personal
revenge), had addressed to the king on April 12, 1768, an exposition which treated of
‘the disorders which exist in Filipinas, and which ought to be corrected.’ In this
document he points out most serious abuses among the friars; in the university,
which was in their charge; among the Jesuits; among the Chinese, protected by the
friars, who preferred them before the Spaniards, driving away and expelling the
latter from their villages; and he censures certain frauds and practices in the public
administration in specified branches of the civil service. The seventy with which
Anda laid bare those abuses drew upon him the hatred of the friars.16 In this
document he demanded a remedy for the disorders which he denounced, pointing out
the method by which this might be effected, and declared that ‘for the radical
correction of these evils it is indispensable to draw up and introduce here a form of
procedure which is clear, and capable of securing the just system which corresponds
thereto, conferring upon the governor all the powers necessary for carrying it into
execution, by those measures which prudence and the actual condition of affairs
shall dictate to him.’ He added: ‘The choice of a zealous governor will materially
contribute to laying the foundations of that great work; but it is necessary to reward
him and give him authority, so that he can work to advantage, and without the
hindrances which have often, by means of secret communications, cunning and
disloyal maneuvers, and other malicious proceedings, frustrated the best and most
carefully formed plans.’ This exposition17 by Anda was certainly taken into account,
for in the ‘royal private instructions’ which were given to him when he was
appointed governor of Filipinas we see that he was ordered to put an end to specified
abuses and disorders, the king using the same terms which Anda had employed in
describing those evils.”

“The archbishop Santa Justa, a man of unparalleled firmness and energetic character,
from the first moment assailed the new governor of Filipinas on the question of the
diocesan visitation, to which the friars continued their opposition, and demanded his
support in order to make it effectual. Anda, who regarded obedience to the laws as a
rule of conduct, and who brought orders from the court to subject the regulars to the
royal patronage, addressed an explicit communication to the superiors of all the
religious institutes, requiring their obedience to the mandate of the sovereign, and
assigning a definite term, which could not be prolonged, for the presentation of their
lists of appointees, in order that the curacies might be filled in this manner. All the
orders of regulars openly refused to yield obedience of this sort, excepting the
Dominicans—who, more circumspect, and endeavoring to avoid the dangers which
they foresaw in resistance, agreed to submit to this command—although many of the
parish priests of the order soon were disobedient to this decision of their superiors.”

The archbishop convened a provincial council at Manila, which held six sessions
during the period May 19–November 24, 1771; various matters of ecclesiastical
administration came before it, the chief of which was the diocesan visit. In the fifth
session, the subjection of the parish priests to the diocesan visitation and the royal
patronage was ordained; and at the final one it was ordered that the decrees of the
council should immediately be promulgated, declaring that those of the council of
Mexico (which Urban VIII had ordered to be observed in Filipinas) were not now
binding. In the first session the bishop of Nueva Cáceres, Fray Antonio de Luna (a
Franciscan), became involved in disputes over the appointment of secretaries, and
was expelled from the assembly; he then retired to his diocese, and during the entire
period of the council opposed its proceedings, with protests, legal formalities, and
official edicts. Bishop Ezpeleta of Cebú died soon after the opening of the council,
and the government of that diocese devolved upon Luna, but, it seems, not its
representation in the council. A secretary of that body, Father Joaquín Traggia, was
sent to Madrid as its agent and bearer of its despatches; but the king refused to
accept his credentials, and ordered him to go to his convent at Zaragoza, forbidding
him to return to Filipinas. (Toward the end of this council, the archbishop, in concert
with his suffragans, drew up a tariff for the parochial fees to be collected by the
curas.) The religious orders finally secured, through influence at the court, the
revocation of the order given to Anda in regard to the regular curas, which had
resulted in many of them being removed from the Indian villages and replaced by
native priests; but no change was made in regard to the diocesan visitation. The
bishop of Nueva Segovia, Fray Miguel Garcia,18 claimed this right, and convened a
diocesan council in 1773; the only result was, to arouse a hot controversy between
Garcia and the Dominicans, to which order he belonged. That order also had a
dispute with the archbishop over his attempt to visit the beaterio of Santa Catalina;
but in 1779 the king decided that this institution should continue to enjoy its
exemption from visitation.

“By royal decree of November 9, 1774, it was ordered that the curacies held by the
regulars should be secularized as fast as they became vacant. Anda suspended the
execution of this command, and wrote to the court, specifying the evils which would
ensue from the secularization of the curacies which the archbishop desired; and in
consequence of this and of the urgent appeals of the Franciscans, Augustinians, and
Recollects, the king ordered by a decree of December 11, 1776, that what had been
decided on this point in the decree of November 9, 1774, should not be put into
execution, and that affairs should be restored to their former status and condition,
and their curacies to the religious; that the regulations for his royal patronage and the
ecclesiastical visitation should be observed, but that the latter might be made by the
bishops in person, or by religious of the same order as those who should serve in the
curacies, and without collecting visitation fees. The king also directed in the said
decree that efforts should be made, by all possible means and methods, to form a
large body of competent clerics, in order that, conformably to the royal decree of
June 23, 1757, these might be installed in the vacant curacies, thus gradually
establishing the secularization that had been decreed.”

Anda took what precautions were available to restrain the Moro pirates, but great
difficulties arose in his way. Ali-Mudin, whom the English had restored to his sway
in Joló, and his son Israel (in whose favor the father had abdicated) were friendly to
the Spaniards, with many of their dattos; but another faction, led by Zalicaya, the
commander of the Joloan armadas, favored the English, who had established
themselves (1762) on the islet of Balambangan19 in the Joló archipelago, which they
had induced Bantilan to grant them; and the English were accused of endeavoring to
incite the Joloans against the Spaniards by intrigue and bribery. Anda decided to
send an expedition to make protest to the English against their occupation of this
island, as being part of the Spanish territory, and entrusted this mission to an Italian
officer named Giovanni Cencelly, who was then in command of one of the infantry
regiments stationed at Manila; the latter sailed from Zamboanga December 30, 1773,
bearing careful instructions as to his mode of procedure, and to avoid any hostilities
with the English and maintain friendship with the Joloans. But Cencelly seems to
have been quite destitute of tact or judgment, and even of loyalty to his governor; for
he disobeyed his instructions, angered the Joloans,20 who could hardly be restrained
by Ali-Mudin from massacring the Spaniards, and at the end of three weeks was
obliged to return to Zamboanga. He was on bad terms with the commandant there
(Raimundo Español), and refused to render him any account of his proceedings at
Joló; and he even tried to stir up a sedition among the Spanish troops against
Español. The English gladly availed themselves of this unfortunate affair to
strengthen their own position in Joló, stirring up the islanders against Spain and
erecting new forts. Later, however, the English at Balambangan showed so much
harshness and contempt for the Moro dattos (even putting one in the pillory) that the
latter plotted to surprise and kill the intruders; and on March 5, 1775, this was
accomplished, the English being all slain except the commandant and five others,
who managed to escape to their ship in the harbor. The fort was seized by the Moros,
who thus acquired great quantities of military supplies, arms, money, and food, with
several vessels.21 Among this spoil were forty-five cannons and $24,000 in silver.
Elated by this success, Tenteng, the chief mover of the enterprise, tried to secure
Zamboanga by similar means; but the new commandant there, Juan Bayot, was on
his guard, and the Moros were baffled. Tenteng then went to Cebú, where he
committed horrible ravages; and other raids of this sort were committed, the
Spaniards being unable to check them for a long time. A letter written to the king by
Anda in 1773 had asked for money to construct light armed vessels, and a royal
order of January 27, 1776, commanded that 50,000 pesos be sent to Filipinas for this
purpose. This money was employed by Anda’s temporary successor, Pedro Sarrio, in
the construction of a squadron of vintas, “vessels which, on account of their
swiftness and exceedingly light draft, were more suitable for the pursuit of the
pirates than the very heavy galleys; they were, besides, to carry pilots of the royal
fleet to reconnoiter the coasts, draw plans of the ports, indicate the shoals and reefs,
take soundings in the sea, etc.”

Notwithstanding the great services which Anda had rendered to his king and country,
his enemies succeeded in procuring from the Spanish government the revocation of
the sentences which had been pronounced in the suits brought by Anda (at the
instance of that very government, and as its representative) against Raon and other
corrupt officials; and Anda was condemned (by decrees in 1775–76) to pay the costs
in these suits, and the further sums of four thousand pesos to the heirs of Raon and
two thousand to the former fiscal, Juan Antonio Cosío. These unexpected and heavy
blows, added to the strain of his official responsibilities and the annoyances caused
by the attacks of his personal enemies, broke down Anda’s health; and he died at the
hospital of San Felipe, Cavite, on October 30, 1776, at the, age of sixty-six years.22

Sultan Israel of Joló was poisoned by the followers of his cousin Ali-Mudin, son of
Bantilan, who therefore assumed the government (early in 1778); immediately the
Moros renewed their raids on the Spanish provinces nearest them, and the
expeditions sent against them by Sarrio could do little to punish them.

In July, 1778, the new proprietary governor arrived at Manila; this was José de
Basco y Vargas, an officer in the Spanish royal navy. The officials of the Audiencia
forthwith sent a remonstrance to the court, against their being subordinated to a man
whose rank “gave him only the right to be addressed as ‘you’ while each one of the
magistrates [of the Audiencia] enjoyed the title of ‘Lordship,’ ” and they asked for
the revocation of Basco’s appointment: but of course this was refused, and they were
rebuked for their officiousness. As a result, the auditors opposed all that Basco
attempted, and even conspired to seize his person and put Sarrio in his place. That
officer, however, refused to join them, and informed the governor of the scheme; in
consequence, Basco arrested the recalcitrant auditors and other persons connected
with their plans (including Cencelly), and sent them all to Spain.23 Now free from
hindrances, he devoted himself to the administration of the government, the welfare
of the country, and the development of its resources.

“In a document entitled ‘A general economic plan,’ he extolled the advantages which
are inherent in the promotion and development of agriculture, commerce, and
industries. He offered therein to bestow rewards and distinctions on the persons who
should excel in agriculture, in making plantations of cotton, of mulberry trees, and of
the choicer spices, as cloves, cinnamon, pepper, and nutmeg; to those who should
establish manufactures of silk, porcelain, and fabrics of hemp, flax,24 and cotton like
those that were received from the Coromandel Coast, Malabar, and China; to those
who would undertake to work the mines of gold, iron, copper, and tin; to those who
should make discoveries useful to the State; and to those who should excel in
sciences, the liberal arts, and mechanics. He also circulated instructions in regard to
the method of cultivating and preparing for use cotton, silk, sugar, etc. He also, in
Camarines, compelled the planting of more than four millions of mulberry trees,
which for several years yielded an excellent product; but these important plantations
were abandoned after his term of office [expired].25 He improved the schools, and
aided the diffusion of knowledge by promoting the knowledge of the Castilian
language. In order to repress the boldness of the murderous highwaymen who
infested the roads in the provinces nearest to Manila, he appointed judges with
power of condemnation [jueces de acordada26]; these, accompanied by a counsellor
and an executioner, by summary process tried the malefactors whom they arrested in
their respective districts, and applied the penalty—a measure so efficacious that in a
short time there was complete security everywhere. The Audiencia appealed against
this measure, and the king issued a decree notifying the governor to abstain from
meddling in the jurisdiction of that court. In acknowledging the receipt of this
sovereign command, Basco remarked that ‘unfortunately it had arrived too late.’ As
war had been again declared between España and Inglaterra, Basco caused the
fortifications of Manila and Cavite, and the forts in the provinces, to be repaired,
changing a great part of the artillery therein for new pieces. He also reorganized the
army. In 1778 the order for the expulsion of the Chinese was revoked, and a
considerable number of them returned to Manila.

A royal decree of November 15, 1777, recommended the establishment of an


institution in which vagrants and dissolute persons might be shut up. Accordingly,
Manuel del Castillo y Negrete, minister of justice for the Philippines, drew up and
printed (Sampaloc, 1779) a manual of ordinances for the management of a general
refuge for poor persons, beggars, women of lewd life, abandoned children, and
orphans. For this project he had obtained the opinions of learned persons, all of
whom extolled it; and he sent this document to the king. Besides promoting all
interests of morality, and the development of agriculture, industry, and commerce,
Basco founded the noted “Economic Society of Friends of the Country.”27 A royal
decree dated August 27, 1780, had ordered him to convene all the learned or
competent persons in the colony, “in order to form an association of selected
persons, capable of producing useful ideas;” but when this decree arrived, Basco had
already founded the above society. On February 7, 1781, the active members of the
general tribunal [junta] of commerce had assembled, and agreed upon the
constitution of the society, a number of them signing their names as its members—
among them the Marqués de Villamediana, the prior of the consulate of commerce.
“The body of merchants endowed the society with a permanent fund of 960 pesos a
year, the value of two toneladas which were assigned to it in the lading of the
Acapulco galleon.” The society was formally inaugurated on May 6, 1781, under the
presidency of Basco, who made an eloquent address. Its first president was the
quartermaster-general of the islands, Ciríaco González Carvajal; according to its first
regulations, it contained the following sections: natural history, agriculture and rural
economy, factories and manufactures, internal and foreign commerce, industries, and
popular education. “Stimulated by Basco, the society undertook with great ardor to
promote the cultivation of indigo, cotton, cinnamon, and pepper, and the silk
industry, according to the orders published by the superior authority. The parish
priest of Tambóbong, Fray Matías Octavio, taught his parishioners to prepare the
indigo, presenting to the society the first specimens, which were adjudged to be of
superior quality. In 1784, the first shipment of this article to Europa was made in the
royal fragata ‘Asunción.’ The society also recommended that effort be made to attain
perfection in weaving and dyeing. (The society declined greatly after the departure
of its founder; and Aguilar roughly opposed it. In 1809 it was extinguished; two
years later, orders were received for its reëstablishment, but this was not
accomplished until 1819. In the following year, its constitution was remodeled; and
in 1821 it founded at its own cost a professorship of agriculture and an academy of
design, and established special instruction in dyeing. In 1824 it resolved to bestow
rewards on the most successful farmers; and it introduced from China martins, to
fight the locusts that were desolating the fields. In 1828 its constitution experienced
another revision; but during more than half a century it gave hardly any sign of its
existence. It had a flash of vitality in 1882, but soon fell again into a decline. To-day
[about 1893] there is hardly any indication that Manila remembers a society of this
sort; and, as it is not in the Guía de forasteros [“Guide for strangers”], it may be said
that it has ceased to exist.)

“Filipinas had been, until the arrival of the illustrious Basco y Vargas in the country,
a heavy burden on the capital, since every year the situado was sent in cash from
México to meet the obligations of the islands. In order to free España from this sort
of load, and to raise the country from its depressed condition, he conceived the vast
project of stimulating the cultivation of tobacco, by establishing a government
monopoly of it.28 He communicated his plan to the Spanish government; and by a
royal order of February 9, 1780, the monopoly of tobacco, similar to that which was
in force in the other dominions of the nation, was decreed. He immediately published
two proclamations, on December 13 and 25 respectively, in 1781, prohibiting the
sale, traffic, and manufacture of tobacco; and on February 16, 1782, he issued
(signed and sealed by himself), ‘Instructions which are given to all the commanders
or heads of the patrols, the provincial administrators, the market inspectors, and
other persons who are under obligation to prevent loss to the revenue from tobacco.’
These were directed to the prevention of smuggling, showing the way in which
investigations should be conducted—including the houses of parish priests, the
convents, colleges, and beaterios, the quarters of the soldiers, etc. He created a board
of direction for this revenue, a general office of administration or agency, and
subordinate offices to this in the provinces. Basco’s idea was strongly opposed by
various interests; but the governor’s energy was able to conquer this unjust
opposition, and the monopoly was organized on March 1, 1782; it constituted the
basis of the prosperity of the exchequer in that country, and its most important source
of revenue.

“The zealous governor visited the provinces in person, in order to inform himself of
their needs and to remedy these, compelling their governors and other functionaries
to fulfil their trusts as they should. He also organized various military expeditions to
occupy the Igorrot country.”
From the first, Basco did what he could to restrain the incursions of the Moro
pirates; but he had many difficulties to encounter. He repaired the forts in Mindanao
and the Visayan Islands; he built small vessels, and stationed them in Cebú, Iloilo,
Zamboanga, and Calamianes, from which points they could more promptly set out to
punish the Moros; and he sent an expedition to Mamburao, in Mindoro, which drove
out the pirates who, as we have already seen, had established themselves there.
These raids being thus checked for the time, trade began to improve; “and from
Sámar alone, whose traffic with Manila had been paralyzed for more than ten years,
forty-three caracoas went to the capital in 1779.” The sultan of Joló humbly asked
Basco for peace, and returned to the Spaniards a small vessel captured near Antique
by one of his dattos, “an unusual proceeding among the pirates.” The natives of
Bulacan voluntarily offered (December, 1781) to pay for the cost of two vessels to
sail against the pirates, and imposed on themselves for this purpose a tax of one-half
a real a year on each tribute; this proving insufficient, they increased it, in the
summer of 1784, with a ganta of unhulled rice per tribute. This example was
immediately followed by the natives of Pampanga. In 1782, the Visayas were
invaded by a Mindanao host; but on several occasions the Spaniards succeeded in
defeating the pirates and sinking many of their boats. Basco conquered the Batanes
Islands, north of Luzon,29 and this enterprise for a time diverted his military forces
from the Moros, who consequently increased their depredations on the Visayan
natives and carried away many captives from Calamianes, Panay, and Negros.

By royal orders of July 17 and 26, 1784, the post of quartermaster-general of the
islands was created, in accordance with a request by Basco; and that of deputy-
intendant of the exchequer was united with it, independent of the superior
government of the islands. It was placed in charge of one of the auditors, Ciriaco
González Carvajal, also at Basco’s recommendation; and from this time the royal
officials were styled “ministers of the royal exchequer.” Carvajal aided Basco greatly
in establishing the monopoly of tobacco, and it was he who drew up the instructions
to officials on this subject. In 1785, a dispute arose between them over the
establishment of the tobacco monopoly in Camarines and Albay, each regarding this
undertaking as the prerogative of his own office. Carvajal proposed that provincial
intendancies should be created in Ilocos, Camarines, Cebú, and Iloilo; this was done,
and approved by royal orders of November 24, 1786; but a year later the Spanish
government suppressed Carvajal’s office, and these provincial intendancies as well.

In 1785, there was a revolt of the heathen Indians in Ituy and Paniqui, headed by a
Calinga chief named Lagutao, who assembled over 1,200 men; but it was put down
by a force of 300 musketeers sent from Cagayán, and Lagutao was killed in battle. A
royal decree of February 25, 1785, ordered the immediate expulsion of all Chinese
from Manila,30 allowing the governor to fix a place outside the walls where a small
number of them might reside, under supervision; and another decree (April 1, 1785)
approved the foundation of a colony of 200 Chinese on Lake Candaba, in Pampanga.
At Carvajal’s instance, a monopoly was decreed (November 4, 1786) on gunpowder
in Filipinas. In the following year, instructions for the execution of this measure
were issued (December 11); and about the same time the monopoly of wines was
placed in control of the exchequer.

The constant opposition to Basco’s reforms and efforts which he encountered finally
wore out his patience, and he offered his resignation; at first it was not accepted, but
he insisted, and the king allowed him to hand over the government of the islands to
Pedro Sarrio. Basco embarked for Spain at the end of November, 1787, and for his
eminent services was promoted in the navy, ennobled, and made governor of
Cartagena. Montero y Vidal praises in high terms the character and achievements of
this distinguished governor, who had secured for Filipinas greater benefits than had
any other, establishing its revenues on a firm basis, introducing most important
reforms, and advancing its material and moral progress; but he was assailed by “the
envy, rivalry, spite, insane hatred, and lack of patriotism of the auditors, merchants,
and other classes, who were governed by base motives and despicable passions, or
by ignorance and covetousness.”

The natives in northern Ilocos were displeased at the monopolies31 on tobacco and
wines, and revolted; but the alcalde-mayor of the province went to meet them, with
Fray Agustín Pedro Blaquier,32 cura of Batao, and persuaded the insurgents to
disperse without bloodshed. Sarrio held the office of governor but six months. After
the death of Archbishop Santa Justa (December 15, 1787), he found it necessary to
allow the regular priests to resume the charge of the parishes, as is shown in the
following extract from his letter to the king, dated a week after that event, explaining
his reasons for this course: “First, because in temporal matters as well as in spiritual
is seen a manifest and notorious difference between the villages administered by the
regulars and those which are in charge of the seculars of Indian and mestizo
(Sangley and Chinese) birth; these are almost the only ones dedicated to the cure of
souls, for in all the islands hardly six curas can be named who are Spaniards or
Spanish mestizos. It can be said, in general, that the villages which are under the
direction of the regulars have adequate spiritual nourishment, which cannot be
asserted of those which are in charge of the Indians and mestizos. These, when they
receive the name of priest, are not thereby deprived of that innate negligence and
indolence with which nature has endowed all these islanders; and hence it results
that, given up to idleness, gambling, and other [like] pursuits, they abandon study,
and begin to lose whatever fitness [for the office] they may have possessed at the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like