PHY202 — (Python) Programming for Physicists
PHY202 is a fully online class that provides an introduction to programming in the Python programming language for physics majors. Although the examples are drawn from first year physics, anyone who is familiar with Newton’s equations of motions and ordinary differential equations will be able to follow. The overall goal is to enable students to write programs to solve their own numerical problems, no matter where the problems come from.
No programming experience is required. Although only 1 credit hour, the class is intense and requires the student to be serious about wanting to learn programming.
PHY202 is offered every semester (Fall, Spring, Summer) to give students an opportunity to learn programming as soon as they can fit the class into their schedule.
The class was designed as part of the new Online BA in Physics (see also description at ASU Online) but can be taken by anyone fullfiling the prerequisites.
The class can also be taken by anyone interested, even if not currently at ASU, by registering as a non-degree-seeking student and signing up. Feel free to contact the instructor, Dr. Beckstein, if you have questions or problems signing up.
Overview
PHY202 is an introductory class that teaches programming in the widely used Python language with applications to physics problems. This course covers the fundamentals of procedural and object oriented programming in Python together with the commonly used scientific libraries numpy for fast array computations and matplotlib for publication-quality plotting and visualization.
Course Learning Outcomes
At the completion of this course, students will be able to:
- write programs in Python to solve problems in physics;
- understand how to conceptualize and formalize a physics problem, cast it into equations, select or derive an algorithm to solve these equations, implement the algorithm in Python code, run the code, and visualize and analyze the output.
These skills are applicable to a wide range of problems and enable them to solve problems using computation that cannot be solved otherwise. The learning objectives are structured so that students achieve their educational goals by working out the exercises, assignments, and tests sequentially.
The class also prepares students for more advanced classes such as PHY432 — Computational Methods in Physics.
Approach
The emphasis of the class is on students programming and solving problems. Students primarily work through an interactive text book (a zyBook) with integrated programming exercises (“zyLabs”). Students write code interactively in a browser environment. The environment provides immediate, automated feedback and can also provide progressive hints to solutions. All assignments are administered through this system. The zyBook is a customized and enhanced version of the Programming Python 3 zyBook, which includes not only basic Python but also applications in Physics.
Instructional videos and other content are provided to explain specific details or put the work into a broader context.
Lesson outline
The class runs in the typical online format with one Module per week. Each week, students have to complete reading and homework assignments. Below is a broad overview of each module’s content
Module 1
- installing a Python development environment
- fundamentals of hard- and software
- the Python interpreter
- basic data types, variables modules
Module 2
- flow control
- container data types
- Midterm Test 1
Module 3
- functions
- modules and packages
- plotting with matplotlib
Module 4
- debugging techniques, exceptions and assertions in Python
- advanced plotting with matplotlib
- fundamentals of objects and object-oriented programming
- Midterm Test 2
Module 5
- NumPy (numerical python, working with arrays)
- Case Study I: The non-linear pendulum
Module 6
- text and files
- Case Study II: Analyzing experimental data
Module 7
- advanced NumPy (linear algebra and fast array operations)
- Case Study III: Solving problems in electrostatics (Laplace’s and Poisson’s equation in 2D)
- Final Test/Project
Requirements
Enrollment: Prerequisite(s): MAT 267 or 272 with C or better; PHY 151 with a C or better or PHY 131 and PHY 132 with C or better (basically, Newtonian physics, ordinary differential equations, vectors)
Text book: You need to buy access to the customized version of the zyBook; details will be made available when enrolling in the class. Familiarize yourself with how to work with the the zyBook and zyLab platform
You need a laptop where you can install software, namely the Anaconda Python distribution so that you can develop and run code locally. (The course provides instructions and helpful hints on how to do this.)
Class
The class is 1 credit hour and runs in the A session (7.5 weeks) of each Spring, Summer, and Fall semesters.
The class is available either as an iCourse (for on-ground students) or online through ASU Online; it’s the same online class, just under different labels. Search for PHY 202 in the ASU course catalog
The class encourages working together (programming is often done in teams, as is most research!) with specific rules for allowed collaboration for assignments and exams. The Canvas discussion forum and (optionally) a Discord Server provide informal spaces for collaboration and rapid interactions with the instructional team and between students.
Discuss: “PHY202 — (Python) Programming for Physicists”