%% Calculate Exponentially Scaled Bessel Function
% Calculate the unscaled (J) and scaled (Js) Bessel function of the first kind J_2 \left(z\right) for complex values of z.

x = -10:0.3:10;
y = x';
z = x + 1i*y;
scale = 1;
J = besselj(2,z);
Js = besselj(2,z,scale);

%
% Compare the plots of the imaginary part of the scaled and unscaled functions. For large values of abs(imag(z)), the unscaled function quickly overflows the limits of double precision and stops being computable. The scaled function removes this dominant exponential behavior from the calculation, and thus has a larger range of computability compared to the unscaled function.

surf(x,y,imag(J))
title('Bessel Function of the First Kind','interpreter','latex')
xlabel('real(z)','interpreter','latex')
ylabel('imag(z)','interpreter','latex')
surf(x,y,imag(Js))
title('Scaled Bessel Function of the First Kind','interpreter','latex')
xlabel('real(z)','interpreter','latex')
ylabel('imag(z)','interpreter','latex')

% Copyright 2018 The MathWorks, Inc.