Mathematica packages


Home > Mathematica packages 

    > LevinIntegrate package 

    > Revision history

Download and usage

To use any of my Mathematica packages, click here to download Moylan.zip and extract the "Moylan" folder to your Mathematica Applications folder, or any other place where it will be found by Needs[].

  • To find a good place to extract it, type $UserBaseDirectory in Mathematica.
  • Be careful not to accidentally create Applications\Moylan\Moylan\. You only need Applications\Moylan\.

Then just type Needs["Moylan`"] in Mathematica. The individual packages will be automatically loaded the first time they are used. You can also explicitly load the individual packages if you wish:

Scroll down for descriptions of the packages in the Moylan` namespace. 

 

NAntiDerivative 

Summary

NAntiDerivative is a numerical version of the operation of anti-differentiation. It automatically calls NDSolve as required to compute values of the antiderivative. When you need to evaluate the antiderivative many times, NAntiDerivative is usually faster than calling NIntegrate many times.

Usage

NAntiDerivative takes the function to anti-differentiate as its argument:


NDerivative

Summary

NDerivative is a numerical version of the Derivative function of Mathematica. The package includes FastND, which is a replacement for NumericalCalculus`ND. FastND gives the same results as ND, but runs faster.

Usage

NDerivative is used like Derivative:

FastND is a replacement for ND:

 

How it works 

The Richardson extrapolation method used by NumericalCalculus`ND` involves taking finite difference approximations of size h to the derivative, then interpolating them as a function of h. This is done by hand in the code of ND, but it's faster to do it directly using Mathematica's built-in InterpolatingPolynomial function.


LevinIntegrate

Summary

LevinIntegrate is an automatic numerical integrator for one-dimensional highly oscillatory integrands. It outperforms existing automatic integrators (such as Mathematica's NIntegrate) for many irregularly-oscillatory functions, including solving some oscillatory integrals that no existing automatic integrator can solve.

Usage

LevinIntegrate is used like NIntegrate:

For more information, see the separate page about LevinIntegrate.


ApproximatelyEqual

Summary

This simple package defines a notion of approximate equality similar to that used by Mathematica's numerical algorithms. You might use it when writing your own numerical algorithms, or for doing fuzzy unit testing.

Usage

By default, ApproximatelyEqual checks for approximate equality to precision MachinePrecision/2. This can be changed using options to ApproximatelyEqual. In general, ApproximatelyEqual checks whether at least one of the Precision or Accuracy options is satisfied.


SubscriptSymbols

Summary

This package makes Mathematica treat all the subscripts in your notebook as symbols. I used it for a long time because it's standard in physics to treat symbols like r, r0, and rcore as unique variables. I now rarely use it, partly because of the caveat described in the section Mathematica 6 below.

Usage

If you set SubscriptSymbols = True, every expression with head SubscriptBox will be transparently converted into a symbol; and that symbol will display as the corresponding SubscriptBoxes on output. You won't normally need to know about the underlying proxy symbol, but you can use Information[] to find out its name.

To disable SubscriptSymbols, just set SubscriptSymbols = False.

Mathematica 6

SubscriptSymbols still works fine in single notebooks in Mathematica 6.

As of Mathematica 6, .m package files created from notebooks using the "Create Auto Save Package" feature will not work with this package (or with the Symbolize function from the built-in Notation package). This is because, as of Mathematica 6, auto-save packages no longer export boxes. Instead, auto-save packages convert to InputForm and write the InputForm to the .m file. A future version of Mathematica 6 might include an option instructing auto-save packages to export boxes rather than InputForm, which would fix this problem.

Warning

I recommend that, if you think the definitions in the notebook you are writing will later be used to create an auto-save package, you don't use SubscriptSymbols.

How it works

SubscriptSymbols works by modifying the definition of MakeExpression for all boxes with head SubscriptBox. It generates hidden proxy symbols for the kernel to use, with names like Moylan`SubscriptSymbols`Private`SubscriptSymbolsProxySymbol$2503. The definition of MakeBoxes is explicitly set for these symbols, to make them display as the right SubscriptBox objects.


Other functions

The Moylan` namespace contains functions apart from those described explicitly on this page. You can see them by typing Names["Moylan`*`*"]:

These functions are used internally, but you can use them for your own purposes too. Let me know by email if you want more information about them.