Computational Physics
Lecture 1
Aims
- Teach the techniques of computational physics and numerical methods
- side benefit: develop familiarity with python
Syllabus
- Numerical differentiation
- Numerical integration
- Numerical solution of ODEs
- Monte Carlo techniques, random walks
- Function minimization and optimization
Organisation
email: peter.richardson@durham.ac.uk
office: OC207
Office Hour: Friday 3-4.45 starting week 2, either in person in my office or via zoom.
Lectures
- Fri 12-13. For week 1 the material will be presented in the lecture. After that we will use the lecture slot to go over the previous weeks assignment and as a Q&A session.
- The material will be available as videos which can be watched while trying the programming.
Workshops
- Mon, Tue, Thu, Fri 17-18
- Attendance is not monitored
- Cannot change the day
- In D/ENGEX1 the annex to engineering, CANNOT be accessed from inside engineering. Enter either via the small door shown below or easier up the hill and turn left.

Computing environment
- We will use Jupyter notebooks for all the works in this course
- System introduced last year:
- electronic submission, marking and feedback
- easier interaction with python
- better integration of plots and animations
- accessible from anywhere
- Please report problems!
- Manual available at https://notes.dmaitre.phyip3.dur.ac.uk/notebooks/
- log in to the server using your CIS username and password: https://compphys-2425.notebooks.danielmaitre.phyip3.dur.ac.uk/
- go to the “Assignment” tab
- select the assignment and “fetch” it
- open the assignment section and select the notebook to use. It will open in a new tab.
- work on the assignment
- your work is automatically saved
- you can also save your work with the “save icon” or the File menu
Programming environment
- we use python 3
- all packages you need should be installed on the server
- if you think a package would be useful but is not installed let me know
Saving your work
- your work is automatically saved every few minutes
- save your work with the “save icon” or the File menu
- your python session will be closed after 1-2 hours of inactivity
- the text and output in the notebook will be saved
- the state of the python interpreter will not be saved:
- you need to reevaluate all cells to restore the state
- use “Kernel” -> “Restart and run all”
- it is useful to do this occasionally to make sure the notebook runs as written and does not rely on code executed previously and edited since
- can save a copy of your notebooks using “File” -> “Download as” -> “Notebook”
- backup every hours of saved files
- only in emergencies: you have to ask me to restore the file
- you can make copies of notebooks “File” -> “Make a copy” but for the assessment only the original file will be considered!
Working on the server
- Feel free to create new notebooks to experiment and play
- I can see everything you do on the server so:
- follow the CIS usage policy
- don’t use the resources for other purposes than academic ones
- don’t try to trick the marking system
Assessments
- 8 assessments
- distributed through the notebook server
- submitted through the notebook server
- deadline: Mondays 14:00 (starting Week 3, i.e. 1st assignment due 21st October)
- the last submission counts! Submit partial work to avoid having no submission in time at all.
- if your first submission is after the deadline no marks will be awarded!
Assessment
- Each assessment will be composed of one or more notebooks
- Each notebook will have a description of the tasks to perform
- It will be in the form of either:
- a piece of code to provide
- a task (for example producing a plot)
- a free text question
Assessment: piece of code
- if you are asked to provide a piece of code the location will be marked by a
# YOUR CODE HERE
marker
def double(x):
# YOUR CODE HERE
raise NotImplementedError()
Assessment: piece of code
- replace the marker (and the
raise
statement) with a valid piece of code:
def double(x):
return 2*x
- code tasks will typically be followed by a test that helps you check that your code’s functionality is correct
assert double(4) == 8
Assessment: piece of code
- when you click on the “validate” button in the notebook or in the assignment list the notebook is run and checks that all these
assert
tests pass, you will get a warning if they don’t.
- these tests are part of the assessment: if they don’t pass you won’t get all marks!
Assessment: free text question
A free text question will be followed by a cell with the text
YOUR ANSWER HERE
You can double click on it and edit the text. You can use $\LaTeX$
Feedback
Feedback will be made available on the notebook server.
I will demonstrate it after your first assignment’s feedback is ready.
Getting Help
Useful packages
matplotlib
: plotting
numpy
: fast numerical calculations with arrays
scipy
: collection of scientific functions
sympy
: symbolic calculation
See new L1 python resource for more on these packages
Useful tips
- tab completion
- inline help (append ? to a command)
- execution can be interrupted using the $\rm {\blacksquare}$ button