This routine uses an analytical method to find all the real roots of an arbitrary function over an arbitrary interval. The approach used is to approximate the function by a series of Chebyshev polynomials, and then to find the roots of the approximation using a very efficient analytical method due to J.P. Boyd [see Appl. Num. Math. 56 pp.1077-1091 (2006)].
In the form given here, the function for which roots must be found is supplied as a MATLAB anonymous function. For example:
FindRealRoots(@(x) besselj(1,x),a,b,n)
...will find all the real roots of the function besselj(1,x) over the interval [a,b] based on an n-element Chebyshev expansion. At the end of the routine, as well as the calculated roots, the routine gives the time taken plus a plot of the original function and its approximation over the required interval: if the two do not coincide then the user should try again with a larger value of 'n'. |