special-functions-test-generator.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. import mpmath as mp
  3. import numpy as np
  4. Du_test = [
  5. # // x, [Re(m), Im(m)], Qext, Qsca, test_name
  6. [0.099, [0.75,0], 7.417859e-06, 7.417859e-06, 'a'],
  7. # [0.101, [0.75,0], 8.033538e-06, 8.033538e-06, 'b'],
  8. # [10, [0.75,0], 2.232265, 2.232265, 'c'],
  9. # [1000, [0.75,0], 1.997908, 1.997908, 'd'],
  10. # [100, [1.33,-1e-5], 2.101321, 2.096594, 'e'],
  11. # [10000, [1.33,-1e-5], 2.004089, 1.723857, 'f'],
  12. # [0.055, [1.5, -1], 0.101491, 1.131687e-05, 'g'],
  13. # [0.056, [1.5, -1], 0.1033467, 1.216311e-05, 'h'],
  14. # [100, [1.5, -1], 2.097502, 1.283697, 'i'],
  15. # [10000, [1.5, -1], 2.004368, 1.236574, 'j'],
  16. # [1, [10, -10], 2.532993, 2.049405, 'k'],
  17. # [100, [10, -10,], 2.071124, 1.836785, 'l'],
  18. [10000, [10, -10], 2.005914, 1.795393, 'm'],
  19. [80, [1.05, 1], 0, 0, 'Yang'],
  20. ]
  21. # // Dtest refractive index is m={1.05,1}, the size parameter is x = 80
  22. n_list = [0,1,30,50,60,70,75,80,85,90,99,116,130];
  23. def get_z_values(du_list):
  24. zlist = []
  25. for record in du_list:
  26. x = mp.mpf(str(record[0]))
  27. m = mp.mpc(str(record[1][0]), str(record[1][1]))
  28. z = x*m
  29. zlist.append(z)
  30. return zlist
  31. # Riccati-Bessel z*j_n(z)
  32. def psi(n,z):
  33. return mp.sqrt( (mp.pi * z)/2 ) * mp.besselj(n+1/2,z)
  34. # to compare r(n,z) with Wolfram Alpha
  35. # n=49, z=1.3-2.1i, SphericalBesselJ[n-1,z]/SphericalBesselJ[n,z]
  36. def r(n,z):
  37. return psi(n-1,z)/psi(n,z)
  38. def D1(n,z):
  39. return r(n,z) - n/z
  40. def main ():
  41. mp.mp.dps = 62
  42. output_dps = 10
  43. zlist = get_z_values(Du_test)
  44. for z in zlist:
  45. print(z)
  46. for n in n_list:
  47. print('{',mp.nstr(D1(n,z).real, output_dps),',',
  48. mp.nstr(D1(n,z).imag, output_dps),'}')
  49. main()