Feed john-d-cook John D. Cook

Favorite IconJohn D. Cook

Link https://www.johndcook.com/blog
Feed http://feeds.feedburner.com/TheEndeavour?format=xml
Updated 2025-04-26 08:31
Creating police siren sounds with frequency modulation
Yesterday I was looking into calculating fluctuation strength and playing around with some examples. Along the way I discovered how to create files that sound like police sirens. These are sounds with high fluctuation strength. The Python code below starts with a carrier wave at fc = 1500 Hz. Not surprisingly, this frequency is near where […]
Frequentist properties of Bayesian methods
Bayesian methods for designing clinical trials have become more common, and yet these Bayesian designs are almost always evaluated by frequentist criteria. For example, a trial may be designed to stop early 95% of the time under some bad scenario and stop no more than 20% of the time under some good scenario. These criteria […]
If it were easy …
“If it were easy, someone would have done it.” Maybe not. Maybe the thing is indeed easy, and has been done before. Then someone was the first to do it. The warning that it had been done before didn’t apply to this person, even though it would apply to the subsequent people with the same […]
The magic / boilerplate trade-off
Phil Webb had an insightful tweet the other day. What would you like to complain about? [ ] Too much magic [ ] Too much boilerplate — Phil Webb (@phillip_webb) March 5, 2016 Programming environments oscillate between boilerplate and magic. APIs tend to start out with all the wires exposed. Programming is tedious, but nothing […]
Correlation of two sine waves
What is the correlation of two sine waves that differ in phase? The result itself is interesting, and the calculation along the way shows tricks to avoid calculating integrals. The correlation of two periodic signals, f and g, is where the integral is over a period of the two functions. For functions known at discrete points […]
Continuum between anecdote and data
The difference between anecdotal evidence and data is overstated. People often have in mind this dividing line where observations on one side are worthless and observations on the other side are trustworthy. But there’s no such dividing line. Observations are data, but some observations are more valuable than others, and there’s a continuum of value. I believe […]
Frequently rediscovered technologies
Greenspun’s tenth rule of programming says Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp. Here I’m going to take seriously a rule that was only not entirely serious. It’s saying three things about Lisp. It’s a frequently rediscovered technology. There’s something inevitable about it. […]
Coffee after Obama
This morning I had coffee and a generous slice of squash bread at Top Pot Doughnuts in Seattle. When I went to pick up my coffee I saw a large photo of President Obama ordering coffee at the same place. This is the second time I’ve been at a shop that proudly remembered our president […]
Octave holes on a saxophone
I’ve played saxophone since I was in high school, and I thought I knew how saxophones work, but I learned something new this evening. I was listening to a podcast [1] on musical acoustics and much of it was old hat. Then the host said that a saxophone has two octave holes. Really?! I only thought […]
Searching files on Windows
Searching files on Windows is a pain. The built-in search features don’t find everything. There may be ways to make them work, but I haven’t persisted long enough to make them work. On Linux, the combination of find, xargs, and grep works well, and sometimes it works on Windows using the GOW or GnuWin port of […]
Energy in frequency modulated signals
In an earlier post we proved that if you modulate a cosine carrier by a sine signal you get a signal whose sideband amplitudes are given by Bessel functions. Specifically: When β = 0, we have the unmodulated carrier, cos(2π fct), on both sides. When β is positive but small, J0(β) is near 1, and so the frequency […]
Quantifying Loudness
How do you quantify how loud a sound is? Sounds like a simple question, but it’s not. What is loudness? It’s not hard to measure the physical intensity of a sound, but loudness is the perceived intensity of a sound. It is not a physical phenomena but a psychological phenomena. Loudness is subjective, but not entirely […]
Rigor and Vigor in Mathematics
I just started reading Frequency Analysis, Modulation and Noise by Stanford Goldman. The writing is strikingly elegant and clear. Here is a paragraph from the introduction. Rigorous mathematics has a rightful place of honor in human thought. However, it has wisely been said that vigor is more important than rigor in the use of mathematics by the average […]
Graphs and square roots modulo a prime
Imagine a clock with a prime number of hours. So instead of being divided into 12 hours, it might be divided into 11 or 13, for example. You can add numbers on this clock the way you’d add numbers on an ordinary clock: add the two numbers as ordinary integers and take the remainder by p, […]
The empty middle: why no one is average
In 1945, a Cleveland newspaper held a contest to find the woman whose measurements were closest to average. This average was based on a study of 15,000 women by Dr. Robert Dickinson and embodied in a statue called Norma by Abram Belskie. Out of 3,864 contestants, no one was average on all nine factors, and fewer than 40 […]
Analyzing an FM signal
Frequency modulation combines a signal with a carrier wave by changing (modulating) the carrier wave’s frequency. Starting with a cosine carrier wave with frequency fc Hz and adding a signal with amplitude β and frequency fm Hz results in the combination The factor β is known as the modulation index. We’d like to understand this signal […]
Formulating applied math problems
Somewhere in school I got the backward idea that solving math problems is hard but that formulating them is easy. I don’t know if anybody ever said that to me. Maybe it was just implied by years of solving problems someone else had formulated. A related wrong idea that I also picked up was that […]
Curious numbers
A an n-digit number is said to be curious if the last n digits of its square are the same as the original number. For example, 252 = 625 and 762 = 5776. (Curious numbers are also known as automorphic numbers.) There are bigger curious numbers, such as 212890625 and 787109376: 2128906252 = 45322418212890625 and 7871093762 = 619541169787109376. And […]
Types of nonlinearity in PDEs
My advisor in grad school used to say “Nonlinear” is not a hypothesis but the lack of a hypothesis. To say something positive about nonlinear equations, you have to replace linearity with some specific property. You want to partially remove the restriction of linearity without letting just anything in. In partial differential equations, one pattern […]
Bayesian and nonlinear
Someone said years ago that you’ll know Bayesian statistics has become mainstream when people no longer put “Bayesian” in the titles of their papers. That day has come. While the Bayesian approach is still the preferred approach of a minority of statisticians, it’s no longer a novelty. If you want people to find your paper interesting, the substance […]
Improving on Chebyshev’s inequality
Chebyshev’s inequality says that the probability of a random variable being more than k standard deviations away from its mean is less than 1/k2. In symbols, This inequality is very general, but also very weak. It assumes very little about the random variable X but it also gives a loose bound. If we assume slightly more, […]
Trends and Opportunities in Data Analysis
Andy Warhol said “In the future, everyone will be world-famous for 15 minutes.” Here’s my 15 seconds of fame, a soundbite from the IBM Insight conference last year. My comments start at 1:30. In a nutshell, I predict that data analytics will work its way down from large companies to small companies.
Maximum principles and bounds for initial value problems
The previous post looked at using maximum principles to bound the solution to a boundary value problem. This is a similar post, focusing on an initial value problem. As before we start with the differential operator L[u] = u” + g(x)u’ + h(x) where g and h are bounded and h is non-positive. We are interested in solutions to the equation L[u] = f, but […]
Maximum principle and approximating boundary value problems
Solutions to differential equations often satisfy some sort of maximum principle, which can in turn be used to construct upper and lower bounds on solutions. We illustrate this in one dimension, using a boundary value problem for an ordinary differential equation (ODE). Maximum principles If the second derivative of a function is positive over an open […]
Musical pitch notation
How can you convert the frequency of a sound to musical notation? I wrote in an earlier post how to calculate how many half steps a frequency is above or below middle C, but it would be useful go further have code to output musical pitch notation. In scientific pitch notation, the C near the threshold of hearing, […]
Fourier transform of a function on a graph
What is a Fourier transform at its core? An expansion of function in terms of eigenfunctions of the Laplacian. For a function on the real line, the Laplacian is simply the second derivative. The functions mapped to multiples of themselves by taking second derivatives are sines and cosines of various frequencies. A Fourier series is a change […]
Connection between hypergeometric distribution and series
What’s the connection between the hypergeometric distributions, hypergeometric functions, and hypergeometric series? The hypergeometric distribution is a probability distribution with parameters N, M, and n. Suppose you have an urn containing N balls, M red and the rest, N – M blue and you select n balls at a time. The hypergeometric distribution gives the probability of selecting k red balls. The probability generating function […]
Structure in jazz and math
Last night I went to a concert by the Branford Marsalis Quartet. One of the things that impressed me about the quartet was how creative they are while also being squarely within a tradition. People who are not familiar with jazz may not realize how structured it is and how much it respects tradition. The spontaneous and […]
Consulting for consultants
They say that doctors make terrible patients, but in my experience consultants make great consulting clients. The best are confident in their own specialization and respect you in yours. They get going quickly and pay quickly. (I’ve only worked for consultants who have small companies. I imagine large consulting companies are as slow as other companies the same […]
Dilogarithm, polylogarithm, and related functions
The functions dilogarithm, trilogarithm, and more generally polylogarithm are meant to be generalizations of the logarithm. I first came across the dilogarithm in college when I was evaluating some integral with Mathematica, and they’ve paid a visit occasionally ever since. Unfortunately polylogarithms are defined in several slightly different and incompatible ways. I’ll start by following An Atlas […]
Regular expression to match any chemical element
Here’s a frivolous exercise in regular expressions: Write a regex to match any chemical element symbol. Here’s one solution. A[cglmrstu]|B[aehikr]?|C[adeflmnorsu]?|D[bsy]|E[rsu]|F[elmr]?|G[ade]|H[efgos]?|I[nr]?|Kr?|L[airuv]|M[dgnot]|N[abdeiop]?|Os?|P[abdmortu]?|R[abefghnu]|S[bcegimnr]?|T[abcehilm]|U(u[opst])?|V|W|Xe|Yb?|Z[nr] Making it more readable Here’s the same expression in more readable form: / A[cglmrstu] | B[aehikr]? | C[adeflmnorsu]? | D[bsy] | E[rsu] | F[elmr]? | G[ade] | H[efgos]? | I[nr]? | Kr? | L[airuv] | […]
Discrete harmonic functions
A (continuous) harmonic function f on an open set a function that is twice differentiable and satisfied Laplace’s equation: ∇2 f = 0. Such functions have a mean value property: at a point x interior to the set, f(x) equals the average value of f over any ball around x that fits inside the region. It turns out that the […]
Mathematics of medical plastics
In this interview, I talk with Ray Rilling about applying mathematics to manufacturing medical plastics. JC: Ray, could you start by saying a little about yourself? RR: Sure. My name is Ray Rilling, and I am the Director of Technology at Putnam Plastics. My initial training was cellular biology with an emphasis on epidemiology, but […]
Hypergeometric bootstrapping: implement one, get seven free
Suppose you have software to compute one hypergeometric function. How many more hypergeometric functions can you compute from it? Hypergeometric functions satisfy a lot of identities, so you can bootstrap one such function into many more. That’s one reason they’re so useful in applications. For this post, I want to focus on just three formulas, the so-called […]
Can you hear the shape of a network?
Mark Kac asked in 1966 whether you can hear the shape of a drum. In other words, can two drums, made of the same material, produce the exact same sound but have different shapes? More formally, Kac asked whether the eigenvalues of the Laplace’s equation with zero boundary conditions uniquely determine the shape of a […]
Discrete Laplace transform
The relationship between the discrete Laplace transform and discrete Fourier transform is not quite the same as that between their continuous counterparts. Continuous Fourier and Laplace transforms The continuous versions of the Fourier and Laplace transforms are given as follows. Fourier transform: Laplace transform: The Fourier transform is defined several ways, and I actually prefer […]
Reproducible randomized controlled trials
“Reproducible” and “randomized” don’t seem to go together. If something was unpredictable the first time, shouldn’t it be unpredictable if you start over and run it again? As is often the case, we want incompatible things. But the combination of reproducible and random can be reconciled. Why would we want a randomized controlled trial (RCT) to […]
Joukowsky transformation
The Joukowsky transformation, or Joukowsky map, is a simple function that comes up in aerospace and electrical engineering calculations. (Here z is a complex variable.) Despite its simplicity, it’s interesting to look at in detail. Mapping lines and circles Let z = r exp(iθ) and let w = u + iv be its image. Writing the Joukowsky transformation in terms of its real and complex parts makes it […]
General birthday problem
The birthday problem, sometimes called the birthday paradox, says that it’s more likely than you’d expect that two people in a group have the same birthday. Specifically, in a random sample of 23 people, there’s about a 50-50 chance that two people share the same birthday. The birthday problem makes a nice party trick, but […]
Random number generator seed mistakes
Long run or broken software? I got a call one time to take a look at randomization software that wasn’t randomizing. My first thought was that the software was working as designed, and that the users were just seeing a long run. Long sequences of the same assignment are more likely than you think. You […]
Bounding a graph’s diameter by its spectrum
You can get upper and lower bounds on the diameter of a connected graph G from its spectrum. If G has r distinct eigenvalues—whether of the adjacency matrix A, Laplacian L, or signless Laplacian Q—then the its diameter d is at most r-1. (Definitions of these matrices here.) If G has n vertices then we […]
Graph regularity and Laplace eigenvalues
You can tell whether a graph is regular, or nearly regular, by looking at its eigenvalues. Let G be a graph with n vertices and m edges and let L be the Laplacian matrix of G. Then the sum of the eigenvalues of L is 2m. (The diagonal of L contains the degrees of each node, so it’s trace is twice the […]
Next areas of math to be applied
Not that long ago number theory was considered strictly pure math. Then came applications to cryptography. Now number theory is at the foundation of the online economy. What are the next areas of pure math to find widespread application? Some people are saying algebraic topology and category theory. [I saw a cartoon to this effect the other day […]
Compressing ten years into six months
The other day I ran across a line from Peter Thiel saying that if you have a plan for where you’d like to be in ten years, ask yourself if you could get there in six months. I don’t think he’s simply saying see if you can do everything 20 times faster. If you estimate something […]
Golden ratio series
Here are a couple elegant series involving the golden ratio φ = (1 + √5)/2. First, reciprocals of integer powers: Then reciprocals of odd powers: Both are easy to prove since they’re geometric series. More posts related to the golden ratio: Imaginary gold Oscillating Fibonacci ratios Golden strings and the rabbit constant Power method and […]
Understanding a graph by peeling away nodes
One way to get some understanding of a graph is to peel away nodes, starting with the least connected. The k-core of a graph is the maximal subgraph such that every vertex has degree at least k. The k-shell is the set of vertices that are part of the k-core but not part of the […]
New prime number record
Last year I wrote a couple posts about what was then the largest known prime, 257885161 – 1. Now there’s a new record, P = 274207281 – 1. For most of the last 500 years, the largest known prime has been a Mersenne prime, a number of the form 2p – 1 where p is itself prime. Such numbers […]
Bipartite graphs and the signless Laplacian
The vertices of a bipartite graph can be divided into two sets where edges only go from one set to the other; there are no edges within each set. For example, in the graph below edges connect blue to green nodes, but not blue to blue or green to green. In this example there are two […]
Spectra of random graphs
Create a graph by first making a set of n vertices and then connecting nodes i and j, i > j, with probability p. This is known as the Erdős-Rényi graph Gn,p. Here’s such a graph with n = 100 and p = 0.1. Then the spectrum of the adjacency matrix A of the graph bounces around the spectrum of the expected […]
Matrix Pythagorean Triples
A Pythagorean triple is a list of positive integers (a, b, c) such that a2 + b2 = c2. Euclid knew how to find all Pythagorean triples: pick two positive integers m and n with m > n and let a = m2 – n2, b = 2mn, c = m2 + n2. Now what if we look at matrices with […]
...495051525354555657