A Primer on Scientific Programming with Python (Google eBook)

Front Cover
Springer Science & Business Media, Aug 7, 2009 - Computational Science and Engineering - 722 pages
3 Reviews
The book serves as a first introduction to computer programming of scientific applications, using the high-level Python language. The exposition is example- and problem-oriented, where the applications are taken from mathematics, numerical calculus, statistics, physics, biology, and finance. The book teaches 'Matlab-style' and procedural programming as well as object-oriented programming. High school mathematics is a required background, and it is advantageous to study classical and numerical one-variable calculus in parallel with reading this book. Besides learning how to program computers, the reader will also learn how to solve mathematical problems, arising in various branches of science and engineering, with the aid of numerical methods and programming. By blending programming, mathematics and scientific applications, the book lays a solid foundation for practicing computational science.
  

What people are saying - Write a review

User Review - Flag as inappropriate

Tok Inf1100 kurset på UiO, der denne boken var pensum.
Boka er veldig bra lagt opp, den starter veldig roligt og jobber trinnvis oppover i vanskelighetsgraden. Synes teksten er godt skrevet, og
forklarer tingene veldig bra. Men noen av oppgavene, kunne vært formulert litt bedre, men det er få av de. Liker godt at han skriver bakgrunnen på formelene, hva de brukes til og hvordan de brukes. Det skaper mer forståelse hvorfor vi løser oppgavene, og gjør det kjekt å jobbe med de.
Anbefales en god del matte kunnskaper på noen kap i bok,hvis du har lyst å forstå 100% det du holder på med, men holder nok med 3MX/R2 kunnskaper også. Vil si at Kap.7 og Kap.9 er de tyngste. Siden differensialligninger er sterkt i fokus der.
Vil anbefale denne boken til de som har lyst å jobbe med Python innen matte,fysikk og andre realfag!
 

Contents

713 Another Function Class Example
346
714 Alternative Function Class Implementations
347
715 Making Classes Without the Class Construct
349
72 More Examples on Classes
352
722 Phone Book
354
723 A Circle
355
73 Special Methods
356
731 The Call Special Method
357

1111 Formatting Text and Numbers
11
12 Computer Science Glossary
13
CelsiusFahrenheit Conversion
18
Integer Division
19
132 Objects in Python
20
133 Avoiding Integer Division
21
14 Evaluating Standard Mathematical Functions
22
Using More Mathematical Functions
25
15 Interactive Computing
26
151 Calculating with Formulas in the Interactive Shell
27
152 Type Conversion
28
153 IPython
29
16 Complex Numbers
31
161 Complex Arithmetics in Python
32
163 Unified Treatment of Complex and Real Functions
33
17 Summary
35
Trajectory of a Ball
38
173 About Typesetting Conventions in This Book
39
18 Exercises
40
Basic Constructions
51
212 While Loops
52
213 Boolean Expressions
54
214 Lists
56
215 For Loops
58
216 Alternative Implementations with Lists and Loops
60
217 Nested Lists
64
218 Printing Objects
65
219 Extracting Sublists
66
2110 Traversing Nested Lists
68
2111 Tuples
70
22 Functions
71
222 Local and Global Variables
73
223 Multiple Arguments
75
224 Multiple Return Values
77
225 Functions with No Return Values
79
226 Keyword Arguments
80
227 Doc Strings
83
228 Function Input and Output
84
2210 The Main Program
86
2211 Lambda Functions
87
23 If Tests
88
24 Summary
91
Tabulate a Function
94
243 How to Find More Python Information
98
25 Exercises
99
Input Data and Error Handling
119
31 Asking Questions and Reading Answers
120
312 The Magic evalFunction
121
313 The Magic execFunction
125
314 Turning String Expressions into Functions
126
32 Reading from the Command Line
127
322 A Variable Number of CommandLine Arguments
128
323 More on CommandLine Arguments
129
324 OptionValue Pairs on the Command Line
130
33 Handling Errors
132
331 Exception Handling
133
332 Raising Exceptions
136
34 A Glimpse of Graphical User Interfaces
139
35 Making Modules
141
Compund Interest Formulas
142
352 Collecting Functions in a Module File
143
353 Using Modules
148
36 Summary
150
Bisection Root Finding
152
37 Exercises
160
Array Computing and Curve Plotting
169
41 Vectors
170
412 Mathematical Operations on Vectors
171
413 Vector Arithmetics and Vector Functions
173
42 Arrays in Python Programs
175
422 Basics of Numerical Python Arrays
176
423 Computing Coordinates and Function Values
177
424 Vectorization
178
43 Curve Plotting
179
431 The SciTools and Easyviz Packages
180
432 Plotting a Single Curve
181
433 Decorating the Plot
183
435 Controlling Line Styles
185
436 Interactive Plotting Sessions
189
437 Making Animations
190
438 Advanced Easyviz Topics
193
439 Curves in Pure Text
198
44 Plotting Difficulties
199
442 Rapidly Varying Functions
205
443 Vectorizing StringFunction Objects
206
45 More on Numerical Python Arrays
207
453 Allocating Arrays
208
454 Generalized Indexing
209
455 Testing for the Array Type
210
456 Equally Spaced Numbers
211
457 Compact Syntax for Array Generation
212
46 HigherDimensional Arrays
213
462 TwoDimensional Numerical Python Arrays
214
463 Array Computing
216
464 TwoDimensional Arrays and Functions of Two Variables
217
47 Summary
219
Animating a Function
220
48 Exercises
225
Sequences and Difference Equations
235
51 Mathematical Models Based on Difference Equations
236
511 Interest Rates
237
512 The Factorial as a Difference Equation
239
513 Fibonacci Numbers
240
514 Growth of a Population
241
515 Logistic Growth
242
516 Payback of a Loan
244
517 Taylor Series as a Difference Equation
245
518 Making a Living from a Fortune
246
519 Newtons Method
247
5110 The Inverse of a Function
251
52 Programming with Sound
253
522 Reading Sound from File
254
523 Playing Many Notes
255
53 Summary
256
Music of a Sequence
257
54 Exercises
260
Files Strings and Dictionaries
269
611 Reading a File Line by Line
270
612 Reading a Mixture of Text and Numbers
273
613 What Is a File Really?
274
62 Dictionaries
278
622 Dictionary Operations
279
Polynomials as Dictionaries
280
File Data in Dictionaries
282
File Data in Nested Dictionaries
283
Comparing Stock Prices
287
63 Strings
291
631 Common Operations on Strings
292
Reading Pairs of Numbers
295
Reading Coordinates
298
64 Reading Data from Web Pages
300
642 How to Access Web Pages in Programs
302
Extracting Data from an HTML Page
304
65 Writing Data to File
308
Writing a Table to File
309
652 Standard Input and Output as File Objects
310
653 Reading and Writing Spreadsheet Files
312
66 Summary
317
A File Database
319
67 Exercises
323
Introduction to Classes
337
71 Simple Function Classes
338
712 Representing a Function as a Class
340
Automagic Integration
360
734 Turning an Instance into a String
362
Phone Book with Special Methods
363
736 Adding Objects
365
738 Arithmetic Operations and Other Special Methods
369
739 More on Special Methods for String Conversion
370
Solution of Differential Equations
372
741 A Function for Solving ODEs
373
742 A Class for Solving ODEs
374
743 Verifying the Implementation
376
Logistic Growth
377
Class for Vectors in the Plane
378
Class for Complex Numbers
382
762 Illegal Operations
383
763 Mixing Complex and Real Numbers
384
764 Special Methods for Right Operands
387
765 Inspecting Instances
388
77 Static Methods and Attributes
389
78 Summary
391
Interval Arithmetics
392
79 Exercises
397
Random Numbers and Simple Games
417
81 Drawing Random Numbers
418
812 Uniformly Distributed Random Numbers
419
813 Visualizing the Distribution
420
814 Vectorized Drawing of Random Numbers
421
815 Computing the Mean and Standard Deviation
422
816 The Gaussian or Normal Distribution
423
82 Drawing Integers
424
821 Random Integer Functions
425
Throwing a Die
426
823 Drawing a Random Element from a List
427
Class Implementation of a Deck
429
83 Computing Probabilities
432
Throwing Dice
433
Drawing Balls from a Hat
435
Policies for Limiting Population Growth
437
84 Simple Games
440
85 Monte Carlo Integration
443
852 Computing Areas by Throwing Random Points
446
86 Random Walk in One Space Dimension
447
861 Basic Implementation
448
862 Visualization
449
864 Computing Statistics of the Particle Positions
450
865 Vectorized Implementation
451
87 Random Walk in Two Space Dimensions
453
872 Vectorized Implementation
455
88 Summary
456
Random Growth
457
89 Exercises
463
ObjectOriented Programming
479
911 A Class for Straight Lines
480
912 A First Try on a Class for Parabolas
481
914 Checking the Class Type
483
915 Attribute versus Inheritance
484
916 Extending versus Restricting Functionality
485
917 Superclass for Defining an Interface
486
92 Class Hierarchy for Numerical Differentiation
488
922 A Flexible Main Program
491
923 Extensions
492
924 Alternative Implementation via Functions
495
925 Alternative Implementation via Functional Programming
496
926 Alternative Implementation via a Single Class
497
93 Class Hierarchy for Numerical Integration
499
932 Classes for Integration
501
933 Using the Class Hierarchy
504
934 About ObjectOriented Programming
507
94 Class Hierarchy for Numerical Methods for ODEs
508
942 Numerical Methods
510
943 The ODE Solver Class Hierarchy
511
944 The Backward Euler Method
515
945 Verification
518
The Logistic Equation
519
An Oscillating System
521
The Trajectory of a Ball
523
95 Class Hierarchy for Geometric Shapes
525
951 Using the Class Hierarchy
526
952 Overall Design of the Class Hierarchy
527
953 The Drawing Tool
529
954 Implementation of Shape Classes
530
955 Scaling Translating and Rotating a Figure
534
96 Summary
538
Input Data Reader
540
97 Exercises
546
Discrete Calculus
573
A11 The Sine Function
574
A12 Interpolation
576
A14 Generalization
577
A2 Differentiation Becomes Finite Differences
579
A21 Differentiating the Sine Function
580
A23 Generalization
582
A3 Integration Becomes Summation
583
A31 Dividing into Subintervals
584
A32 Integration on Subintervals
585
A33 Adding the Subintervals
586
A34 Generalization
587
A4 Taylor Series
589
A43 More Accurate Expansions
590
A44 Accuracy of the Approximation
592
A45 Derivatives Revisited
594
A46 More Accurate Difference Approximations
595
A47 SecondOrder Derivatives
597
A5 Exercises
599
Differential Equations
605
B1 The Simplest Case
606
B2 Exponential Growth
608
B3 Logistic Growth
612
B4 A General Ordinary Differential Equation
614
B5 A Simple Pendulum
615
B6 A Model for the Spread of a Disease
619
B7 Exercises
621
A Complete Project
625
Motion and Forces in Physics
626
C12 The Computational Algorithm
628
C14 Derivation of the Algorithm
631
C2 Program Development and Testing
632
C22 Callback Functionality
635
C23 Making a Module
636
C24 Verification
637
C3 Visualization
639
C32 Some Applications
642
C33 Remark on Choosing Δt
643
C34 Comparing Several Quantities in Subplots
644
C35 Comparing Approximate and Exact Solutions
645
C36 Evolution of the Error as Δt Decreases
646
C4 Exercises
649
Debugging
651
D2 How to Debug
653
D21 A Recipe for Program Writing and Debugging
654
D22 Application of the Recipe
656
Technical Topics
669
E13 Executing Python Programs on Windows
671
E14 Executing Python Programs on Macintosh
673
E3 Visualizing a Program with Lumpy
674
E4 Doing Operating System Tasks in Python
675
E5 Variable Number of Function Arguments
678
E51 Variable Number of Positional Arguments
679
E52 Variable Number of Keyword Arguments
681
E6 Evaluating Program Efficiency
683
E62 Profiling Python Programs
685
References
687
Index
688
Copyright

Common terms and phrases

Bibliographic information