Bessel function


Bessel function Plot for order n:
from pylab import*
def fact(n):
    if n<=1:
        return(1)
    else:
        return(n*fact(n-1))
xdat=linspace(0,9,200)
n=input('Give Order n of Bessel function : ')
jnx=[]
for x in xdat:
    sum=0
    for k in range(0,50):
        sum+=(-1)**k*(x/2)**(n+2*k)/(fact(k)*fact(n+k))
    jnx.append(sum)
plot(xdat,jnx)
show()


#Bessel function plot upto order 5:
from pylab import*
def fact(n):
    if n<=1:
        return(1)
    else:
        return(n*fact(n-1))
xdat=linspace(0,9,200)
for n in range(5):
    jnx=[]
    for x in xdat:
        sum=0
        for k in range(0,50):
            sum+=(-1)**k*(x/2)**(n+2*k)/(fact(k)*fact(n+k))
        jnx.append(sum)
    plot(xdat,jnx)
legend(['n=0','n=1','n=2','n=3','n=4'])
show()

Comments