Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to code generating exponetial random variables? Exponential RV Generation wi

ID: 3935208 • Letter: H

Question

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

Explanation / Answer

#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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote