NUMERICAL CALCULUS 程序包 教程
Numerical Calculus Package
The functions defined in the
context provide support for finding numerical solutions to calculus-related problems.
Numerical Calculation of Limits
The built-in 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  |
Computing numerical limits.
Here is the numerical computation of a limit.
| Out[2]= |  |
The limit gives the number known as Euler's gamma.
| Out[3]= |  |
You can also compute limits as

approaches infinity.
| Out[4]= |  |
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 built-in 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.
Options for EulerSum.
This uses
EulerSum to compute a numerical approximation to the sum of an alternating series.
| Out[5]= |  |
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.
| Out[6]= |  |
The result is also in good agreement with the known exact result.
| Out[7]= |  |
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 built-in function D.
| ND[f,x,x0] | gives a numerical approximation to evaluated at the point  |
| ND[f,{x,n},x0] | gives the derivative |
Numerical computation of derivatives.
Here is a numerical approximation of the derivative of

at

.
| Out[8]= |  |
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.
| Out[9]= |  |
This is the error in the numerical derivative using Cauchy's integral formula.
| Out[10]= |  |
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 Mathematica 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 |
Numerical evaluation of residues.
Options for NResidue.
Find the residue of

at the origin.
| Out[2]= |  |
Define an expression whose residue you will find.
| Out[3]= |  |
Find the residue. Strictly speaking,

has no singularity at

, but it has one very near to 1.7.
| Out[4]= |  |
Numerically find the residue.
| Out[5]= |  |
This is another way to find the residue.
| Out[6]= |  |
Numerical Calculation of Series Expansions
The Mathematica 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 including the terms through |
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.
Options for NSeries.
This gives an approximation to the series expansion of

about the origin. Note that
NSeries is unable to recognize small numbers that should in fact be zero.
| Out[2]= |  |
| Out[3]= |  |
If the radius is too small, cancellation becomes a problem.
| Out[4]= |  |
| Out[5]= |  |
If the radius is too large, the sample points become too scattered and it starts looking like poles exist.
| Out[6]= |  |
| Out[7]= |  |