besselj - Bessel functions of the first kind (J sub alpha).
besselj(alpha,x) computes Bessel functions of the first kind (J sub alpha), for real, non-negative order alpha and argument x
alpha and x may be vectors. The output is m -by- n with m = size(x,'*') , n = size(alpha,'*') whose (i,j) entry is besselj(alpha(j),x(i)) .
J_alpha and Y_alpha (see bessely ) Bessel functions are 2 independant solutions of the Bessel 's differential equation :
2 2 2
x y" + x y' + (x - alpha ) y = 0 , alpha >= 0
// example #1 : display some bessel functions
x = linspace(0,40,5000)';
y = besselj(0:4,x);
xbasc()
plot2d(x,y, style=2:6, leg="J0@J1@J2@J3@J4")
xtitle("Some bessel functions of the first kind")
// example #2 : use the fact that J_(1/2)(x) = sqrt(2/(x pi)) sin(x)
// to compare the algorithm of besselj(0.5,x) with
// a more direct formula
x = linspace(0.1,40,5000)';
y1 = besselj(0.5, x);
y2 = sqrt(2 ./(%pi*x)).*sin(x);
er = abs((y1-y2)./y2);
ind = find(er > 0 & y2 ~= 0);
xbasc()
subplot(2,1,1)
plot2d(x,y1,style=2)
xtitle("besselj(0.5,x)")
subplot(2,1,2)
plot2d(x(ind), er(ind), style=2, logflag="nl")
xtitle("relative error between 2 formulae for besselj(0.5,x)")
W. J. Cody (code from Netlib (specfun))