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-06-07 01:16
Why a slide rule works
Suppose you have two sticks. The length of one is log x, and the length of the other is log y. If you put the two sticks end to end, the combined length is log x + log y = log xy. That’s the basic idea behind a slide rule. The simplest slide rule consists […]The post Why a slide rule works first appeared on John D. Cook.
Hilbert transform and Mathematica
The Hilbert transform of a function f(t) is a function fH(x) defined [1] by The integral must be interpreted in the sense of the Cauchy principal value: The integrand is not absolutely integrable because of the singularity at x and so the value of the integral depends on how you handle the singularity. The Cauchy […]The post Hilbert transform and Mathematica first appeared on John D. Cook.
Visual integration
The plot below is of a meromorphic function f(z). That is, the function f(z) is analytic except possibly at poles, and the colors represent the phase angles, the values of θ if you write the function values in polar form. What is the value of the integral where C is the perimeter of the square? […]The post Visual integration first appeared on John D. Cook.
Regular expressions and successive approximation
Regular expressions can do a lot of tasks in practice that they cannot do in theory. That’s because a particular application of regular expressions comes with context and with error tolerance. For example, much has been said about how regular expressions cannot parse HTML. This is strictly true, but it says nothing about how well […]The post Regular expressions and successive approximation first appeared on John D. Cook.
Sum the zeros of an analytic function without finding them first
A couple days ago I wrote about how Vieta’s formulas let you sum the zeros of a polynomial without having to first compute the zeros. This is especially handy for high-order polynomials since there is no explicit formula for the zeros. Most functions that arise in applications are not polynomials. How could you find the […]The post Sum the zeros of an analytic function without finding them first first appeared on John D. Cook.
Bounding zeros of an analytic function
The previous post looked at the problem of finding the zeros of a cubic polynomial. Assuming we’re going to use a numerical method to calculate the zero, the hard part is knowing where to tell the numerical method to look. That post showed how to use a change of variables to guarantee that the polynomial […]The post Bounding zeros of an analytic function first appeared on John D. Cook.
Numerically finding roots of a cubic
The analog of the quadratic formula for cubic equations is cumbersome. A lot of people naturally say “Forget all that. If I need to find the roots of a cubic, I’ll just use a numerical method like Newton’s method.” Sounds good. Where to start? But how do you know where to look for the roots? […]The post Numerically finding roots of a cubic first appeared on John D. Cook.
Mathematics and piano tuning
The following is a slightly edited version of a Twitter thread on @AlgebraFact. The lowest C on a piano is called C1 in scientific pitch notation. The C one octave up is C2 and so forth. Middle C is C4. The frequency of Cn is approximately 2n+4 Hz. This would be exact if C0 were […]The post Mathematics and piano tuning first appeared on John D. Cook.
Computing functions of roots without computing roots
Once in a while it’s necessary to calculate some function of the roots of a polynomial, and it may be possible to do this without first calculating the roots. Quadratics The quadratic formula gives explicit solutions to the equation The two solutions for x are where The awkward part is taking the square root of […]The post Computing functions of roots without computing roots first appeared on John D. Cook.
FWHM for a quadratic
This post contains a derives a result I needed recently. The derivation is simple but a little tedious, so I wanted to save it in case I need it again. Full width half maximum A common way to measure the width of a function peak in a function f(x) is to find the place x0 […]The post FWHM for a quadratic first appeared on John D. Cook.
Number slang and numbered lists
Here’s a list of five numbers used as slang in various contexts. Location (CB and police radio) End of column (journalism) Best wishes (ham radio) All aircraft in area (US Navy) I love you (text messages) The motivation for this post was an article Those HTML attributes you never use. I wanted to make a […]The post Number slang and numbered lists first appeared on John D. Cook.
Oscillations in RLC circuits
Electrical and mechanical oscillations satisfy analogous equations. This is the basis of using the word “analog” in electronics. You could study a mechanical system by building an analogous circuit and measuring that circuit in a lab. Mass, dashpot, spring Years ago I wrote a series of four posts about mechanical vibrations: Free, undamped vibrations Free, […]The post Oscillations in RLC circuits first appeared on John D. Cook.
How is portable AM radio possible?
The length of antenna you need to receive a radio signal is proportional to the signal’s wavelength, typically 1/2 or 1/4 of the wavelength. Cell phones operate at gigahertz frequencies, and so the antennas are small enough to hide inside the phone. But AM radio stations operate at much lower frequencies. For example, there’s a […]The post How is portable AM radio possible? first appeared on John D. Cook.
Applications of continued fractions
At first glance, continued fractions look more like a curiosity than like useful mathematics. And yet they come up surprisingly often in applications. For an irrational number x, the numbers you get by truncating the infinite continued fraction for x are the optimal rational approximations to x given the size of their denominators. For example, […]The post Applications of continued fractions first appeared on John D. Cook.
Smoothed step function
I mentioned smoothed step functions in the previous post. What would you do if you needed to concretely use a smoothed step function and not just know that one exists? We’ll look at smoothed versions of the signum function sgn(x) = x / |x| which equals -1 for negative x and +1 for positive x. […]The post Smoothed step function first appeared on John D. Cook.
Partitions of unity, smooth ramps, and CW clicks
Partitions of unity are a handy technical device. They’re seldom the focus of attention but rather are buried in the middle of proofs. The name sounds odd, but it’s descriptive. A partition of unity is a set of smooth functions into the interval [0, 1] that add up to 1 at every point. The functions […]The post Partitions of unity, smooth ramps, and CW clicks first appeared on John D. Cook.
Looking for the next prime
Suppose you start with some large number x and want to find a prime number at least as big as x. First you test whether x is prime. Then you test whether x + 1 is prime. Then you test whether x + 2 is prime, and so on until you find a prime. Of […]The post Looking for the next prime first appeared on John D. Cook.
Seed vault, but for code
I had heard of the Svalbard Global Seed Vault, but I hadn’t heard of the nearby Arctic World Archive until today. The latter contains source code preserved on film, a format that should last at least 500 years.The post Seed vault, but for code first appeared on John D. Cook.
Series for π
Here’s a curious series for π that I ran across on Math Overflow. In case you’re unfamiliar with the notation, n!! is n double factorial, the product of the positive integers up to n with the same parity as n. More on that here. When n is 0 or -1, n!! is defined to be […]The post Series for π first appeared on John D. Cook.
Morse code numbers and abbreviations
Numbers in Morse code seem a little strange. Here they are: |-------+-------| | Digit | Code | |-------+-------| | 1 | .---- | | 2 | ..--- | | 3 | ...-- | | 4 | ....- | | 5 | ..... | | 6 | -.... | | 7 | --... | | 8 […]The post Morse code numbers and abbreviations first appeared on John D. Cook.
Multiple Frequency Shift Keying
A few days ago I wrote about Frequency Shift Keying (FSK), a way to encode digital data in an analog signal using two frequencies. The extension to multiple frequencies is called, unsurprisingly, Multiple Frequency Shift Keying (MFSK). What is surprising is how MFSK sounds. When I first heard MFSK I immediately recognized it as an […]The post Multiple Frequency Shift Keying first appeared on John D. Cook.
Dial tone and busy signal
Henry Lowengard left a comment on my post Phone tones in musical notation mentioning dial tones and busy signals, so I looked these up. Tones According to this page, a dial tone in DTMF [1] is a chord of two sine waves at 350 Hz and 440 Hz. In musical notation: According to the same […]The post Dial tone and busy signal first appeared on John D. Cook.
Solar declination
This post expands on a small part of the post Demystifying the Analemma by M. Tirado. Apparent solar declination given δ by δ = sin-1( sin(ε) sin(θ) ) where ε is axial tilt and θ is the angular position of a planet. See Tirado’s post for details. Here I want to unpack a couple things […]The post Solar declination first appeared on John D. Cook.
Reverse engineering Fourier conventions
The most annoying thing about Fourier analysis is that there are many slightly different definitions of the Fourier transform. One time I got sufficiently annoyed that I creates a sort of Rosetta Stone of Fourier theorems under eight different conventions. Later I discovered that Mathematica supports these same eight definitions, but with slightly different notation. […]The post Reverse engineering Fourier conventions first appeared on John D. Cook.
Dividing an octave into 14 pieces
Keenan Pepper left a comment on my previous post saying that the DTMF tones used by touch tone phones “are actually quite close to 14 equal divisions of the octave (rather than the usual 12).” Let’s show that this is right using a little Python. import numpy as np freq = np.array([697, 770, 852, 941, […]The post Dividing an octave into 14 pieces first appeared on John D. Cook.
Phone tones in musical notation
The sounds produced by a telephone keypad are a combination of two tones: one for the column and one for the row. This system is known as DTMF (dual tone multiple frequency). I’ve long wondered what these tones would be in musical terms and I finally went to the effort to figure it out when […]The post Phone tones in musical notation first appeared on John D. Cook.
Frequency shift keying (FSK) spectrum
This post will look encoding digital data as an analog signal using frequency shift keying (FSK), first directly and then with windowing. We’ll look at the spectrum of the encoded signal and show that basic FSK uses much less bandwidth than direct encoding, but more bandwidth than FSK with windowing. Square waves The most natural […]The post Frequency shift keying (FSK) spectrum first appeared on John D. Cook.
Approximating the range of normal samples
On Monday I wrote a blog post that showed you can estimate the standard deviation of a set of data by first computing its range and then multiplying by a constant. The advantage is that it’s easy to compute a range, but computing a standard deviation in your head would be tedious to say the […]The post Approximating the range of normal samples first appeared on John D. Cook.
Order statistics for normal distributions
The last couple posts have touched on order statistics for normal random variables. I wrote the posts quickly and didn’t go into much detail, and more detail would be useful. Given two integers n ≥ r ≥ 1, define E(r, n) to be the rth order statistic of n samples from standard normal random variables. […]The post Order statistics for normal distributions first appeared on John D. Cook.
Range trick for larger sample sizes
The previous post showed that the standard deviation of a sample of size n can be well estimated by multiplying the sample range by a constant dn that depends on n. The method works well for relatively small n. This should sound strange: typically statistical methods work better for large samples, not small samples. And […]The post Range trick for larger sample sizes first appeared on John D. Cook.
Estimating standard deviation from range
Suppose you have a small number of samples, say between 2 and 10, and you’d like to estimate the standard deviation σ of the population these samples came from. Of course you could compute the sample standard deviation, but there is a simple and robust alternative Let W be the range of our samples, the […]The post Estimating standard deviation from range first appeared on John D. Cook.
Varicode
Varicode is a way of encoding text and control characters into binary using code words of variable length. It was developed as part of the PSK31 protocol for digital communication over amateur radio. In the spirit of Morse code, it uses short code words for common characters and longer code words for less common characters […]The post Varicode first appeared on John D. Cook.
Catenary kiln
Will Buckner sent me an email with the following question recently. (I’m sharing this with permission.) I am building a kiln using a catenary arch. The rear wall and front wall/door will be vertical and fill in the space under the arch, which has the dimensions of 41″W x 39.5″H. I need the area within […]The post Catenary kiln first appeared on John D. Cook.
Connecting powers of two and decibels
Colin Wright pointed out a pattern in my previous post that I hadn’t seen before. He wrote about it here a couple years ago. Start with the powers of 2 from the top of the post: 21 = 2 22 = 4 23 = 8 24 = 16 25 = 32 26 = 64 27 […]The post Connecting powers of two and decibels first appeared on John D. Cook.
100 digits worth memorizing
I was thinking today about how people memorize many digits of π, and how it would be much more practical to memorize a moderate amount of numbers to low precision. So suppose instead of memorizing 100 digits of π, you memorized 100 digits of other numbers. What might those numbers be? I decided to take […]The post 100 digits worth memorizing first appeared on John D. Cook.
Morse code in musical notation
Maybe this has been done before, but I haven’t seen it: Morse code in musical notation. Here’s the Morse code alphabet, one letter per measure; in practice there would be less space between letters [1]. A dash is supposed to be three times as long as a dot, so a dot is a sixteenth note […]The post Morse code in musical notation first appeared on John D. Cook.
Find log normal parameters for given mean and variance
Earlier today I needed to solve for log normal parameters that yield a given mean and variance. I’m going to save the calculation here in case I needed in the future or in case a reader needs it. The derivation is simple, but in the heat of the moment I’d rather look it up and […]The post Find log normal parameters for given mean and variance first appeared on John D. Cook.
Q codes in Seveneves
The first time I heard of Q codes was when reading the novel Seveneves by Neal Stephenson. These are three-letter abbreviations using in Morse code that all begin with Q. Since Q is always followed by U in native English words, Q can be used to begin a sort of escape sequence [1]. There are […]The post Q codes in Seveneves first appeared on John D. Cook.
Algorithms at Work
Brian Christian and Tom Griffiths have just published a new book, Algorithms at Work. You can hear me talking about queues in Episode 2. More on queueing theory What happens when you add a new teller? Queueing and economies of scale Upper bound on wait timesThe post Algorithms at Work first appeared on John D. Cook.
What use is mental math in 2022?
Now that most people are carrying around a powerful computer in their pocket, what use is it to be able to do math in your head? Here’s something I’ve noticed lately: being able to do quick approximations in mid-conversation is a superpower. When I’m on Zoom with a client, I can’t say “Excuse me a […]The post What use is mental math in 2022? first appeared on John D. Cook.
Missing Morse codes
Morse codes for Latin letters are sequences of between one and four symbols, where each symbol is a dot or a dash. There are 2 possible sequences with one symbol, 4 with two symbols, 8 with three symbols, and 16 with four symbols. This makes a total of 30 sequences with up to four symbols. […]The post Missing Morse codes first appeared on John D. Cook.
Almost periodic functions
When you see the word “almost” in a mathematical context, it might be used informally, but often it has a precise meaning. I wrote about this before in the post Common words that have a technical meaning. Often the technical meaning of “almost” is “within any finite tolerance.” That’s how it is used in the […]The post Almost periodic functions first appeared on John D. Cook.
2s, 5s, and decibels
Last night I ran across a delightful Twitter thread by Nathan Mishra-Linger that starts out by saying It’s nice that 2^7 ≈ 5^3, because that lets you approximate any integer valued decibel quantity as a product of powers of 2 and 5. The observation that 27 ≈ 53, is more familiar if you multiply both […]The post 2s, 5s, and decibels first appeared on John D. Cook.
A Bayesian approach to pricing
Suppose you want to determine how to price a product and you initially don’t know what the market is willing to pay. This post outlines some of the things you might think about, and how Bayesian modeling might help. This post is not the final word on the subject, or even my final word on […]The post A Bayesian approach to pricing first appeared on John D. Cook.
Chaos in the frequency domain
Solutions to the non-linear differential equation x ″ + 0.25x ′ + x(x² – 1) = 0.3 cos t are chaotic. It’s more common to see plots of chaotic systems in the time domain, so I wanted to write a post looking at the power spectrum in the frequency domain. The following plot was created by solving […]The post Chaos in the frequency domain first appeared on John D. Cook.
The tent map
Yesterday I said that Lyapunov exponents can’t be calculated exactly except in the case of toy problems. One such toy model is the tent map. The graph of function on the right hand side looks a tent. It’s zero at x = 0 and at x = 1 and rises to a height of r […]The post The tent map first appeared on John D. Cook.
Aliasing in a nutshell
Suppose you have a sine wave with frequency f0 Hz. We’re going to discretize this signal by sampling it fs times per second. That is, we’re going to evaluate S at integer multiples of The result is the sequence where n runs through the integers. Next, let k be an integer and consider the sine […]The post Aliasing in a nutshell first appeared on John D. Cook.
Lyapunov exponents
Chaotic systems are unpredictable. Or rather chaotic systems are not deterministically predictable in the long run. You can make predictions if you weaken one of these requirements. You can make deterministic predictions in the short run, or statistical predictions in the long run. Lyapunov exponents are a way to measure how quickly the short run […]The post Lyapunov exponents first appeared on John D. Cook.
Self-orthogonal vectors and coding
One of the surprising things about linear algebra over a finite field is that a non-zero vector can be orthogonal to itself. When you take the inner product of a real vector with itself, you get a sum of squares of real numbers. If any element in the sum is positive, the whole sum is […]The post Self-orthogonal vectors and coding first appeared on John D. Cook.
Ternary Golay code in Python
Marcel Golay discovered two “perfect” error-correcting codes: one binary and one ternary. These two codes stick out in the classification of perfect codes [1]. The ternary code is a linear code over GF(3), the field with three elements. You can encode a list of 5 base-three digits by multiplying the list as a row vector […]The post Ternary Golay code in Python first appeared on John D. Cook.
...18192021222324252627...