def jn_zeros(n, k, method='sympy', dps=15):
 from math import pi
 if (method == 'sympy'):
  from mpmath import besseljzero
  from mpmath.libmp.libmpf import dps_to_prec
  from sympy import Expr
  prec = dps_to_prec(dps)
  return [Expr._from_mpmath(besseljzero(S((n + 0.5))._to_mpmath(prec), int(l)), prec) for l in range(1, (k + 1))]
 elif (method == 'scipy'):
  from scipy.special import sph_jn
  from scipy.optimize import newton
  f = (lambda x: sph_jn(n, x)[0][(-1)])
 else:
  raise NotImplementedError('Unknown method.')
 def solver(f, x):
  if (method == 'scipy'):
   root = newton(f, x)
  else:
   raise NotImplementedError('Unknown method.')
  return root
 root = (n + pi)
 root = solver(f, root)
 roots = [root]
 for i in range((k - 1)):
  root = solver(f, (root + pi))
  roots.append(root)
 return roots

def jn_zeros ( n , k , method = 'sympy' , dps = 15 ) : from math import pi if ( method == 'sympy' ) : from mpmath import besseljzero from mpmath . libmp . libmpf import dps_to_prec from sympy import Expr prec = dps_to_prec ( dps ) return [ Expr . _from_mpmath ( besseljzero ( S ( ( n + 0.5 ) ) . _to_mpmath ( prec ) , int ( l ) ) , prec ) for l in range ( 1 , ( k + 1 ) ) ] elif ( method == 'scipy' ) : from scipy . special import sph_jn from scipy . optimize import newton f = ( lambda x : sph_jn ( n , x ) [ 0 ] [ ( - 1 ) ] ) else : raise NotImplementedError ( 'Unknown method.' ) def solver ( f , x ) : if ( method == 'scipy' ) : root = newton ( f , x ) else : raise NotImplementedError ( 'Unknown method.' ) return root root = ( n + pi ) root = solver ( f , root ) roots = [ root ] for i in range ( ( k - 1 ) ) : root = solver ( f , ( root + pi ) ) roots . append ( root ) return roots
compute zeros of integer-order bessel function jn(x) .