# Numerical Calculus Package

The functions defined in the NumericalCalculus` context provide support for finding numerical solutions to calculus-related problems.

## Numerical Calculation of Limits

The builtin function Limit computes limits using symbolic and analytic methods. The function NLimit contained in the NumericalCalculus package works by numerically evaluating a short sequence of function values as the argument approaches the specified point. The result of this calculation is passed to a routine that uses either Wynn's algorithm or a generalized Euler transformation to find an approximation to the limit.

 NLimit[expr,x->x0] numerically finds the limit as x approaches x0

Computing numerical limits.

Here is the numerical computation of a limit.
The limit gives the number known as Euler's gamma.
You can also compute limits as x approaches infinity.
 option name default value WorkingPrecision MachinePrecision number of digits of precision to be used Scale 1 initial step size Terms 7 total number of terms generated in the sequence Method EulerSum method of evaluation, either EulerSum or SequenceLimit WynnDegree 1 degree to use in the Wynn method

Options for NLimit.

There are many specialized techniques for accelerating the convergence of a series. Faster convergence means that in a numerical evaluation fewer terms are needed to give a result of the desired accuracy. One such technique, Euler's transformation, is used by EulerSum.

EulerSum is particularly good for working with alternating series and series whose terms have the form where is a polynomial in . It is a useful adjunct to the builtin NSum, which is designed to be an effective general case algorithm.

 EulerSum[f,{i,imin,Infinity}] uses Euler's transformation to numerically evaluate Numerical evaluation of sums using Euler's transformation.

 option name default value WorkingPrecision MachinePrecision number of digits of precision to be used Terms 5 total number of terms generated before extrapolation ExtraTerms 7 number of terms to be used in the extrapolation process; must be at least 2 EulerRatio Automatic the fixed ratio to be used in the transformation

Options for EulerSum.

This uses EulerSum to compute a numerical approximation to the sum of an alternating series.
Increasing the precision and the number of terms does not change the answer in the first six decimal places. This provides a check on the accuracy of the numerically computed result.
The result is also in good agreement with the known exact result.

There are occasionally instances in which it is difficult or impossible to analytically compute the derivative of a function. In these cases you can compute the derivative using the function ND instead of the builtin function D.

 ND[f,x,x0] gives a numerical approximation to evaluated at the point x0 ND[f,{x,n},x0] gives the nth derivative

Numerical computation of derivatives.

Here is a numerical approximation of the derivative of at .
After increasing the setting of the option Terms, the difference between the symbolically computed result and the numerical result for a third derivative is quite small.
This is the error in the numerical derivative using Cauchy's integral formula.
 option name default value WorkingPrecision MachinePrecision number of digits of precision to be used Scale 1 size of steps in the evaluation Terms 7 total number of terms generated in the sequence Method EulerSum method of evaluation, either EulerSum (numerical limit of difference quotients) or NIntegrate (Cauchy's integral formula)

Options for ND.

You should realize that with sufficiently pathological examples, the algorithms used for EulerSum, NLimit, or ND can give wrong answers. In most cases, you can test your answer by looking at the sensitivity to changes in the setting of options.

## Numerical Calculation of Residues

The Wolfram Language function Residue symbolically finds the residue of an expression at a point in the complex plane. Because it is symbolic in nature, it is sometimes unable to get a result.

NResidue is the numerical version of Residue. It works by numerically integrating around a small circle centered at the point at which the residue is being sought. The obvious problem with this approach is that it in fact finds the sum of the residues at all of the points contained within the circle. By making the radius of the circle sufficiently small, you can exclude all singularities but the one in question.

 NResidue[expr,{x,x0}] numerically find the residue of expr at the point x=x0

Numerical evaluation of residues.

 Radius specifies the radius of the circle around which the integration is performed PrecisionGoal the PrecisionGoal to be used by NIntegrate WorkingPrecision the WorkingPrecision to be used by NIntegrate

Options for NResidue.

Find the residue of at the origin.
Define an expression whose residue you will find.
Find the residue. Strictly speaking, has no singularity at , but it has one very near to 1.7.
Numerically find the residue.
This is another way to find the residue.

## Numerical Calculation of Series Expansions

The Wolfram Language function Series finds a power series expansion of a function about a point by evaluating derivatives. However, sometimes you only want a numerical approximation to a series and the derivatives are difficult to evaluate. You could use ND to evaluate the derivatives, but that would involve repeating most of the work (i.e., evaluating the function itself at several points) for each derivative. If the function is analytic and can be evaluated in the complex plane, the solution is to use the NSeries.

 NSeries[f,{x,x0,n}] gives a numerical approximation to the series expansion of f about x=x0 including the terms (x-x0)-n through (x-x0)n

Numerically finding series expansions.

NSeries works by evaluating the function at discrete points on a circle centered at the expansion point. It then uses InverseFourier to express the function as a sum of orthogonal basis functions, each of which is trivial to integrate around the circle. By Cauchy's integral formula it is seen that InverseFourier essentially gives us the required series coefficients; very little additional work is required and NSeries does it all for you. Because it is based on Cauchy's integral formula, care should be taken to ensure that no singularities of the function occur inside the circle of sample points.

 option name default value WorkingPrecision MachinePrecision precision of the arithmetic to use in calculations Radius 1 radius of the circle on which the function is sampled

Options for NSeries.

This gives an approximation to the series expansion of x about the origin. Note that NSeries is unable to recognize small numbers that should in fact be zero.
Chop and Rationalize can often clean up the result.
If the radius is too small, cancellation becomes a problem.
Increasing the WorkingPrecision will usually solve this problem.
If the radius is too large, the sample points become too scattered and it starts looking like poles exist.
NSeries also recognizes poles.