MTH3007b Lecture 11

Me, in the lecture

zzzzz…

This is a revision session. The structure is: feedback on the Python arrays/matrices exercise from lecture 10, feedback on the implicit BTCS code, then a list of revision exercises to consolidate the whole module.

Section 50: Arrays and Matrices - Python Feedback

Finding the Maximum in a Matrix

Two approaches for finding the maximum absolute difference between two arrays, as introduced in lecture 10:

Python
Output

The iterative loop and the np.amax version are equivalent. The vectorised form is preferred for clarity and speed.

Array copying reminder

Use B = 1.0*A or B = A.copy() for genuine copies. B = A creates an alias - modifying B will also modify A.

Section 50.2: Implicit Method (BTCS) - Code Feedback

The full BTCS implementation using matrix inversion is:

Python
Output

Key points from the feedback: the matrix is built once before the time loop; np.linalg.inv(A) is called once; np.matmul(Ainv, u) advances the solution at each step. BTCS is unconditionally stable so no check is needed.

Section 51: Revision Exercises

Retry all exercises from previous sessions of this module.

Additionally, work through the following exercises from Chapra & Canale:

1st Order ODEs

  • 25.1, 25.3, 25.4, 25.5, 25.6, 25.17, 25.19, 25.21
  • Try each with RK4, implicit Euler, and implicit trapezoid.

Systems of ODEs

  • 25.7, 25.25, 28.10

2nd Order ODEs

  • 25.16, 25.18, 25.22

1D Monte Carlo Integration

  • 22.1, 22.2, 22.3

PDEs

  • 30.7 (PDE - Dirichlet BCs)
  • 30.16 (PDE - Neumann BCs)

Test scope

Stochastic ODEs are not included in the Chapra & Canale exercise list above, but they could be asked in the test.


Pre-Lecture Notes from University Notes

  • Feedback on array/matrix Python: np.amax vs iterative loop for max difference; array copy pitfalls.
  • BTCS feedback: build once, invert once with np.linalg.inv, apply np.matmul each time step.
  • Revision: retry all module exercises; plus Chapra & Canale 25.1-25.21 (ODEs), 25.7/25.25/28.10 (systems), 25.16-25.22 (2nd order), 22.1-22.3 (MC), 30.7/30.16 (PDEs).
  • Stochastic ODEs not in the exercise list but may appear in the test.