%% Calculate Exponentially Scaled Bessel Function
% Calculate the unscaled (Y) and scaled (Ys) Bessel function of the second kind Y_2 \left(z\right) for complex values of z.

x = -10:0.35:10;
y = x';
z = x + 1i*y;
scale = 1;
Y = bessely(2,z);
Ys = bessely(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(Y))
title('Bessel Function of the Second Kind','interpreter','latex')
xlabel('real(z)','interpreter','latex')
ylabel('imag(z)','interpreter','latex')
surf(x,y,imag(Ys))
title('Scaled Bessel Function of the Second Kind','interpreter','latex')
xlabel('real(z)','interpreter','latex')
ylabel('imag(z)','interpreter','latex')

%
% Copyright 2018 The MathWorks, Inc.