This is not terrible code ... but it could be better.
First of all, it brackets a root, then it uses bisection to find the root. WHY???? Why not use fzero, which will be faster than a bisection code. Use existing tools wherever you can. Don't reinvent the wheel, especially not if your invented version of the wheel is square.
Next, the help is poor. If you try this:
help BessDerivZerosBisect
you get no information about what the arguments are. What shape should they be? What do they mean?
The help also does not explain what is returned. What should you expect from the code? Good help should do all of this.
Next, there is no H1 line. An H1 line is what the lookfor utility needs to work. It is the very first line of the help block. It will be searched for any keywords. This way, next year when someone wants to use that code they downloaded to compute bessel function roots, they can find it. What are the odds otherwise that they will remember the name BessDerivZerosBisect without some aid?
Other problems. There is no error checking. What size and shape must the arguments be? Since the help does not tell us, we must just guess? Must they be integers? Scalar? Vector? Positive numbers? Tell your user these things, then verify that they have provided the proper inputs. If not, then supply a NICE error message that tells them what they should have done.
Make it easy for others to use your code, otherwise why bother submitting it to the file exchange?
Next, why does this code compute the roots of the Bessel function derivatives of only order greater than zero? The zero'th order bessel function also has zeros in its derivative.
ezplot(@(x) BesselJ(0,x))
Finally, I'm not entirely sure what is the utility of this code. Yes, it computes a table of roots of derivatives. But with computers, tables themselves tend not to be terribly useful. Instead, a function that would compute the k'th zero of the m'th order bessel function might be useful.
I've not actually checked to see if the computed roots are correct yet. So its time to do so.
r = BessDerivZerosBisect(1,10)'
r =
1.8412
5.3314
8.5363
11.706
14.864
18.016
21.164
24.311
27.457
30.602
Are these truly zeros of the derivative? I'll check the result with my own derivest code.
fun = @(x) besselj(1,x);
derivest(fun,r(1))
ans =
-2.9057e-07
So it looks like the function is finding an approximate zero of the derivative, but what is the accuracy? This brings up an important point. When you write a rootfinding code, give the user a tolerance they can control. Or at least, tell the user what tolerance was used! Nowhere in the help is this actually indicated.