MATLAB: Using chebfun to find roots of function with tangent

chebfunfind roots with chebfuntrig functions in chebfun

Hello,
I have to find the nonzero roots of an equation and then plug them into a summation. I determined chebfun is probably the best way to find the nonzero roots but I receive errors about the function being unresolved using 65000+ points and have I tried 'splitting on' which I think is due to tan(x) being in my function?
The function I need to non-zero roots for is below, where alpha is a previously found integer. I don't even need all the non-zero roots the first 5 or so (say a range of 0:30) would be sufficient): f = tan(x)-((3*x)./(3+alpha*(x^2)))
I then need to plug-in these non-zero positive roots to this second equation as the variable "r" so I was going to step through the roots matrix and sum the values of the function below. Again "alpha" is a pre-defined integer and so is "Deff". (6*alpha*(1+alpha)*exp(-Deff*(r.^2)*(t/(rS.^2))))/(9+9*(r.^2)*(alpha.^2))
Thank you! Melissa

Best Answer

It is PERHAPS due to the tangent in there? Have you thought about the shape of that function? Plot it if you are unsure, which is ALWAYS something I recommend.
It will have singularities at pi/2, at 3*pi/2, etc. Chebfun is unhappy about the singularities. Infinity is a tricky thing after all. Using chebfun is completely unnecessary though, if all you want is a root.
For example, if I pick alpha=17 as the archetypal integer, then the first non-zero root will be found in the interval [pi/2,3*pi/2].
alpha = 17;
f = @(x) tan(x)-((3*x)./(3+alpha*(x.^2)));
fzero(f,pi/2*[1 3].*(1 + 100*eps*[1 -1]))
ans =
3.19582070959222
The second non-zero root is...
fzero(f,pi/2*[3 5].*(1 + 100*eps*[1 -1]))
ans =
6.31101707788965
While I could have used chebfun (a truly beautiful set of tools), it would have taken another step that would serve no real purpose. fzero was trivial to use. Just loop over the intervals between singularities.