neumann_zeros_example_1.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright Christopher Kormanyos 2013.
  2. // Copyright Paul A. Bristow 2013.
  3. // Copyright John Maddock 2013.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or
  6. // copy at http://www.boost.org/LICENSE_1_0.txt).
  7. #ifdef _MSC_VER
  8. # pragma warning (disable : 4512) // assignment operator could not be generated.
  9. # pragma warning (disable : 4996) // assignment operator could not be generated.
  10. #endif
  11. #include <iostream>
  12. #include <limits>
  13. #include <vector>
  14. #include <algorithm>
  15. #include <iomanip>
  16. #include <iterator>
  17. //[neumann_zeros_example_1
  18. /*`[h5 Calculating zeros of the Neumann function.]
  19. This example also shows how Boost.Math and Boost.Multiprecision can be combined to provide
  20. a many decimal digit precision. For 50 decimal digit precision we need to include
  21. */
  22. #include <boost/multiprecision/cpp_dec_float.hpp>
  23. /*`and a `typedef` for `float_type` may be convenient
  24. (allowing a quick switch to re-compute at built-in `double` or other precision)
  25. */
  26. typedef boost::multiprecision::cpp_dec_float_50 float_type;
  27. //`To use the functions for finding zeros of the `cyl_neumann` function we need:
  28. #include <boost/math/special_functions/bessel.hpp>
  29. //] [/neumann_zerso_example_1]
  30. int main()
  31. {
  32. try
  33. {
  34. {
  35. //[neumann_zeros_example_2
  36. /*`The Neumann (Bessel Y) function zeros are evaluated very similarly:
  37. */
  38. using boost::math::cyl_neumann_zero;
  39. double zn = cyl_neumann_zero(2., 1);
  40. std::cout << "cyl_neumann_zero(2., 1) = " << zn << std::endl;
  41. std::vector<float> nzeros(3); // Space for 3 zeros.
  42. cyl_neumann_zero<float>(2.F, 1, nzeros.size(), nzeros.begin());
  43. std::cout << "cyl_neumann_zero<float>(2.F, 1, ";
  44. // Print the zeros to the output stream.
  45. std::copy(nzeros.begin(), nzeros.end(),
  46. std::ostream_iterator<float>(std::cout, ", "));
  47. std::cout << "\n""cyl_neumann_zero(static_cast<float_type>(220)/100, 1) = "
  48. << cyl_neumann_zero(static_cast<float_type>(220)/100, 1) << std::endl;
  49. // 3.6154383428745996706772556069431792744372398748422
  50. //] //[/neumann_zeros_example_2]
  51. }
  52. }
  53. catch (std::exception const& ex)
  54. {
  55. std::cout << "Thrown exception " << ex.what() << std::endl;
  56. }
  57. } // int main()
  58. /*
  59. Output:
  60. cyl_neumann_zero(2., 1) = 3.38424
  61. cyl_neumann_zero<float>(2.F, 1,
  62. 3.38424
  63. 6.79381
  64. 10.0235
  65. 3.61544
  66. */