Blog Archives

Relating Airy and Bessel functions

The Airy functions Ai(x) and Bi(x) are independent solutions to the differential equation For negative x they act something like sin(x) and cos(x). For positive x they act something like exp(x) and exp(-x). This isn’t surprising if you look at

Tagged with: , , ,
Posted in Math, Python

Ramanujan approximation for circumference of an ellipse

There’s no elementary formula for the circumference of an ellipse, but there is an elementary approximation that is extremely accurate. An ellipse has equation (x/a)² + (y/b)² = 1. If a = b, the ellipse reduces to a circle and

Tagged with: ,
Posted in Math

Rolling dice for normal samples: Python version

A handful of dice can make a decent normal random number generator, good enough for classroom demonstrations. I wrote about this a while ago. My original post included Mathematica code for calculating how close to normal the distribution of the sum

Tagged with: , , ,
Posted in Math, Python

New introduction to SciPy

The Python stack for scientific computing is more modular than say R or Mathematica. Python is a general-purpose programming language that has libraries for scientific computing. R and Mathematica are statistical and mathematical programming languages that have general-purpose features. The

Tagged with: ,
Posted in Python

Three new Python books

This post reviews three Python books that have come out recently: SciPy and NumPy from O’Reilly Python for Kids: A Playful Introduction to Programming from No Starch Press NumPy Cookbook from Packt SciPy and NumPy by Eli Bressert is the

Tagged with: , ,
Posted in Python

Winston Churchill, Bessie Braddock, and Python

Last night I was talking with someone about the pros and cons of various programming languages and frameworks for data analysis. One of the pros of Python is its elegance. The primary con is that it can be slow. The

Tagged with: ,
Posted in Python, Software development

Python for data analysis

I recommend using Python for data analysis, and I recommend Wes McKinney’s book Python for Data Analysis. I prefer Python to R for mathematical computing because mathematical computing doesn’t exist in a vacuum; there’s always other stuff to do. I

Tagged with: ,
Posted in Python

Computing log gamma differences

Statistical computing often involves working with ratios of factorials. These factorials are often too big to fit in a floating point number, and so we work with logarithms. So if we need to compute log(a! / b!), we call software

Tagged with: ,
Posted in Computing, Python, Statistics

Using SciPy with IronPython

Three years ago I wrote a post about my disappointment using SciPy with IronPython. A lot has changed since then, so I thought I’d write a short follow-up post. To install NumPy and SciPy for use with IronPython, follow the

Tagged with: , ,
Posted in Python

Math languages vs. application languages

Last Friday I posted on @SciPyTip a summary of why I like SciPy, the scientific programming library for Python. I’d rather do math in a general-purpose language than try to do general-purpose programming in a math language. Mathematical software is

Tagged with: ,
Posted in Python

SciPy integration misunderstanding

Today I needed to compute an integral similar to this: I used the following SciPy code to compute the integral: from scipy.integrate import quad def f(x): return 0.01*x**-3 integral, error = quad(f, 1000, sp.inf, epsrel = 1e-6) print integral, error

Tagged with: , ,
Posted in Python

Approximating Earth as a sphere

Isaac Newton suggested in 1687 that the earth is not a perfectly round sphere but rather an ellipsoid, and he was right. But since our planet is roughly a sphere, it’s often useful to approximate it by a sphere. So

Tagged with: , ,
Posted in Math, Python, Science

Example of not inverting a matrix: optimization

People are invariably surprised when they hear it’s hardly ever necessary to invert a matrix. It’s very often necessary solve linear systems of the form Ax = b, but in practice you almost never do this by inverting A. This

Tagged with: , ,
Posted in Python

How to compute jinc(x)

The function jinc(x) that I wrote about yesterday is almost trivial to implement, but not quite. I’ll explain why it’s not quite as easy as it looks and how one might implement it in C and Python.

Tagged with: ,
Posted in Python

Benford’s law and SciPy

Imagine you picked up a dictionary and found that the pages with A’s were dirty and the Z’s were clean. In between there was a gradual transition with the pages becoming cleaner as you progressed through the alphabet. You might

Tagged with: ,
Posted in Python