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,
Langley Hall A202,
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 programming problems and
the project. There will be no other quizzes, tests, or exams.
Topics:
-
Access to Python:
Python may already be installed on your laptop;
You can use Anaconda to install Python and its libraries;
You can use the web application Google CoLab to create,
edit, and run Python code.
-
Basics, Interactive Python. Mathematical functions.
Creating and using variables.
-
If, using if statements and logical expressions to
control a calculation.
-
For, repeating a block of computations using a for or
while statement. Setting the loop index with the range
statement. Jumping to the next index with continue, or
exiting the loop with break.
-
Functions, organizing a small, useful calculation as a function.
Using the def statement to mark the start of a function, and
the return statement to return a computed value.
-
Lists, make a collection delimited by {[*,*,*]}; add or
remove elements. To copy a list, use .copy() rather than
an equal sign!
-
Prime numbers, starting and exiting loops. Testing a number
for primality.
-
Collatz conjecture, a problem for which mathematics is not ready,
according to Paul Erdös. The Collatz iteration. Number of
iterations to reach 1. Highest value encountered in a sequence.
Using a dictionary to build a table of results.
-
Vectors, how the vectors of linear algebra can be
created, modified, analyzed, and indexed, using the numpy() library.
-
Matplotlib, how to plot lines, functions, data sets, using
the matplotlib() library.
-
Matrices, how to define a matrix as a array of arrays of rows;
how to plot a matrix of data;
how to matrix-vector multiply; how to solve a linear system.
-
Magic, practice using numpy() arrays to create a magic
matrix, and test that the rows, columns, and diagonals
have a common sum.
-
REF, interactive Elementary Row Operations (EROs) to transform
a matrix to Row Echelon Form.
-
ChatGPT, chatting, not cheating, with ChatGPT. How to use online
resources without pretending it's your own work.
-
Linear Algebra, vector angles; solving linear systems;
finding eigenvalues; LU, QR, SVD factorizations.
-
The Page Rank algorithm, a method of assigning importance
to every node in a graph; this is the basis of the Google
search algorithm; it is also an example of the power method
for an enormous matrix; to get the power method to work on
an enormous network, the algorithm's inventors had to
patch the original method, and add a randomization feature,
in order to get good results quickly. This is a fundamental
algorithm of machine learning.
-
Random numbers, uniform and normal distributions.
Choosing a generator. Repeating a random number sequence.
-
Sampling, creating models of systems with variable
behavior; uniform sampling of geometric regions; histograms
and variance;
-
Simulation, using random sampling to estimate the behavior
of a system that has a random component. Estimating the
probability density function with a histogram.
-
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.
-
Euler's ODE Solver, simulation in time;
the initial value problem; Euler's method;
the phase plane portrait.
-
Systems of Differential equations,
solving a pair of ODE's; solving a second order ODE.
-
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 {\tt{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.
Assignments:
Files:
Links:
-
https://www.anaconda.com/ ,
Anaconda;
-
https://colab.research.google.com/ ,
Google Colab;
-
https://docs.python.org/3/tutorial/ ,
Python tutorial;
-
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;
Last revised on 09 December 2024.