How to code generating exponetial random variables Exponenti
How to code generating exponetial random variables?
Exponential RV Generation with C++
1. Generate exponential RVs Y with lambda = 0.169 (no. of generations = 100,000)
2. Find the mean (1st moment), the second moment from (1), and calculate the variance of Y
3. Calculate the mean and the variance of Y theoretically by hands
4. Compare two results from (2) and (3), and discuss
How to code generating exponetial random variables?
Exponential RV Generation with C++
1. Generate exponential RVs Y with lambda = 0.169 (no. of generations = 100,000)
2. Find the mean (1st moment), the second moment from (1), and calculate the variance of Y
3. Calculate the mean and the variance of Y theoretically by hands
4. Compare two results from (2) and (3), and discuss
Exponential RV Generation with C++
1. Generate exponential RVs Y with lambda = 0.169 (no. of generations = 100,000)
2. Find the mean (1st moment), the second moment from (1), and calculate the variance of Y
3. Calculate the mean and the variance of Y theoretically by hands
4. Compare two results from (2) and (3), and discuss
1. Generate exponential RVs Y with lambda = 0.169 (no. of generations = 100,000)
2. Find the mean (1st moment), the second moment from (1), and calculate the variance of Y
3. Calculate the mean and the variance of Y theoretically by hands
4. Compare two results from (2) and (3), and discuss
1. Generate exponential RVs Y with lambda = 0.169 (no. of generations = 100,000)
2. Find the mean (1st moment), the second moment from (1), and calculate the variance of Y
3. Calculate the mean and the variance of Y theoretically by hands
4. Compare two results from (2) and (3), and discuss
Solution
#include <iostream>
using namespace std;
int main(){
//declaring random array 10000
double array[10000];
//generating random variables
for(int i=0;i<10000;i++){
array[i] = (double)rand() / 10.0 ;
}
// calculating mean and variance
double mean = 0;
for(int i=0;i<10000;i++){
mean = mean + array[i];
}
mean = mean/10000;
cout<<\"\ Mean: \"<<mean;
// calculating standard deviation..
double variance = 0;
for(int i = 0; i < 10000; i++)
{
variance += (array[i] - mean) * (array[i] - mean) ;
}
variance = variance / mean;
//printing variance
cout<<\"\ Variance: \"<<variance;
return 0;
}
