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-05 08:01
Kinds of elliptic integrals
There are three fundamental kinds of elliptic integrals, and these are prosaically but unhelpfully called elliptic integrals of the first kind, the second kind, and the third kind. These names sound odd to modern ears, but it’s no different than classical musicians naming symphonies Symphony No. 1, Symphony No. 2, etc. This post covers the […]The post Kinds of elliptic integrals first appeared on John D. Cook.
Three interesting curves
Here are three curves that have interesting names and interesting shapes. The fish curve The fish curve has parameterization x(t) = cos(t) – sin²(t)/√2 y(t) = cos(t) sin(t) We can plot this curve in Mathematica with ParametricPlot[ {Cos[t] - Sin[t]^2/Sqrt[2], Cos[t] Sin[t]}, {t, 0, 2 Pi}] to get the following. It’s interesting that the image […]The post Three interesting curves first appeared on John D. Cook.
What is a Pentanomial GFSR random number generator?
The ISO random number generation standard, ISO 28640, speaks of a “Pentanomial GFSR method” for generating random variates. What is this? We’ll break it down, starting with GFSR. GFSR In short, a GFSR random number generator is what is now more commonly called a linear feedback shift register, or LFSR. The terminology “GFSR” was already […]The post What is a Pentanomial GFSR random number generator? first appeared on John D. Cook.
Systematically solving trigonometric equations
Students are asked to solve trigonometric equations shortly after learning what sine and cosine are. By some combination of persistence and luck they may be able to find a solution. After proudly presenting the solution to a teacher, the teacher may ask “Is that the only solution?” A candid student would respond by saying “How […]The post Systematically solving trigonometric equations first appeared on John D. Cook.
Nephroids and evolutes
The previous post looked at the evolute of an ellipse. This post will look at evolutes more generally, and then look at nephroids. As a quick reminder, given a curve curve c, a point on its evolute is the center of curvature for a point on c. See the previous post for a detailed example. […]The post Nephroids and evolutes first appeared on John D. Cook.
Evolute of an ellipse
Suppose you’re standing on an ellipse. (You actually are: lines of longitude are elliptical because of earth’s equatorial bulge.) Now draw a line perpendicular to where you’re standing. Lines of longitude are nearly circles, but we’ll look at a more obviously elliptical ellipse. The line is perpendicular to the northeast side of the ellipse where […]The post Evolute of an ellipse first appeared on John D. Cook.
Newton’s method: The Good, The Bad, and The Ugly
This post will give examples where Newton’s method gives good results, bad results, and really bad results. Our example problem is to solve Kepler’s equation M = E – e sin E for E, given M and e, assuming 0 ≤ M ≤ π and 0 < e < 1. We will apply Newton’s method […]The post Newton’s method: The Good, The Bad, and The Ugly first appeared on John D. Cook.
Uniform sampling from an ellipse
There is a simple way to randomly sample points from an ellipse, but it is not uniform. Assume your ellipse is parameterized by with t running from 0 to 2π. The naive approach would be to take uniform samples from t and stick them into the equations above. Rather than looking at random sampling, this […]The post Uniform sampling from an ellipse first appeared on John D. Cook.
How to calculate length of an elliptic arc
This post will show how to find the length of piece of an ellipse and explain what elliptic integrals have to do with ellipses. Assume we have an ellipse centered at the origin with semi-major axis a and semi-minor axis b. So a > b > 0, the longest diameter of the ellipse is 2a […]The post How to calculate length of an elliptic arc first appeared on John D. Cook.
Python code to solve Kepler’s equation
The previous post looked at solving Kepler’s equation using Newton’s method. The problem with using Newton’s method is that it may not converge when the eccentricity e is large unless you start very close to the solution. As discussed at the end of that post, John Machin came up with a clever way to start […]The post Python code to solve Kepler’s equation first appeared on John D. Cook.
Solving Kepler’s equation with Newton’s method
In the introduction to his book Solving Kepler’s Equation Over Three Centuries, Peter Colwell says In virtually every decade from 1650 to the present there have appeared papers devoted to the Kepler problem and its solution. This is remarkable because Kepler’s equation isn’t that hard to solve. It cannot be solved in closed form using […]The post Solving Kepler’s equation with Newton’s method first appeared on John D. Cook.
The world is lumpy
The Pareto principle, or the 80-20 rule, says that 80% of output comes from 20% of inputs. For example, maybe the top 20% of salesmen generate 80% of a company’s revenue. For some reason, the Pareto principle angers some people. Mention the Pareto principle and someone will explain why it can’t be true, based on […]The post The world is lumpy first appeared on John D. Cook.
Another problem with A/B testing: interaction effects
The previous post looked at a paradox with A/B testing: your final result may depend heavily on the order of your tests. This post looks at another problem with A/B testing: the inability to find interaction effects. Suppose you’re debating between putting a photo of a car or a truck on your web site, and […]The post Another problem with A/B testing: interaction effects first appeared on John D. Cook.
A/B testing and a voting paradox
One problem with A/B testing is that your results may depend on the order of your tests. Suppose you’re testing three options: X, Y, and Z. Let’s say you have three market segments, equal in size, each with the following preferences. Segment 1: X > Y > Z. Segment 2: Y > Z > X. Segment […]The post A/B testing and a voting paradox first appeared on John D. Cook.
Smoothly extending arctan(k tan(t))
I wrote a while back about the function f(t) = arctan(k tan(t)). I keep running into this function. Has anybody given this function a name or studied it? The direct implementation has a discontinuity at π/2 but I needed to extend it continuously. Using the two-argument version of inverse tangent fixes this. In Python, the […]The post Smoothly extending arctan(k tan(t)) first appeared on John D. Cook.
Random illustrations of Pascal’s theorem
Pascal’s theorem begins by selecting any six distinct points on an ellipse and drawing a “hexagon.” I put hexagon in quotes because the result need not look anything like a hex nut. In this context it simply means to pick one point, connect it to some other point, and so forth, joining the points in […]The post Random illustrations of Pascal’s theorem first appeared on John D. Cook.
Finding where two quadratic curves intersect
Suppose you have two quadratic polynomials in two real variables, f(x, y) and g(x, y), and you want to know whether the two curves f(x, y) = 0 and g(x, y) = 0 intersect, and if they do, find where they intersect. David Eberly has a set of notes on solving systems of polynomial equations that […]The post Finding where two quadratic curves intersect first appeared on John D. Cook.
A more convenient squircle equation
A few years ago I wrote several posts about “squircles”, starting with this post. These are shapes satisfying where typically p = 4 or 5. The advantage of a squircle over a square with rounded edges is that the curvature varies continuously around the figure rather than jumping from a constant positive value to zero. […]The post A more convenient squircle equation first appeared on John D. Cook.
Determining a conic by points and tangents
The first post this series said that a conic section has five degrees of freedom, and that any theorem that claims to determine a conic by less than five numbers is using some additional implicit information. The second post looked at Gibbs’ method which uses three observations, and a variation on the method uses just […]The post Determining a conic by points and tangents first appeared on John D. Cook.
Four views of multisets
This post will define multisets and basic operations on multisets. We’ll view union, intersection, inclusion and sum each from four perspectives: Examples with words Example with prime factorization Using Python’s multiset module Multisets as functions Definition and examples A multiset is like a set, except each element may appear more than once. We say each […]The post Four views of multisets first appeared on John D. Cook.
Lambert’s theorem
At the start of this series we pointed out that a conic section has five degrees of freedom, and so claims to be able to determine an orbit from less than five numbers must be hiding information somewhere. That is the case with Lambert’s theorem which reportedly determines an orbit from two numbers. Lambert’s theorem […]The post Lambert’s theorem first appeared on John D. Cook.
Gibbs’ method of determining an orbit
Josiah Willard Gibbs (1839–1903) was prominent American scientist at a time when America had yet to produce many prominent scientists. I first heard of him via Gibbs phenomenon and later by attending one of the Gibbs lectures at an AMS meeting. Gibbs came up with a method of determining an orbit from three observations. As […]The post Gibbs’ method of determining an orbit first appeared on John D. Cook.
ASQ/ANSI Z1.4 sampling procedures
I mentioned the other day that the US military standard MIL-STD-105 for statistical sampling procedures lives on in the ASQ/ANSI standard Z1.4. The Department of Defense cancelled their own standard in 1995 in favor of adopting civilian standards, in particular ASQ/ANSI Z1.4. There are two main differences between military standard and its replacement. First, the […]The post ASQ/ANSI Z1.4 sampling procedures first appeared on John D. Cook.
Five points determine a conic section
This post is the first in a series looking at determining an orbit. Lambert’s theorem is often summarized by saying you can determine an orbit from two observations. This statement isn’t true without further assumptions, assumptions I plan to make explicit. A solution to the two-body problem is an orbit given by a conic section, […]The post Five points determine a conic section first appeared on John D. Cook.
Sharing data without letting it go
Suppose two companies would like to share data, but they’d also each like to retain ownership of their own data. They’d like to enable querying as if each company had given the other all its data, without actually letting go of its data. Maybe the two companies are competitors who want to collaborate for a […]The post Sharing data without letting it go first appeared on John D. Cook.
Robustness of mean range
Let’s suppose we have data that comes from a distribution that is approximately normal but has a heavier right tail, specifically a gamma distribution with shape 6. We’d like to estimate the standard deviation of the data source. If the data were normally distributed, the sample standard deviation would be the most efficient unbiased estimator. […]The post Robustness of mean range first appeared on John D. Cook.
Average digit sum
Suppose you write down a number and take the sum of its digits. In what base will this sum be the smallest on average? Let’s do a couple examples comparing base 10 and base 2. The number 2022 in base 10 has digit sum 6, but its binary equivalent 11111100110 has digit sum 8, so […]The post Average digit sum first appeared on John D. Cook.
Using mean range method to measure variability
The most common way to measure variability, at least for data coming from a normal distribution, is standard deviation. Another less common approach is to use mean range. Standard deviation is mathematically simple but operationally a little complicated. Mean range, on the other hand, is complicated to analyze mathematically but operationally very simple. ASQ/ANSI Z1.9 […]The post Using mean range method to measure variability first appeared on John D. Cook.
Elliptical orbit example: Mars Orbiter Mission
This post will look at India’s first interplanetary mission, Mars Orbiter Mission, to illustrate points in recent posts. As suggested by the logo, the probe had a very eccentric orbit of Mars with periareion 3,812 km and apoareion 80,384 km. We can derive everything else from these numbers. [1] Peri-what?! As mentioned in footnote 2 […]The post Elliptical orbit example: Mars Orbiter Mission first appeared on John D. Cook.
Military Standard 105
Military Standard 105 (MIL-STD-105) is the grand daddy of sampling acceptance standards. The standard grew out of work done at Bell Labs in the 1930s and was first published during WWII. There were five updates to the standard, the last edition being MIL-STD-105E, published in 1989. In 1995 the standard was officially cancelled when the […]The post Military Standard 105 first appeared on John D. Cook.
Mean anomaly, true anomaly, and eccentric anomaly
Orbital mechanics has a lot of arcane terminology because it has been studied for centuries. V. I. Arnold said that orbital mechanics was one of the three main sources of modern mathematics. Mean anomaly, true anomaly, and eccentric anomaly are three ways of describing where an object is in its orbit. All would be the […]The post Mean anomaly, true anomaly, and eccentric anomaly first appeared on John D. Cook.
Cryptography, hydrodynamics, and celestial mechanics
Last night I was reading a paper by the late Russian mathematician V. I. Arnold “Polymathematics: is mathematics a single science or a set of arts?” and posted a lightly edited extract of it on Twitter. It begins All mathematics is divided into three parts: cryptography, hydrodynamics, and celestial mechanics. Arnold is alluding to the […]The post Cryptography, hydrodynamics, and celestial mechanics first appeared on John D. Cook.
Repeat shell command replacing a word
Suppose you’ve typed a long command and you need to rerun it with a small modification. Say you need to replace foo with bar. Bash will let you do this with ^foo^bar^. And although you’re supposed to put the final caret on the end, it will let you get by without it. $ echo foo […]The post Repeat shell command replacing a word first appeared on John D. Cook.
How eccentricity matters
I wrote last week that the eccentricities of planet orbits in our solar system do not effect the shape of the orbit very much. Here’s a plot of all the orbits, shifted to have the same center and scaled to have the same minor axis. However, the planet orbits do not have a common center. […]The post How eccentricity matters first appeared on John D. Cook.
Directrix of a conic
The most common way to define an ellipse geometrically is as the set of points whose distances to two foci sum to a constant. There is another way, however, to define an ellipse that generalizes to include the two other conic sections, parabolas and hyperbolas. You can define a conic section as the set of […]The post Directrix of a conic first appeared on John D. Cook.
Latus rectum of an ellipse
Ellipses have been studied for over two thousand years, and so some of the terminology is ancient and sounds odd to modern ears. One such term is latus rectum. What is the latus rectum and does have it anything to do with anatomy? This post defines the latus rectum for an ellipse. See the next […]The post Latus rectum of an ellipse first appeared on John D. Cook.
Inequalities for inequality: Gini coefficient lower bounds
The Gini coefficient, a.k.a. Gini index, of a set of numbers is the average of all differences divided by twice the mean. Specifically, let Then the Gini coefficient of x is defined to be where μ is the mean of the set. The Gini coefficient is often used in economics to measure inequalities in wealth. […]The post Inequalities for inequality: Gini coefficient lower bounds first appeared on John D. Cook.
Trading generalized derivatives for classical ones
Generalized functions have generalized derivatives. This is how we make sense of things like delta “functions” that are not functions, or functions that are not differentiable satisfying a differential equation. More on that here. A major theme in the modern approach to partial differential equations is to first look for solutions in a space of […]The post Trading generalized derivatives for classical ones first appeared on John D. Cook.
The view from a Galilean moon
The Galilean moons are the four largest moons of Jupiter, first observed by Galileo, contra Stigler’s law of eponymy. This post shows what the Jovian system look like from the perspective of each of these moons, a sort of pre-Copernican perspective in a Jovian context. The view from Io Here’s what Europa would look like […]The post The view from a Galilean moon first appeared on John D. Cook.
What if Copernicus had been a Martian?
The genius of Copernicus was to realize that this plot becomes this plot under a clever change of coordinates. The first plot is the apparent motion of Mars, Jupiter, and Saturn as viewed from Earth over the course of 30 years. Of course Copernicus knew of Mercury and Venus as well, but I’ve omitted them […]The post What if Copernicus had been a Martian? first appeared on John D. Cook.
How the orbit of one planet appears from another
This post shows how the orbits some planets appear from other planets. I’ve give a few of my favorite examples and include a Python program you could use to create your own plots. We will assume the planets move in circles around the sun. They don’t exactly—they don’t exactly move in ellipses either—but their orbits […]The post How the orbit of one planet appears from another first appeared on John D. Cook.
Using Python as a statistical calculator
This post is for someone unfamiliar with SciPy who wants to use Python to do basic statistical calculations. More specifically, this post will look at working with common families of random variables—normal, exponential, gamma, etc.—and how to calculate probabilities with these. All the statistical functions you need will be in the stats subpackage of SciPy. […]The post Using Python as a statistical calculator first appeared on John D. Cook.
Eccentricity, Flattening, and Aspect Ratio
There are at least three common ways to describe the shape of an ellipse: eccentricity e, flattening f, and aspect ratio r. Each is a number between 0 and 1. (Flattening is also called ellipticity, which is a descriptive name, but unfortunately it sounds a lot like eccentricity.) Although converting between these three descriptions is […]The post Eccentricity, Flattening, and Aspect Ratio first appeared on John D. Cook.
Planetary orbits are very nearly circular
If a science book shows you obviously elliptical orbits of planets, it is literally stretching the truth. I was taught that our benighted ancestors insisted that planetary orbits are circles for philosophical reasons. In fact, they insisted planetary orbits are circular because they very nearly are. Here’s a plot of the orbits of all nine […]The post Planetary orbits are very nearly circular first appeared on John D. Cook.
Saving money on big queries
I was surprised the first time a client told me that a query would cost them $100,000 to run. If you think about querying a database on your laptop, a long query would take a minute, and what’s the cost of a minute’s worth of electricity? Too small to meter. But some of my clients […]The post Saving money on big queries first appeared on John D. Cook.
The Pluto-Charon orbit
The Moon doesn’t orbit the center of the Earth; it orbits the center of mass of the Earth-Moon system, which is inside the Earth. The distinction matters for designing satellite orbits, but it cannot be seen on a plot to scale. We’ll quantify this below. Pluto’s moon Charon, however, is so large relative to Pluto […]The post The Pluto-Charon orbit first appeared on John D. Cook.
Shape of moon orbit around sun
The earth’s orbit around the sun is nearly a circle, and the moon’s orbit around the earth is nearly a circle, but what is the shape of the moon’s orbit around the sun? You might expect it to be bumpy, bending inward when the moon is between the earth and the sun and bending output […]The post Shape of moon orbit around sun first appeared on John D. Cook.
A more direct approach to series solutions
In the previous post we found a solution to using operator calculus, i.e. treating the differential operator D like a number and doing tricks with it. See the earlier post for a justification of why we can get away with unorthodox manipulations. We can generalize the method of the previous post to say that a […]The post A more direct approach to series solutions first appeared on John D. Cook.
Operator calculus
Students who take a course in differential equations don’t really learn how to solve differential equations. The problems whose solutions they reproduce were solved over 300 years ago. The methods taught in undergraduate ODE classes are in some sense mnemonics, a way to remember a solution discovered long ago. Abandon hope of originality The more […]The post Operator calculus first appeared on John D. Cook.
Writing math with Unicode
A LaTeX document looks better than an HTML document, but an HTML document looks better than an awkward hybrid of HTML and inline images created by LaTeX. My rule is to only use LaTeX-generated images for displayed equations and not for math symbols in the middle of a sentence. This works pretty well, but it’s […]The post Writing math with Unicode first appeared on John D. Cook.
...14151617181920212223...