//
// A C++ program for integrating a continuous random variable (1-x^2)^(3/2) between 0-1 and finding its expected value or mean.//
#include <iostream>
int Kvalue;
float Svalue;
int Seed;
float x;
int countK;
float Expected;
int main()
{
std::cout << "Enter integer for random seed: ";
std::cin >> Seed;
void srand(unsigned int Seed);
std::cout << "Enter integer for length of Simulation: ";
std::cin >> Kvalue;
countK=0;
Svalue = 0;
while (Kvalue >= countK){
x= (float) ( rand() / (RAND_MAX + 1 ) );
Svalue= Svalue + pow((1-x*x),(3/2));
countK++;
}
Expected= Svalue/Kvalue;
std::cout << "Expected Value = ";
std::cout << Expected;
std::cout << "Svalue = ";
std::cout << Svalue;
std::cout << "Kvalue = ";
std::cout << Kvalue;
return 0;
}
No comments:
Post a Comment