1. 2013
    Nov
    10

    Adding 2D interpolation and quasi-Monte Carlo integration to GSL

    Here’s another post for my more technically-minded readers: in the course of writing the software for my latest research project (which I am still going to post about later this month), I needed algorithms for two-dimensional interpolation and quasi-Monte Carlo integration. Neither of these exists in GSL — the GNU Scientific Library, kind of a standard set of libraries for scientific software. So I wrote my own.

    • interp2d is a simple generalization of the 1D GSL interpolation routines to 2D interpolation
    • The insightfully named quasimontecarlo is practically a copy of GSL’s Monte Carlo integrator, except that it uses a quasirandom number generator instead of a pseudorandom number generator.

    These might be useful for anyone else doing scientific computation.

  2. 2012
    Nov
    13

    A reminder to always check your definitions

    I’ve been working on some code using GSL and wondering why it didn’t match the results I was getting from Mathematica and other programs. Well, one (of perhaps many) differences is that GSL defines the sinc function as

    $$\operatorname{sinc}(x) = \frac{\sin \pi x}{\pi x}$$

    for \(x\neq 0\), but Mathematica defines it as

    $$\operatorname{sinc}(x) = \frac{\sin x}{x}$$

    The latter is the definition I was using in my math, and I didn’t realize it didn’t match the one in GSL until I broke the code down to individual mathematical terms.

    So remember to make sure that any code you use is actually doing what you think it’s doing!