Jake Bobowski
~Home~
SCI 261
jake.bobowski@ubc.ca
   UBCO

Here is a set of Python tutorials designed for the physics undergraduate. I am a Python novice. These tutorials are not intended to cover everything task that you might encounter. However, I hope to add scripts that cover many of the basic tasks that come up repeatedly.

The scripts were written using Anaconda toolkit. It is free and open source. You can download the Individual Edition from the Anaconda website. After the installation is complete, I recommend openning the 'Anaconda Powershell Prompt' and executing the command 'conda update --all' to update all of the packages before starting.

I wrote and executed my Python scripts using Spyder.

UBC students can write and run Python code in Jupyter Notebooks using UBC's Jupyter Hub. You don't need to install any software, just log in using your CWL.




BASICS
Preliminaries
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Operating on a list/array
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Merging lists/arrays
Jupyter Notebook
.py/.html/output html
.ipynb/.html

SYSTEMS OF EQUATIONS
Linear and simple systems
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Nonlinear equations and systems
Jupyter Notebook
.py/.html/output html
.ipynb/.html

PLOTTING
Plotting data, formatting plots, saving plots
outputs
   
   
   
   

Jupyter Notebook
notebook output files

.py/.html/output html
test_plot.png
test_plot.jpg
test_plot.svg
test_plot.pdf
test_plot.eps

.ipynb/.html
Jupyter test_plot.png
Jupyter test_plot.jpg
Jupyter test_plot.svg
Jupyter test_plot.pdf
Jupyter test_plot.eps

Adding curves/data to existing plots
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Plotting a function
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Loglog and semilog plots
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Histograms
Jupyter Notebook
notebook output files
.py/.html/output html
.ipynb/.html
plot (pdf)
plot (jpg)
plot (png)
plot (eps)
Surface plots
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Interactive plots
Jupyter Notebook
import files

.ipynb/.html
F-H-data.txt
hydrogen spectrum.txt
Creating a gif from data
data file
data gif

Jupyter Notebook
data file
Jupyter data gif

.py/.html/output html
.txt
.gif

.ipynb/.html
.txt
.gif


FUNCTIONS
Functions in a script
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Creating functions to be called by other scripts
Jupyter Notebook
modules/functions
   
all primes from 1 to 1e6
.py/.html/output html
.ipynb/.html
mod1.py/mod1.html
mod2.py/mod2.html
primes_1e6.txt
Jupyter primes_1e6.txt
A more "advanced" fubction
Jupyter Notebook
modules/functions
largest number checked for "primeness"
all primes from 1 to ~1.317e9 (compressed)
read me
.py/.html/output html
.ipynb/.html
modAdv.py/modAdv.html
primes_max.txt
primes_list.zip
read_me.txt

IMPORTING/EXPORTING DATA
Importing data
Jupyter Notebook
import file
.py/.html/output html
.ipynb/.html
.txt import
Importing multiple files
Jupyter Notebook
import files
.py/.html/output html
.ipynb/.html
file001data.txt
file002data.txt
file003data.txt
file004data.txt
file005data.txt
file008data.txt
file012data.txt
Exporting data
output file

Jupyter Notebook
output file

.py/.html/output html
matrix data.txt

.ipynb/.html
Jupyter matrix data.txt


FITTING DATA
Weighted linear fit
Jupyter Notebook
notebook output files
.py/.html/output html
.ipynb/.html
plot (pdf)
Weighted polynomial fit
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Weighted linear-in-parameters fit
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Weighted nonlinear fit
Jupyter Notebook #1
Jupyter Notebook #2
.py/.html/output html
.ipynb/.html
.ipynb/.html (error estimates)
Simultaneous nonlinear fits
Jupyter Notebook
data file
.py/.html/output html
.ipynb/.html
S11 - real imag.dat

INTERPOLATING DATA
Interpolation
Jupyter Notebook
data files
.py/.html/output html
.ipynb/.html
calibration data
experimental data

FOURIER TRANSFORMS
Fourier transform
Jupyter Notebook
data file
.py/.html/output html
.ipynb/.html
fftData.dat

INVERSE LAPLACE TRANSFORMS
Inverse Laplace transform
Jupyter Notebook
.py/.html/output html
.ipynb/.html

CONTROL STRUCTURES
For loops
Jupyter Notebook
.py/.html/output html
.ipynb/.html
If statements
Jupyter Notebook
.py/.html/output html
.ipynb/.html
While loops
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Nested structures
Jupyter Notebook
.py/.html/output html
.ipynb/.html

MATRICES
Matrix basics
Jupyter Notebook
.py/.html/output html
.ipynb/.html

CALCULUS
Symbolic derivatives
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Symbolic integrals
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Discrete derivatives
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Discrete integrals
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Solving ordinary differential equations (ODEs)
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Another ODE example
Jupyter Notebook

.ipynb/.html
Solving partial differential equations (PDEs)
Jupyter Notebook
.py/.html/output html
.ipynb/.html

NUMERICAL SOLUTIONS
Solving transcendental equations
Jupyter Notebook

.ipynb/.html
Numerical integration
Jupyter Notebook

.ipynb/.html
Numerically solving integral equations
Jupyter Notebook

.ipynb/.html

COMPLEX NUMBERS
Manipulating and ploting complex numbers
Jupyter Notebook
figure
.py/.html/output html
.ipynb/.html
Circuit diagram

NYQUIST RECONSTRUCTION
Reconstructing signals from samples
Jupyter Notebook
.py/.html/output html
.ipynb/.html

IMAGE PROCESSING
Basics of image processing
input image
output image one
output image two

Jupyter Notebook
input image
output image one
output image two

.py/.html/output html
30min.jpg
30min-enhanced.jpg
enhancedInt.jpg

.ipynb/.html
30min.jpg
Jupyter 30min-enhanced.jpg
Jupyter enhancedInt.jpg


MONTE CARLO BASICS
Monte Carlo Hit & Miss integration
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Monte Carlo f-average integration
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Volume of a sphere in d dimensions
Jupyter Notebook
figure
.py/.html/output html
.ipynb/.html
Wikipedia figure
Photomultiplier Tube (PMT) simulation
Jupyter Notebook
.py/.html/output html
.ipynb/.html

DISPLAYING LATEX
Displaying LaTeX in the IPython console
Jupyter Notebook
.py/.html/output html
.ipynb/.html




created by Jake Bobowski,
jake.bobowski@ubc.ca

last modified: August 9, 2021

URL: https://cmps-people.ok.ubc.ca/jbobowsk/Python.html

Giant Sequoia