PHYS 5P10 - Introduction to Scientific Computing
Course outline
Instructor: E. Sternin

What Brock calendar entry says (slightly revised for the current calendar):

  • Survey of computational methods and techniques commonly used in condensed matter physics research; graphing and visualization of data; elements of programming and programming style; use of subroutine libraries; common numerical tasks; symbolic computing systems. Case studies from various areas of computational physics. Discipline-specific scientific writing and preparation of documents and presentations.

What do I need to bring into the course?

  • This course is a core course of the MSMP program, and is recommended to all Physics graduate students. Basic familiarity with Linux is assumed, and will be reviewed briefly.

Course Goals

  • to develop a working knowledge of interactions with Linux OS
  • to become proficient in experimental data graphing and numerical analysis
  • to gain working knowledge of program development
  • to become familiar with one or several interpreted programming environments, and to acquire basic scripting skills
  • to become proficient in LaTeX and use it for scientific papers and presentations


There is no formal textbook for the course. A number of online resources are available and can be used as reference material for the lectures. Some of these are: This list will grow as the course progresses.
This is an approximate outline. Topics not on this list may get covered as time permits.
  • A common toolbox
    • interacting with the OS; CLI vs GUI
    • Linux as a collection of small tools + pipes between them
    • the basics of programming: shell, C, scripting languages
    • code development: edit, compile, run, make and Makefile structure, elementary debugging, linking to program libraries
    • visualization with gnuplot and other graphing tools

  • Numerical methods
    • Numerical differentiation: finite differences, interpolation, root finding
    • Numerical integration: special functions and quadrature
    • Solution of Ordinary Differential Equations: Euler-Cromer, Runge-Kutta
    • Linear algebra: methods of solving systems of equations and eigenvalue problems
    • Stochastic Methods:Random number generators, importance sampling, Molecular dynamics, Monte-Carlo techniques

  • Case Studies/Projects
    • Least-squares problem: experimental noisy data, noise distribution and filtering, importance of baseline, assumption of Gaussian noise, chi-squared; classification of LS problems, regularization and selection of lambda. Test case: a spectrum of exponential relaxation rates
    • Molecular modeling: protein database data, force fields, GROMACS simulation package. Test case: a lipid bilayer with cholesterol guests (T.Harroun)
    • Models of solids: Ising model, magnetic moment, temperature, heat capacity, Metropolis' algorithm. Test case: magnetic transitions in an Ising lattice
    • Image Analysis: filtering to remove noise, segmentation to isolate regions and objects of interest, regional and spectral analysis to extract statistical data. Test case: spatial frequency distribution of a line image
Component % of the final mark Notes
Projects 70% Six (or seven, time permitting) extended projects. Project submissions should be made in the form of a jupyter notebook file, via email to the instructor.
Final presentation 30% One of the projects (selected at random) submitted in the form of a scientific journal submission, using Phys. Rev. or Can. J. Phys. format, and presented in-class as a research seminar.

Here is a summary of our expectations of you, which are your responsibilities. You are expected to:

  • Attend each scheduled lecture and laboratory session;
  • Do your work honestly and maintain academic integrity (see a separate section below for details);
  • Take responsibility for your own learning. The lectures/tutorials are there to guide you and assist you, but only you can actually do the hard work of learning the course material. To get the most out of the course, work on it a little bit every day. Daily work is key for placing your learning in long-term memory, where it will be readily available to help you to advance your knowledge in subsequent years. It is way too late to start working on a homework assignment the night before it is due.
  • Take pride in your work. After completing the computational tasks, take a look at the presentation: is it neat? is it clear? can it be made more efficient/effective? does it tell an interesting story to the reader? Effectively communicating your results to others is an important aspect of being a physicist, aim to hone your communications skills.
  • Use your time effectively. Study smart, instead of hard. Ask questions in class. Your instructor has an open-door policy, so outside of a few restricted hours, you are always welcome to come and ask a question one-on-one. Do not wait until you have a "worthy" pageful of questions - that's too long to let them fester unanswered. It is better to come three times with one or two questions than once with a list accumulated over the past several weeks, when things get too desperate.
Week 1. Due Th Sep 14
  • Cover all sections until the "Advanced Unix/Linux", but including the "File System Basics" from
  • Develop a personal "cheat sheet" of useful commands.
  • Choose an editor (vi or gedit) and learn its basics
  • Learn to use "jupyter notebook" to keep notes in this class; see /work/5P10/Lectures.
Week 2. Due Thursday Sep 21
  • Familiarize yourself with the "Advanced Unix/Linux" from
  • Complete a bash script for your choice of a task, involving file operations, searching for textual information inside files, etc.
  • Review and revise the skeleton Makefile distributed in the lecture; adapt it to the needs of your version of packet.c.
  • Modify and extend the functionality of packet.c to accept additional command-line switches, with and without parameters. Add error checking against invalid parameter values as needed.
  • Read through packet.f and reconcile its code to the derivation of the solution for the Schrödinger equation developed in class. Convert the solution into a dimensionless form.
Week 3. Due Thursday Sep 28
  • Complete the packet project. With the help of the existing Fortran code, develop packet.c that calculates a Gaussian packet, at a moment in time specified as a parameter at run time. Ample comments throughout your code must make its logic and its overall structure clear to any reader.
  • Develop a gnuplot script that runs your program repeatedly and demonstrates the evolution of the packet encountering a square-well potential.
  • Embed your code and your plots in a jupyter notebook, add markup cells that describe what your project has achieved, and what you learned along the way. Make sure your name is included in the top (header) markup cell of the project file.
  • Your jupyter notebook must be submitted via email to the instructor.
Week 4. Due Thursday Oct 5
  • Complete a plot and analysis of/work/5P10/Cavendish.dat, extract the value of \( G \) and its error estimate, and produce a publication-quality plot.

    Use one of eXtrema, gnuplot, octave, or python for plotting, provide detailed comments in the script, and ensure that a different data set could easily be analyzed using the same script, by changing only the data file name.

    The distance to the board on which the position of the laser dot was recorded is \(L=10.31\)m.

Week 5. Reading Week.
Week 6. Introduction to MATLAB/octave
  • Complete the introductory tutorial: basics, 2D and 3D plotting, loops, functions.
  • Explore at least two advanced topics: ODEs, integration, least-squares fits, linear algebra methods (e.g. svd).
  • Convert one of previously obtained graphing/fitting exercises (VI.dat, Cavendish.dat) to octave.
Week 7. MATLAB/octave project (to be submitted Oct.30)
  • Follow the skeleton of the project as posted in Lectures to learn how to read in the data from remote sites, parse and plot it, bring into a common data structure with a common time base.
  • Perform regression analysis to determine the role played by the two obvious major influencers.
  • Analyse trends in the adjusted data, with influencers removed.
Weeks 8-9. Inverse theory methods (to be submitted Nov.13)
  • Review the concept of SVD decomposition.
  • Analyze the skeleton code of regularize(); make sure you understand every line.
  • Modify the main code by adding appropriate loops, etc. to reproduce the results presented for the exponential example, including the L-curves, on the sample data provided in /work/5P10/test.dat
  • Automate the optimum selection of parameter λ. One possible approach is to seek the value that corresponds to the shortest distance to the origin on the L-curve. Be efficient: vary the step size in λ depending on how strong the dependence on λ is.
  • Optionally, use your program to analyze a real experimental data set (in /work/5P10/Inverse/).
Weeks 9-10. 2D FFT in polar coordinates (to be submitted Nov.23)
  • Carefully read the entire paper: Averbuch et al., 2005.
  • Explore 1D FFT (see the skeleton script below) to build intuition into its properties. Vary the width, position, and shape of pulses in the time domain, and see how the FT changes.
  • Create a family of test images that represent a cosinusoidal wave emanating radially from the centre in all directions, decaying with a Gaussian envelope as a function of the radial distance from the center. Postulate what a 2D FT in polar coordinates should look like for such test images, and perform the PPFFT. Was your initial guess correct?
  • Vary parameters of your test file: rate of Gaussian decay of signal intensity, size of the test image, level of random noise added, the execution time, the map of phase errors, etc. Choose some interesting aspect to explore extensively and prepare a summary table (and a plot, if appropriate) of your findings. Reflect and discuss the result in your conclusions.
  • See if you can measure the spacing of interference lines obtained in PHYS 3P91 experiments by using FFT. Sample images can be found in /work/5P10/Images. Use appropriate forms of FFT, depending on the image.
  • Prepare and submit a full project write-up, as a Jupyter notebook.
Weeks 10-11. Ising Model of ferromagnetism (to be submitted Dec.4)
  • Modify Evolve() function to implement the Metropolis algorithm.
  • Calculate total energy and magnetization and keep a record of these.
  • Repeat until the values settle to a stable equilibrium value; may need to ignore some early states that may reflect the initial conditions, wait until those are "forgotten".
  • Change the temperature and repeat, recording the equilibrium values and the extent of fluctuations for each temperature.
  • Plot magnetization as a function of temperature, find the conditions for ferromagnetic and antiferromagnetic transitions by exploring a range of parameters.
  • As an independent part of the project, modify to consider one of:
    • nearest- and next-nearest-neighbour interactions
    • triangular lattice
    • anisotropic spin-spin interactions, e.g. East-West coupling is different in strength from North-South coupling
    • lattice of spins that can re-orient at their sites, with the Hamiltonian given by $$ {\cal H} = - J \sum_{i,j} \vec{s}_i \cdot \vec{s}_j -\mu \sum_j \vec{h} \cdot \vec{s}_j $$ i.e. dependent on the [cos of the] angle between the two nearest-neigbour spins, and of each spin with the direction of external magnetic field. Without loss of generality, one can assume that $\forall j, \vec{h}_j=\vec{h}=h\hat{k}$.
Week 12. Final paper (to be submitted Th Dec.14)
  • Choose one of your previously completed octave/MATLAB jupyter notebooks and convert it to a scientific publication;
  • Report your results as if these were novel, and this means relating them to the previously known results (in the Introduction), reporting Methods and Results, and discussing the implications in Conclusions;
  • 5P10 students: review the instructions for authors of one of the AIP or Elsevier journals and select an appropriate LaTeX style file on;
  • 4P10 students: you can choose to do the same, or use a Lab Report template, i.e. generating not an original research publication, but an internal laboratory report; the rest of the requirements are the same and all of the above sections need to be present;
  • Before submitting, make sure that all figures and formulas remain legible and satisfy the journal guidelines in the final form of the publication, not just the preprint one.

Academic misconduct is a serious offence. The principle of academic integrity, particularly of doing one’s own work, documenting properly (including use of quotation marks, appropriate paraphrasing and referencing/citation), collaborating appropriately, and avoiding misrepresentation, is a core principle in university study. Students should consult “Academic Misconduct” section in the Undergraduate Calendar to view a fuller description of prohibited actions, and the procedures and penalties. The University takes academic misconduct extremely seriously and will follow its strict procedures to the letter in all cases.

A helpful website explains Brock's Academic Integrity Policy. Please consult it, as all students are expected to know and abide by its provisions.

Courses may use, a phrase-matching software, to verify originality of your submitted lab reports and written assignments. If you object to uploading your assignmentsr to for any reason, please notify the instructor to discuss alternative submissions.

Be aware that it is the policy of the Department of Physics that any academic misconduct including (but not limited to) possessing, using or accessing unauthorized material in any form (including online) during final exams or assessments will automatically result in zero grade for the exam. Since most courses require a minimum passing grade on the final exam to complete the course, this will likely lead to a failure in the course.

FMS Penalties for Academic Misconduct

Unless otherwise specified, the Department of Physics follows the following minimum penalty guidelines for cases of academic misconduct in the Faculty of Mathematics and Science (FMS). Please be aware that the Associate Dean, Undergraduate Programs, may assign different penalties than those listed here, depending on the details of individual cases. Also note that cheating on exams carries significantly higher penalties.

First offence:
Zero grade on the assignment, additional penalty of 100% of the weight of the assignment to be subtracted from the final grade, mandatory completion of the AZLS Academic Integrity workshop
Second offence:
Zero grade on assignment, additional penalty of 200% of the weight of the assignment to be subtracted from the final grade, 4-month suspension
Third or additional offence:
Zero grade in the course, 1-year suspension, permanent removal from major program.
Cheating on exams:
Zero grade in the course, including for first offenses.
Intellectual Property Notice

All slides, presentations, handouts, tests, exams, and other course materials created by the instructor in this course are the intellectual property of the instructor. A student who publicly posts or sells an instructor’s work, without the instructor’s express consent, may be charged with misconduct under Brock’s Academic Integrity Policy and/or Code of Conduct, and may also face adverse legal consequences for infringement of intellectual property rights.

Important dates

Please be aware of all the important dates, such as the first/last days of classes, snow days and reading week, as well as the deadline for withdrawal without academic penalty. For the current academic term, this information can be found here.


The University is committed to fostering an inclusive and supportive environment for all students and will adhere to the Human Rights principles that ensure respect for dignity, individualized accommodation, inclusion and full participation. The University provides a wide range of resources to assist students, as follows:

  1. If you require academic accommodation because of a disability or an ongoing health or mental health condition, please contact Student Accessibility Services at or 905 688 5550 ext. 3240.
  2. Medical Self-Declaration Forms (brief absence up to 72 hours)

    In the case of a short-term medical circumstance, if a student wishes to seek an academic consideration, please use the Medical Self-Declaration Form. The request is to be made in good faith by the student requesting the academic consideration due to a short-term condition that impacts their academic activities (e.g., participation in academic classes, delay in assignments, etc.). The period of this short-term medical condition for academic consideration must fall within a 72-hour (3 day) period. The form must be submitted to the instructor either during your brief absence or if you are too unwell, within 24 hours of the end of your 3 day brief absence.

    Medical Verification Form (extended duration)

    In cases where a student requests academic consideration due to a medical circumstance that exceeds 72 hours (three days) and will impact their academic activities (e.g., participation in academic classes, delay in assignments, etc.), or in the case of a final exam deferral, the medical verification form must be signed by the student and the health professional as per process set out in the Faculty Handbook III:9.4.1.

  3. If you are experiencing mental health concerns, contact the Student Wellness and Accessibility Centre. Good2Talk is a service specifically for post-secondary students, available 24/7, 365 days a year, and provides anonymous assistance. Follow the above link or call 1-866-925-5454. For information on wellness, coping and resiliency, visit: Brock University (Mental Health).
  4. If you require academic accommodation on religious grounds, you should make a formal, written request to your instructor(s) for alternative dates and/or means of satisfying requirements. Such requests should be made during the first two weeks of any given academic term, or as soon as possible after a need for accommodation is known to exist.
  5. If you have been affected by sexual violence, the Human Rights & Equity Office offers support, information, reasonable accommodations, and resources through the Sexual Violence Support & Education Coordinator. For information on sexual violence, visit Brock's Sexual Assault and Harassment Policy or contact the Sexual Violence Support & Response Coordinator at or 905 688 5550 ext. 4387.
  6. If you have experienced discrimination or harassment on any of the above grounds, including racial, gender or other forms of discrimination, contact the Human Rights and Equity Office at

For a full description of academic policies in the Faculty of Mathematics and Science, consult