File Exchange

image thumbnail

Adaptive numerical limit (and residue) estimation

version 1.1 (50.5 KB) by

Numerical extrapolation of a limit (with an error estimate) from only function values



View License

LIMEST will find the limit of a general function (specified only for evaluation) at a given point. You might think of limest like quad, but for limits.
While to me this seems to appear more often as a homework exercise than anything else, it was an interesting problem to solve as robustly as possible for a general case.

As an example, I'll use a moderately difficult one that is simple to analyze, but more difficult to deal with numerically.

fun = @(x) (exp(x)-1-x)./x.^2;

This function cannot be evaluated in MATLAB at x = 0, returning a NaN. While a Taylor series expansion shows the limit to be 1/2, the brute force evaluation of fun anywhere near zero results in numerical trash because of the two orders of cancellation.

ans =

ans =

ans =

ans =

ans =

Limest computes the limit, also returning an approximate error estimate.

[lim,err] = limest(fun,0)
lim =
err =

I've now added the residueEst tool, for computation of the residue of a function at a known pole. For example, here is a function with a first order pole at z = 0
[r,e]=residueEst(@(z) 1./(1-exp(2*z)),0)
r =
e =

Again, both an estimate of the residue, as well as an uncertainty around that estimate are provided. Next, consider a function with a second order pole around z = pi.
[r,e]=residueEst(@(z) 1./(sin(z).^2),pi,'poleorder',2)
r =
e =

See the included demos for many other examples of use.

Comments and Ratings (5)

David Berger

Really great! Documentation emphasizes vectorization, which suggests that it can handle vector-valued functions. It seems like it ought to be able to, but if not, it ought to indicate that it can't.

adrian zizo

nice worke

C Schwalm

Well done! And useful...

Bill McKeeman

Nice work.



Included residueEst

Improved some error messages

MATLAB Release
MATLAB 7.4 (R2007a)

Inspired by: Adaptive Robust Numerical Differentiation

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video