Using chebfun to find roots of function with tangent

6 views (last 30 days)
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

Accepted Answer

John D'Errico
John D'Errico on 14 Dec 2014
Edited: John D'Errico on 14 Dec 2014
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.
  3 Comments
John D'Errico
John D'Errico on 14 Dec 2014
As I said, ALWAYS plot everything. Even after all these years, I can still learn so much about what I need to do from a plot.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!