RSS Amplifier

Blog

JMFT

jmft.devRSS feed ↗36 posts

Written by

Latest posts

Solutions to the heat equation converge to the similarity solution

The heat equation $$ \begin{align} u_t &= u_{xx}, \quad x \in \mathbb{R}, \quad t > 0, \\ u(x, 0) &= u_0(x) \end{align} $$ admits a self-similar solution of the form $$ K(x, t) = \frac{1}{(4 \pi t)^{1/2}} \exp\left(\frac{-x^2}{4t}\right) $$ when the initial …

Why the tax year starts 6 April: Further calendar pains

Following the saga about dates, times and timezones and times and clocks in computer systems ... I was reading the Wikipedia article on Robert Hooke , and noticed this horrifying footnote about the date of his death: These dates are according to the Julian calendar, which was still in use in England …

The price of dot

Here are a few different ways to do the same thing. x = [1, 2, 3, 4] # Option 1 x[0] # Option 2 x.__getitem__(0) # Option 3 from operator import getitem getitem(x, 0) # Option 4 import operator operator.getitem(x, 0) Functionally, they are meant to be equivalent to …

How to think about Python decorators (or, everything you never wanted to know about decorators but have been forced to find out anyway)

Function decorators are one of the most powerful features in the Python language, as they provide a succinct way to modify the behaviours of functions – often providing a quick one-liner to endow functions with useful behaviours or properties. However, they can be confusing because (a) the syntax for creating decorators …

Making a simple image slideshow with moviepy

I am working on a project in which I have a sequence of photos (JPEG files, all the same size) that I want to put into a slideshow, along with a background soundtrack. The examples that Stack Overflow, Reddit, Google AI and Claude gave me were all incorrect: imports didn't …

Making approximations in fluid mechanics: The weir problem

I am supervising an intro to fluid dynamics course. My students often find that the maths, formulae and calculations are not difficult, but find it harder to know when to make what assumptions/approximations/simplifications, how to justify them, and then when the formulae apply. Learning to make appropriate assumptions …

Part II Mathematical Biology resources

The Part II Mathematical Biology course is an excellent introduction to mathematical modelling of dynamical systems, and opens the way to many applications in diverse areas. This page is work in progress, and I shall add to it as I find more interesting stuff. Suggestions are always welcome, email me …

Sketch proof of the Arnold-Liouville theorem

This is a high-level, informal summary of the proof of the Arnold-Liouville theorem as stated and proved in V. I. Arnold's Mathematical Methods of Classical Mechanics (chapter 10, page 271). Due acknowledgement must also be given to Maciej Dunajski's notes on Integrable Systems ( web ), which I used as a reference …

Part IB Fluid Dynamics resources

Fluid dynamics is a huge and broad topic spanning physics, maths, engineering, geosciences, and many more. The introductory course only scratches the surface of classical fluid dynamics theory; and there is much fascinating, but accessible, material for the aspiring fluid dynamicist. This page lists some of my favourites, and it …

A functional Fizzbuzz implementation

from functools import reduce from itertools import count FACTORS = {3: 'fizz', 5: 'buzz'} fizzbuzz = lambda n: reduce( str.__add__, (FACTORS[d] for d in FACTORS if n % d == 0), "" ) or str(n) print( *map(fizzbuzz, range(1, 31)), sep='\n' )

Putting Jupyter notebooks under source control with Quarto

Jupyter notebooks are an excellent way to provide interactivity. Extremely helpful when building tutorials and demos. However, putting Jupyter notebooks under source control is messy: the .ipynb format is a JSON-based format that combines content (code and Markdown text) with state information (outputs, version numbers, etc.), and you need to …

Notes on the method of characteristics (short version)

Just some of my old notes that I dug up on the method of characteristics from when I taught this in 2021: download I'll write these up properly later.

The semitone filter: Adding a pipe organ to The Magic Flute Overture

Over the Christmas holiday I've had a chance to play around with a few ideas that I've had with signal processing. One idea that I had was to try a "semitone filter", emphasising out precisely certain frequencies in an audio signal while suppressing all others. This is not the same …

Manipulating PDF files in Python, and fun with itertools

I have access to a scanner that can scan multiple pages, but does not have a duplexer. So to scan double-sided, I need to feed in the pages face up, scan them, then turn the pages face-down and scan again. Thus I need to interleave the pages from the two …

Part IB Quantum Mechanics resources

This page lists things possibly of interest to my Part IB Quantum Mechanics students. It will be updated from time to time. Reference material The Schedules define the limits of the course (specifically, a lower bound for lectured material and an upper bound for examinable material). Examples Sheets for this …

But what does $\delta F = 0$ mean?

The following discussion is meant to give some more formalism to students of the Variational Principles course and perhaps tie it to material that they might have come across in analysis or linear algebra courses. A functional is a function of a function: $$ F[y] = \int_a^b f(x, y …

Quantum mechanics revision guide

This page, which will be updated occasionally, summarises important results and useful formulae for the Part IB Quantum Mechanics course. Vector spaces, inner products and duality Let $V$ be an inner product space over $\mathbb{C}$. We use ket notation for vectors: $|\psi\rangle \in V$ The inner product between …

Storing times, and precision of float64

This is the second article about how working with temporal information in computer systems. The first article was about contained some definitions about astronomical time and timezones. This article describes options for storing temporal values in your programs, and their limitations. In particular, it describes two pitfalls that can happen …

Pseudovectors and transformations

Here are some notes for my Fluid Dynamics II students about vectors, pseudovectors and how they transform under reflections. $$ \newcommand{n}{\mathbf{n}} \newcommand{r}{\mathbf{r}} \newcommand{v}{\mathbf{v}} \newcommand{L}{\mathbf{L}} \newcommand{R}{\mathsf{R}} $$ Let $\n$ be a unit vector, $\Pi$ be the plane perpendicular …

Naming is power

Many cultural and religious traditions place a lot of importance in names, and hold that names have power. There is something magical about them. In Classical Greek tradition, Hades was feared and his name was not spoken. The Bible supposes that the name of God is to be used for …

Why learners find classes and objects confusing

One reason why Python is such a popular and powerful language is that it is straightforward to learn and make good progress. Learners can quickly become comfortable with many aspects of the language, such as control flow and functions. The first obstacle that many learners come across is when they …

Date, time and timezones

This is a collection of notes about time and related concepts. A future post will talk about the problems of representing time in computer systems, especially distributed systems. These notes will be occasionally updated. Introduction Time is taken to be a primitive concept that cannot be defined in terms of …

Does vibecoding make coding more accessible?

I was a volunteer and organiser for codebar for several years and was heavily involved in outreach activities during my time at Cambridge. In the face of cuts to DEI initiatives, I believe that the lack of diversity at all levels of the tech sector seriously harms the sector. Besides …

Category theoretic ideas in data engineering systems design

I have been reading – at a very shallow level – about category theory ( wiki ), and thinking about its applicability to software and system design for data engineering. This post is a loose collection of thoughts on the subject, and a manifesto for employing a more rigorous language when building such systems …

On regulation in software engineering

Emergency services, GPs, hospitals, transportation systems and the like are funded, at least in part, by public money. When their computer systems go down, the public is badly affected and people can get hurt, and lives can be put at risk. So what regulations and quality controls are there on …

Logging in Python

Having reliable, detailed but searchable logs is an essential part of any application, especially of long-running services that need to be debugged and monitored for uptime and stability. As one of the oldest modules in the Python standard library, the logging module provides a very powerful set of tools for …

Object creation patterns in Python: Static factory methods

The basic way to create and initialize an object in Python is using the default constructor, defined as the __init__() method: class MyClass: def __init__(self, x: float) -> None: self.x: float = x print(f"created an object with x = {x}") obj = MyClass(5) Usually, initial values of instance variables …

In Praise of Visualization

A little investment into building a GUI for live visualizations and control provides huge improvements in iteration speed. I recently came across the excellent video Coding Adventure: Simulating Fluids wonderfully explained by Sebastian Lague . The video walks through the steps to build a simple smoothed particle hydrodynamics simulation from nothing …

Communicating with the past and the future

Originally written May 2022. Introduction In his dialogue Phaedrus , Plato has unflattering things to say about the development of writing, arguing among other things that it weakens the memory: And so it is that you by reason of your tender regard for the writing that is your offspring have declared …

Are vegans vegetarians? and related questions

I recently asked the following questions: Assuming all other requirements are the same: Is a vegan a vegetarian? Is a vegetarian a vegan? To my (somewhat) surprise, this drew quite a lot of interest from colleagues, friends, and even people on Facebook I hadn't talked to for years, with lots …

Self-hosting a minimal website with nginx and HTTPS

This website is now self-hosted on a Raspberry Pi server at home. I had struggled with nginx and HTTPS in the past, so was rather pleasantly surprised to see how straightforward it was. I couldn't find anything on the web that walked one through the whole process, so here are …

for loops in Python are a bit weird

A quiz: What does the following JavaScript code print and why? for (let i = 0; i < 3; i++) { console.log(i); i -= 3 } What does the following Python code print and why? for i in range(3): print(i) i -= 3

The uncertainty principle and spectrograms

In the previous post I discussed how, when measuring the frequency (tempo) of a signal that itself changes in time, there is necessarily a tradeoff between the precision in the measured frequency and precision in the time at which the measurement is taken: A more precise measurement of frequency requires …

The uncertainty principle is obvious to musicians

Most people are introduced to the term 'uncertainty principle' in the context of quantum mechanics. It is usually described as the idea that a particle's position and momentum cannot be simultaneously measured to arbitrary precision, but that improved precision in one must be traded off against increased uncertainty in the …

The Bohr model: Some history and context

This page is intended to give a little context behind the "Bohr model" that is introduced in the first part of the Part IB Quantum Mechanics course. Background Like all atomic models, the Bohr model attempts to answer the question "Why do atoms exhibit the properties that they do?", proposing …

Historical and philosophical contexts of the calculus of variations

What is a variational principle? A variational principle is a mathematical or physical law expressed in terms of maximising or minimising a certain quantity. The simplest example was known to ancient Egyptian builders and surveyers: a taut rope stretched between two points takes the shape that minimises its length. This …