Spherical Bessel Functions causing "invalid __array_struct__"

100 views Asked by At

I'm trying to calculate the differential cross section(function of and angle and the "order" l) in a scattering problem. I would like to do this for different values of l and plot the cross section. I think that the division of the Bessel functions is the problem but I don't know how to solve it. Any solutions/tips? Thanks

This is my code:

import numpy as np
import scipy as sp
from scipy import special



def j_l(l,k):
    sp.special.spherical_jn(l, k)
    return np.ndarray
def j_l1(l,k):
    sp.special.spherical_jn(l, k, True)
    return np.ndarray
def n_l(l, k):
    sp.special.spherical_yn(l, k)
    return np.ndarray
def n_l1(l, k):
    sp.special.spherical_yn(l, k, True)
    return np.ndarray




def delta_l(k_1, k_2,r, l):
    np.arctan(np.divide(k_1*np.divide(j_l1(l,k_1),j_l(l,k_1))*j_l(l,k_2)-k_2*r*j_l1(l,k_2)),(k_1*np.divide(j_l1(l,k_1),j_l(l,k_1))*n_l(l,k_2)-k_2*r*n_l1(l,k_2)))

def dcross(l,t,k_2,k_1):
    (1/k_2*(2*l+1)*np.exp(delta_l(k_1,k_2,2,l))*np.sin(delta_l(k_1,k_2,2,l))*sp.special.lpmv(0, l, np.cos(t)))**2






t=np.linspace(0, 10, 10000)
fig = plt.figure()




plt.plot(t,dcross(1,t,1,0.5))
fig.savefig('dcross.png')

plt.show() ```
1

There are 1 answers

2
GrimTrigger On BEST ANSWER

My physics is a little rusty so I could not check the formulas but there were two problems: a paranthesis-error in the delta_l (the outer true divide) and the proper returns on the Bessel functions and its derivatives:

import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
from scipy import special

def j_l(l,k):
    return sp.special.spherical_jn(l, k)
    #return np.ndarray

def j_l1(l,k):
    return sp.special.spherical_jn(l, k, True)
    #return np.ndarray

def n_l(l, k):
    return sp.special.spherical_yn(l, k)
    #return np.ndarray

def n_l1(l, k):
    return sp.special.spherical_yn(l, k, True)
    #return np.ndarray

def delta_l(k_1, k_2,r, l):
    return np.arctan(np.divide(k_1*np.divide(j_l1(l, k_1), j_l(l ,k_1))*j_l(l, k_2)-k_2*r*j_l1(l, k_2),
              (k_1*np.divide(j_l1(l,k_1), j_l(l,k_1))*n_l(l, k_2)-k_2*r*n_l1(l, k_2))))

def dcross(l,t,k_2,k_1):
    return (1/k_2*(2*l+1)*np.exp(delta_l(k_1,k_2,2,l))*np.sin(delta_l(k_1,k_2,2,l))*sp.special.lpmv(0, l, np.cos(t)))**2


t=np.linspace(0, 10, 10000)
fig = plt.figure()

plt.plot(t,dcross(1,t,1,0.5))
#fig.savefig('dcross.png')

plt.show()

producing (if this is what you are looking for):

enter image description here