test_bessel.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //**********************************************************************************//
  2. // Copyright (C) 2009-2015 Ovidio Pena <ovidio@bytesfall.com> //
  3. // Copyright (C) 2013-2015 Konstantin Ladutenko <kostyfisik@gmail.com> //
  4. // //
  5. // This file is part of scattnlay //
  6. // //
  7. // This program is free software: you can redistribute it and/or modify //
  8. // it under the terms of the GNU General Public License as published by //
  9. // the Free Software Foundation, either version 3 of the License, or //
  10. // (at your option) any later version. //
  11. // //
  12. // This program is distributed in the hope that it will be useful, //
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  15. // GNU General Public License for more details. //
  16. // //
  17. // The only additional remark is that we expect that all publications //
  18. // describing work using this software, or all commercial products //
  19. // using it, cite the following reference: //
  20. // [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by //
  21. // a multilayered sphere," Computer Physics Communications, //
  22. // vol. 180, Nov. 2009, pp. 2348-2354. //
  23. // //
  24. // You should have received a copy of the GNU General Public License //
  25. // along with this program. If not, see <http://www.gnu.org/licenses/>. //
  26. //**********************************************************************************//
  27. #include <complex>
  28. #include <cmath>
  29. #include <cstdio>
  30. #include <stdexcept>
  31. #include <vector>
  32. #include "../../bessel.h"
  33. int main(int argc, char *argv[]) {
  34. // auto result = nmie::bessel::bh_bessel_j(20, 1);
  35. auto result = nmie::bessel::bessel_j(20, 1);
  36. printf("Calculate and compare against Wolfram Alpha\n");
  37. printf("j(0,1) = %16.18f\n", real(result[0]));
  38. printf("WA j() = 0.841470984807896506652502321630\n");
  39. printf("j(1,1) = %16.18f\n", real(result[1]));
  40. printf("WA j() = 0.301168678939756789251565714187322395890252640\n");
  41. printf("j(20,1) = %16.18f\n", real(result[20]));
  42. printf("WA j() = 7.537795722236872993957557741584960855614358030 × 10^-26\n");
  43. result = nmie::bessel::bessel_j(4, std::complex<double>(1,2));
  44. printf("Calculate and compare against Wolfram Alpha\n");
  45. printf("j(0,1+i2) = re(%16.18f)\n im(%16.18f)\n",
  46. real(result[0]),
  47. imag(result[0]));
  48. printf("WA j() = re(1.4169961192118759)\n im(-0.874391197002)\n");
  49. printf("j(1,1+i2) = re(%16.18f)\n im(%16.18f)\n",
  50. real(result[1]),
  51. imag(result[1]));
  52. printf("WA j() = re(0.74785726329830368)\n im(0.68179207555304)\n");
  53. printf("j(4,1+i2) = re(%16.18f)\n im(%16.18f)\n",
  54. real(result[4]),
  55. imag(result[4]));
  56. printf("WA j() = re(-0.01352410550046)\n im(-0.027169663050653)\n");
  57. int n = 10;
  58. std::complex<double> z(1.0, 2.0);
  59. int nm;
  60. std::vector< std::complex<double> > csj, cdj, csy, cdy;
  61. nmie::bessel::csphjy (n, z, nm, csj, cdj, csy, cdy );
  62. result = csj;
  63. printf("===========Calculate and compare against Wolfram Alpha\n");
  64. printf("j(0,1+i2) = re(%16.18f)\n im(%16.18f)\n",
  65. real(result[0]),
  66. imag(result[0]));
  67. printf("WA j() = re(1.4169961192118759)\n im(-0.874391197002)\n");
  68. printf("j(1,1+i2) = re(%16.18f)\n im(%16.18f)\n",
  69. real(result[1]),
  70. imag(result[1]));
  71. printf("WA j() = re(0.74785726329830368)\n im(0.68179207555304)\n");
  72. printf("j(4,1+i2) = re(%16.18f)\n im(%16.18f)\n",
  73. real(result[4]),
  74. imag(result[4]));
  75. printf("WA j() = re(-0.01352410550046)\n im(-0.027169663050653)\n");
  76. }