arcsine_example.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // arcsine_example.cpp
  2. // Copyright John Maddock 2014.
  3. // Copyright Paul A. Bristow 2014.
  4. // Use, modification and distribution are subject to the
  5. // Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt
  7. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. // Example for the arcsine Distribution.
  9. // Note: Contains Quickbook snippets in comments.
  10. //[arcsine_snip_1
  11. #include <boost/math/distributions/arcsine.hpp> // For arcsine_distribution.
  12. //] [/arcsine_snip_1]
  13. #include <iostream>
  14. #include <exception>
  15. #include <boost/assert.hpp>
  16. int main()
  17. {
  18. std::cout << "Examples of Arcsine distribution." << std::endl;
  19. std::cout.precision(3); // Avoid uninformative decimal digits.
  20. using boost::math::arcsine;
  21. arcsine as; // Construct a default `double` standard [0, 1] arcsine distribution.
  22. //[arcsine_snip_2
  23. std::cout << pdf(as, 1. / 2) << std::endl; // 0.637
  24. // pdf has a minimum at x = 0.5
  25. //] [/arcsine_snip_2]
  26. //[arcsine_snip_3
  27. std::cout << pdf(as, 1. / 4) << std::endl; // 0.735
  28. //] [/arcsine_snip_3]
  29. //[arcsine_snip_4
  30. std::cout << cdf(as, 0.05) << std::endl; // 0.144
  31. //] [/arcsine_snip_4]
  32. //[arcsine_snip_5
  33. std::cout << 2 * cdf(as, 1 - 0.975) << std::endl; // 0.202
  34. //] [/arcsine_snip_5]
  35. //[arcsine_snip_6
  36. std::cout << 2 * cdf(complement(as, 0.975)) << std::endl; // 0.202
  37. //] [/arcsine_snip_6]
  38. //[arcsine_snip_7
  39. std::cout << quantile(as, 1 - 0.2 / 2) << std::endl; // 0.976
  40. std::cout << quantile(complement(as, 0.2 / 2)) << std::endl; // 0.976
  41. //] [/arcsine_snip_7]
  42. {
  43. //[arcsine_snip_8
  44. using boost::math::arcsine_distribution;
  45. arcsine_distribution<> as(2, 5); // Cconstructs a double arcsine distribution.
  46. BOOST_ASSERT(as.x_min() == 2.); // as.x_min() returns 2.
  47. BOOST_ASSERT(as.x_max() == 5.); // as.x_max() returns 5.
  48. //] [/arcsine_snip_8]
  49. }
  50. return 0;
  51. } // int main()
  52. /*
  53. [arcsine_output
  54. Example of Arcsine distribution
  55. 0.637
  56. 0.735
  57. 0.144
  58. 0.202
  59. 0.202
  60. 0.976
  61. 0.976
  62. ] [/arcsine_output]
  63. */