Computational Physics With Python - UNIOS
Computational Physics With Python
Dr. Eric Ayars California State University, Chico
ii
Copyright c 2013 Eric Ayars except where otherwise noted. Version 0.9, August 18, 2013
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi
0 Useful Introductory Python
1
0.0 Making graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 1
0.1 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
0.2 Reading data from files . . . . . . . . . . . . . . . . . . . . . 6
0.3 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1 Python Basics
13
1.0 The Python Interpreter . . . . . . . . . . . . . . . . . . . . . 13
1.1 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2 Simple Input & Output . . . . . . . . . . . . . . . . . . . . . 16
1.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.4 Mathematical Operators . . . . . . . . . . . . . . . . . . . . . 27
1.5 Lines in Python . . . . . . . . . . . . . . . . . . . . . . . . . . 28
1.6 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . 29
1.7 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.8 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.9 Expanding Python . . . . . . . . . . . . . . . . . . . . . . . . 40
1.10 Where to go from Here . . . . . . . . . . . . . . . . . . . . . . 43
1.11 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2 Basic Numerical Tools
47
2.0 Numeric Solution . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.0.1 Python Libraries . . . . . . . . . . . . . . . . . . . . . 55
2.1 Numeric Integration . . . . . . . . . . . . . . . . . . . . . . . 56
2.2 Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.3 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
iv
CONTENTS
3 Numpy, Scipy, and MatPlotLib
73
3.0 Numpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.1 Scipy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.2 MatPlotLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.3 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4 Ordinary Differential Equations
83
4.0 Euler's Method . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.1 Standard Method for Solving ODE's . . . . . . . . . . . . . . 86
4.2 Problems with Euler's Method . . . . . . . . . . . . . . . . . 90
4.3 Euler-Cromer Method . . . . . . . . . . . . . . . . . . . . . . 91
4.4 Runge-Kutta Methods . . . . . . . . . . . . . . . . . . . . . . 94
4.5 Scipy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5 Chaos
109
5.0 The Real Pendulum . . . . . . . . . . . . . . . . . . . . . . . 110
5.1 Phase Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.2 Poincar?e Plots . . . . . . . . . . . . . . . . . . . . . . . . . . 116
5.3 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
6 Monte Carlo Techniques
123
6.0 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . 124
6.1 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
6.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
7 Stochastic Methods
131
7.0 The Random Walk . . . . . . . . . . . . . . . . . . . . . . . . 131
7.1 Diffusion and Entropy . . . . . . . . . . . . . . . . . . . . . . 135
7.2 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8 Partial Differential Equations
141
8.0 Laplace's Equation . . . . . . . . . . . . . . . . . . . . . . . . 141
8.1 Wave Equation . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.2 Schr?odinger's Equation . . . . . . . . . . . . . . . . . . . . . . 147
8.3 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
A Linux
155
A.0 User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . 156
A.1 Linux Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
A.2 The Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
CONTENTS
v
A.3 File Ownership and Permissions . . . . . . . . . . . . . . . . . 162 A.4 The Linux GUI . . . . . . . . . . . . . . . . . . . . . . . . . . 163 A.5 Remote Connection . . . . . . . . . . . . . . . . . . . . . . . . 163 A.6 Where to learn more . . . . . . . . . . . . . . . . . . . . . . . 165 A.7 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
B Visual Python
169
B.0 VPython Coordinates . . . . . . . . . . . . . . . . . . . . . . 171
B.1 VPython Objects . . . . . . . . . . . . . . . . . . . . . . . . . 171
B.2 VPython Controls and Parameters . . . . . . . . . . . . . . . 174
B.3 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
C Least-Squares Fitting
177
C.0 Derivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
C.1 Non-linear fitting . . . . . . . . . . . . . . . . . . . . . . . . . 181
C.2 Python curve-fitting libraries . . . . . . . . . . . . . . . . . . 181
C.3 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
References
185
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- computational physics with python unios
- python data science handbook
- let s try some random projections of the data
- chapter plotting data using 4 matplotlib
- optimization in python
- matplotlib tutorialspoint
- matplotlib 2d and 3d plotting in python
- mathematics in python
- networkx tutorial stanford university
- seaborn tutorialspoint
Related searches
- physics tests with answers
- physics quiz with answers
- physics mcqs with answers pdf
- physics mcq question with answer
- general physics test with answers
- physics exams with answers
- free physics worksheets with answers
- help with physics problem
- free help with physics homework
- statistics with python pdf
- university physics with modern physics
- physics calculator with steps