Introduction
Computational Modelling
Introduction
Computational Modelling
Programming to support computational modelling
Why Python for scientific computing?
Optimisation strategies
Get it right first, then make it fast
Prototyping in Python
Literature
Recorded video lectures on Python for beginners
Python tutor mailing list
Python version
These documents
Your feedback
A powerful calculator
Python prompt and Read-Eval-Print Loop (REPL)
Calculator
Integer division
How to avoid integer division
Why should I care about this division problem?
Mathematical functions
Variables
Terminology
Impossible equations
The += notation
Data Types and Data Structures
What type is it?
Numbers
Integers
Integer limits
Floating Point numbers
Complex numbers
Functions applicable to all types of numbers
Sequences
Sequence type 1: String
Sequence type 2: List
Sequence type 3: Tuples
Indexing sequences
Slicing sequences
Dictionaries
Passing arguments to functions
Call by value
Call by reference
Argument passing in Python
Performance considerations
Inadvertent modification of data
Copying objects
Equality and Identity/Sameness
Equality
Identity / Sameness
Example: Equality and identity
Introspection
dir()
Magic names
type
isinstance
help
Docstrings
Input and Output
Printing to standard output (normally the screen)
Simple print
Formatted printing
str and __str__
repr and __repr__
New-style string formatting
Changes from Python 2 to Python 3: print
Reading and writing files
File reading examples
Control Flow
Basics
Conditionals
If-then-else
For loop
While loop
Relational operators (comparisons) in if and while statements
Exceptions
Raising Exceptions
Creating our own exceptions
LBYL vs EAFP
Functions and modules
Introduction
Using functions
Defining functions
Default values and optional parameters
Modules
Importing modules
Creating modules
Use of __name__
Example 1
Example 2
Functional tools
Anonymous functions
Map
Filter
List comprehension
Reduce
Why not just use for-loops?
Speed
Common tasks
Many ways to compute a series
Sorting
Efficiency
From Matlab to Python
Important commands
The for-loop
The if-then statement
Indexing
Matrices
Python shells
IDLE
Python (command line)
Interactive Python (IPython)
IPython console
Jupyter Notebook
Spyder
Editors
Symbolic computation
SymPy
Output
Symbols
isympy
Numeric types
Differentiation and Integration
Ordinary differential equations
Series expansions and plotting
Linear equations and matrix inversion
Non linear equations
Output: LaTeX interface and pretty-printing
Automatic generation of C code
Related tools
Numerical Computation
Numbers and numbers
Limitations of number types
Using floating point numbers (carelessly)
Using floating point numbers carefully 1
Using floating point numbers carefully 2
Symbolic calculation
Summary
Exercise: infinite or finite loop
Numerical Python (numpy): arrays
Numpy introduction
History
Arrays
Convert from array to list or tuple
Standard Linear Algebra operations
More numpy examples…
Numpy for Matlab users
Visualising Data
Matplotlib (Pylab) – plotting y=f(x), (and a bit more)
Matplotlib and Pylab
First example
How to import matplotlib, pylab, pyplot, numpy and all that
IPython's inline mode
Saving the figure to a file
Interactive mode
Fine tuning your plot
Plotting more than one curve
Histograms
Visualising matrix data
Plots of z=f(x,y) and other features of Matplotlib
Visual Python
Basics, rotating and zooming
Setting the frame rate for animations
Tracking trajectories
Connecting objects (Cylinders, springs, …)
3d vision
Visualising higher dimensional data
Mayavi, Paraview, Visit
Writing vtk files from Python (pyvtk)
Numerical Methods using Python (scipy)
Overview
SciPy
Numerical integration
Exercise: integrate a function
Exercise: plot before you integrate
Solving ordinary differential equations
Exercise: using odeint
Root finding
Root finding using the bisection method
Exercise: root finding using the bisect method
Root finding using the fsolve funcion
Interpolation
Curve fitting
Fourier transforms
Optimisation
Other numerical methods
scipy.io: Scipy-input output
Where to go from here?
Advanced programming
Compiled programming language
Testing
Simulation models
Software engineering for research codes
Data and visualisation
Version control
Parallel execution
Acknowledgements