This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / Introduction  /

Numerical Mathematics Packages

The standard add-on packages for numerical mathematics extend the set of built-in numerical functions, and take advantage of the arbitrary-precision arithmetic that is the foundation of numerical computations in Mathematica. The NumericalMath packages provide fitting functions (polynomial, spline, trigonometric), numerical versions of some of the kernel functions (ND, NLimit, NResidue, NSeries), numerical integration functions (CauchyPrincipalValue, ListIntegrate, NIntegrateInterpolationFunction), support for numerical solution of differential equations (BesselZeros, Butcher, OrderStar), alternatives to FindRoot using interpolation or interval methods, functions for approximating by a ratio of polynomials or arranging a polynomial in Horner form, and pedagogical functions for exploring floating-point arithmetic and numerical quadrature.

  • This initializes the numerical mathematics packages so that they load as needed.
  • In[1]:= <<NumericalMath`

  • Here is a set of points that lie approximately on a circle.
  • In[2]:= (data = Table[(x = Random[Real, {-1, 1}];
    Table[Random[Real, {-.1, .1}], {2}] +
    {x, Sign[.5 - Random[]] Sqrt[1 - x^2]}), {15}];
    ListPlot[data, AspectRatio -> 1,
    Ticks -> {{-1., -.5, .5, 1.}, Automatic}])


  • The points given to SplineFit are first sorted according to polar angle. The resulting spline interpolates the points.
  • In[3]:= (data = Map[Last,
    Sort[Map[{Apply[ArcTan, #], #}&, data]]];
    spline = SplineFit[Join[data, {First[data]}], Cubic];
    ParametricPlot[spline[u], {u, 0, 15},
    AspectRatio -> 1, Compiled -> False,
    Ticks -> {{-1., -.5, .5, 1.}, Automatic}])


    Out[3]=



  • You can use GeneralMiniMaxApproximation to approximate the inverse to the Euler gamma function on an interval. This shows the gamma function on

    .
  • In[4]:= Plot[Gamma[t], {t, 1.5, 6},
    AxesOrigin -> {1.5, 0}, AspectRatio ->1,
    AxesLabel -> {"t", "Gamma[t]"}]


    Out[4]=





  • This gives a degree rational function that approximates the inverse on

    .
  • In[5]:= (gmma = GeneralMiniMaxApproximation[{Gamma[t], t},
    {t, {1.5, 6}, 2, 4}, s];
    inverseGamma = gmma[[2, 1]])

    Out[5]=

  • Here is a plot of the approximation. For a minimax approximation, the error is distributed over the interval.
  • In[6]:= (Plot[inverseGamma, {s, Gamma[1.5], Gamma[6]},
    AxesOrigin -> {0, 1.5},
    AspectRatio ->1, AxesLabel -> {"s", "inverseGamma[s]"}])


    When you want to solve differential equations approximately, there are many considerations to take into account. You must ensure that the numerical solution process is sufficiently accurate (it is consistent with the differential system), that it actually solves the problem in which you are interested (it is convergent), and that any errors do not cause your approximate solution to drift far from the true solution (it is stable). Further, you may wish to ensure that your approximate solution samples (interpolates) the exact solution at specific points. Order stars provide a framework for the study and construction of numerical methods with these desirable properties.







  • Here the Padé approximation to represents the approximate solution of a differential equation, while

    represents the exact solution.
  • In[7]:= (f = (z^2*(1 + z^2) + (1 + z/2)*(1 - z - z^3))/
    (z^2*(1 + z^2) + (1 - z/2)*(1 - z - z^3));
    r = Pade[f, {z, 0, 1, 1}])

    Out[7]=

  • This is an order star plot for analyzing the numerical method represented by the Padé approximation.
  • In[8]:= OrderStar[r, f, OrderStarInterpolation->True,
    OrderStarLegend->True]

    Pade::shdw: Symbol Pade appears in multiple contexts {Calculus`Pade`, Global`}; definitions in context Calculus`Pade` may shadow or be shadowed by other definitions.

    OrderStar::sols: Warning: No interpolation points of approximant found using NSolve. Either inverse functions or transcendental dependencies were involved. Try specifying omitted points using options.

    OrderStar::sols: Warning: No zeros of approximant found using NSolve. Either inverse functions or transcendental dependencies were involved. Try specifying omitted points using options.

    CompiledFunction::crcx: Compiled expression Pade[0.441172 - 0.0858739 I, {-1.63786 - 2.30658 I, 0. + 0. I, 1. + 0. I, 1. + 0. I}] should be a machine-size complex number.

    CompiledFunction::cfex: External evaluation error at instruction 139; proceeding with uncompiled evaluation.

    CompiledFunction::crcx: Compiled expression Pade[0.441172 - 0.0858739 I, {-1.63786 - 2.30658 I, 0. + 0. I, 1. + 0. I, 1. + 0. I}] should be a machine-size complex number.

    CompiledFunction::cfex: External evaluation error at instruction 139; proceeding with uncompiled evaluation.

    2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 + ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2 2 NumericalMath`OrderStar`Private`symb$748 3 2
    (NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 - ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )) Pade[-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------, {NumericalMath`OrderStar`Private`symb$748, 0, 1, 1}]
    2 2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 - ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2
    ContourPlot::plnr: CompiledFunction[{NumericalMath`OrderStar`Private`symb$748}, Abs[----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------], -CompiledCode-][NumericalMath`OrderStar`Private`x$766 + I NumericalMath`OrderStar`Private`y$766] is not a machine-size real number at {NumericalMath`OrderStar`Private`x$766, NumericalMath`OrderStar`Private`y$766} = {-1.63786, -2.30658}.
    2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 + ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2

    CompiledFunction::crcx: Compiled expression Pade[0.442028 - 0.0882006 I, {-1.58374 - 2.30658 I, 0. + 0. I, 1. + 0. I, 1. + 0. I}] should be a machine-size complex number.

    General::stop: Further output of CompiledFunction::crcx will be suppressed during this calculation.

    CompiledFunction::cfex: External evaluation error at instruction 139; proceeding with uncompiled evaluation.

    General::stop: Further output of CompiledFunction::cfex will be suppressed during this calculation.

    2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 + ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2 2 NumericalMath`OrderStar`Private`symb$748 3 2
    (NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 - ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )) Pade[-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------, {NumericalMath`OrderStar`Private`symb$748, 0, 1, 1}]
    2 2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 - ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2
    ContourPlot::plnr: CompiledFunction[{NumericalMath`OrderStar`Private`symb$748}, Abs[----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------], -CompiledCode-][NumericalMath`OrderStar`Private`x$766 + I NumericalMath`OrderStar`Private`y$766] is not a machine-size real number at {NumericalMath`OrderStar`Private`x$766, NumericalMath`OrderStar`Private`y$766} = {-1.58374, -2.30658}.
    2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 + ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2

    2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 + ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2 2 NumericalMath`OrderStar`Private`symb$748 3 2
    (NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 - ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )) Pade[-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------, {NumericalMath`OrderStar`Private`symb$748, 0, 1, 1}]
    2 2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 - ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2
    ContourPlot::plnr: CompiledFunction[{NumericalMath`OrderStar`Private`symb$748}, Abs[----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------], -CompiledCode-][NumericalMath`OrderStar`Private`x$766 + I NumericalMath`OrderStar`Private`y$766] is not a machine-size real number at {NumericalMath`OrderStar`Private`x$766, NumericalMath`OrderStar`Private`y$766} = {-1.52961, -2.30658}.
    2 2 NumericalMath`OrderStar`Private`symb$748 3
    NumericalMath`OrderStar`Private`symb$748 (1 + NumericalMath`OrderStar`Private`symb$748 ) + (1 + ----------------------------------------) (1 - NumericalMath`OrderStar`Private`symb$748 - NumericalMath`OrderStar`Private`symb$748 )
    2

    General::stop: Further output of ContourPlot::plnr will be suppressed during this calculation.

    ContourGraphics::ctsm: It is not possible to shade a ContourGraphics object if some of the mesh points do not evaluate to numbers.

    ContourGraphics::ctpnt: The contour is attempting to traverse a cell in which some of the points have not evaluated to numbers, and it will be dropped.

    ContourGraphics::ctpnt: The contour is attempting to traverse a cell in which some of the points have not evaluated to numbers, and it will be dropped.

    ContourGraphics::ctpnt: The contour is attempting to traverse a cell in which some of the points have not evaluated to numbers, and it will be dropped.

    General::stop: Further output of ContourGraphics::ctpnt will be suppressed during this calculation.

    ContourGraphics::ctsm: It is not possible to shade a ContourGraphics object if some of the mesh points do not evaluate to numbers.




    The order star reflects the fact that the order of the approximant at the origin is

    , which is one less than the number of adjoining sectors there. The shaded region gives the region of growth of the approximant over the function and yields information on the accumulation of numerical errors.