Example Python programs

Here, you can find a small collection of Python code examples. These programs were originally written by Prof. Hans Petter Langtangen. They have now been simplified and/or adjusted to be compatible with Python 3.

Python code as solution of exercise "Differentiate a function" from the stand-alone module of "Finite Difference Computing with Exponential Decay Models"

Python code as solution of exercise "Exponential growth" from the stand-alone module of "Finite Difference Computing with Exponential Decay Models"

Python code as solution of Problem 1.1 (Use linear/quadratic functions for verification) from Chapter 1 of "Finite Difference Computing with PDEs"

Python code as solution of Exercise 2.1 (Simulate a standing wave) from Chapter 2 of "Finite Difference Computing with PDEs"

Python code as an example of solving a 2D wave equation, relevant for Section 2.11 of "Finite Difference Computing with PDEs". (Note: This code example can be modified to solve the first mandatory project.)

Python code that corresponds to Section 3.2.4 of text book 2 (Introduction to Numerical Methods for Variational Problems)

FEniCS example 1 (solving a 2D Poisson equation)

FEniCS example 2 (solving a 2D heat equation with Backward Euler time discretization)

Useful resources: A tutorial about how to use the Matplotlib module.

By Xing Cai
Published Sep. 11, 2020 5:04 PM - Last modified Oct. 28, 2020 4:36 PM