Computational Physics
Lecture 1
Aims
- Teach the techniques of computational physics and numerical methods
- side benefit: develop familiarity with python
Syllabus
- Numerical Differentiation: Learn methods for approximating derivatives when analytical solutions are not feasible or too complicated.
- Numerical Integration: Techniques for estimating the integral of functions that cannot be integrated using elementary calculus will be explored.
- Numerical Solution of ODEs: Understand methods to solve Ordinary Differential Equations that appear in various scientific and engineering disciplines.
- Monte Carlo Techniques & Random Walks: We will delve into probabilistic algorithms used for simulations in diverse applications like finance and molecular modeling.
- Function Minimization and Optimization: Learn the key methods for finding optimum points of a function, a crucial task in machine learning, economics, and engineering.
Organisation
email: will.yeadon@durham.ac.uk
office: TLC033
Office Hour: Friday 2-4.55 starting week 2, either in person in my office PHY304 or via Teams.
Lectures
- Fri 12-13. This week half the lecture is covering organisation, from next week onwards this section will be to go over the previous weeks assignment and as a Q&A session.
- The technical material will also be available as videos on learn ultra which can be watched while trying the programing.
- Adaptable format depending on people's needs. Currently the lectures are directly on this site so that you can easily refer to them.
Workshops
- Mon, Tue, Thu, Fri 17-18
- Attendence is not monitored
- Cannot change the day
- In ENGEX1
Computing environment
- We will use Jupyter notebooks for all the works in this course
- System introduced to you 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-2324.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 16th 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!
- Each assessement 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 and Data Visualization
- Why It's Useful: Data visualization is crucial for understanding data trends, making predictions, or presenting your findings. matplotlib provides a comprehensive range of plotting tools, from basic line and scatter plots to complex 3D visualizations.
- Key Features: Customizable plots, support for various formats like PNG, PDF, and SVG, and integration with Jupyter notebooks for real-time data visualization.
-
numpy
: Fast Numerical Calculations with Arrays
- Why It's Useful: Numerical computing is the backbone of data science, machine learning, and scientific computing. numpy offers a fast and efficient multidimensional array object that dramatically speeds up numerical calculations.
- Key Features: Element-wise operations, broadcasting, linear algebra functions, and tight integration with other scientific libraries.
-
scipy
: Collection of Scientific Functions
- Why It's Useful: While numpy provides the foundational building blocks for numerical computation, scipy goes a step further by offering a large set of algorithms and utility functions for specialized scientific computing tasks.
- Key Features: Optimization, signal processing, integration, interpolation, eigenvalue problems, and more.
-
sympy
: Symbolic Calculation
- Why It's Useful: Unlike numerical computing, which provides approximate solutions, symbolic computing deals with mathematical objects analytically. sympy allows for algebraic manipulation, equation solving, and calculus operations in symbolic form.
- Key Features: Symbolic algebra, calculus, equation solving, and pretty printing of mathematical expressions.
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