1

I have some function handle which has a variable input x, along with some parameters. I am trying to compute the limit when x goes to zero from above of that function, for different values of the parameters, so for given a, b and c, I type:

limit(f(x, a, b, c), x, 0, 'right')).

For some reason, Matlab is able to compute the limit for some values of a, b and c, but not for others. Worse, for those problematic parameters, Matlab wouldn't even compute the limit at, say, x = 0.1, even though the function is defined there!

edit: to be more specific:

syms f(x, a, b, c)
f(x,a, b, c) = ((x./(2*(1+a.*tanh(x*b).*tanh(x*c)))).*
(tanh(x*b)+tanh(x*c) + x.^2.*(tanh(x*b)+a.*tanh(x*c)) - ((tanh(x*b)+tanh(x*c) + 
x.^2.*(tanh(x*b)+a.*tanh(x*c))).^2 - 4.*tanh(x*b).*tanh(x*c).*
(1-a).*(1+a.*tanh(x*b).*tanh(x*c)).*(1+x.^2)).^0.5)).^0.5;

It is the function's derivative (which is not defined at x = 0) that I am in fact interested in:

g = diff(f,x);

good example:

double(limit(g(x, 0.3, 5, 5), x, 0, ‘right’)
ans = 1.5038

bad example (forget even the limit at zero, compute at x = 0.1 instead):

g(0.1, 0.3, 5, 10)
ans = 1.4914

but

double(limit(g(x, 0.3, 5, 10), x, 0.1, ‘right’) 
ans = limit(((tanh(5*x) + tanh(10*x) - …
  • I don't find Matlab to be very good at calculating symbolic expressions. Sometimes, it will simply not calculate some expressions. In other occasions, it will have trouble finding a way to actually express/present the results, even though it could calculate it. If you could provide us the code, it would be easier for us to investigate the problem on your particular problem – Thales Jan 27 '20 at 16:50

0 Answers0