bessel_K does not accept an element of a numpy array [closed]

asked 4 years ago

Galedon gravatar image

I had a problem with classical sage ploting of Bessel K function in classical way, so I tried to manage through python matplotlib.pyplot and numpy library.

My code looks like this (for some reasons the formating put lines together, co I had to add a free line every time - just here, there are not present in original code):

import numpy as np

import matplotlib.pyplot as plt

def P(l,m,x): return (-1)^mgamma(l+m+1)(1-x^2)^(m/2)/2^m/gamma(l-m+1)/gamma(m+1)*hypergeometric([m-l,m+l+1],[1+m],(1-x)/2)

N=1000

l1=-0.01996

romin=0

romax=1

a=sqrt(3).n()

R=1

m=0

roDD=R*a/sqrt(1+a^2).n()

nu=a*i/2

xDD=asqrt(abs(l1(l1+1)))

ccD=1/sqrt(1+a^2)

A=P(l1,m,ccD)/bessel_K(nu,xDD)

f2=np.zeros(N)

ro2=np.linspace(roDD,romax,N)

for i in range(N):

 f2[i]=A*bessel_K(nu,(1/R)*sqrt(1+a^2)*sqrt(abs(l1*(l1+1)))*ro2[i])

But it gives me the following error message:

NotImplementedError: The Function bessel_K does not support numpy arrays as arguments

If I delete " *ro2[i] ", everything works just fine. If I print for example r2[100] I get a real number, not an array.

Any ideas what could it be?

Preview: (hide)

Closed for the following reason duplicate question by tmonteil
close date 2020-04-08 02:32:24.716674