%% Calculate Exponentially Scaled Modified Bessel Functions
% Calculate the scaled modified Bessel functions of the second kind K_{\nu } \left(z\right)\cdot e^{\;z} for values of z in the interval \left\lbrack 0,5\right\rbrack and for orders of \nu between 0 and 3.

z = linspace(0,5);
scale = 1;
Ks = zeros(4,100);
for nu = 0:3
  Ks(nu+1,:) = besselk(nu,z,scale);
end

%
% Plot all of the functions in the same figure. For large values of z, the scaled functions do not underflow the limits of double precision as quickly as the unscaled functions, extending their range of computability.

plot(z,Ks)
ylim([0 3])
legend('K_0','K_1','K_2','K_3')
title('Scaled Mod. Bessel Functions of the Second Kind for $\nu \in \left[0, 3 \right]$','interpreter','latex')
xlabel('z','interpreter','latex')
ylabel('$K_\nu(z) \cdot e^{z}$','interpreter','latex')

% Copyright 2018 The MathWorks, Inc.