Function Repository Resource:

NLimit

Source Notebook

Find the limiting value of an expression numerically

Contributed by: Wolfram Research

ResourceFunction["NLimit"][expr,zz0]

numerically finds the limiting value of expr as z approaches z0.

Details and Options

The expression expr must be numeric when its argument z is numeric.
ResourceFunction["NLimit"] constructs a sequence of values that approach the point z0 and uses extrapolation to find the limit.
ResourceFunction["NLimit"] is unable to recognize small numbers that should in fact be zero. Chop may be needed to eliminate these spurious residuals.
ResourceFunction["NLimit"] often fails when the limit has a power law approach to infinity.
The following options can be given:
WorkingPrecisionMachinePrecisionprecision to use in internal computations
DirectionAutomaticvector giving the direction of approach
"Scale"1initial step size in the sequence of steps
"Terms"7number of terms used to evaluate the limit
Method"EulerSum"the method used to evaluate the result
"WynnDegree"1degree used in Wynn's epsilon algorithm
The option Directiond specifies that the approach vector to a finite limit point z0 is given by the complex number d. The default setting DirectionAutomatic is equivalent to Direction-1, and computes the limit as z approaches z0 from larger values.
ResourceFunction["NLimit"] approaches infinite limit points on a ray from the origin.
The option "Scale" specifies the initial step in the constructed sequence.
For finite limit points x0, the initial step is a distance "Scale" away from x0. For infinite limit points, the initial step is a distance "Scale" away from the origin.
The accuracy of the result is generally improved by increasing the number of terms, although increased WorkingPrecision will also usually be necessary.
Possible settings for Method include:
"EulerSum"converts sequence to a sum
"SequenceLimit"constructs a sequence
The option "WynnDegree" specifies the number of iterations of Wynn's epsilon algorithm to be used by "SequenceLimit". In general, there must be at least 2(n+1) terms for n iterations.

Examples

Basic Examples (2) 

Find the limit at zero:

In[1]:=
ResourceFunction["NLimit"][Sin[x]/x, x -> 0]
Out[1]=

Find the limit at infinity:

In[2]:=
ResourceFunction["NLimit"][(1 + 1/n)^n, n -> \[Infinity]]
Out[2]=

Scope (2) 

The expression can be manifestly complex:

In[3]:=
ResourceFunction["NLimit"][(1 + I/x)^x, x -> \[Infinity]]
Out[3]=

The limit point can be complex:

In[4]:=
ResourceFunction["NLimit"][Tanh[\[Pi] x]/(1 + x^2), x -> I]
Out[4]=

Options (16) 

Terms (2) 

Expressions that approach their limiting value exponentially need fewer terms:

In[5]:=
ResourceFunction["NLimit"][Tanh[x], x -> \[Infinity]]
Out[5]=
In[6]:=
ResourceFunction["NLimit"][Tanh[x], x -> \[Infinity], "Terms" -> 3]
Out[6]=

Increasing the number of terms can improve accuracy:

In[7]:=
lim = Limit[(10^x - 1)/x, x -> 0]
Out[7]=

Error in numerical approximation:

In[8]:=
ResourceFunction["NLimit"][(10^x - 1)/x, x -> 0, Method -> "SequenceLimit"] - lim
Out[8]=

Use more terms to reduce error:

In[9]:=
ResourceFunction["NLimit"][(10^x - 1)/x, x -> 0, "Terms" -> 10, Method -> "SequenceLimit"] - lim
Out[9]=

Scale (2) 

Use "Scale" to avoid regions where the expression is undefined:

In[10]:=
f[a_?NumericQ] := NIntegrate[Zeta[a z], {z, 2/a, 1}] /; a > 1
In[11]:=
ResourceFunction["NLimit"][f[a], a -> Infinity]
Out[11]=

The function f(x) diverges for f(1), so choose the initial step to avoid this divergence:

In[12]:=
ResourceFunction["NLimit"][f[a], a -> \[Infinity], Scale -> 10]
Out[12]=

Direction (3) 

Approach 0 along the negative real axis:

In[13]:=
ResourceFunction["NLimit"][z + z\[Conjugate]/z, z -> 0, Direction -> 1]
Out[13]=

Approach 0 along the positive imaginary axis:

In[14]:=
ResourceFunction["NLimit"][z + z\[Conjugate]/z, z -> 0, Direction -> -I] // Chop
Out[14]=

Approach 0 from the 3rd quadrant, at 225°:

In[15]:=
ResourceFunction["NLimit"][z + z\[Conjugate]/z, z -> 0, Direction -> -Exp[225 \[Degree] I]] // Chop
Out[15]=

Method (2) 

An example where the default method works fairly well:

In[16]:=
ResourceFunction["NLimit"][Sin[x]/x, x -> \[Infinity]]
Out[16]=

Using "SequenceLimit" produces poorer results:

In[17]:=
ResourceFunction["NLimit"][Sin[x]/x, x -> \[Infinity], Method -> "SequenceLimit"]
Out[17]=

An example where the default method works poorly:

In[18]:=
ResourceFunction["NLimit"][Tan[z], z -> \[Infinity] I]
Out[18]=

Here, "SequenceLimit" produces the correct result:

In[19]:=
ResourceFunction["NLimit"][Tan[z], z -> \[Infinity] I, Method -> "SequenceLimit"]
Out[19]=

WynnDegree (3) 

When using Method"SequenceLimit", increasing "WynnDegree" may improve the accuracy of the limit:

In[20]:=
lim = SinIntegral[\[Infinity]]
Out[20]=

Error with "WynnDegree"1:

In[21]:=
ResourceFunction["NLimit"][SinIntegral[z], z -> \[Infinity], "Terms" -> 10, Method -> "SequenceLimit", "WynnDegree" -> 1] - lim
Out[21]=

Error with "WynnDegree"3:

In[22]:=
ResourceFunction["NLimit"][SinIntegral[z], z -> \[Infinity], "Terms" -> 10, Method -> "SequenceLimit", "WynnDegree" -> 3] - lim
Out[22]=

WorkingPrecision (4) 

Increasing WorkingPrecision alone does not produce a more accurate result:

In[23]:=
lim = Limit[(10^x - 1)/x, x -> 0]
Out[23]=

Error with WorkingPrecision20:

In[24]:=
ResourceFunction["NLimit"][(10^x - 1)/x, x -> 0, WorkingPrecision -> 20] - lim
Out[24]=

Error with WorkingPrecision30:

In[25]:=
ResourceFunction["NLimit"][(10^x - 1)/x, x -> 0, WorkingPrecision -> 30] - lim
Out[25]=

To improve accuracy, the number of terms needs to be increased:

In[26]:=
ResourceFunction["NLimit"][(10^x - 1)/x, x -> 0, WorkingPrecision -> 20, "Terms" -> 10] - lim
Out[26]=

Applications (2) 

Find the limit of a numerically defined function:

In[27]:=
g[a_?NumericQ] := 1/a Log[NIntegrate[z^a Cot[z], {z, 0, Pi/2}, MaxRecursion -> 10]]
In[28]:=
ResourceFunction["NLimit"][g[a], a -> Infinity, "Terms" -> 10]
Out[28]=

Limits where parts of the expression have essential singularities:

In[29]:=
ResourceFunction["NLimit"][(Sqrt[z] BesselJ[0, z])/Cos[z - \[Pi]/4], z -> \[Infinity], "Terms" -> 10]
Out[29]=

In this case, the exact limit can be found:

In[30]:=
lim = Sqrt[z]/
   Cos[z - \[Pi]/4] Series[BesselJ[0, z], {z, \[Infinity], 0}] // Normal
Out[30]=

Check:

In[31]:=
N[lim]
Out[31]=

Possible Issues (1) 

Limits whose value approaches infinity are sometimes unable to be computed:

In[32]:=
ResourceFunction["NLimit"][1/x, x -> 0]
Out[32]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 14 March 2019

Related Resources

License Information