No BSD License  

Highlights from
BessDerivZerosBisect

2.0

2.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 2.25 KB File ID: #18756

BessDerivZerosBisect

by Larry Forbes

 

15 Feb 2008 (Updated 15 Feb 2008)

Calculates the zeros of J_m prime

| Watch this File

File Information
Description

Calculates a table of the first k zeros of the first m functions J'm. Here Jm is the first-kind Bessel function of integer order m, and J'm is its derivative. These functions arise in many problems involving cylindrical geometry. A simple bisection algorithm is used, since it allows intervals to be constructed that bracket each successive root.

Acknowledgements
This submission has inspired the following:
Bessel Derivative Zeros
MATLAB release MATLAB 7.0.4 (R14SP2)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
16 Feb 2008 John D'Errico

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.

Good code does all of these things. Sorry.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
approximation Larry Forbes 22 Oct 2008 09:47:39
interpolation Larry Forbes 22 Oct 2008 09:47:39
zeros Larry Forbes 22 Oct 2008 09:47:39
bisection algorithm Larry Forbes 22 Oct 2008 09:47:39
firstkind bessel function derivative Larry Forbes 22 Oct 2008 09:47:39
bessel Carey Smith 23 Jun 2010 19:27:28
bessel derivative Carey Smith 23 Jun 2010 19:27:28

Contact us at files@mathworks.com