Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <iomanip>
- const double alphpa = 0.5; //Probability to miss the snowball
- const size_t N = 10000; //Amount of terms in the sum
- int main()
- {
- std::cout << std::setprecision(30);
- double complementary_alpha = 1.0 - alphpa;
- std::vector<double> a, b, result;
- a.push_back(1.0);
- a.push_back(0.0);
- b.push_back(a[0]);
- b.push_back(alphpa * b[0] + a[1]);
- result.push_back(b.back());
- //Print probability of getting 0 points
- //std::cout << 0 << '\t' << result.back() << std::endl;
- for (size_t i = 1; i <= N; ++i) {
- a.push_back(0.0);
- b.push_back(0.0);
- for (size_t j = 0; j <= i - 1; ++j) {
- a[j] = complementary_alpha * b[j];
- }
- a[i] = 0.0;
- b[0] = a[0];
- for (size_t j = 1; j <= i + 1; ++j) {
- b[j] = alphpa * b[j - 1] + a[j];
- }
- result.push_back(b[i + 1]);
- //Print probability of getting 10i points
- //std::cout << 10 * i << '\t' << result.back() << std::endl;
- }
- ////Print partial sums of probabilities of getting each amount of points
- //for (size_t i = 0; i < result.size(); ++i) {
- // double sum = 0.0;
- // for (size_t j = 0; j <= i; ++j) {
- // sum += result[j];
- // }
- // std::cout << sum << std::endl;
- //}
- double expectation = 0.0;
- for (size_t i = 0; i < result.size(); ++i) {
- expectation += 10 * i * result[i];
- //Print partial sums of average amount of points
- //std::cout << expectation << std::endl;
- }
- //Print average amount of points
- std::cout << expectation << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement