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