function X = bessel_zeros(k, n)
%BESSEL_ZEROS : calculates the first k zeros of the bessel function Jn
% k : No. of ROOTS to be evaluated
% n : Order of the Bessel function Jn
% X : stores the roots in serial order i.e. X(1) gives the first root,
% X(2) gives the second and so on
X = zeros(1,k);% empty array of lenght k
count = 1;%this acts as a counter to k
dx = 0.1;%step size within which, by assumption, no roots exist
x = 0;
tol = 1e-8;%tolerace for zero
while count <= k
if(besselj(n,x)*besselj(n,x+dx) < 0)%root found
%apply bisection
a = x;
b = x + dx;
c = (a+b)/2;
while (abs(besselj(n,c)) >= tol)
if(besselj(n,c)*besselj(n,b)>0)
b = c;
else
a = c;
end
c = (a+b)/2;
end
X(count) = c;
count = count + 1;
end
x = x + dx;
end
end