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 will 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:

  1. 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.
  2. Basics, Interactive Python. Mathematical functions. Creating and using variables.
  3. If, using if statements and logical expressions to control a calculation.
  4. 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.
  5. 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.
  6. Lists, make a collection delimited by {[*,*,*]}; add or remove elements. To copy a list, use .copy() rather than an equal sign!
  7. Prime numbers, starting and exiting loops. Testing a number for primality.
  8. 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.
  9. Vectors, how the vectors of linear algebra can be created, modified, analyzed, and indexed, using the numpy() library.
  10. Matplotlib, how to plot lines, functions, data sets, using the matplotlib() library.
  11. 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.
  12. Magic, practice using numpy() arrays to create a magic matrix, and test that the rows, columns, and diagonals have a common sum.
  13. Linear Algebra, vector angles; solving linear systems; finding eigenvalues; LU, QR, SVD factorizations.
  14. 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.
  15. Random numbers, uniform and normal distributions. Choosing a generator. Repeating a random number sequence.
  16. Sampling, creating models of systems with variable behavior; uniform sampling of geometric regions; histograms and variance;
  17. Simulation, using random sampling to estimate the behavior of a system that has a random component. Estimating the probabiity density function with a histogram.
  18. Grids, how to describe, access, manipulate and plot data on a rectangular grid of cells.
  19. 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.
  20. Euler's ODE Solver, simulation in time; the initial value problem; Euler's method; the phase plane portrait.
  21. Systems of Differential equations, solving a pair of ODE's; solving a second order ODE.
  22. 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.
  23. 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.
  24. 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.
  25. Text, transfer information between a text file and a Python string or list of words. Read 'Alice in Wonderland' and count the words.
  26. 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.
  27. 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.
  28. 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.
  29. 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.
  30. 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.
  31. pandas() Data Analysis, a package for collecting, cleaning, and analyzing large sets of data. The library includes two new data types: Series and DataFrames.
  32. 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.
  33. Symbolic computing, using sympy; doing exact calculations with symbolic variables; differentiation; integration; simplifying products and quotients.
  34. Plane geometry, the convex hull; the Delaunay triangulation; the Voronoi diagram.

  35. Following topics to be written up soon.
  36. Nonlinear equations, defining a function; implementing a solution iteration; testing for convergence.
  37. Heat, solving the steady state heat equation over a rectangular region.
  38. Spiral PDE, solving partial differential equations over time and two space dimensions.
  39. Geometry, the Convex Hull; the Voronoi diagram; Delaunay triangulation;

Assignments:

Files:

Links:


Last revised on 08 November 2024.