python_2025
https://people.sc.fsu.edu/~jburkardt/classes/python_2025/python_2025.html
python_2025 is the home page for the class:
MATH 2604: Advanced Scientific Computing 4,
"Mathematical Programming with Python,"
University of Pittsburgh,
Monday/Wednesday/Friday, 1:00-1:50pm,
Instructor: John Burkardt,
Spring Semester 2025.
This course teaches you how to write computer programs in the
Python language that can represent, illustrate, or solve
various common mathematical problems. You will write and run
many programs on your personal laptop. The emphasis will be
on learning the numpy numerical library and the
matplotlib graphics system. We may also work with a few
functions from graphviz (for visualizing a mathematical graph),
pandas (a statistics and data library), PIL (the Python
image library), scipy (scientific Python library), and
sympy (for symbolic calculations). These tools will be used
on various simple examples of mathematical questions.
No previous computing experience is required. The mathematics
will be at an introductory level, and all details will be explained,
so students from other scientific disciplines should also be
able to handle the matrieral.
A problem list will be assigned each week, and you will select three
to work on. By the end of the semester, you will also have created
and presented a programming project based on some topic of interest
to you. Your grade will be based on the assignments and
the project. There will be no other quizzes, tests, or exams.
Choice of future topics:
-
RREF, interactive Elementary Row Operations (ERO) to transform
a matrix to Reduced Row Echelon Form.
-
ChatGPT, chatting, not cheating, with ChatGPT. How to use online
resources without pretending it's your own work.
-
Regression, given a set of data (x,y), making a parameterized
model y=f(x:a,b,c,...), and seeking parameter values that minimize
the total error of the model. This is an important idea in the
field of machine learning.
-
Grids, how to describe, access, manipulate and plot data
on a rectangular grid of cells.
-
Grid simulation, examples of simulation of events in which
a spatial component is represented by a grid of cells, including
the movement of Mexican jumping beans, the spread of forest fires,
the percolation of a liquid underground and the progress of
an epidemic disease.
-
Using a scipy() ODE solver,
stiff ODE's; the scipy() function solve_ivp();
solving the predator-prey and van der Pol equations
again; a challenging problem: the Arenstorf orbit.
-
Conservation Laws for ODE's,
even if you don't know the exact solution of an ODE, you may
know that the solution must satisfy a conservation law.
In a disease model, the total number of people should be
constant (unless we include births and deaths); when describing
motion over the earth's surface, the next position can't suddenly
drift up into the air, or down into the ground; a swinging
pendulum might slow down if we include friction, but we don't
believe a solution in which the swings get ever larger.
-
BVP, solving a boundary value problem in one dimension,
defined by a second order differential equation, with a separate
boundary condition at each endpoint.
-
Animation,
many computations don't make sense or don't make an impression
until you can present them graphically. For time-dependent
results, an animation can bring your results to life. Animations
can be built by saving a sequence of snapshot files and calling
some function to paste them together, or by using the Python
utility FuncAnimation(). We focus on animating the Arenstorf orbit,
to see how the orbiter is able to rendezvous with a moving target.
-
Text, transfer information between a text file and a Python
string or list of words. Read 'Alice in Wonderland' and count
the words.
-
Dictionaries, the Python dictionary data type is a very
clever and useful extension of the array. Instead of a numeric
index, a dictionary uses a keyword to find an item. It is easy
to add new entries to the dictionary. We will see that a
dictionary can be used to make our Collatz conjecture code
much more efficient, so that our data begins to resemble a
tree structure with each number pointing to its successor in
the sequence.
-
Graph_tools, a number of algorithms on graphs. There are a variety
of ways to represent a graph, including the use of an adjacency
matrix, a list of pairs of nodes, and dictionaries. There is
also a very useful graph_viz() library for plotting. We can
listing nodes or edges, finding isolated nodes,
adding a node or an edge, determining all nodes reachable from
a given node, finding a path from one node to another.
-
TSP, the Traveling Salesperson Problem, seeks the shortest
round trip on a graph that visits every node exactly once.
There is no algorithm that is guaranteed to produce the best
solution. We will look at brute force for small problems, some
simple approaches that seem likely to handle moderate problems,
discover that even visiting the 48 "mainland" state capitals is
NOT a moderate problem, and then see that an approach suggested
by Cleve Moler does a very good job on that problem.
-
Knapsack, the Knapsack Problem seeks to maximize the
value of loot taken by a burglar whose knapsack has a weight limit.
We seek solutions by random sampling, brute force check of all
possibilities, ranking the items greedily adding the next best
item, or using dynamic programming. For the brute force approach,
Python's itertools() library will generate all subsets for us.
-
Matplotlib Plus, how to plot pairs of graphs, scatter plots,
contours, surface plots, vector plots, mathematical graphs,
the area between two curves, histograms, color-filled polygons.
-
scipy() Scientific Computing, a scientific computation
library, including
sublibraries for special functions (Airy, Bessel, Beta,
Elliptic, Error, Gamma, ...), numerical integration,
differential equations, image processing, optimization,
interpolation, and linear algebra.
-
pandas() Data Analysis, a package for collecting, cleaning,
and analyzing large sets of data. The library includes two new
data types: Series and DataFrames.
-
Basketball Bucks, using the pandas() library, we can read
a dataset of statistics for a basketball team into a DataFrame,
update the dataset with new information, compute statistical
factors, make histograms and scatterplots, and use linear
regression to construct simple models of the data to investigate
patterns in salary.
-
Symbolic computing, using sympy; doing exact calculations
with symbolic variables; differentiation; integration;
simplifying products and quotients.
-
Plane geometry, the convex hull; the Delaunay triangulation;
the Voronoi diagram.
-
Gaussian Primes, these play a similar role for complex integers,
to what we know about the familiar prime numbers. Plotting the
locations of the Gaussian prime numbers, we can define a sort of
pinball game, which creates Gaussian Prime Spirals. An unproved
conjecture suggests that every game ends in a finite number of steps.
You may design a project based on your own ideas and interests.
But if you can't think of one, here are some suggestions. If you
choose one of these, let me know so I can reserve it for you.
-
Calendar, a calendar is a device for naming and indexing days.
Because calendars include information about the day of the week,
the month, the season, the year, it becomes difficult to answer
simple questions like what day of the week was I born, how many
days have I lived, what is today's date in the Chinese calendar,
and so on. In this project, you will try to write programs that
answer some of these questions.
-
Cats, a common machine learning task is to ``classify'' data,
that is, to make a judgment about what class it belongs to. An
especially difficult classification problem involves images.
A special kind of technique for this problem is known as a
convolutional neural network, which is able to identify specific
features that show up in related images. This project involves
running a keras program that tries to determine whether a picture
is a cat or a dog. Your task would be to explain how the program
works, and what special features of a convolutional neural network
make it possible to sort the images.
Student I.Z. may be interested in this project.
-
Flow Optimization, based on an article by Reinhard Sellmair,
which considers the problem of a directed network which includes
source and sink nodes, whose links have limited capacity. It is
desired to plan the movement of some objects from the source nodes
to the sink nodes, minimizing an associated cost. The article
points to a Python implementation. You could start by trying to
get this code and run it. Then you might try to explain some of
what is going on, or come up with some new examples to test the
code on.
-
HJB PDEs,
This project involves Principal Agent problems,
which can be formulated as a Hamilton-Jacobi-Bellman PDE. It is
interesting to study how the initial condition affects the
resulting solution.
Student C.D. has suggested and reserved this project.
-
Keras, using the keras program to analyze a set of 50,000
movie reviews from the Internet Movie Database, which have already
been labeled "positive" or "negative" reviews. By looking at the
word choice in each review, try to predict the positive or negative
rating.
Student I.Z. may be interested in this project.
-
Life, this project asks you to implement
a Python version of John Conway's Game of Life. This is a simulation
studying the changes in a grid of cells, some of which are living
and some dead. Deaths and births occur according to a set of rules.
Student T.Y. has reserved this project.
-
Maze, decide how to represent a maze as a rectangular logical
array; generate a random maze; try several algorithms that seek a
path from a starting point to an end point. Discuss why some
algorithms fail.
Student M.S. has reserved this project.
-
Minecraft, an ice farm can be established on an n by n grid
of cells. Some cells can be initialized to be permanently
occupied by water. A miner can collect the cells that have turned
to ice. Afterwards, emptied cells with appropriate neighbors
may refill up water, which may then turn to ice. The goal is to
generate appropriate choices of the fixed water cells which guarantee
a rapid restoration of the ice field.
Student E.H. has reserved this project.
-
Polygon, for an arbitrary polygon, determine if it is convex
or regular (not self-intersecting). Compute the area and centroid.
Triangulate a convex polygon (not hard) or a regular polygon
(hard, I can give you a code to do this). Compute random samples
of a polygon, and estimate integrals. Is a point in the polygon?
Do two polygons intersect?
-
Primality, finding new prime numbers is useful, because they
are part of many encryption systems. Fermat and Mersenne both
considered special classes of numbers that seemed to contain many
large primes. Checking the primality of a very large number is
a difficult task. One tool is the Lucas-Lehmer test. In this
project, you will look at using implementing this tool in Python
and applying it to several candidates that might be prime.
-
Scattering, an important problem in geometry is how to
evenly distribute a set of points inside a given shape,
which might be a square or circle, a polygon, an ellipse,
or an irregular shape such as the outline of a body. A good
method for doing this mainly requires the ability to produce
as many random sample points from the region as we need. In
this project, you will start with a bad arrangement of points
inside a circle, and try to transform them into a neat pattern.
-
StarBattle,
an online puzzle game in which you are given a
grid subdivided into regions. The player must place a star
in each region. However, there must never be two stars in the
same row or column.
Student G.R. has reserved this project.
-
Triangle, compare several methods for generating random points
in a triangle. Some of them will not do a good job. Use each
method to plot 1000 points and see which plots seem uniform.
For the acceptance/rejection approach, you will need to work out
a method that decides whether each point you generate is inside
the triangle.
Links:
-
https://www.anaconda.com/ ,
Anaconda;
-
https://colab.research.google.com/ ,
Google Colab;
-
https://hub.docker.com/_/python ,
Docker;
-
https://docs.python.org/3/tutorial/ ,
Python tutorial;
-
https://pypi.org/ ,
Python Package Index (Over half a million projects);
-
https://scikit-learn.org/stable/ ,
scikit-learn, machine learning in Python ;
-
https://keras.io/ ,
keras, deep learning for humans;
-
https://www.johndcook.com/blog ,
John D Cook's blog, frequently discusses small Python programs;
-
https://github.com/guttag/Intro-to-Computation-and-Programming ,
John Guttag,
Introduction to Computation and Programming Using Python;
-
https://scipython.com/ ,
Christian Hill, Learning Scientific Programming with Python;
-
https://pythonnumericalmethods.berkeley.edu/notebooks/Index.html ,
Qingkai Kong, Timmy Siauw, Alexandre Bayen,
Python Programming and Numerical Methods;
-
https://link.springer.com/book/10.1007/978-3-031-16972-4 ,
Einar Smith,
Introduction to the Tools of Scientific Computing;
-
https://towardsdatascience.com/ ,
Towards Data Science, a web site with many articles that use
Python for data science applications.
Last revised on 14 February 2025.