NSum
NSum[f,{i,imin,imax}]
gives a numerical approximation to the sum .
NSum[f,{i,imin,imax,di}]
uses a step di in the sum.
Details and Options
- NSum can be used for sums with both finite and infinite limits.
- NSum[f,{i,…},{j,…},…] can be used to evaluate multidimensional sums.
- The following options can be given:
-
AccuracyGoal Infinity number of digits of final accuracy sought EvaluationMonitor None expression to evaluate whenever f is evaluated Method Automatic method to use NSumTerms 15 number of terms to use before extrapolation PrecisionGoal Automatic number of digits of final precision sought VerifyConvergence True whether to explicitly test for convergence WorkingPrecision MachinePrecision the precision used in internal computations - Possible settings for the Method option include:
-
"AlternatingSigns" method for summands with alternating signs "EulerMaclaurin" Euler–Maclaurin summation method "WynnEpsilon" Wynn epsilon extrapolation method - With the Euler–Maclaurin method, the options AccuracyGoal and PrecisionGoal can be used to specify the accuracy and precision to try and get in the final answer. NSum stops when the error estimates it gets imply that either the accuracy or precision sought has been reached.
- You should realize that with sufficiently pathological summands, the algorithms used by NSum can give wrong answers. In most cases, you can test the answer by looking at its sensitivity to changes in the setting of options for NSum.
- VerifyConvergence is only used for sums with infinite limits.
- N[Sum[…]] calls NSum for sums that cannot be done symbolically.
- NSum first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.
- NSum has attribute HoldAll, and effectively uses Block to localize variables.
Examples
open allclose allScope (5)
Options (9)
AccuracyGoal and PrecisionGoal (1)
EvaluationMonitor (3)
Method (1)
Use a method for alternating series to get a very precise sum approximation:
The error from the exact result computed by Sum:
NSumTerms (1)
By default NSum uses 15 terms at the beginning before approximating the tail:
The error for this example is large because the summand peaks at 20:
Increasing NSumTerms to include this feature improves the approximation:
VerifyConvergence (2)
Applications (2)
Approximate the sum of the reciprocals of the Fibonacci numbers:
Find the approximate limit of a slowly converging sequence by summing the difference:
Properties & Relations (3)
When the closed-form sum is available, Sum can be used instead of NSum:
The results of Sum and NSum agree closely:
Using Log and Exp to estimate a product:
The estimate compares well with the exact result:
The approximation can be done directly with NProduct:
NSum can be used to calculate oscillatory integrals over (0,∞):
NIntegrate gives the same result:
Possible Issues (3)
Wynn's extrapolation algorithm loses precision for series that are not alternating:
Uses of NIntegrate by NSum may lead to convergence messages:
The error compared to the exact value of is large:
You can increase the appropriate parameters for NIntegrate using Method options:
Find the error versus the exact value of :
NSum may not detect divergence for some infinite sums:
Convergence verification is based on a ratio test that is inconclusive when equal to 1:
Text
Wolfram Research (1988), NSum, Wolfram Language function, https://reference.wolfram.com/language/ref/NSum.html (updated 2007).
CMS
Wolfram Language. 1988. "NSum." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/NSum.html.
APA
Wolfram Language. (1988). NSum. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NSum.html