# How to find a limit without syms and limit function

125 次查看（过去 30 天）
Florin Florin2019-5-25

Let's take the limit . How can i calculate it without using syms and matlab's function limit?

### 采纳的回答

Star Strider 2019-5-25

Crude but effective (for this function, may not be universally applicable):
fcn = @(x) (x.^3 - 1) ./ (x - 1);
x = 1;
lm = fcn(x-1E-15)
lm =
3
Experiment to get the result you want.
EDIT —
Another option is to use a simple numerical derivative:
dfdx = @(f,x) (f(x + 1E-8) - f(x)) ./ 1E-8;
fcnn = @(x) x.^3 - 1;
fcnd = @(x) x - 1;
xv = 1;
Lm = dfdx(fcnn,xv) ./ dfdx(fcnd,xv)
producing:
Lm =
3
##### 2 个评论显示隐藏 1更早的评论
Star Strider 2021-10-6
@Gustav Garpebo — Sure! (I probably should have explained those originally, describing them in comments, although they were clear in the context 2½ years ago.)
The forward-difference derivative ‘dfdx’ function requires a function handle (first argument) and a value of ‘x’ at which the function is evaluated (second argument), and since the function is being evaluated at 1 that is what ‘xv’ is assigned to be. The two other functions, ‘fcnn’ and ‘fcnd’ are the numerator and denominator of the original function, respectively. The rest is straightforward.
.

### 更多回答（1 个）

John D'Errico 2021-10-6

You can use my limest function. It is on the file exchange.
>> fun= @(x) (x.^3 - 1)./(x-1)
fun =
function_handle with value:
@(x)(x.^3-1)./(x-1)
Now use limest. It even provides an estimate of how well it thinks that limit is known.
[L,errest] = limest(fun,1)
L =
3
errest =
2.20957326622612e-14
Is that correct? l'hopital would tell me of course. Thus, if I differentiate the numerator and the demoninator, we would have 3^x^2/1. At x==1, that is 3.
The symbolic toolbox would agree, but you don't want to see that.
syms X
F = (x^3-1)/(x-1)
limit(F,1)
ans =
3
But we can still use the symbolic TB, without use of limit, just using l'hopital...
subs(diff(X^3-1),X,1)/subs(diff(X-1),X,1)
ans =
3
As expected, it returns 3 as the desired limit.
You can find limest on the file exchange, here:
LIMEST uses an adaptive, multi-order Richardson extrapolation scheme, modified to provide also an estimate of the uncertainty at the extrapolation point, all of my invention.)

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!