1

Say I have the following symbolic function:

syms f(t)
f(t)=sin(t)/t

I want to get the limit using another symbolic function. I tried:

syms lim(x)
lim(x)=limit(f(t),t,x)

But when I tried to use lim(0) I got this error:

Error using symengine (line 59) Division by zero.

Can this be fixed?

Jerry
  • 4,258
  • 3
  • 31
  • 58

2 Answers2

1

Take a look at lim(x). For some reason the limit is gone. I don't really understand what is going wrong there. If you use an anonymous function instead of a function handle, the evaluation of limit is postponed until x has a value and it works.

>> lim=@(x)limit(f(t),t,x)

lim = 

    @(x)limit(f(t),t,x)

>> lim(0)

ans =

1
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • `lim(x)` is not a function handle. It's a `symfun`, as is `f`, which does not delayed evaluation. – horchler Mar 18 '16 at 02:15
  • Thanks. This was my second choice. But I want to do it using symbolic functions. For one, I'll be able to pass a vector to `lim`. – Jerry Mar 18 '16 at 09:54
  • @horchler: I would have expected some behaviour like you often see with `int` where the expression is not resolved. Those cases where the evaluation of `int(f)` is `int(f)`. – Daniel Mar 18 '16 at 09:59
  • @Jerry: The `limit` function does not support vectors. You won't get that done. – Daniel Mar 18 '16 at 10:00
  • No: `limit(x,[1,2,3])` results in `Error in MuPAD command: Limit point must be a scalar.`. – Daniel Mar 18 '16 at 10:52
1

Matlab does not have delayed assignments as discussed here. Therefore, when lim is created, the call to limit is immediately evaluated with x replacing t:

>> syms t x f(t) lim(x)
>> f(t) = sin(t)/t
f(t) =
sin(t)/t

>> lim(x) = limit(f(t),t,x)
lim(x) =
sin(x)/x

And when you evaluate lim(0), you get sin(0)/0, which throws the error.

Community
  • 1
  • 1
TroyHaskin
  • 8,361
  • 3
  • 22
  • 22
  • For the symbolic math toolbox there is something like delayed evaluation. Try for example `int(exp(sin(a^b + b^a*g)+a*3),a)`, here the `int` is not evaluated. I would expect the same behaviour with `sym/limit` which is called in this case. – Daniel Mar 18 '16 at 01:59
  • @Daniel Not on my R2014b install. `limit`, in this instance, does a direct substitution of variables although your `int` example does not. I guess a more precise wording is "Matlab does not currently have a facility for explicit delayed evaluation though certain functions may exhibit the behavior". – TroyHaskin Mar 18 '16 at 05:09