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:
  • AccuracyGoalInfinitynumber of digits of final accuracy sought
    EvaluationMonitor Noneexpression to evaluate whenever f is evaluated
    Method Automaticmethod to use
    NSumTerms 15number of terms to use before extrapolation
    PrecisionGoalAutomaticnumber of digits of final precision sought
    VerifyConvergence Truewhether to explicitly test for convergence
    WorkingPrecision MachinePrecisionthe precision used in internal computations
  • Possible settings for the Method option include:
  • "AlternatingSigns"method for summands with alternating signs
    "EulerMaclaurin"EulerMaclaurin summation method
    "WynnEpsilon"Wynn epsilon extrapolation method
  • With the EulerMaclaurin 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 all

Basic Examples  (1)

Approximate an infinite sum numerically:

The error versus the exact value of :

Scope  (5)

Approximate the value of a finite sum:

This is effectively the difference of two infinite sums:

Approximate a multidimensional sum:

Approximate a multidimensional sum with the second index depending on the first:

Complex series summation:

Sum the even terms of a series:

An equivalent way of specifying the same sum:

Options  (9)

AccuracyGoal and PrecisionGoal  (1)

Approximate a sum with the default tolerances:

Find the error versus the exact value of :

The error with smaller absolute and relative tolerances:

The error with larger absolute and relative tolerances:

EvaluationMonitor  (3)

Get the number of evaluation points used in a numerical summation:

The evaluation points used in a summation approximated by an integration method:

The evaluation points used in a summation approximated by the sequence extrapolation method:

Method  (1)

Use a method for alternating series to get a very precise sum approximation:

The error from the exact result computed by Sum:

The error using the default method:

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)

By default the summand's convergence is verified:

Generally, if the convergence is not verified the summation is faster:

Approximate the formal sum without verifying convergence:

This is roughly equivalent to the formal symbolic result:

WorkingPrecision  (1)

Use higher precision to get a better approximation:

Find the error versus the exact value of :

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:

Compare to the exact result:

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:

The error is much smaller:

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:

Wolfram Research (1988), NSum, Wolfram Language function, https://reference.wolfram.com/language/ref/NSum.html (updated 2007).

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

BibTeX

@misc{reference.wolfram_2023_nsum, author="Wolfram Research", title="{NSum}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/NSum.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_nsum, organization={Wolfram Research}, title={NSum}, year={2007}, url={https://reference.wolfram.com/language/ref/NSum.html}, note=[Accessed: 18-March-2024 ]}