การใช้งานฟังก์ชัน 'besselk', "Modified Bessel function of the second kind" ใน Scilab
โปรแกรม Scilab มาพร้อมกับฟังก์ชันสำเร็จรูป 'besselk' ซึ่งใช้ในการคำนวณค่า modified Bessel function of the second kind Kalpha(x), ของ x โดยที่ x เป็นจำนวนจริงบวกค่าเดี่ยว หรือ เป็นเวกเตอร์ของจำนวนจริงบวก และ alpha คืออันดับ (order) ของฟังก์ชัน โปรแกรมภาษา Scilab ข้างล่างสาธิตลักษณะของฟังก์ชันประเภทนี้ในรูปแบบต่าง ๆ กัน
// =======================================================
// 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)")
//
ตัวอย่างการใช้งานฟังก์ชัน 'besselk' ใน Scilab
คัดลอกโปรแกรมภาษา Scilab ในตารางข้างบนแล้ววางลงในหน้าจอดำเนินงานของ Scilab เมื่อสั่งให้โปรแกรมทำงานจะมีกรอบหน้าต่างกราฟฟิกเปิดขึ้น ภายในมีกราฟแสดงค่าของ modified Bessel function of the second kind แบบต่าง ๆ จำนวน 4 กราฟ กราฟแรกแสดงค่าฟังก์ชัน K1(x), K2(x), K3(x), K4(x), และ K5(x) สำหรับค่า x จาก 0 ถึง 6 ฟังก์ชันทั้ง 5 เส้นนี้ มีอันดับ (order) เท่ากับ 1, 2, 3, 4 และ 5 ตามลำดับ ในทำนองเดียวกัน ฟังก์ชันที่มีอันดับเท่ากับ 1/3, 2/3, 3/3, 4/3, และ 5/3 แสดงไว้ในกราฟที่สอง สำหรับกราฟที่ 3 นั้น เป็นการแสดงค่าของ modified Bessel function ของ x ด้วยอันดับ 5/3 ฟังก์ชันแบบนี้มีใช้ในการคำนวณความเข้มของแสงซินโครตรอนที่แผ่ออกมาจาก อิเล็กตรอนซึ่งเคลื่อนที่ผ่านแม่เหล็กโค้งด้วยความเร็วเกือบเท่าแสง ส่วนกราฟสุดท้าย แสดงค่าของ modified Bessel function of the second kind อันดับ 5/3 ซึ่งถูกคูณด้วยตัวประกอบ exp(x) โดยการเพิ่มอาร์กิวเมนท์ "1" เข้าไปในฟังก์ชัน besselk(5/3, x, 1) ซึ่งอาร์กิวเมนท์ตัวสุดท้าย นี้ เราไม่ระบุลงไป Scilab จะถือว่าเป็นศูนย์ ทำให้ใส่หรือไม่ใส่ก็มีค่าเท่ากัน ดังนั้น besselk(5/3, x) จึงเหมือนกันกับ besselk(5/3, x, 0) นั่นเอง