version 1.1 (31.7 KB) by
Jason Nicholson

Finds the zeros of besselj and bessely in an ordered fashion. No zeros are missed.

besselzero.m is the function. Other code is documentation.

This code is valid for abs(order) less than or equal 146222.16674537213 and 370030.762407380 for Bessel function of the first and second kind respectively. It is very fast and flexible too. 2 million zeros (0:10000 orders and 200 roots per order) can be found in 200 seconds on standard laptop. Accuracy is set to a default of 12 significant digits.

This code is based on another submission. I fixed the bugs, improved the documentation, improved the code quality, and improved the speed of the code. If you have problems, let me know. If I have time, I will fix them.

How it works:

the first three roots of any order Bessel can be approximated by a simple equations. These equations were generated using a least squares fit of the roots from orders of n=0:10000. The approximation is used to start the iteration of Halley's method. The 4th and higher roots can be approximated by understanding the roots are regularly spaced for a given order. Once the 2nd and 3rd roots are found, the spacing can be approximated by the distance between the 2nd and 3rd root. Then again Halley's method can be applied to precisely locate the root.Because the algorithm depends on good guesses of the first three zeros, if the guess is to far away then Halley's method will converge to the wrong zero which will subsequently cause any other zero to be incorrectly located. Therefore, a limit is put on Bessel order, abs(n), of 146222.16674537213 and 370030.762407380 for first and second kind respectively. If n is specified above these limits, then an error is thrown.

Jason Nicholson (2021). Bessel Zero Solver (https://www.mathworks.com/matlabcentral/fileexchange/48403-bessel-zero-solver), MATLAB Central File Exchange. Retrieved .

Created with
R2014b

Compatible with any release

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

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

José Irusta SoleraOlufolahan OgidanThank you for your help, and yes I am new to MATLAB.

Jason Nicholson1. Yes you can set the path in an educational version. I cannot troubleshoot this via the comment section because it could be some many things ranging from your IT department to windows or even some other things. I am not sure.

2. From your posts here and what you are struggling with, you need help with learning MATLAB. I think you should aim to get help with MATLAB. I would recommend calling Mathworks if you have a license that will allow this (it does not seem like you do but I am not sure). I would also recommend MATLAB Answers: https://www.mathworks.com/matlabcentral/answers/index/?s_tid=gn_mlc_an

Olufolahan OgidanI have tried putting it in the same directory and its not working, I am tasing the code in the editor tab . I also cannot set the path as it is an educational license, for the school am running MATLAB on.

Jason NicholsonJust put besselzero in the same directory as your script. Or if you are using the command line, make the current directory the directory where besselzero is located.

More on setting your path:

https://www.mathworks.com/help/releases/R2018b/matlab/matlab_env/add-remove-or-reorder-folders-on-the-search-path.html

Olufolahan Ogidanthank you for your quick response Jason, can you please direct me as to adding the besseslzero() function on my MATLAB path. I guessed that was the issue and tried checking to see how to add it but was not able to. thanks again

Jason NicholsonOlufolahan Ogidan, the code snippet you gave me runs on my computer with MATLAB 2018b. The code I used is repeated again for directness and clarity:

clc; clear; close all;

n = (1:2)';

k = 10;

kind = 1;

z = besselzero(n, k, kind);

x = linspace(0, z(end), 1000);

y = nan(2, length(x));

y(1,:) = besselj(n(1), x);

y(2,:) = besselj(n(2), x);

nz = nan(size(z));

nz(1,:) = besselj(n(1), z(1,:));

nz(2,:) = besselj(n(2), z(2,:));

plot(x, y, z, nz,'kx')

I think that besselzero() function isn't on your MATLAB path.

Olufolahan OgidanI tried running this and the example on this discussion. am trying to calculate the Bessel zeros of the first and second kind.

here is the code

n = (1:2)';

k = 10;

kind = 1;

z = besselzero(n, k, kind);

x = linspace(0, z(end), 1000);

y = nan(2, length(x));

y(1,:) = besselj(n(1), x);

y(2,:) = besselj(n(2), x);

nz = nan(size(z));

nz(1,:) = besselj(n(1), z(1,:));

nz(2,:) = besselj(n(2), z(2,:));

plot(x, y, z, nz,'kx')

and the ERROR

Error in zerossss (line 4)

z = besselzero(n, k, kind);

I also tried Jason's code below here but its the same kind of error am getting. Please help, am new to Matlab.

thanks

Jason NicholsonYao, I don't see the issue. Use the "contact" link to drop me an email. The code below does exactly what I think it should.

clc; clear; close all;

% This finds the first 5 zeros the order 1 bessel function of the first

% kind

order = 1;

kind =1;

numberOfZeros = 5;

zerosOfBesselOfFirstKind = besselzero(order,numberOfZeros,kind);

% This finds the first 5 zeros the order 1 bessel function of the second

% kind

kind =2;

zerosOfBesselOfSecondKind = besselzero(order,numberOfZeros,kind);

% plot order 1 bessel functions of first and second kind

x = linspace(0,max([zerosOfBesselOfFirstKind, zerosOfBesselOfSecondKind]), 1000);

j1 = besselj(order,x); % bessel function of first kind

y1 = bessely(order,x); % bessel function of second kind

plot(x,j1,'b');

xlim(xlim); ylim(ylim); % causes the axis limits to not update due to bessel function of second kind

hold all;

plot(x,y1,'r');

% plot zeros

plot(zerosOfBesselOfFirstKind,zeros(1,numberOfZeros),'bx', ...

zerosOfBesselOfSecondKind,zeros(1,numberOfZeros),'xr');

legend({'Bessel Function of 1st Kind', ...

'Bessel Function of 2nd Kind', ...

sprintf('First %d zeros of Bessel Function of 1st Kind',numberOfZeros), ...

sprintf('First %d zeros of Bessel Function of 2nd Kind',numberOfZeros)});

Luming YAOI checked again when the order n=-0.5, this mistake will happen.

Luming YAOHi, I have a little problem when I use this code to solve the zeros of Bessel functions. When I set kind=1, the solution is the zeros for Bessel function of the second kind.

Mazin MustafaJason NicholsonHoncai, you miss understand the definition of k for "besselzero.m". k is the number of zeros. k cannot be 0.

Hongcai ChenI think this code is missing the k=0 point for n>1 cases. Please check.

Igor Gaydayzip-file contains only license, without the actual code