Matlab refuses to compute a limit

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) - …

Namsaknoi

Posted 2020-01-27T16:17:43.413

Reputation: 11

Question was closed 2020-01-27T18:56:39.243

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 – 2020-01-27T16:50:18.273

Answers

0

Quite some years ago I used the Newton-Raphson formula to numerically solve problems - that was for problems present in schoolbooks on the level below university. The knowledge was less useful later in my education ...

I remember some though;

  1. The more distinctly the derivative function changes in the interesting range, the easier it is to solve the function for it's roots.
  2. As the 'degree' (n in x^n) rises - the solving quickly get more complex, and that varies wildly with very minor changes starting already at n=3.
  3. Choosing x0, the starting value for the interpolation is very critical for anything just slightly above the basics.

Based on this I'd say; you must get to know your function well, where it has local extremes or even undefined points or areas.

I have no idea which method Matlab uses, nor how complex your functions is - still the above should fit as an answer on the general level.


The above text is "translated" from Swedish, I hope it still makes sense.

Hannu

Posted 2020-01-27T16:17:43.413

Reputation: 4 950