此为 Mathematica 4 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.2)

NIntegrate

Usage

NIntegrate[f,  x, xmin, xmax ] 给出积分的  数值近似.


Notes

• 同Integrate一样,NIntegrate也可以指定多重积分.
NIntegrate 可检测出积分在积分上、下限的奇异性.
NIntegrate[f,  x,  ,  , ... ,   ]可检测积分在点  的奇异性.如果没有奇异点, 该结果等价于从  的积分.你可以使用复数  来指定复平面上的积分围线.
• 可以使用下列可选项:
"\!\(\*StyleBox[\"\\\"AccuracyGoal\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"Infinity\\\"\", \"MR\"]\) "绝对精确搜索的数位
"\!\(\*StyleBox[\"\\\"Compiled\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"True\\\"\", \"MR\"]\) ""积分式是否被编译"
"\!\(\*StyleBox[\"\\\"GaussPoints\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"Automatic\\\"\", \"MR\"]\) ""初始采样点数"
"\!\(\*StyleBox[\"\\\"MaxPoints\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"Automatic\\\"\", \"MR\"]\) "最大采样点总数
"\!\(\*StyleBox[\"\\\"MaxRecursion\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"6\\\"\", \"MR\"]\) ""最大递归划分数"
"\!\(\*StyleBox[\"\\\"Method\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"Automatic\\\"\", \"MR\"]\) "要使用的方法
"\!\(\*StyleBox[\"\\\"MinRecursion\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"0\\\"\", \"MR\"]\) "最小递归划分数
"\!\(\*StyleBox[\"\\\"PrecisionGoal\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"Automatic\\\"\", \"MR\"]\) "结果的精确度
"\!\(\*StyleBox[\"\\\"SingularityDepth\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"4\\\"\", \"MR\"]\) "变量改变之前的递归划分数
"\!\(\*StyleBox[\"\\\"WorkingPrecision\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"$MachinePrecision\\\"\", \"MR\"]\) "内部计算所使用的小数数位
NIntegrate通常使用一个自适应算法,该算法按需要递归地对积分区域进行划分. 在一维情形,GaussPoints指定要选择的初始点数目.GaussPoints的缺省设置是Floor[WorkingPrecision/3]。在任意维数下,MinRecursion指定试图进行的递归划分的最小数目。MaxRecursion给出最小值。
NIntegrate通常不断进行子划分直至达到由AccuracyGoalPrecisionGoal指定的最后结果所需要的误差估计为止.
PrecisionGoal的缺省设置通常等于WorkingPrecision设置减去10个数位.
• 如果明确给定MaxPoints设置,NIntegrate会使用拟Monte Carlo方法来获得结果的一个估计,且至多对指定的点数进行采样.
• 在这种情形下,PrecisionGoal的缺省设置取为2.
• 需要注意,对于充分病态的函数,NIntegrate所使用的算法可能给出错误结果. 在多数情形下,你可以通过观察结果相对于可选项设置的敏感性来检测结果.
N[Integrate[ ... ]]调用NIntegrate计算不能被符号地求解的积分.
NIntegrate具有HoldAll属性.
Method的可能设置有GaussKronrod, DoubleExponential, Trapezoidal, Oscillatory, MultiDimensional, MonteCarlo,和QuasiMonteCarlo.GaussKronrodMultiDimensional 是自适应方法. MonteCarloQuasiMonteCarlo 是随机方法, 用来逼近高阶重积分.
• 参见 Mathematica 全书: 1.6.2节, 3.9.1节, 3.9.2节 and 3.9.3节.
• 实现注释: 参见 A.9.4节.
• 同时参见: NDSolve, NSum.
Further Examples

Functions that cannot be integrated using algebraic routines can nonetheless be integrated numerically.

In[1]:=  

Out[1]=

There are some functions that will give NIntegrate trouble, using the default values.

In[2]:=  

Out[2]=

In[3]:=  

Out[3]=

In this case, increasing the number of recursive bisections that can be performed will help to give a more reliable result. (The warning message here can be disregarded; although the integrand is oscillatory, the Oscillatory setting for the Method option is inappropriate because it is meant for integrands that are products of a certain type.)

In[4]:=  

Out[4]=

With the default settings for all options, NIntegrate misses the peak in  near x = 0, and gives the wrong answer for the integral.

In[5]:=  

Out[5]=

Setting the option MinRecursion to  , NIntegrate samples enough points to detect the peak around  . With the default setting of MaxRecursion, however, NIntegrate cannot use enough sample points to be able to expect an accurate answer.

In[6]:=  

Out[6]=

With this setting of MaxRecursion, NIntegrate can get an accurate answer for the integral.

In[7]:=  

Out[7]=

Another way to solve the problem is to make NIntegrate break the integration region into several pieces, with a small piece that explicitly covers the neighborhood of the peak.

In[8]:=  

Out[8]=

The Method option lets you choose the method used to perform the integration. The methods implemented are GaussKronrod, DoubleExponential, Trapezoidal, MultiDimensional, MonteCarlo and QuasiMonteCarlo; the default value Automatic corresponds to GaussKronrod in one dimension and to MultiDimensional in several. Here we use the MonteCarlo method, which is occasionally advantageous in dimensions greater than 1.

In[9]:=  

Out[9]=

Setting the option Method to MonteCarlo[24] is equivalent to using SeedRandom[24] to reset the random number generator, then running the integral as in the preceding example.

In[10]:=  

Out[10]=

You can specify how many function evaluations are used in the methods MonteCarlo and QuasiMonteCarlo by giving a value to MaxPoints (the default being 50000).

In[11]:=  

Out[11]=

If the AccuracyGoal and PrecisionGoal are set to Automatic, they will be set to 2 in the methods MonteCarlo and QuasiMonteCarlo, and to 6 in all the other methods.