How to use a Scilab function 'besselk', "Modified Bessel function of the second kind".
Scilab comes with a built-in function 'besselk' which computes a modified Bessel function of the second kind Kalpha(x), where x is a single non-negative value or a vector of non-negative values and alpha is an order of the function. To demonstrate the use of this function, various modified Bessel functions of the second kind can be computed and plotted using Scilab scripts below.
// =======================================================
// How to use a Scilab function besselk,
// "Modified Bessel function of the second kind".
=======================================================
//
// # besselk(alpha,x) computes modified Bessel functions
// of the second kind (K sub alpha), for real order
// alpha and argument x.
//
// # besselk(alpha,x,1) computes besselk(alpha,x).*exp(x).
//
// =======================================================
//
xbasc() // Restart new graphical window.
//
// For 0.01 < x < 10,
//
x = linspace(0.01,10,500)'; Define a vector {x}.
//
//
// Plot K1(x), K2(x), K3(x), K4(x), K5(x).
//
subplot(4,1,1)
plot2d(x,besselk(1:5,x), style=1:5, rect=[0,0,6,10])
legend('K'+string(1:5)+'(x)',1);
xtitle("Modified Bessel functions of the second kind: K1(x), K2(x), K3(x), K4(x), K5(x)")
//
//
// Plot K1/3(x), K2/3(x), K3/3(x), K4/3(x), K5/3(x).
//
subplot(4,1,2)
plot2d(x,besselk((1:5)/3,x), style=1:5, rect=[0,0,6,10])
legend('K'+string(1:5)+'/3(x)',1);
xtitle("Modified Bessel functions of the second kind: K1/3(x), K2/3(x), K3/3(x), K4/3(x), K5/3(x)")
//
//
// Plot K5/3(x).
//
subplot(4,1,3)
plot2d(x,besselk(5/3,x), style=1, rect=[0,0,6,10])
legend('K5/3(x)',1);
xtitle("Modified Bessel function of the second kind: K5/3(x)")
//
//
// Plot K5/3(x).*exp(x).
//
subplot(4,1,4)
plot2d(x,besselk(5/3,x,1), style=1, rect=[0,0,6,10])
legend('K5/3(x).*exp(x)',1);
xtitle("Scaled modified Bessel function of the second kind: K5/3(x).*exp(x)")
//
Examples for computations and plots of the Scilab 'besselk' function
Copy and paste the above Scilab scripts into your Scilab console and then execute them. A graphic window will pop-up and four cases of modified Bessel functions of the second kind will be plotted as shown below. This graphic window is divided into four subplots. The first one shows plots of the modified Bessel function of the second kind from x=0 to x=6. The functions K1(x), K2(x), K3(x), K4(x), and K5(x), have orders of 1, 2, 3, 4 and 5, respectively. Similar functions with orders 1/3, 2/3, 3/3, 4/3, and 5/3 are shown in the second subplot. In the third subplot, the modified Bessel function of x with an order of 5/3 is plotted against x. A function of this type is used in calculations of synchrotron light intensity generated by electrons traveling through a bending magnet approximately at a speed of light. The last subplot depicts a modified Bessel function of the second kind that has been scaled by a factor exp(x) by adding another argument "1" in the Scilab function besselk(5/3, x, 1). By default, this last argument is set to 0. Therefore, besselk(5/3, x) is the same as besselk(5/3, x, 0).
[ Home ] [ หน้านี้เป็นภาษาไืทย ]