# Bessel¶

Show the different kinds of Bessel functions available in ROOT To execute the macro type in:

root[0] .x Bessel.C


It will create one canvas with the representation of the cylindrical and spherical Bessel functions regular and modified

Based on Bessel.C by Magdalena Slawinska

Author: Juan Fernando Jaramillo Botero
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, August 17, 2022 at 09:34 AM.

In [1]:
from ROOT import TCanvas, TF1, gSystem, gPad, TLegend, TPaveLabel, kBlack

DistCanvas = TCanvas("DistCanvas", "Bessel functions example", 10, 10, 800, 600)
DistCanvas.SetFillColor(17)
DistCanvas.Divide(2, 2)
DistCanvas.cd(1)
leg = TLegend(0.75, 0.7, 0.89, 0.89)

Welcome to JupyROOT 6.27/01


Drawing the set of Bessel J functions

n is the number of functions in each pad

In [2]:
n = 5
JBessel = []
for nu in range(n):
jbessel = TF1("J_0", "ROOT::Math::cyl_bessel_j([0],x)", 0, 10)
jbessel.SetParameters(nu, 0.0)
jbessel.SetTitle("")
jbessel.SetLineStyle(1)
jbessel.SetLineWidth(3)
jbessel.SetLineColor(nu + 1)
JBessel.append(jbessel)


Setting x axis for JBessel

In [3]:
xaxis = JBessel[0].GetXaxis()
xaxis.SetTitle("x")
xaxis.SetTitleSize(0.06)
xaxis.SetTitleOffset(.7)


setting the title in a label style

In [4]:
p1 = TPaveLabel(.0, .90, .0 + .50, .90 + .10, "Bessel J functions", "NDC")
p1.SetFillColor(0)
p1.SetTextFont(22)
p1.SetTextColor(kBlack)


setting the legend

In [5]:
leg.AddEntry(JBessel[0].DrawCopy(), " J_0(x)", "l")

leg.Draw()
p1.Draw()


Set canvas 2

In [6]:
DistCanvas.cd(2)
leg2 = TLegend(0.75, 0.7, 0.89, 0.89)


Drawing Bessel k

In [7]:
KBessel = []
for nu in range(n):
kbessel = TF1("J_0", "ROOT::Math::cyl_bessel_k([0],x)", 0, 10)
kbessel.SetParameters(nu, 0.0)
kbessel.SetTitle("Bessel K functions")
kbessel.SetLineStyle(1)
kbessel.SetLineWidth(3)
kbessel.SetLineColor(nu+1)
KBessel.append(kbessel)
kxaxis = KBessel[0].GetXaxis()
kxaxis.SetTitle("x")
kxaxis.SetTitleSize(0.06)
kxaxis.SetTitleOffset(.7)


setting title

In [8]:
p2 = TPaveLabel(.0, .90, .0 + .50, .90 + .10, "Bessel K functions", "NDC")
p2.SetFillColor(0)
p2.SetTextFont(22)
p2.SetTextColor(kBlack)


setting legend

In [9]:
leg2.AddEntry(KBessel[0].DrawCopy(), " K_0(x)", "l")
leg2.Draw()
p2.Draw()


Set canvas 3

In [10]:
DistCanvas.cd(3)
leg3 = TLegend(0.75, 0.7, 0.89, 0.89)


Drawing Bessel i

In [11]:
iBessel = []
for nu in range(5):
ibessel = TF1("J_0", "ROOT::Math::cyl_bessel_i([0],x)", 0, 10)
ibessel.SetParameters(nu, 0.0)
ibessel.SetTitle("Bessel I functions")
ibessel.SetLineStyle(1)
ibessel.SetLineWidth(3)
ibessel.SetLineColor(nu + 1)
iBessel.append(ibessel)

iaxis = iBessel[0].GetXaxis()
iaxis.SetTitle("x")
iaxis.SetTitleSize(0.06)
iaxis.SetTitleOffset(.7)


setting title

In [12]:
p3 = TPaveLabel(.0, .90, .0 + .50, .90 + .10, "Bessel I functions", "NDC")
p3.SetFillColor(0)
p3.SetTextFont(22)
p3.SetTextColor(kBlack)


setting legend

In [13]:
leg3.AddEntry(iBessel[0].DrawCopy(), " I_0", "l")
leg3.Draw()
p3.Draw()


Set canvas 4

In [14]:
DistCanvas.cd(4)
leg4 = TLegend(0.75, 0.7, 0.89, 0.89)


Drawing sph_bessel

In [15]:
jBessel = []
for nu in range(5):
jbessel = TF1("J_0", "ROOT::Math::sph_bessel([0],x)", 0, 10)
jbessel.SetParameters(nu, 0.0)
jbessel.SetTitle("Bessel j functions")
jbessel.SetLineStyle(1)
jbessel.SetLineWidth(3)
jbessel.SetLineColor(nu+1)
jBessel.append(jbessel)
jaxis = jBessel[0].GetXaxis()
jaxis.SetTitle("x")
jaxis.SetTitleSize(0.06)
jaxis.SetTitleOffset(.7)


setting title

In [16]:
p4 = TPaveLabel(.0, .90, .0 + .50, .90 + .10, "Bessel j functions", "NDC")
p4.SetFillColor(0)
p4.SetTextFont(22)
p4.SetTextColor(kBlack)


setting legend

In [17]:
leg4.AddEntry(jBessel[0].DrawCopy(), " j_0(x)", "l")

leg4.Draw()
p4.Draw()

DistCanvas.cd()

Out[17]:
<cppyy.gbl.TCanvas object at 0x8986500>

Draw all canvases

In [18]:
from ROOT import gROOT
gROOT.GetListOfCanvases().Draw()