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

Programming For Computations - Python: A Gentle Introduction To Numerical Simulations With Python 3.6 Svein Linge - Download the full ebook now to never miss any detail

The document promotes a collection of ebooks focused on programming with Python, particularly for scientific and engineering applications. It highlights the importance of programming skills for understanding and solving complex mathematical problems, emphasizing the integration of programming into educational curricula. The book 'Programming for Computations - Python' serves as a foundational resource for beginners, covering essential programming concepts and numerical methods using Python.

Uploaded by

ashiyemerang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
24 views

Programming For Computations - Python: A Gentle Introduction To Numerical Simulations With Python 3.6 Svein Linge - Download the full ebook now to never miss any detail

The document promotes a collection of ebooks focused on programming with Python, particularly for scientific and engineering applications. It highlights the importance of programming skills for understanding and solving complex mathematical problems, emphasizing the integration of programming into educational curricula. The book 'Programming for Computations - Python' serves as a foundational resource for beginners, covering essential programming concepts and numerical methods using Python.

Uploaded by

ashiyemerang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

Explore the full ebook collection and download it now at 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/

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!

Introduction to Scientific Programming with Python Joakim


Sundnes

https://textbookfull.com/product/introduction-to-scientific-
programming-with-python-joakim-sundnes/

textbookfull.com

Python for kids a playful introduction to programming 1st


Edition Briggs

https://textbookfull.com/product/python-for-kids-a-playful-
introduction-to-programming-1st-edition-briggs/

textbookfull.com

Bite Size Python An Introduction to Python Programming 1st


Edition April Speight

https://textbookfull.com/product/bite-size-python-an-introduction-to-
python-programming-1st-edition-april-speight/

textbookfull.com

Introduction to Computation and Programming Using Python


with Application to Understanding Data Guttag

https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-with-application-to-understanding-data-
guttag/
textbookfull.com
Python Projects for Beginners: A Ten-Week Bootcamp
Approach to Python Programming Milliken

https://textbookfull.com/product/python-projects-for-beginners-a-ten-
week-bootcamp-approach-to-python-programming-milliken/

textbookfull.com

Python Basics A Practical Introduction to Python 3


Fletcher Heisler

https://textbookfull.com/product/python-basics-a-practical-
introduction-to-python-3-fletcher-heisler/

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/

textbookfull.com

A Concise Introduction to Programming in Python Second


Edition Mark J. Johnson

https://textbookfull.com/product/a-concise-introduction-to-
programming-in-python-second-edition-mark-j-johnson/

textbookfull.com

Introduction to GIS Programming and Fundamentals with


Python and ArcGIS 1st Edition Chaowei Yang

https://textbookfull.com/product/introduction-to-gis-programming-and-
fundamentals-with-python-and-arcgis-1st-edition-chaowei-yang/

textbookfull.com
15

Svein Linge · Hans Petter Langtangen

Programming for
Computations –
Python
Second Edition Editorial Board
T. J.Barth
M.Griebel
D.E.Keyes
R.M.Nieminen
D.Roose
T.Schlick
Texts in Computational
Science and Engineering
15

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

Programming for
Computations - Python
A Gentle Introduction to Numerical
Simulations with Python 3.6

Second Edition
Svein Linge Hans Petter Langtangen
Fac of Tech, Natural Sci & Maritime Sci Simula Research Laboratory BioComp
University of South-Eastern Norway Lysaker, Norway
Porsgrunn, Norway

ISSN 1611-0994 ISSN 2197-179X (electronic)


Texts in Computational Science and Engineering
ISBN 978-3-030-16876-6 ISBN 978-3-030-16877-3 (eBook)
https://doi.org/10.1007/978-3-030-16877-3

Mathematics Subject Classification (2010): 26-01, 34A05, 34A30, 34A34, 39-01, 40-01, 65D15,
65D25, 65D30, 68-01, 68N01, 68N19, 68N30, 70-01, 92D25, 97-04, 97U50

This book is an open access publication.

© The Editor(s) (if applicable) and The Author(s) 2020


Open Access This book is licensed under the terms of the Creative Commons Attribution 4.0 Inter-
national License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation,
distribution and reproduction in any medium or format, as long as you give appropriate credit to the
original author(s) and the source, provide a link to the Creative Commons licence and indicate if changes
were made.
The images or other third party material in this book are included in the book’s Creative Commons
licence, unless indicated otherwise in a credit line to the material. If material is not included in the
book’s Creative Commons licence and your intended use is not permitted by statutory regulation or
exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this
publication does not imply, even in the absence of a specific statement, that such names are exempt
from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors, and the editors are safe to assume that the advice and information in this
book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors
or the editors give a warranty, express or implied, with respect to the material contained herein or for any
errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Springer imprint is published by the registered company Springer Nature Switzerland AG.
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
To My Family
Thanks to my dear wife, Katrin, and our lovely
children, Stian, Mia, and Magnus, for their love,
support, and patience. I am a very lucky man.

To Hans Petter
Dear friend and coauthor, it is so sad you are no
longer among us.1 Thank you for everything. I
dedicate this second edition of our book to you.

Porsgrunn, Norway Svein Linge


June 2018

1 Professor Hans Petter Langtangen (https://en.wikipedia.org/wiki/Hans_Petter_Langtangen)


passed away with cancer on the 10th of October, 2016.
Preface

Computing, in the sense of doing mathematical calculations, is a skill that mankind


has developed over thousands of years. Programming, on the other hand, is in
its infancy, with a history that spans a few decades only. Both topics are vastly
comprehensive and usually taught as separate subjects in educational institutions
around the world, especially at the undergraduate level. This book is about the
combination of the two, because computing today becomes so much more powerful
when combined with programming.
Most universities and colleges implicitly require students to specialize in com-
puter science if they want to learn the craft of programming, since other student
programs usually do not offer programming to an extent demanded for really
mastering this craft. Common arguments claim that it is sufficient with a brief
introduction, that there is not enough room for learning programming in addition
to all other must-have subjects, and that there is so much software available that
few really need to program themselves. A consequence is that engineering students
often graduate with shallow knowledge about programming, unless they happened
to choose the computer science direction.
We think this is an unfortunate situation. There is no doubt that practicing
engineers and scientists need to know their pen-and-paper mathematics. They must
also be able to run off-the-shelf software for important standard tasks and will
certainly do that a lot. Nevertheless, the benefits of mastering programming are
many.

Why Learn Programming?

1. Ready-made software is limited to handling certain standard problems. What do


you do when the problem at hand is not covered by the software you bought?
Fortunately, a lot of modern software systems are extensible via programming.
In fact, many systems demand parts of the problem specification (e.g., material
models) to be specified by computer code.
2. With programming skills, you may extend the flexibility of existing software
packages by combining them. For example, you may integrate packages that do
not speak to each other from the outset. This makes the work flow simpler, more
efficient, and more reliable, and it puts you in a position to attack new problems.

vii
viii Preface

3. It is easy to use excellent ready-made software the wrong way. The insight
in programming and the mathematics behind is fundamental for understanding
complex software, avoiding pitfalls, and becoming a safe user.
4. Bugs (errors in computer code) are present in most larger computer programs
(also in the ones from the shop!). What do you do when your ready-made
software gives unexpected results? Is it a bug, is it the wrong use, or is it the
mathematically correct result? Experience with programming of mathematics
gives you a good background for answering these questions. The one who can
program can also make tailored code for a simplified problem setting and use
that to verify the computations done with off-the-shelf software.
5. Lots of skilled people around the world solve computational problems by writing
their own code and offering those for free on the Internet. To take advantage of
this truly great source of software in a reliable way, one must normally be able
to understand and possibly modify computer code offered by others.
6. It is recognized worldwide that students struggle with mathematics and physics.
Too many find such subjects difficult and boring. With programming, we can
execute the good old subjects in a brand new way! According to the authors’
own experience, students find it much more motivating and enlightening when
programming is made an integrated part of mathematics and physical science
courses. In particular, the problem being solved can be much more realistic than
when the mathematics is restricted to what you can do with pen and paper.
7. Finally, we launch our most important argument for learning computer program-
ming: the algorithmic thinking that comes with the process of writing a program
for a computational problem enforces a thorough understanding of both the
problem and the solution method. We can simply quote the famous Norwegian
computer scientist Kristen Nygaard: “Programming is understanding.”

In the authors’ experience, programming is an excellent pedagogical tool for


understanding mathematics: “You think you know when you can learn, are more
sure when you can write, even more when you can teach, but certain when you
can program” (Alan Perlis, computer scientist, 1922–1990). Consider, for example,
integration. A numerical method for integration has a much stronger focus on what
the integral actually is and means compared to analytical methods, where much
time and effort must be devoted to integration by parts, integration by substitution,
etc. Moreover, when programming the numerical integration formula, it becomes
evident that it works for “all” mathematical functions and that the implementation
should be in terms of a general function applicable to “all” integrals. In this way,
students learn to recognize a special problem as belonging to a class of problems
(e.g., integration, differential equations, root finding), for which we have general
numerical methods implemented in a widely applicable software. When they write
this software, as we do in this book, they learn how to generalize and increase the
abstraction level of the mathematical problem. When they use this software, they
learn how a special case should be attacked by general methods and software for
the class of problems that comprises the special case at hand. This is the power of
mathematics in a nutshell, and it is paramount that students understand this way of
thinking.
Preface ix

Target Audience and Background Knowledge This book was written for
students, teachers, engineers, and scientists who know nothing about programming
and numerical methods from before but who seek a minimum of the fundamental
skills required to get started with programming as a tool for solving scientific
and engineering problems. Some knowledge of one- and multivariable calculus
is assumed. The basic programming concepts are presented in Chaps. 1–5 (about
150 pages), before practical applications of these concepts are demonstrated in
important mathematical subjects addressed in the remaining parts of the book
(Chaps. 6–9). Each chapter is followed by a set of exercises that covers a wide range
of application areas, e.g., biology, geology, statistics, physics, and mathematics.
The exercises were particularly designed to bring across important points from the
text.
Learning the very basics of programming should not take long, but as with any
other craft, mastering the skill requires continued and extensive practice. Some
beginning practice is gained through Chaps. 6–9, but the authors strongly emphasize
that this is only a start. Students should continue to practice programming in
subsequent courses, while those who exercise self-study should keep up the learning
process through continued application of the craft. The book is a good starting point
when teaching computer programming as an integrated part of standard university
courses in mathematics and natural science. In our experience, such an integration
is doable and indeed rewarding.

Numerical Methods An overall goal with this book is to motivate computer pro-
gramming as a very powerful tool for doing mathematics. All examples are related to
mathematics and its use in engineering and science. However, to solve mathematical
problems through computer programming, we need numerical methods. Explaining
basic numerical methods is therefore an integral part of the book. Our choice of
topics is governed by what is most needed in science and engineering, as well as
in the teaching of applied natural science courses. Mathematical models are then
central, with differential equations constituting the most frequent type of models.
Consequently, the numerical focus in this book is on differential equations. As soft
pedagogical starters for the programming of mathematics, we have chosen the topics
of numerical integration and root finding. We remark that the book is deliberately
brief on numerical methods. This is because our focus is on implementing numerical
algorithms, and to develop reliable, working programs, the programmer must be
confident about the basic ideas of the numerical approximations involved.

The Computer Language: Python We have chosen to use the programming


language Python, because this language gives a very compact and readable code
that closely resembles the mathematical recipe for solving the problem at hand.
Python also has a gentle learning curve.
Other computer languages, like Fortran, C, and C++, have a strong position in
science and engineering. During the last two decades, however, there has been a
significant shift in popularity from these compiled languages to more high-level and
easier-to-read languages, for instance, MATLAB, Python, R, Maple, Mathematica,
and IDL. This latter class of languages is computationally less efficient but superior
with respect to overall human problem-solving efficiency. This book emphasizes
x Preface

how to think like a programmer, rather than focusing on technical language


details. Thus, the book should put the reader in a good position for learning other
programming languages later, including the classic ones: Fortran, C, and C++.

How This Book Is Different There are numerous texts on computer programming
and numerical methods, so how does the present one differ from the existing
literature? Compared to standard books on numerical methods, our book has a much
stronger emphasis on the craft of programming and on verification. We want to give
students a thorough understanding of how to think about programming as a problem-
solving method and how to provide convincing evidence for program correctness.
Even though there are lots of books on numerical methods where many algo-
rithms have a corresponding computer implementation (see, e.g., [1, 3–6, 10, 15–
17, 20, 23, 25, 27–31]—the latter two apply Python), it is often assumed that the
reader “can program” beforehand. The present book teaches the craft of structured
programming along with the fundamental ideas of numerical methods. In this book,
unit testing and corresponding test functions are introduced early on. We also put
much emphasis on coding algorithms as functions, as opposed to “flat programs,”
which often dominate in the literature and among practitioners. Functions are
reusable because they utilize the general formulation of a mathematical algorithm
such that it becomes applicable to a large class of problems.
There are also numerous books on computer programming, but not many that
really emphasize how to think about programming in the context of numerical
methods and scientific applications. One such book is [11], which gives a compre-
hensive introduction to Python programming and the thinking about programming
as a computer scientist.
Sometimes, however, one needs a text like the present one. It does not go so
deep into language-specific details, but rather targets the shortest path to reliable
mathematical problem-solving through programming. With this attitude in mind, a
lot of topics were left out of the present book, simply because they were not strictly
needed in the mathematical problem-solving process. Examples of such topics are
object-oriented programming and Python dictionaries (of which the latter omission
is possibly subject to more debate). If you find the present book too shallow, [11]
might be the right choice for you. That source should also work nicely as a more
in-depth successor of the present text.
Whenever the need for a structured introduction to programming arises in science
and engineering courses, the present book may be your option, either for self-study
or for use in organized teaching. The thinking, habits, and practice covered herein
will put readers in a firm position for utilizing and understanding the power of
computers for problem-solving in science and engineering.

Changes to the First Edition

1. All code is now in Python version 3.6 (the previous edition was based on Python
version 2.7).
2. In the first edition, the introduction to programming was basically covered in 50
pages by Chap. 1 (The First Few Steps) and Chap. 2 (Basic Constructions). This
is enough to get going, but many readers soon want more details. In this second
edition, these two chapters have therefore been extended and split up into five
Preface xi

chapters. Explanations are now more complete, previous examples have been
modified, new examples have been added, and more. In particular, the importing
of code is now elaborated on in a greater detail, so is the making of modules.
Also, Sect. 4.2 is new, illustrating the important stepwise strategy of code writing
through a dedicated example. The five first chapters now cover about 150 pages
that explain, in a brief and simple manner, all the code basics required to follow
the remaining parts of the book.
3. The new Chap. 6 (Computing Integrals and Testing Code) and Chap. 7 (Solving
Nonlinear Algebraic Equations) are seen as gentle first applications of program-
ming to problem-solving in mathematics. Both these chapters now precede the
mathematically more challenging Chaps. 8 and 9, which treat basic numerical
solving of ODEs and PDEs, respectively (the chapter Solving Nonlinear Alge-
braic Equations was, in the first edition, the final chapter of the book, but it
seems more appropriate to let it act as a “warm-up” chapter, together with the
new Chap. 6, for the two final chapters on differential equation solving).
4. Section 8.1 (Filling a Water Tank: Two Cases) is new, particularly written for
readers who lack experience with differential equations.
5. Section 8.5 (Rate of Convergence) is new, explaining convergence rate related to
differential equations.
6. New exercises have been added, e.g., on Fibonacci numbers, the Leapfrog
method, Adams-Bashforth methods, and more.
7. Errors and typos have been corrected, and many explanations have been refor-
mulated throughout.

Supplementary Materials All program and data files referred to herein are
available from the book’s (2nd edition) primary web site:
https://github.com/slgit/prog4comp_2.

Acknowledgments We want to thank all students who attended the courses


FM1006 Modelling and simulation of dynamic systems, FM1115 Scientific Comput-
ing, FB1012 Mathematics, and FB2112 Physics at the University of South-Eastern
Norway over the last 5–10 years. They worked their way through early versions of
this text and gave us constructive and positive feedback that helped us correct errors
and improve the book in so many ways. Special acknowledgment goes to Guandong
Kou, Edirisinghe V. P. J. Manjula, and Yapi Donatien Achou for their careful reading
of the manuscript (first edition) and constructive suggestions for improvement. The
constructive feedback and good suggestions received from Om Prakash Chapagain
(second edition) is also highly appreciated. We thank all our good colleagues at the
University of South-Eastern Norway, the University of Oslo, and Simula Research
Laboratory for their continued support and interest, for the enlightening discussions,
and for providing such an inspiring environment for teaching and science.
Special thanks go to Prof. Kent-Andre Mardal, the University of Oslo, for his
insightful comments and suggestions.
xii Preface

The authors would also like to thank the Springer team with Dr. Martin Peters,
Thanh-Ha Le Thi, and Leonie Kunz for the effective editorial and production
process.
This text was written in the DocOnce1 [12] markup language.

Lysaker, Norway Hans Petter Langtangen


December 2015
Porsgrunn, Norway Svein Linge
June 2018

1 https://github.com/hplgit/doconce.
Abstract

This second edition of the book presents computer programming as a key method
for solving mathematical problems and represents a major revision: all code is now
written in Python version 3.6 (the first edition was based on Python version 2.7).
The first two chapters of the previous edition have been extended and split up into
five new chapters, thus expanding the introduction to programming from 50 to 150
pages. Throughout, explanations are now more complete, previous examples have
been modified, and new sections, examples, and exercises have been added. Also,
errors and typos have been corrected. The book was inspired by the Springer book
TCSE 6, A Primer on Scientific Programming with Python (by Langtangen), but
the style is more accessible and concise in keeping with the needs of engineering
students. The book outlines the shortest possible path from no previous experience
with programming to a set of skills that allows the students to write simple programs
for solving common mathematical problems with numerical methods in engineering
and science courses. The emphasis is on generic algorithms, clean design of
programs, use of functions, and automatic tests for verification.

xiii
Contents

1 The First Few Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


1.1 What Is a Program? And What Is Programming? . . . . . . . . . . . . . . . . 1
1.1.1 Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 A Python Program with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.1 The Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 Dissecting the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.3 Why Use Variables? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.4 Mathematical Notation Versus Coding . . . . . . . . . . . . . . . . . 10
1.2.5 Write and Run Your First Program . . . . . . . . . . . . . . . . . . . . 10
1.3 A Python Program with a Library Function . . . . . . . . . . . . . . . . . . . . . 12
1.4 Importing from Modules and Packages . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4.1 Importing for Use Without Prefix . . . . . . . . . . . . . . . . . . . . . . 14
1.4.2 Importing for Use with Prefix . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.3 Imports with Name Change . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.4 Importing from Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.5 The Modules/Packages Used in This Book . . . . . . . . . . . . . . 19
1.5 A Python Program with Vectorization and Plotting . . . . . . . . . . . . . . 19
1.6 Plotting, Printing and Input Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.6.1 Plotting with Matplotlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.6.2 Printing: The String Format Method . . . . . . . . . . . . . . . . . . . 27
1.6.3 Printing: The f-String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.6.4 User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.7 Error Messages and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.8 Concluding Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.8.1 Programming Demands You to Be Accurate! . . . . . . . . . . . . 34
1.8.2 Write Readable Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.8.3 Fast Code or Slower and Readable Code? . . . . . . . . . . . . . . 35
1.8.4 Deleting Data No Longer in Use . . . . . . . . . . . . . . . . . . . . . . 36
1.8.5 Code Lines That Are Too Long . . . . . . . . . . . . . . . . . . . . . . . 36
1.8.6 Where to Find More Information? . . . . . . . . . . . . . . . . . . . . . 36
1.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

xv
xvi Contents

2 A Few More Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39


2.1 Using Python Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.1.1 The IPython Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.1.2 Command History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.1.3 TAB Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.2 Variables, Objects and Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.2.1 Choose Descriptive Variable Names . . . . . . . . . . . . . . . . . . . 41
2.2.2 Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.2.3 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.2.4 Object Type and Type Conversion . . . . . . . . . . . . . . . . . . . . . 42
2.2.5 Automatic Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.2.6 Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.2.7 Division—Quotient and Remainder . . . . . . . . . . . . . . . . . . . 45
2.2.8 Using Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.2.9 Round-Off Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.2.10 Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.3 Numerical Python Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.3.1 Array Creation and Array Elements . . . . . . . . . . . . . . . . . . . 47
2.3.2 Indexing an Array from the End . . . . . . . . . . . . . . . . . . . . . . 50
2.3.3 Index Out of Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.3.4 Copying an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.3.5 Slicing an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.3.6 Two-Dimensional Arrays and Matrix Computations . . . . . . 52
2.4 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3 Loops and Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.1 The for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.1.1 Example: Printing the 5 Times Table . . . . . . . . . . . . . . . . . . . 59
3.1.2 Characteristics of a Typical for Loop . . . . . . . . . . . . . . . . . . . 60
3.1.3 Combining for Loop and Array . . . . . . . . . . . . . . . . . . . . . . . 62
3.1.4 Using the range Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.1.5 Using break and continue . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.2 The while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.2.1 Example: Finding the Time of Flight . . . . . . . . . . . . . . . . . . . 65
3.2.2 Characteristics of a Typical while Loop . . . . . . . . . . . . . . . . 66
3.3 Branching (if, elif and else) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.3.1 Example: Judging the Water Temperature . . . . . . . . . . . . . . 68
3.3.2 The Characteristics of Branching . . . . . . . . . . . . . . . . . . . . . . 70
3.3.3 Example: Finding the Maximum Height . . . . . . . . . . . . . . . . 70
3.3.4 Example: Random Walk in Two Dimensions . . . . . . . . . . . . 72
3.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4 Functions and the Writing of Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.1 Functions: How to Write Them? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.1.1 Example: Writing Our First Function . . . . . . . . . . . . . . . . . . 79
4.1.2 Characteristics of a Function Definition . . . . . . . . . . . . . . . . 80
4.1.3 Functions and the Main Program . . . . . . . . . . . . . . . . . . . . . . 82
4.1.4 Local Versus Global Variables . . . . . . . . . . . . . . . . . . . . . . . . 83
Contents xvii

4.1.5 Calling a Function Defined with Positional Parameters . . . 83


4.1.6 A Function with Two Return Values . . . . . . . . . . . . . . . . . . . 85
4.1.7 Calling a Function Defined with Keyword Parameters . . . . 85
4.1.8 A Function with Another Function as Input Argument . . . . 86
4.1.9 Lambda Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.1.10 A Function with Several Return Statements . . . . . . . . . . . . . 87
4.2 Programming as a Step-Wise Strategy . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.2.1 Making a Times Tables Test . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.2.2 The 1st Version of Our Code . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.2.3 The 2nd Version of Our Code . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2.4 The 3rd Version of Our Code . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5 Some More Python Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.1 Lists and Tuples: Alternatives to Arrays . . . . . . . . . . . . . . . . . . . . . . . 103
5.2 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.2.1 The Fourth Version of Our Times Tables Program . . . . . . . . 106
5.3 Symbolic Computations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
5.3.1 Numerical Versus Symbolic Computations . . . . . . . . . . . . . . 111
5.3.2 SymPy: Some Basic Functionality . . . . . . . . . . . . . . . . . . . . . 112
5.3.3 Symbolic Calculations with Some Other Tools . . . . . . . . . . 112
5.4 Making Our Own Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.4.1 A Naive Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
5.4.2 A Module for Vertical Motion . . . . . . . . . . . . . . . . . . . . . . . . 115
5.4.3 Module or Program? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
5.5 Files: Read and Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
5.6 Measuring Execution Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.6.1 The timeit Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
6 Computing Integrals and Testing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
6.1 Basic Ideas of Numerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . 132
6.2 The Composite Trapezoidal Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
6.2.1 The General Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
6.2.2 A General Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
6.2.3 A Specific Implementation: What’s the Problem? . . . . . . . . 139
6.3 The Composite Midpoint Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
6.3.1 The General Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
6.3.2 A General Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
6.3.3 Comparing the Trapezoidal and the Midpoint Methods . . . 145
6.4 Vectorizing the Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
6.4.1 Vectorizing the Midpoint Rule . . . . . . . . . . . . . . . . . . . . . . . . 146
6.4.2 Vectorizing the Trapezoidal Rule . . . . . . . . . . . . . . . . . . . . . . 147
6.4.3 Speed up Gained with Vectorization . . . . . . . . . . . . . . . . . . . 148
6.5 Rate of Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
6.6 Testing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
6.6.1 Problems with Brief Testing Procedures . . . . . . . . . . . . . . . . 150
6.6.2 Proper Test Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
xviii Contents

6.6.3 Finite Precision of Floating-Point Numbers . . . . . . . . . . . . . 153


6.6.4 Constructing Unit Tests and Writing Test Functions . . . . . . 155
6.7 Double and Triple Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
6.7.1 The Midpoint Rule for a Double Integral . . . . . . . . . . . . . . . 157
6.7.2 The Midpoint Rule for a Triple Integral . . . . . . . . . . . . . . . . 161
6.7.3 Monte Carlo Integration for Complex-Shaped Domains . . . 163
6.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
7 Solving Nonlinear Algebraic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
7.1 Brute Force Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
7.1.1 Brute Force Root Finding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
7.1.2 Brute Force Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
7.1.3 Model Problem for Algebraic Equations . . . . . . . . . . . . . . . . 180
7.2 Newton’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
7.2.1 Deriving and Implementing Newton’s Method . . . . . . . . . . 181
7.2.2 Making a More Efficient and Robust Implementation . . . . . 184
7.3 The Secant Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
7.4 The Bisection Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
7.5 Rate of Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
7.6 Solving Multiple Nonlinear Algebraic Equations . . . . . . . . . . . . . . . . 195
7.6.1 Abstract Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
7.6.2 Taylor Expansions for Multi-Variable Functions . . . . . . . . . 195
7.6.3 Newton’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
7.6.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
7.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
8 Solving Ordinary Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . 203
8.1 Filling a Water Tank: Two Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
8.1.1 Case 1: Piecewise Constant Rate . . . . . . . . . . . . . . . . . . . . . . 205
8.1.2 Case 2: Continuously Increasing Rate . . . . . . . . . . . . . . . . . . 207
8.1.3 Reformulating the Problems as ODEs . . . . . . . . . . . . . . . . . . 209
8.2 Population Growth: A First Order ODE . . . . . . . . . . . . . . . . . . . . . . . . 210
8.2.1 Derivation of the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
8.2.2 Numerical Solution: The Forward Euler (FE) Method . . . . 213
8.2.3 Programming the FE Scheme; the Special Case . . . . . . . . . . 217
8.2.4 Understanding the Forward Euler Method . . . . . . . . . . . . . . 219
8.2.5 Programming the FE Scheme; the General Case . . . . . . . . . 220
8.2.6 A More Realistic Population Growth Model . . . . . . . . . . . . 221
8.2.7 Verification: Exact Linear Solution of the Discrete
Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
8.3 Spreading of Disease: A System of First Order ODEs . . . . . . . . . . . . 225
8.3.1 Spreading of Flu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
8.3.2 A FE Method for the System of ODEs . . . . . . . . . . . . . . . . . 228
8.3.3 Programming the FE Scheme; the Special Case . . . . . . . . . . 229
8.3.4 Outbreak or Not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
8.3.5 Abstract Problem and Notation . . . . . . . . . . . . . . . . . . . . . . . 232
8.3.6 Programming the FE Scheme; the General Case . . . . . . . . . 232
8.3.7 Time-Restricted Immunity . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Contents xix

8.3.8 Incorporating Vaccination . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236


8.3.9 Discontinuous Coefficients: A Vaccination Campaign . . . . 237
8.4 Oscillating 1D Systems: A Second Order ODE . . . . . . . . . . . . . . . . . 239
8.4.1 Derivation of a Simple Model . . . . . . . . . . . . . . . . . . . . . . . . 240
8.4.2 Numerical Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
8.4.3 Programming the FE Scheme; the Special Case . . . . . . . . . . 242
8.4.4 A Magic Fix of the Numerical Method . . . . . . . . . . . . . . . . . 243
8.4.5 The Second-Order Runge-Kutta Method (or Heun’s
Method) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
8.4.6 Software for Solving ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . 249
8.4.7 The Fourth-Order Runge-Kutta Method . . . . . . . . . . . . . . . . 254
8.4.8 More Effects: Damping, Nonlinearity, and External
Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
8.4.9 Illustration of Linear Damping . . . . . . . . . . . . . . . . . . . . . . . . 260
8.4.10 Illustration of Linear Damping with Sinusoidal
Excitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
8.4.11 Spring-Mass System with Sliding Friction . . . . . . . . . . . . . . 264
8.4.12 A Finite Difference Method; Undamped, Linear Case . . . . 266
8.4.13 A Finite Difference Method; Linear Damping . . . . . . . . . . . 268
8.5 Rate of Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
8.5.1 Asymptotic Behavior of the Error . . . . . . . . . . . . . . . . . . . . . 270
8.5.2 Computing the Convergence Rate . . . . . . . . . . . . . . . . . . . . . 270
8.5.3 Test Function: Convergence Rates for the FE Solver . . . . . . 272
8.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
9 Solving Partial Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
9.1 Example: Temperature Development in a Rod . . . . . . . . . . . . . . . . . . 288
9.1.1 A Particular Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
9.2 Finite Difference Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
9.2.1 Reduction of a PDE to a System of ODEs . . . . . . . . . . . . . . 290
9.2.2 Construction of a Test Problem with Known Discrete
Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
9.2.3 Implementation: Forward Euler Method . . . . . . . . . . . . . . . . 293
9.2.4 Animation: Heat Conduction in a Rod . . . . . . . . . . . . . . . . . 295
9.2.5 Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
9.2.6 Using Odespy to Solve the System of ODEs . . . . . . . . . . . . 299
9.2.7 Implicit Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
9.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303

A Installation and Use of Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311


A.1 Recommendation: Install Anaconda and Odespy . . . . . . . . . . . . . . . . 311
A.2 Required Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
A.3 Anaconda and Spyder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
A.3.1 Spyder on Mac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
A.3.2 Installation of Additional Packages . . . . . . . . . . . . . . . . . . . . 313
A.4 How to Write and Run a Python Program . . . . . . . . . . . . . . . . . . . . . . 314
A.4.1 Spyder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
A.4.2 Text Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
xx Contents

A.4.3 Terminal Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315


A.4.4 Using a Plain Text Editor and a Terminal Window . . . . . . . 315
A.5 Python with Jupyter Notebooks and Web Services . . . . . . . . . . . . . . . 316

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
List of Exercises

Exercise 1.1: Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37


Exercise 1.2: Volume of a Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.3: Area and Circumference of a Circle . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.4: Volumes of Three Cubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exercise 1.5: Average of Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Exercise 1.6: Formatted Print to Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Exercise 2.1: Interactive Computing of Volume . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.2: Interactive Computing of Circumference and Area . . . . . . . . . . . 56
Exercise 2.3: Update Variable at Command Prompt . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.4: Multiple Statements on One Line . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercise 2.5: Boolean Expression—Even or Odd Number? . . . . . . . . . . . . . . . . 57
Exercise 2.6: Plotting Array Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Exercise 2.7: Switching Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Exercise 2.8: Drawing Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exercise 3.1: A for Loop with Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.2: The range Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.3: A while Loop with Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.4: while Loop Instead of for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.5: Compare Integers a and b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Exercise 3.6: Area of Rectangle Versus Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.7: Frequency of Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.8: Game 21 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Exercise 3.9: Simple Search: Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 3.10: Sort Array with Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 3.11: Compute π . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercise 4.1: Errors with Colon, Indent, etc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Exercise 4.2: Reading Code 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Exercise 4.3: Reading Code 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Exercise 4.4: Functions for Circumference and Area of a Circle . . . . . . . . . . . . 98
Exercise 4.5: Function for Adding Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Exercise 4.6: Function for Area of a Rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.7: Average of Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.8: When Does Python Check Function Syntax? . . . . . . . . . . . . . . . . 99
Exercise 4.9: Find Crossing Points of Two Graphs . . . . . . . . . . . . . . . . . . . . . . . 99
xxi
xxii List of Exercises

Exercise 4.10: Linear Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99


Exercise 4.11: Test Straight Line Requirement . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Exercise 4.12: Fit Straight Line to Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Exercise 4.13: Fit Sines to Straight Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Exercise 5.1: Nested for Loops and Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Exercise 5.2: Exception Handling: Divisions in a Loop . . . . . . . . . . . . . . . . . . . 125
Exercise 5.3: Taylor Series, sympy and Documentation . . . . . . . . . . . . . . . . . . . 125
Exercise 5.4: Fibonacci Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Exercise 5.5: Read File: Total Volume of Boxes . . . . . . . . . . . . . . . . . . . . . . . . . 127
Exercise 5.6: Area of a Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Exercise 5.7: Count Occurrences of a String in a String . . . . . . . . . . . . . . . . . . . 128
Exercise 5.8: Compute Combinations of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Exercise 6.1: Hand Calculations for the Trapezoidal Method . . . . . . . . . . . . . . 169
Exercise 6.2: Hand Calculations for the Midpoint Method . . . . . . . . . . . . . . . . . 169
Exercise 6.3: Compute a Simple Integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Exercise 6.4: Hand-Calculations with Sine Integrals . . . . . . . . . . . . . . . . . . . . . . 169
Exercise 6.5: Make Test Functions for the Midpoint Method . . . . . . . . . . . . . . . 169
Exercise 6.6: Explore Rounding Errors with Large Numbers . . . . . . . . . . . . . . . 169
4√
Exercise 6.7: Write Test Functions for 0 xdx . . . . . . . . . . . . . . . . . . . . . . . . . 170
Exercise 6.8: Rectangle Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Exercise 6.9: Adaptive Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Exercise 6.10: Integrating x Raised to x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Exercise 6.11: Integrate Products of Sine Functions . . . . . . . . . . . . . . . . . . . . . . 172
Exercise 6.12: Revisit Fit of Sines to a Function . . . . . . . . . . . . . . . . . . . . . . . . . 172
Exercise 6.13: Derive the Trapezoidal Rule for a Double Integral . . . . . . . . . . . 173
Exercise 6.14: Compute the Area of a Triangle by Monte Carlo
Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Exercise 7.1: Understand Why Newton’s Method Can Fail . . . . . . . . . . . . . . . . 198
Exercise 7.2: See If the Secant Method Fails . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Exercise 7.3: Understand Why the Bisection Method Cannot Fail . . . . . . . . . . 199
Exercise 7.4: Combine the Bisection Method with Newton’s Method . . . . . . . 199
Exercise 7.5: Write a Test Function for Newton’s Method . . . . . . . . . . . . . . . . . 199
Exercise 7.6: Halley’s Method and the Decimal Module . . . . . . . . . . . . . . . . . . 199
Exercise 7.7: Fixed Point Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Exercise 7.8: Solve Nonlinear Equation for a Vibrating Beam . . . . . . . . . . . . . . 201
Exercise 8.1: Restructure a Given Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Exercise 8.2: Geometric Construction of the Forward Euler Method . . . . . . . . 273
Exercise 8.3: Make Test Functions for the Forward Euler Method . . . . . . . . . . 273
Exercise 8.4: Implement and Evaluate Heun’s Method . . . . . . . . . . . . . . . . . . . . 274
Exercise 8.5: Find an Appropriate Time Step; Logistic Model . . . . . . . . . . . . . 274
Exercise 8.6: Find an Appropriate Time Step; SIR Model . . . . . . . . . . . . . . . . . 274
Exercise 8.7: Model an Adaptive Vaccination Campaign . . . . . . . . . . . . . . . . . . 274
Exercise 8.8: Make a SIRV Model with Time-Limited Effect
of Vaccination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Exercise 8.9: Refactor a Flat Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Exercise 8.10: Simulate Oscillations by a General ODE Solver . . . . . . . . . . . . 275
Exercise 8.11: Compute the Energy in Oscillations . . . . . . . . . . . . . . . . . . . . . . . 276
List of Exercises xxiii

Exercise 8.12: Use a Backward Euler Scheme for Population Growth . . . . . . . 276
Exercise 8.13: Use a Crank-Nicolson Scheme for Population Growth . . . . . . . 277
Exercise 8.14: Understand Finite Differences via Taylor Series . . . . . . . . . . . . 277
Exercise 8.15: The Leapfrog Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Exercise 8.16: The Runge-Kutta Third Order Method . . . . . . . . . . . . . . . . . . . . 280
Exercise 8.17: The Two-Step Adams-Bashforth Method . . . . . . . . . . . . . . . . . . 280
Exercise 8.18: The Three-Step Adams-Bashforth Method . . . . . . . . . . . . . . . . . 282
Exercise 8.19: Use a Backward Euler Scheme for Oscillations . . . . . . . . . . . . . 282
Exercise 8.20: Use Heun’s Method for the SIR Model . . . . . . . . . . . . . . . . . . . . 283
Exercise 8.21: Use Odespy to Solve a Simple ODE . . . . . . . . . . . . . . . . . . . . . . 283
Exercise 8.22: Set up a Backward Euler Scheme for Oscillations . . . . . . . . . . . 284
Exercise 8.23: Set up a Forward Euler Scheme for Nonlinear and Damped
Oscillations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Exercise 8.24: Solving a Nonlinear ODE with Backward Euler . . . . . . . . . . . . 285
Exercise 8.25: Discretize an Initial Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Exercise 9.1: Simulate a Diffusion Equation by Hand . . . . . . . . . . . . . . . . . . . . 303
Exercise 9.2: Compute Temperature Variations in the Ground . . . . . . . . . . . . . . 303
Exercise 9.3: Compare Implicit Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Exercise 9.4: Explore Adaptive and Implicit Methods . . . . . . . . . . . . . . . . . . . . 305
Exercise 9.5: Investigate the θ Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Exercise 9.6: Compute the Diffusion of a Gaussian Peak . . . . . . . . . . . . . . . . . . 306
Exercise 9.7: Vectorize a Function for Computing the Area of a Polygon . . . . 307
Exercise 9.8: Explore Symmetry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Exercise 9.9: Compute Solutions as t → ∞ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Exercise 9.10: Solve a Two-Point Boundary Value Problem . . . . . . . . . . . . . . . 309
The First Few Steps
1

1.1 What Is a Program? And What Is Programming?

Computer Programs Today, most people are experienced with computer pro-
grams, typically programs such as Word, Excel, PowerPoint, Internet Explorer, and
Photoshop. The interaction with such programs is usually quite simple and intuitive:
you click on buttons, pull down menus and select operations, drag visual elements
into locations, and so forth. The possible operations you can do in these programs
can be combined in seemingly an infinite number of ways, only limited by your
creativity and imagination.

© The Author(s) 2020 1


S. Linge, H. P. Langtangen, Programming for Computations - Python,
Texts in Computational Science and Engineering 15,
https://doi.org/10.1007/978-3-030-16877-3_1
2 1 The First Few Steps

Nevertheless, programs often make us frustrated when they cannot do what


we wish. One typical situation might be the following. Say you have some
measurements from a device, and the data are stored in a file with a specific format.
You may want to analyze these data in Excel and make some graphics out of it.
However, assume there is no menu in Excel that allows you to import data in this
specific format. Excel can work with many different data formats, but not this one.
You start searching for alternatives to Excel that can do the same and read this type
of data files. Maybe you cannot find any ready-made program directly applicable.
You have reached the point where knowing how to write programs on your own
would be of great help to you! With some programming skills, you may write your
own little program which can translate one data format to another. With that little
piece of tailored code, your data may be read and analyzed, perhaps in Excel, or
perhaps by a new program tailored to the computations that the measurement data
demand.

Programming The real power of computers can only be utilized if you can
program them, i.e., write the programs yourself. With programming, you can tell
the computer what you want it to do, which is great, since it frees you from possible
limitations that come with programs written by others! Thus, with this skill, you get
an important extra option for problem solving that goes beyond what ready-made
programs offer.
A program that you write, will be a set of instructions that you store in a file.
These instructions must be written (according to certain rules) in a very specialized
language that has adopted words and expressions from English. Such languages
are known as programming (or computer) languages. When you have written your
instructions (your program), you may ask the programming language to read your
program and carry out the instructions. The programming language will then (if
there are no errors) translate the meaning of your instructions into real actions inside
the computer.
To write a program that solves a computing problem, you need to have a thorough
understanding of the given problem. That understanding may have to be developed
along the way and will obviously guide the way you write your solution program.
Typically, you need to write, test and re-write your program several times until you
get it right. Thus, what starts out with a computing problem and ends with a sensible
computer program for its solution, is a process that may take some time. By the term
programming, we will mean the whole of this process.
The purpose of this book is to teach you how to develop computer programs ded-
icated to solve mathematical and engineering problems by fundamental numerical
methods.

Programming Languages There are numerous computer languages for different


purposes. Within the engineering area, the most widely used ones are Python,
MATLAB, Octave, Fortran, C, C++, and to some extent, Maple and Mathematica.
The rules for how to write the instructions (i.e. the syntax) differ between the
languages. Let us use an analogy.
Assume you are an international kind of person, having friends abroad in
England, Russia and China. They want to try your favorite cake. What can you
1.1 What Is a Program? And What Is Programming? 3

do? Well, you may write down the recipe in those three languages and send them
over. Now, if you have been able to think correctly when writing down the recipe,
and you have written the explanations according to the rules in each language, each
of your friends will produce the same cake. Your recipe is the “computer program”,
while English, Russian and Chinese represent the “computer languages” with their
own rules of how to write things. The end product, though, is still the same cake.
Note that you may unintentionally introduce errors in your “recipe”. Depending
on the error, this may cause “baking execution” to stop, or perhaps produce the
wrong cake. In your computer program, the errors you introduce are called bugs
(yes, small insects! . . . for historical reasons), and the process of fixing them is called
debugging. When you try to run your program that contains errors, you usually get
warnings or error messages. However, the response you get depends on the error and
the programming language. You may even get no response, but simply the wrong
“cake”. Note that the rules of a programming language have to be followed very
strictly. This differs from languages like English etc., where the meaning might be
understood even with spelling errors and “slang” included.

We Use Python 3.6 in This Book For good reasons, the programming language
used in this book is Python (version 3.6). It is an excellent language for beginners
(and experts!), with a simple and clear syntax. Some of Python’s other strong
properties are1 : It has a huge and excellent library (i.e., ready-made pieces of
code that you can utilize for certain tasks in your own programs), many global
functions can be placed in only one file, functions are straightforwardly transferred
as arguments to other functions, there is good support for interfacing C, C++ and
Fortran code (i.e., a Python program may use code written in other languages), and
functions explicitly written for scalar input often work fine, without modification,
also with vector input. Another important thing, is that Python is available for free.
It can be downloaded at no cost from the Internet and will run on most platforms.

A Primer on Scientific Programming with Python


Readers who want to expand their scientific programming skills beyond the
introductory level of the present exposition, are encouraged to study A Primer
on Scientific Programming with Python [11]. This comprehensive book is
as suitable for beginners as for professional programmers, and teaches the
art of programming through a huge collection of dedicated examples. This
book is considered the primary reference, and a natural extension, of the
programming matters in the present book. Note, however, that this reference
[11] uses version 2.7 of Python, which means that, in a few cases, instructions
will differ somewhat from what you find in the present book.

1 Some of the words here will be new to you, but relax, they will all be explained as we move
along.
4 1 The First Few Steps

Some computer science terms


Note that, quite often, the terms script and scripting are used as synonyms for
program and programming, respectively.
The inventor of the Perl programming language, Larry Wall, tried to
explain the difference between script and program in a humorous way (from
perl.coma): Suppose you went back to Ada Lovelaceb and asked her the
difference between a script and a program. She’d probably look at you funny,
then say something like: Well, a script is what you give the actors, but a
program is what you give the audience. That Ada was one sharp lady. . . Since
her time, we seem to have gotten a bit more confused about what we mean
when we say scripting. It confuses even me, and I’m supposed to be one of the
experts.
There are many other widely used computer science terms to pick up as
well. For example, writing a program (or script or code) is often expressed as
implementing the program. Executing a program means running the program.
A default value is what will be used if nothing is specified. An algorithm
is a recipe for how to construct a program. A bug is an error in a program,
and the art of tracking down and removing bugs is called debugging (see,
e.g., Wikipediac). Simulating or simulation refers to using a program to mimic
processes in the real world, often through solving differential equations that
govern the physics of the processes. A plot is a graphical representation of
a data set. For example, if you walk along a straight road, recording your
position y with time t, say every second, your data set will consist of pairs
with corresponding y and t values. With two perpendicular axes in a plane
(e.g., a computer screen or a sheet of paper), one “horizontal” axis for t and
one “vertical” axis for y, each pair of points could be marked in that plane. The
axes and the points make up a plot, which represents the data set graphically.
Usually, such plotting is done by a computer.
a http://www.perl.com/pub/2007/12/06/soto-11.html.
b http://en.wikipedia.org/wiki/Ada_Lovelace.
c http://en.wikipedia.org/wiki/Software_bug#Etymology.

1.1.1 Installing Python

To study this book, you need a Python installation that fits the purpose. The quickest
way to get a useful Python installation on your Windows, Mac, or Linux computer,
is to download and install Anaconda.2 There are alternatives (as you can find on
the internet), but we have had very good experiences with Anaconda for several
years, so that is our first choice. No separate installation of Python or Spyder (our
recommended environment for writing Python code) is then required, as they are
both included in Anaconda.

2 https://www.anaconda.com/distribution.
1.2 A Python Program with Variables 5

To download Anaconda, you must pick the Anaconda version suitable for your
machine (Windows/Mac/Linux) and choose which version of Python you want
(3.6 is used for this book). When the download has completed, proceed with the
installation of Anaconda.
After installation, you may want to (search for and) start up Spyder to see what
it looks like (see also Appendix A). Spyder is an excellent tool for developing
Python code. So, unless you have good reasons to choose otherwise, we recommend
Spyder to be your main “working” environment, meaning that to read, write and run
code you start Spyder and do it there. Thus, it is a good idea to make Spyder easy
accessible on your machine.
With Anaconda installed, the only additional package you need to install is
Odespy.3 Odespy is relevant for the solving of differential equations that we treat in
Chaps. 8 and 9.
In Appendix A you will find more information on the installation and use of
Python.

1.2 A Python Program with Variables

Our first example regards programming a mathematical model that predicts the
height of a ball thrown straight up into the air. From Newton’s 2nd law, and
by assuming negligible air resistance, one can derive a mathematical model that
predicts the vertical position y of the ball at time t:

y = v0 t − 0.5gt 2 .

Here, v0 is the initial upwards velocity and g is the acceleration of gravity, for which
9.81 ms−2 is a reasonable value (even if it depends on things like location on the
earth).
With this formula at hand, and when v0 is known, you may plug in a value for
time and get out the corresponding height.

1.2.1 The Program

Let us next look at a Python program for evaluating this simple formula. To do this,
we need some values for v0 and t, so we pick v0 = 5 ms−1 and t = 0.6 s (other
choices would of course have been just as good). Assume the program is contained
as text in a file named ball.py, reading
# Program for computing the height of a ball in vertical motion

v0 = 5 # Initial velocity
g = 9.81 # Acceleration of gravity

3 The original version of Odespy (https://github.com/hplgit/odespy) was written in Python 2.7 by


H.P. Langtangen and L. Wang. However, since the sad loss of Prof. Langtangen in 2016, Ode-
spy has been updated to Python 3.6 (https://github.com/thomasantony/odespy/tree/py36/odespy),
thanks to Thomas Antony. This version is the one used herein.
6 1 The First Few Steps

t = 0.6 # Time

y = v0*t - 0.5*g*t**2 # Vertical position

print(y)

Let us now explain this program in full detail.

Typesetting of Code Computer programs, and parts of programs, are typeset with
a blue background in this book. When a complete program is shown, the blue
background has a slightly darker top and bottom bar (as for ball.py here). Without
the bars, the code is just a snippet and will normally need additional lines to run
properly.
We also use the blue background, without bars, for interactive sessions
(Sect. 2.1).

1.2.2 Dissecting the Program

A computer program like ball.py contains instructions to the computer written as


plain text. Humans can read the code and understand what the program is capable
of doing, but the program itself does not trigger any actions on a computer before
another program, the Python interpreter, reads the program text and translates this
text into specific actions.

You must learn to play the role of a computer


Although Python is responsible for reading and understanding your program,
it is of fundamental importance that you fully understand the program
yourself. You have to know the implication of every instruction in the program
and be able to figure out the consequences of the instructions. In other words,
you must be able to play the role of a computer.
One important reason for this strong demand is that errors unavoidably, and
quite often, will be committed in the program text, and to track down these
errors, you have to simulate what the computer does with the program. Also,
you will often need to understand code written by other people. If you are able
to understand their code properly, you may modify and use it as it suits you.

When you run your program in Python, it will interpret the text in your file line
by line, from the top, reading each line from left to right. The first line it reads is
# Program for computing the height of a ball in vertical motion.

This line is what we call a comment. That is, the line is not meant for Python to read
and execute, but rather for a human that reads the code and tries to understand what
is going on. Therefore, one rule in Python says that whenever Python encounters the
sign # it takes the rest of the line as a comment. Python then simply skips reading
the rest of the line and jumps to the next line. In the code, you see several such
comments and probably realize that they make it easier for you to understand (or
1.2 A Python Program with Variables 7

guess) what is meant with the code. In simple cases, comments are probably not
much needed, but will soon be justified as the level of complexity steps up.
The next line read by Python is
v0 = 5 # Initial velocity

In Python, a statement like v0 = 5 is known as an assignment statement.


After this assignment, any appearance of v0 in the code will “represent” the initial
velocity, being 5 ms−1 in this case. This means that, whenever Python reads v0,
it will replace v0 by the integer value 5. One simple way to think of this, might
be as follows. With the assignment v0 = 5, Python generates a “box” in computer
memory with the name v0 written on top. The number 5 is then put into that box.
Whenever Python later meets the name v0 in the code, it finds the box, opens it,
takes out the number (here 5) and replaces the name v0 with the number.
The next two lines
g = 9.81 # Acceleration of gravity
t = 0.6 # Time

are also assignment statements, giving two more “boxes” in computer memory. The
box named g will contain the value 9.81, while the box named t contains 0.6.
Similarly, when Python later reads g and t in the code, it plugs in the numerical
values found in the corresponding boxes.

The assignments in a bit more detail


When Python interprets the assignment statement v0 = 5, the integer 5
becomes an object of type int and the variable name on the left-hand side
becomes a named reference for that object. Similarly, when interpreting the
assignment statements g = 9.81 and t = 0.6, g and t become named
references to objects created for the real numbers given. However, since we
have real numbers, these objects will be of type float (in computer language,
a real number is called a “floating point number”).

Now, with these assignments in place, Python knows of three variables (v0, g, t)
and their values. These variables are then used by Python when it reads the next
line, the actual “formula”,
y = v0*t - 0.5*g*t**2 # Vertical position

Again, according to its rules, Python interprets * as multiplication, − as minus and


** as exponentiation (let us also add here that, not surprisingly, + and / would
have been understood as addition and division, if such signs had been present in the
expression). Having read the line, Python performs the mathematics on the right-
hand side, and then assigns the result (in this case the number 1.2342) to the variable
name y.
Finally, Python reads
print(y)
Another Random Scribd Document
with Unrelated Content
Shaneyfelt Exhibit No. 31 is a photograph taken from in front of
the school book depository building looking down toward the Triple
Underpass, showing in the center area of the picture two men in
white shirts standing along the south curb of Main Street at the
point where the mark on the curb was found.
Shaneyfelt Exhibit No. 32 is a photograph made from under the
Triple Underpass looking past the point where the mark on the curb
was located towards the Texas School Book Depository Building,
which relates this area to the rest of the assassination site.
There is a marker that has been set up on the curb with an
arrow pointing down, that is directly over the area where the mark is
located on the south curb of Main Street.
The photograph, Shaneyfelt Exhibit No. 33, is a photograph
made from the location of Mr. Abraham Zapruder who made motion
pictures of the assassination on November 22, and this photograph
was made having a man who can be seen standing in the center of
the picture, placed in the center of Elm Street, along a straight line
between the mark on the curb and the assassination window in the
Texas School Book Depository Building, the sixth floor.
The man is standing in that direct straight line between the
assassination window and the mark on the curb, and the photograph
then shows where the President in the Presidential limousine, would
have been on Elm Street as related to the Zapruder films if a bullet
going from the sixth floor window to the mark on the curb went
directly over the President’s head.
Mr. Redlich. Are you able to tell us the frame in Zapruder’s
sequence which would correspond to the position of the man
standing on Elm Street in Shaneyfelt Exhibit No. 33?
Mr. Shaneyfelt. Yes; this would correspond to frame No. 410 in
the Zapruder films. Of course, this, as stated, is based on the
assumption that a bullet going from the window to the mark on the
curbing went directly over the President’s head. It would have
occurred at approximately frame 410.
In relating this to other previously determined facts regarding
the Zapruder films, this would be 97 frames after the frame 313,
which is the frame of the Zapruder films that shows the shot that
struck the President in the head. At 18.3 frames per second, this 97
frames would represent a lapse of time of 5.3 seconds between the
shot to the President’s head at frame 313, and any shot that would
have occurred at frame 410, if such did occur.
Mr. Redlich. Now, with further reference to the relationship of this
location to the Zapruder films, the Commission previously requested
that the Bureau, advise us as to when Special Agent Hill of the
Secret Service reached the Presidential car. Can you tell us now the
results of that investigation?
Mr. Shaneyfelt. Yes; I examined the Zapruder film and determined
that Agent Hill first places his hand on the Presidential car at frame
343. This is approximately 1.6 seconds after the President is hit in
the head at frame 313.
Special Agent Hill placed one foot on the bumper of the car at
frame 368, which is approximately 3 seconds after frame 313. Agent
Hill had both feet on the car at frame 381, which is approximately
3.7 seconds after frame 313.
Mr. Redlich. Going back now to frame 410 on the Zapruder film,
which is the frame that would correspond to the location of a man
appearing on Elm Street in Shaneyfelt Exhibit No. 33, can you tell us
the location of Special Agent Hill and Mrs. Kennedy at frame 410?
Mr. Shaneyfelt. At frame 410 in the Zapruder films, Mrs. Kennedy
has returned to the seat beside the President after having climbed
out on the back deck or the trunk lid, and Secret Service Agent Hill is
in the process of climbing from the bumper into the back seat of the
car and is about midway from the back bumper to the President,
crawling across the trunk lid.
Mr. Redlich. Is it correct to say, Mr. Shaneyfelt, that at frame 410
the principal target on the back of the Presidential limousine would
have been Special Agent Hill and not any of the other occupants of
the rear seat of the car?
Mr. Shaneyfelt. I do not have an opinion on that, except my
recollection of the frame, as I recall it, the Connallys are down in the
car, and the President is down in the car to a point where he may
not be visible from the sixth floor window. Mrs. Kennedy would still
be visible, and Agent Hill; Mrs. Kennedy and Agent Hill, as I recall,
are the only ones readily visible or that are visible.
Mr. Redlich. Turning now, Mr. Shaneyfelt, to the curb mark itself;
you have brought with you today the actual piece of curbing which
contains the mark referred to in your testimony; is that correct?
Mr. Shaneyfelt. That is correct.
Mr. Redlich. That piece of curbing has been designated as
Shaneyfelt Exhibit No. 34.
(The article referred to was marked Shaneyfelt Exhibit No. 34.)
Mr. Redlich. Were you present at the time this curbing was
removed?
Mr. Shaneyfelt. Yes; it was removed under my supervision.
Mr. Redlich. Can you then describe the subsequent investigation
that was conducted in connection with this curbing?
Mr. Shaneyfelt. Yes; the section of curbing, Shaneyfelt Exhibit No.
34, was cut out from the curbing along the south side of Main Street
in the assassination area. The mark on the curb having been located
23 feet, 4 inches from the abutment of the triple underpass. It was
cut out under my supervision, and I personally returned it to the FBI
laboratory. In the FBI laboratory it was examined for the presence of
any foreign material.
Mr. Redlich. For the record, the results of this investigation have
been summarized in a communication from Director Hoover to Mr.
Rankin, dated August 12, 1964, and designated now as the
Shaneyfelt Exhibit No. 27; is that correct, Mr. Shaneyfelt?
The absence of copper precludes the possibility that the mark on
the curbing in the laboratory resulted in the finding of foreign metal
smears adhering to the curbing section within the area of the mark.
These metal smears were spectrographically determined to be
essentially lead with a trace of antimony. No copper was found.
The lead could have originated from the lead core of a mutilated
metal-jacketed bullet such as the type of bullet loaded into the 6.5-
millimeter Mannlicher Carcano cartridges, or from some other source
having the same composition.
The absence of copper precludes the possibility that the mark on
the curbing section was made by an unmutilated military full metal-
jacketed bullet such as the bullet from Governor Connally’s stretcher.
The damage to the curbing would have been much more
extensive if a rifle bullet had struck the curbing without first having
struck some other object. Therefore, this mark could not have been
made by the first impact of a high velocity rifle bullet.
Mr. Redlich. Based on your examination of the mark on the curb,
can you tell us whether the mark which we have been referring to is
a nick on the curb, that is, has a piece of the curb been chipped
away, or is it instead a simple marking of lead?
Mr. Shaneyfelt. Yes; it is not a chip. There is no indication of any
of the curbing having been removed, but rather it is a deposit of
lead on the surface of the curbing that has given the appearance of
a mark.
It was also established from a microscopic study of the curbing
that the lead object that struck the curbing that caused the mark,
was moving in a general direction away from the Texas School Book
Depository Building.
Mr. Redlich. In connection with this investigation into the
microscopic characteristics of the mark, a photograph was prepared
which is designated as Shaneyfelt Exhibit No. 35. Will you describe
that photograph?
(The photograph referred to was marked Shaneyfelt Exhibit No.
35.)
Mr. Shaneyfelt. Yes; Shaneyfelt Exhibit No. 35 is a color
photograph that I made of the mark on the curbing, which is
Shaneyfelt Exhibit No. 34. This is magnified about five times, and
shows only the marked area. There is a red area in the lower left
corner marked A which designates the point of initial impact, and the
lead deposit is then sprayed out in a fanlike direction from that
arrow.
Mr. Redlich. Does point A in Shaneyfelt Exhibit No. 35 refer to or
correspond to the portion of the marking which is visible in
Shaneyfelt Exhibit No. 34?
Mr. Shaneyfelt. It refers to the lower right-hand portion of that
mark on Shaneyfelt Exhibit No. 34. It is this area here, and this area
here [indicating].
Mr. Redlich. Was Shaneyfelt Exhibit No. 35 the photograph on the
basis of which the direction of the bullet fragment was determined?
Mr. Shaneyfelt. No; the direction was determined from an actual
examination of the curbing itself rather than from the photograph.
Shaneyfelt Exhibit No. 35, was made primarily to show this lead
deposit more clearly than Exhibit 34 shows it.
Mr. Redlich. I realize, Mr. Shaneyfelt, that the next question may
be out of your area of specialization, and you may not be able to
answer it. But are you able to tell us whether, if there had been
copper deposits indicating a fully jacketed bullet, whether in the
intervening period of time between the assassination and the time
the curbstone was examined these copper deposits might have been
removed by rain or erosion or any other natural causes?
Mr. Shaneyfelt. It is my understanding that there is no more
reason for the copper to be removed than the lead to be removed,
and it is my observation of the mark itself, the lead deposits, that
the effect of time on it was to add a layer of dirt and film over it
which covered it—more an adding on of dirt and other matter which
covered it rather than a wearing away.
So, based on this, although it is not possible to state whether or
not copper was there initially and eroded away or washed away or
wore away, it seems logical that copper would have no more reason
to become worn away than lead.
Mr. Redlich. Previous investigation, Mr. Shaneyfelt, as well as the
results of the reenactment in Dallas, have led, as you know, to a
tentative conclusion that if three shots were fired during the
assassination sequence, that one of these three shots missed the
occupants of the car.
Assuming that tentative conclusion to be a definite finding of
fact for purposes of this question, are you able to tell us whether in
your opinion, the location, the presence, of the lead marking on the
curb, which has been designated as Shaneyfelt Exhibit No. 34,
provides any basis for determining which of the three shots fired by
the assassin missed the Presidential limousine?
Mr. Shaneyfelt. Based on the assumptions as stated, it is my
opinion that the examination of the mark on the curb has furnished
only limited further information in this regard because it is not
possible to establish whether or not this mark on the curb could
have been made from a fragment of the shot that hit the President
in the head or a fragment of another shot that missed. The very fact
that it can be considered as one of the possibilities suggests a
possibility of a third shot that missed.
Mr. Redlich. How far from the President’s position at frame 313
was the mark on the curb?
Mr. Shaneyfelt. I don’t have that figure here at the present time.
To the best of my recollection, it was approximately 260 feet from
where the President would have been at frame 313 to the mark on
the south side of Main Street which has been designated as
Shaneyfelt Exhibit No. 34.
Mr. Redlich. I would like to designate at this time a number,
Shaneyfelt Exhibit No. 36, which we will apply to a communication
which I asked you to furnish to the Commission giving us the exact
distance between the President’s location at frame 313 and the mark
on the curb, Shaneyfelt Exhibit No. 34.
Mr. Shaneyfelt. All right.
(The article referred to was marked Shaneyfelt Exhibit No. 36 for
identification.)
Mr. Redlich. Have you completed your answer to my question
with regard to whether this information offers any basis upon which
one can conclude which of the three shots missed?
Mr. Shaneyfelt. Yes; I believe I have. I have very little opinion
regarding that.
Mr. Redlich. Mr. Shaneyfelt, prior to our deposition you and I
discussed the matters concerning which you were going to testify,
and during the course of this deposition there were a few
conversations which were not transcribed, is that correct?
Mr. Shaneyfelt. That is correct.
Mr. Redlich. Is all of your testimony which has been transcribed
completely consistent with any information which you have provided
in the off-the-record conversations?
Mr. Shaneyfelt. Yes.
Mr. Redlich. Is there any relevant material which you provided in
any off-the-record conversations which has not been covered in the
course of our record deposition?
Mr. Shaneyfelt. No.
Mr. Redlich. Is there anything concerning the matters to which
you testified that you would like to add at the present time?
Mr. Shaneyfelt. No; I believe not.
Mr. Redlich. A copy of this deposition will be available for your
review.
AFFIDAVIT OF PAUL MORGAN
STOMBAUGH
The following affidavit was executed by Paul Morgan Stombaugh
on September 4, 1964.

AFFIDAVIT
PRESIDENT’S COMMISSION
ON THE ASSASSINATION OF
PRESIDENT JOHN F. KENNEDY
District of Columbia, ss:
Paul Morgan Stombaugh, being duly sworn, deposes and says:
1. This affidavit is made at the request of the President’s
Commission on the Assassination of President Kennedy, for the
purpose of supplementing the testimony I gave before the
Commission concerning certain hairs and fibers I examined.
2. The principal characteristics of cotton fibers used for
comparison purposes are color and shade; and degree of twist. Of
these, color and shade are by far the most significant. The principal
characteristics of viscose used for comparison purposes are color
and shade, diameter, and size and distribution of delustering agent.
3. The orange-yellow and grey-black cotton fibers in the shirt,
Commission Exhibit 150, were respectively of uniform shades; the
dark blue cotton fibers in the shirt were of three different shades. All
the fibers in the shirt were mercerized, and of a substantially
uniform twist.
4. The green cotton fibers found in the paper bag, Commission
Exhibit 142, varied in shade, but were of a uniform twist. The brown
viscose fibers in the blanket, Commission Exhibit 140, varied in
diameter, shade, size, and distribution of delustering agent.
5. Stombaugh Exhibits 1–6 consist of the following items:
(a) Stombaugh Exhibit 1 consists of the hairs I found on the
blanket, Commission Exhibit 140.
(b) Stombaugh Exhibit 2 consists of the known sample of Lee
Harvey Oswald’s hairs sent to me by the Dallas Office of the FBI.
(c) Stombaugh Exhibit 3 consists of the fibers I found in the
paper bag, Commission Exhibit 142.
(d) Stombaugh Exhibit 4 consists of a sample of fibers from the
blanket, Commission Exhibit 140.
(e) Stombaugh Exhibit 5 consists of the fibers I found on the
rifle, Commission Exhibit 139.
(f) Stombaugh Exhibit 6 consists of a sample of fibers from the
shirt, Commission Exhibit 150.
Signed this 4th day of September, 1964.
(S) Paul Morgan Stombaugh,
Paul Morgan Stombaugh.
AFFIDAVIT OF L. J. LEWIS
The following affidavit was executed by L. J. Lewis on August 26,
1964.

AFFIDAVIT
PRESIDENT’S COMMISSION
ON THE ASSASSINATION OF
PRESIDENT JOHN F. KENNEDY
I, L. J. Lewis, being duly sworn, depose as follows:
I do not at the present time have a permanent residence but can
be contacted at my present place of employment, Kemp’s Garage,
634 West Davis, Dallas, Texas. On January 21, 1964, I was residing
at 7616 Hume, Pleasant Grove, Texas, and was then self-employed
as a wholesale car dealer.
On January 21, 1964, I was interviewed by Special Agents John
T. Kesler and Vernon Mitchem of the Federal Bureau of Investigation
concerning what I had seen on November 22, 1963, as it related to
Lee Harvey Oswald, the shooting of Dallas Police Officer, J. D. Tippit,
and the assassination of President John Fitzgerald Kennedy.
B
I have been shown the written report of the results of this
interview of January 21, 1964, by Special Agents John T. Kesler and
Vernon Mitchem of the Federal Bureau of Investigation. While this
report is substantially correct, I wish at this time to make the
following clarifications in regard to the last sentence in paragraph
one and the entirety of paragraph two.
“Upon hearing the shots and recognizing them as gunshot
sounds, I immediately called the Dallas Police Department to report
a shooting. There was so much confusion at the Police Department
end of the telephone conversation, they were having trouble making
out what I was telling them. A few minutes later, I observed a white
male, approximately thirty years of age, running south on Patton
Avenue, carrying either an automatic pistol or a revolver in his hand,
and while running was either attempting to reload same or
attempting to conceal the weapon in his belt.
“Upon reaching the intersection of Patton Avenue and Jefferson
Boulevard, the individual then proceeded west on Jefferson
Boulevard.”
I have read this written report and with the exception of the
aforementioned clarifications, it reveals a correct report of what I
saw on November 22, 1963.
Signed this 26th day of August 1964.
(S) L. J. Lewis,
L. J. Lewis.
B
This report was labeled L. J. Lewis Exhibit A.
TESTIMONY OF ALWYN COLE
The testimony of Alwyn Cole was taken at 3:26 p.m., on
September 4, 1964, at 200 Maryland Avenue NE., Washington, D.C.,
by Mr. Melvin Aron Eisenberg, assistant counsel of the President’s
Commission.

Mr. Eisenberg. Mr. Cole, you have given testimony to the


Commission at a previous time, and this is a continuation of that
testimony. So you will still be under oath from the previous session.
Mr. Cole. I understand.
Mr. Eisenberg. Could you state your full name and position once
more?
Mr. Cole. Alwyn Cole, examiner of questioned documents, U.S.
Treasury Department.
Mr. Eisenberg. Now, Mr. Cole, I will hand you for your examination
the following exhibits: Commission Exhibit No. 795, which is a
Selective Service System notice of classification in the name of Alek
James Hidell; Commission Exhibit No. 806, which is a certificate of
service in the U.S. Marine Corps, in the name of Alek James Hidell;
Commission Exhibit No. 801, which is a Selective Service System
notice of classification in the name of Lee Harvey Oswald;
Commission Exhibit No. 802, which is a Selective Service System
registration certificate in the name of Lee Harvey Oswald;
Commission Exhibit No. 811, which is a retouched negative of a
registration certificate; Commission Exhibit No. 812, which consists
of two retouched negatives of a certificate of service in the U.S.
Marine Corps; Commission Exhibit No. 803, which consists of a
retouched negative of the face of a Selective Service System notice
of classification; Commission Exhibit No. 804, which consists of a
retouched negative of the face of a Selective Service System notice
of classification; Commission Exhibit No. 805, which consists of a
retouched negative of a portion of the face of a Selective Service
System notice of classification; and a certificate of service in the U.S.
Marine Corps in the name of Lee Harvey Oswald, which I am
labeling Cole Exhibit No. 1.
(Cole Exhibit No. 1 was marked for identification.)
I ask you whether these are the items you have considered in
connection with your previous testimony?
Mr. Cole. Yes, sir.
Mr. Eisenberg. Now, beginning with Exhibit No. 795, which is—at
least as to its face—a Selective Service System notice of
classification in the name of Alek James Hidell, can you tell us
whether the face of this Exhibit was produced from the negatives
803, 804, and 805?
Mr. Cole. Yes, sir. Exhibit No. 795 is in fact a photographic print
from the negative, Exhibit No. 804, as to the face. Prior to that
photographic negative, however, other negatives were made, the
first one being the negative 803, and then another negative involved
in the production of Exhibit No. 795 is 805, which gives that part of
the text of the card beginning “The law requires” and ending “for
advice see your Government appeal agent.”
In other words, the negatives just described finally culminated in
the production of the photographic print, Exhibit No. 795.
Mr. Eisenberg. Now, Mr. Cole, have you yourself made prints of
these negatives, 803, 804, and 805?
Mr. Cole. Yes, sir; I have.
Mr. Eisenberg. That is by transmitted light, the normal way of
printing a negative?
Mr. Cole. I have made them in that manner; yes, sir.
Mr. Eisenberg. Now, I now hand you Cole Exhibits Nos. 2, 3, and
4, and I ask you whether those are the prints you have made from
Commission Exhibits Nos. 803, 804, and 805?
(Cole Exhibits Nos. 2, 3, and 4 were marked for identification.)
Mr. Cole. Yes, sir. Cole Exhibit No. 2 is a photographic print from
negative 805. Cole Exhibit No. 3 is a photographic print from
negative 804. Cole Exhibit No. 4 is a photographic print from
negative 803.
Mr. Eisenberg. Have you also made photographs of these
negatives by reflected light, Mr. Cole?
Mr. Cole. Yes, sir.
Mr. Eisenberg. I now hand you Cole Exhibits Nos. 5 and 6 and ask
you whether the photographs on these Exhibits labeled 803, 804,
and 805 are the photographs of the negatives which you made by
reflected light.
(Cole Exhibits Nos. 5 and 6 were marked for identification.)
Mr. Cole. Yes, sir. These prints are from photographic negatives
made by reflected light, and I should point out that the prints are
enlarged somewhat over the original size of the negatives, about
1.25 diameters.
Mr. Eisenberg. And what is the difference between Cole Exhibit
No. 5 and Cole Exhibit No. 6?
Mr. Cole. Cole Exhibit No. 6 shows that side of the negatives to
which the opaquing medium or retouching medium was applied,
whereas Cole Exhibit No. 5 shows the opposite side of the negative.
Mr. Eisenberg. Now, Mr. Cole, did you attempt to determine
whether the negatives, 803, 804, and 805, had been made from the
Selective Service notice in the name Oswald, which is Commission
Exhibit No. 801—that is, from the face of that card?
Mr. Cole. Yes, sir; I did.
Mr. Eisenberg. And what was your conclusion?
Mr. Cole. It is my conclusion that the negatives 803, 804, and
805, were in fact made from Exhibit No. 801.
Mr. Eisenberg. Now, how were you able to link up the negatives
803, 804, and 805, and the Oswald notice, Exhibit No. 801?
Mr. Cole. That was done chiefly by a close study of the
typewritten material following the line—I am now referring to Exhibit
No. 801—following the line “Selective Service Number,” in which
there are four small rectangles showing the insertion of typewritten
numbers, and by study of the signature of the member or clerk of
local board where it intersects printed matter of the original form.
The typewritten matter and the inked lines of the signature have
been the subject of opaquing or retouching. With respect to the
typewriting of the Selective Service number, the original typewriting
fell exactly on the base line of the ruled rectangles of the original
printed card. This created a rather difficult problem about opaquing
out the typewritten matter. The opaquing material was brought very
close to the ruled line, but some of that line was permitted to remain
unretouched. Since this line had in effect been reinforced by the
base of the typewritten material, the line appears somewhat heavier.
This heaviness comes through on the final photographic print which
is Exhibit No. 795.
Now, by this strange heaviness, I am referring to the lower
border of the four rectangles which follow the wording “Selective
Service Number.”
Now, with respect to intersections of the signature of member or
clerk of local board, this also presented quite a problem of
retouching; that is, in an effort to remove the signature or opaque it
from the negative 803, it was necessary to retouch or deform certain
parts of the original printing as represented by that negative, one
word being the word “President” at about the center of the right side
of the card. The letter “r” has been mutilated by the opaquing
material and this mutilation comes through on the final print, which
is Exhibit No. 795.
Also where an effort was made to opaque the lower extension of
the two letters “f” of the signature previously referred to, which
intersects the word “violation,” here also there was a mutilation of
certain letters of that word, namely, the “v” and “i” and the “a.”
This mutilation also comes through on the final print, Exhibit No.
795. So that there is a clear record from the original card, Exhibit
No. 801, through to the negatives, exhibits 803, 804, and 805, and
then to the final print, Exhibit No. 795.
Mr. Eisenberg. Now, Mr. Cole, did you attempt to determine
whether the negative 811 was a negative of the reverse side of the
registration certificate in the name of Oswald, Commission Exhibit
No. 802?
Mr. Cole. Yes, sir. I did make such a determination.
Mr. Eisenberg. And what was your conclusion?
Mr. Cole. That the negative, Exhibit No. 811, is in fact a
photographic reproduction made from the original card, Exhibit No.
802. That is referring to the reverse of this card.
Mr. Eisenberg. Now, did you also make a print from that negative,
Mr. Cole?
Mr. Cole. Yes, sir; I did.
Mr. Eisenberg. And is that print Cole Exhibit No. 7, which I now
hand you?
(Cole Exhibit No. 7 was marked for identification.)
Mr. Cole. Yes, sir; it is.
Mr. Eisenberg. And are the sections of Cole Exhibits Nos. 5 and 6
which are labeled 811, photographs taken of that negative by
reflected light?
Mr. Cole. Yes, sir.
Mr. Eisenberg. Now, did you attempt to determine, Mr. Cole,
whether the negative 811 had been used to make the reverse side
of the Notice of Classification in the name of Hidell?
Mr. Cole. Yes, sir; I did make such a determination.
Mr. Eisenberg. What was your conclusion?
Mr. Cole. It is my conclusion that the negative 811 was actually
used to make the photographic reproduction, that is, a photographic
print, which is the reverse of Exhibit No. 795.
Mr. Eisenberg. Now, can you tell us how you were able to link up
the Oswald registration certificate, the negative 811, and the reverse
side of the Hidell notice of classification?
Mr. Cole. Yes, sir. Returning to Commission Exhibit 802, the
reverse side shows the original insertion of certain descriptive words,
color of eyes, blue, complexion, medium, weight, 150, height, 5′11″.
Now, with particular regard to the word “blue”—excuse me. I believe
I didn’t mention the abbreviation, Brn, or color of hair. And referring
to that abbreviation, and the insertion of the typewritten word
“blue,” the insertion of the figure 150 for weight, it is observed that
each of these intersect the dotted lines provided on the original
printing of this card.
Now, here also an effort was made to opaque out the
typewritten material just mentioned. Since the typewritten material
intersects these ruled dotted lines, the opaquing material was
brought very close to the lines and in some cases caused small
imperfections of the dots. Now, these imperfections are present on
the photographic print, Exhibit No. 795, that is referring to the
reverse of that exhibit, in exactly the same position that they appear
on the opaqued negative 811. And from that I concluded that this
very negative was used to produce the photographic print which
forms the reverse of Exhibit No. 795.
Mr. Eisenberg. Now, did you attempt to determine, Mr. Cole,
whether the two negatives, Commission Exhibit No. 812, have been
produced from the certificate of service in the name of Oswald which
is Cole Exhibit No. 1?
Mr. Cole. Yes, sir; I did.
Mr. Eisenberg. And what was your conclusion?
Mr. Cole. It is my conclusion that the two negatives, Commission
Exhibit No. 812, actually reproduce the card, Cole Exhibit No. 1.
Mr. Eisenberg. Did you make prints of these negatives?
Mr. Cole. I did.
Mr. Eisenberg. And are those prints Cole Exhibits Nos. 8 and 9,
which I now hand you?
(Cole Exhibits Nos. 8 and 9 were marked for identification.)
Mr. Cole. Yes, sir; they are.
Mr. Eisenberg. And do the sections of Cole Exhibits Nos. 5 and 6
labeled 812 represent photographs of the negatives in 812 taken by
reflected light?
Mr. Cole. Yes, sir; they do.
Mr. Eisenberg. Did you attempt to determine, Mr. Cole, whether
Commission Exhibit No. 806, the certificate of service in the name of
Hidell, had been produced from the negatives in 812?
Mr. Cole. Yes, sir.
Mr. Eisenberg. And what was your conclusion?
Mr. Cole. It is my conclusion that Exhibit No. 806 was in fact
prepared from or represents a photographic print made from the
negatives, Commission Exhibit No. 812.
Mr. Eisenberg. Could you tell us how you were able to link up Cole
Exhibit No. 1, the negatives in 812, and Commission Exhibit No.
806?
Mr. Cole. With respect to Cole Exhibit No. 1, as compared with
the negative, Exhibit No. 812, that one representing the face of the
document, it is observed that the opaquing medium which was used
to block out the name Lee Harvey Oswald and the number 1653230
still makes it possible to read that name and number from the face
of the negative, and it is observed that this typewritten material has
precisely the same relationship on the negative as observed on the
card, Cole Exhibit No. 1. Now there are no intersections of the
opaquing with the original printed material of the card, Cole Exhibit
No. 1. However, this negative gives an exact reproduction of all of
the printed material on the card, including the form number which is
DD Form 217 MC 1 January 1951. Now, this amount of connection,
of course, is not as conclusive as one where an imperfection
resulting in the application of an opaquing medium is observable,
but yet as far as a comparison can be made, there is a perfect
agreement and there are no differences.
Now, with respect to the reverse side of Cole Exhibit No. 1, it is
observed that the original signature, Lee Harvey Oswald, intersected
a part of the printing of the word “signature” just above that
signature mentioned. The intersection affects chiefly the left side of
the letter “u” of the word “signature.” In other words, a part of the
opaquing medium affected that particular letter and this imperfection
is also shown in the final photographic print which is the reverse of
Commission’s Exhibit No. 806.
Mr. Eisenberg. Now, I hand you Commission Exhibit No. 810, Mr.
Cole. Is this a side-light photograph you took of the reverse side of
Hidell certificate of service, that is, Commission Exhibit No. 806.
Mr. Cole. Yes; it is.
Mr. Eisenberg. Did you find any traces of a signature or letters in
the box for signature of individual?
Mr. Cole. I did find some indentations in that area.
Mr. Eisenberg. Could you describe to us what you believe those
indentations might represent?
Mr. Cole. Yes, sir; just below the printed word “of” in the line
“signature of individual,” there are two vertical indentations which fill
about three-fourths of the space available, and there is a diagonal
mark slanting from the base of the left vertical to about the midpoint
of the right vertical, the total effect being of a printed letter “H,”
capital “H.” I also observe just below the second “i” of the printed
word “individual” a vertical indentation and just below the third “i” of
the word “individual” another vertical indentation. These could be
the vertical parts of “d’s” or “l’s.” However, with respect to mention
of the letter “d”, I do not observe any corresponding oval or circular
part of that letter which would be required for a printed form.
Mr. Eisenberg. You mean a hand-printed form?
Mr. Cole. Yes.
Mr. Eisenberg. Are those indentations visible to the naked eye on
the card itself?
Mr. Cole. Yes, they are, if the card is held in a special way so that
the light strikes the card at an angle.
Mr. Eisenberg. How do you think those indentations might have
been caused, Mr. Cole?
Mr. Cole. They could have been made by any sharp instrument,
for example, by a ballpoint pen which was not delivering ink at this
particular time, or by a stylus-like instrument such as those that are
used in preparing mimeograph forms, or even by a toothpick.
Mr. Eisenberg. Now, returning for a moment to the face of
Commission Exhibit No. 795, in your previous testimony, as I recall
it, you stated that while you could not make out precisely the
signature of the member or clerk of local board, it appeared to be
the name Good Hoffer, is that correct?
Mr. Cole. That is correct.
Mr. Eisenberg. Now, did that appear to be one word or two
words?
Mr. Cole. It appears to me to be two words or two names, capital
G-o-o-d, and then the name capital H-o-f-f-e-r.
Mr. Eisenberg. Now how did that compare to the signature of the
member or clerk of local board on Commission Exhibit No. 801, the
Oswald notice of classification?
Mr. Cole. Well, it is not the same name but it has some parts
which correspond, namely, the letter “f.” That is, there are obviously
two hand-written letters “f” in the last name of member or clerk of
local board on Exhibit No. 801, and we also have a representation of
hand-written letters “f” in about the same position on Commission
Exhibit No. 795.
Mr. Eisenberg. Off the record.
(Discussion off the record.)
Mr. Eisenberg. On the record. Do you have any further
observations on the comparison of the two names on the two cards,
Mr. Cole?
Mr. Cole. Yes; I would say that a possible interpretation of the
name on the original card, Exhibit No. 801, would be that it begins
with either a capital “E” or a capital “G.” There is a very small
circular form following that which does not appear to form any
intelligible name when linked with the first capital letter. However,
the last name suggests to me that it might be the name Schiffen, S-
c-h-i-f-f-e-n.
Now, I consider it quite possible that a person looking at this
name, which does not have a good legibility, might interpret it to be
the name which is finally written on the line for signature of member
or clerk of local board as it shows on Commission Exhibit No. 795.
Now, as to why a name might be removed by opaquing material and
then written in in a similar form by pen and ink, it is my view that
this might be done in order to have what would appear to be an
original, personally written signature on the final card, Exhibit No.
795, instead of having a photographic reproduction of a signature.
Mr. Eisenberg. Why do you think a person might write back in the
same name that he had taken out, rather than a different name?
Mr. Cole. As I say, in order to have on the final card an actual
manually written signature with pen and ink which would, one might
suppose, carry more validating effect than a photographic
reproduction of a signature.
Mr. Eisenberg. So that he would not necessarily be interested in
changing the name?
Mr. Cole. Not necessarily.
Mr. Eisenberg. Now, on the reverse side of the notice of
classification, Exhibit No. 795, there is typed in semilegible form the
name and address of the local board which issued the registration
certificate, and this seems to correspond to the name and address
which had been opaqued out of the Oswald registration certificate,
Commission Exhibit No. 802. Is that your observation?
Off the record, please.
(Discussion off the record.)
Mr. Eisenberg. On the record. Now, I now hand you, in order to
help you make this judgment, Commission Exhibit No. 799, which is
a side light photograph—introduced in connection with your earlier
testimony—of the reverse side of Exhibit No. 795, and I wonder
whether, with the aid of that side light photograph, you could
compare the entry in the space for local board on Commission
Exhibit No. 802, as opposed to the entry in the corresponding space
on the reverse side of Commission Exhibit No. 795.
Mr. Cole. The typewritten information inserted on the reverse
side of Commission Exhibit No. 795 is virtually the same as the
printed information which appears on the reverse of Commission
Exhibit 802, with just some slight differences. On Commission Exhibit
No. 795, and as now being read from the side light photograph,
Exhibit No. 799, the inserted typewriting which is read partly by an
existing scanty deposit of ink and partly by an indent from the
striking of the typewriter keys, the wording is “Texas Local Board
114.” In other words, on that line the abbreviation, No., for number
is omitted.
The next line being read from Exhibit No. 799 is “Selective
Service.” That means that the word “System” is omitted, which
appears on that second line of Exhibit No. 802.
Now, the next line, again being read from Exhibit No. 799, is
“Room 2226,” differing only as to the last figure. This read “Room
2227,” on Exhibit No. 802.
The street is given as 400 instead of 300 as it appears on Exhibit
No. 802. The name of the street is the same, “W. Vickery St.”
Reading the last line from Exhibit No. 799, there are the words
“Fort Worth, Texas,” and this means that there is omitted the zone
No. 4, which appears on Exhibit No. 802. Except for the differences
mentioned, the material is the same.
Mr. Eisenberg. Do you have any opinion why a person might have
gone to the trouble of opaquing out the original name and address
and then typing back in a substantially similar name and address?
Mr. Cole. Yes, sir; I do have an opinion. It is my belief that one
might suppose that the insertion of original typewriting on the final
blank photographic card would carry more of a validating force or
would give a greater impression of being an original card than would
the reproduction, photographic reproduction, of printed material.
Mr. Eisenberg. Now, Mr. Cole, reviewing the Exhibits which consist
of prints of the negatives we have been discussing, that is, Cole
Exhibits Nos. 2, 3, 4, 7, 8, and 9, it appears that these prints
essentially resemble blank forms, blank printed forms. Can you
explain the reason for that?
Mr. Cole. The reason is that these prints are made from
negatives which I believe were a part of a purpose for preparing
final photographic prints which appear to be blank forms.
Mr. Eisenberg. And in the case of Exhibits—Cole Exhibits Nos. 5
and 6, can you explain the reason why Cole Exhibit No. 6 shows
various splotches or splotchylike patterns, whereas Cole Exhibit No.
5 does not?
Mr. Cole. Well, Exhibit No. 6 shows that side of the negative to
which the opaquing medium was actually applied, whereas Exhibit
No. 5 shows the opposite side. Now, on the opposite side, you can
actually read the material that was being opaqued from the negative
because the opaquing material is a dull red color and it actually
reflects a considerable amount of light. However, it will not transmit
any light, and the fact that it will not transmit light is shown by the
prints made from these same negatives such as Cole Exhibits Nos. 2,
3, 4, 7, 8, and 9.
Mr. Eisenberg. As I understand it, then, in examining the
negatives by reflected light, the opaquing material on the reverse
side would serve as a background, and therefore would not prevent
you from reading the material which was eventually opaqued out, is
that correct?
Mr. Cole. That is true as to Exhibit No. 5.
Mr. Eisenberg. Yes.
Mr. Cole. But you observe on Exhibit No. 6 you cannot read the
material opaqued.
Mr. Eisenberg. That is—yes. I should have said when the
negatives are examined from their front—is that right?
Mr. Cole. When the negative is examined from the side to which
the opaquing material was applied, you cannot read the material
that was blocked out by the opaquing.
Mr. Eisenberg. And when it is examined from the other side you
can?
Mr. Cole. You can.
Mr. Eisenberg. Because the material serves as a background?
Mr. Cole. That is correct.
Mr. Eisenberg. And is my understanding also correct that when
the negative is printed by transmitted light, the opaquing blocks the
light from passing through those portions of the negative which have
been opaqued, therefore blocking those portions from being printed
in the final prints?
Mr. Cole. That is correct; yes.
Mr. Eisenberg. Thank you very much, Mr. Cole.
TESTIMONY OF PROF. REVILO
PENDLETON OLIVER
The testimony of Prof. Revilo Pendleton Oliver was taken at 2
p.m., on September 9, 1964, at 200 Maryland Avenue NE.,
Washington, D.C., by Mr. Albert E. Jenner, Jr., assistant counsel of
the President’s Commission. Professor Oliver was accompanied by
his attorney, Mr. John Unger.

Mr. Jenner. Mr. Reporter, this is Mr. Revilo Pendleton Oliver of


Urbana, Ill.
Doctor, would you mind standing so I can swear you.
Do you swear that in the deposition which you are about to give
that you will tell the truth, the whole truth and nothing but the
truth?
Mr. Oliver. I do.
This is a deposition and not a hearing?
Mr. Jenner. It is the same thing. We call hearings when the
Commission, a member of the Commission is present. These are
hearings but we call them deposition hearings. And all of your
testimony will be published in full in volume XV of the testimony
volumes, and without any editing, expurgating, or deletion.
Mr. Oliver. Will all testimony be published?
Mr. Jenner. Yes, sir; every bit. It now runs 15 printed volumes.
Mr. Unger. May I interrupt just a second. I notice that under the
resolution adopting the rules that it provides that one or more
members of the Commission shall be present at all hearings.
Don’t you intend to have a member of the Commission present
at this hearing?
Mr. Jenner. No; unless you desire to have one.
Mr. Unger. Well, I didn’t understand that it was a matter of
preference. I understood that under the rules under which you
operated it wasn’t a legal hearing unless you did have one.
Mr. Jenner. It is a hearing; what you are reading is a hearing at
which the Commission is sitting as distinguished from a deposition
hearing. You will find also in the rules, John, that you have, that they
provide for the deposition hearings.
Mr. Unger. Are you referring now to the second paragraph which
says that any member of the Commission or any agent or agency
designated by the Commission for such purpose may administer
oaths and affirmation, examine witnesses, and receive evidence?
Mr. Jenner. Yes, sir.
Mr. Unger. I wouldn’t normally take that as repealing a previous
section that a member be present at all hearings.
Mr. Jenner. It doesn’t repeal it, it supplements it.
Mr. Unger. You see, the subpena under which Dr. Oliver is here
commands him to appear before the President’s Commission.
Mr. Jenner. That is right.
Mr. Unger. Well, I have made my point. I have some question as
to whether or not this would be a proper hearing in the absence of a
Commission member, and I have so stated in the record.
Mr. Jenner. But if you—Mr. McCloy happens to be here this
afternoon, and if you want Mr. McCloy present, why we will have him
present.
Mr. Unger. We have no preference in the matter.
Mr. Jenner. Off the record.
(Discussion off the record.)
Mr. Jenner. Dr. Oliver, the nature of the inquiry enjoined upon the
Commission in the discharge of which it has been assiduously
engaged is to determine the facts and circumstances relating to the
deaths of President John F. Kennedy and Lee Harvey Oswald. There
has come to the attention of the Commission and its staff an article
entitled, “Marxmanship in Dallas,” of which we understand you were
the author, published in two parts in American Opinion, a magazine
published by the John Birch Society, part I, in the February 1964
issue, pages 13 through 28, and part II in the March 1964 issue,
pages 65 through 78.
That article—it is charged among other things that President
Kennedy’s assassination was a part of a Communist plot engineered
with the help of the Central Intelligence Agency, that Lee Harvey
Oswald was a Communist agent trained in sabotage, terrorism, and
guerrilla warfare, including accurate shooting from ambush, in a
school for international criminals near Minsk, Russia, under order
from Secretary of Defense Robert S. McNamara, the U.S. Army
began to rehearse for President Kennedy’s funeral more than a week
before the funeral actually took place——
Mr. Oliver. Now, are we not confusing quite a number of things,
here, Mr. Jenner?
Mr. Jenner. Well, you may comment when I finish the statement,
if you please.
Mr. Oliver. Very good.
Mr. Jenner. That Lee Harvey Oswald was sent to Dallas where he
tried to murder Gen. Edwin A. Walker; that in November, Oswald
was sent back from New Orleans, La., to Dallas, Tex., where a job at
a suitably located building had been arranged for him and that
something went wrong with the Communist conspiracy’s plans, as a
result of which Oswald was apprehended and identified.
There has also come to the attention of the Commission various
news items and newspapers published in Washington, D.C., Illinois,
Mississippi, Arizona, Texas, Colorado, California, and other States,
which contain reports of lectures and speeches made by you from
time to time, in which you have repeated, elaborated upon, or added
to the charges and claims made in your article in the American
Opinion which I have summarized.
The Commission is interested, among other things, in obtaining
from you the sources of, and the basis for, the foregoing charges and
claims appearing in your article and those reported in the news
media as having been made by you in lectures and speeches.
John, if you want that, there it is.
Mr. Unger. Thank you.
Mr. Jenner. I wanted to give you the framework of the
examination.
Mr. Oliver. May I point out that the article to which you originally
referred contained no reference to a rehearsal for the funeral, and
certainly contained no statement that the CIA had engineered the
assassination.
Mr. Jenner. What we will do, I will go into the article. I
understand you brought copies of it, and we can put the article in
the record and it will speak for itself.
Mr. Oliver. The entire article will be reproduced in the record?
Mr. Jenner. I beg your pardon?
Mr. Oliver. Will the entire article be reproduced in the record?
Mr. Jenner. Yes, sir.
Mr. Oliver. All right.
Mr. Jenner. Have I stated your name accurately, that is, Revilo
Pendleton Oliver.
Mr. Oliver. Yes.
Mr. Jenner. You do reside at 710 West Ohio Street?
Mr. Oliver. 701, simply Ohio Street there being no West.
Mr. Jenner. You are a professional man. What is your profession,
sir?
Mr. Oliver. I am a professor of classical philology in the
University of Illinois.
Mr. Jenner. You have held that position since when?
Mr. Oliver. I held rank as a full professor, I believe, since 1953, it
could be 1954.
Mr. Jenner. You are the holder of a doctor of philosophy degree,
are you not?
Mr. Oliver. That is right.
Mr. Jenner. From what university, sir?
Mr. Oliver. The University of Illinois.
Mr. Jenner. When did you receive your doctorate?
Mr. Oliver. To the best of my recollection, 1940.
Mr. Jenner. Approximately?
Mr. Oliver. 1940.
Mr. Jenner. Have you resided in Urbana or in Champaign, at least
in the university area, from the time you became a member of the
faculty of the University of Illinois and a professor?
Mr. Oliver. Legally, I believe; yes.
Mr. Jenner. Would you want to explain to me what you mean by
“legally”?
Mr. Oliver. Well, I have lived elsewhere during that time; I have
been abroad, and I have lived in Washington, D.C., and in Virginia,
but I maintained a legal residence in Urbana.
Mr. Jenner. These, I take it, were either special assignments, or
vacations, or sabbatical leaves to which you refer?
Mr. Oliver. Right, and let us say Urbana and/or Champaign,
because during some of those years I lived in the adjacent town of
Champaign.
Mr. Jenner. Yes. Urbana/Champaign, they are twin cities, and the
university is located in both cities, is that not correct?
Mr. Oliver. Between the two.
Mr. Jenner. Between the two. Although their boundaries touch?
Mr. Oliver. Yes; in fact, their boundaries so touch they have a
problem because cars parked in one city would find the parking
meters on the curb of the other city.
Mr. Jenner. Would you give me, but not in great elaboration, your
career from your college days. You received a master’s degree,
where did you receive that?
Mr. Oliver. Out at the University of Illinois, also.
Mr. Jenner. Just tell us in summary.
Mr. Oliver. I took my doctoral degree at the University of Illinois,
under Prof. William Abbott Oldfather.
Mr. Jenner. A very great man.
Mr. Oliver. A very distinguished man. I have been successively
instructor, assistant professor, associate professor, and professor of
the classics, and I have also been assistant professor, associate
professor, and full professor of Spanish and Italian—largely a matter
of my giving courses in the Renaissance.
Mr. Jenner. Do you teach Latin and Greek, too, or have you?
Mr. Oliver. Oh, that is classics.
Mr. Jenner. I see. During the war did you have some special
assignment militarily oriented or Government oriented?
Mr. Oliver. Yes; during the war I was on leave from the university
for service with the War Department.
Mr. Jenner. And without revealing any secrets, would you tell us
the general nature of that?
Mr. Oliver. The general nature of that was work that is
supposedly secret in nature. I can only say I was with the War
Department and that the offices in which I principally worked were
located on Lee Boulevard in Arlington, and not in the Pentagon.
Mr. Jenner. Was this civilian oriented rather than army oriented?
Mr. Oliver. I was a civilian expert. It was, however, an Army
Establishment under the command of a general.
Mr. Jenner. What was that, research work?
Mr. Oliver. Yes; under the command of a brigadier general, I
should say.
Mr. Jenner. This research work, did that involve any work of
investigating or inquiring into the commission of crimes or
conspiracies, work of that nature?
Mr. Oliver. Not actual investigation on my part.
Mr. Jenner. But——
Mr. Oliver. It involved the use of the results of the investigations
of others.
Mr. Jenner. So that you had experience in examining
investigators’ reports and reaching judgments from those reports?
Mr. Oliver. Yes.
Mr. Jenner. And reporting your judgment to your superiors.
Mr. Oliver. That is right.
Mr. Jenner. Are you a member of the John Birch Society?
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