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

Need need help with my C lab. The randomx.h is used in the program. I have a sep

ID: 3847682 • Letter: N

Question

Need need help with my C lab. The randomx.h is used in the program. I have a seprate file linking the randomx.h, I just need help with the code part.



5. Verify the Normal Random Number You are asked to veri the rx normal function whether it generates Gaussian random numbers. Call the rx normal (u, s) for n times where u and s are the desired mean and standard deviation, respectively. calculate their sum and sum of square as yx and Ex2 and compare their real mean and standard deviation to the desired mean and standard deviation. E[X] E[X2] Verify the ratio of samples within u to, u t 20, t 3o ranges based on the statistics from the wikipedia https n wiki wiki Norm distribution).

Explanation / Answer

I am not sure about linking the randomx.h.As far as the code is concerned, this should do it.

#include<iostream>
#include<randomx.h>
#include<math.h>
using namespace std;
int main()
{
   int n;
   cout<<"Enter number of values needed: ";
   cin>>n;
   double values[n];
   double sum=0;
   double sumsq=0;
   double Dmean,Ddev;
   cout<<" Enter desired mean and desired standard deviation ";
   cin>>Dmean>>Ddev;
   for(int i=0;i<n;i++)
   {
       values[i]=rx_normal(Dmean,Ddev);//generates n numbers from rx_normal and stores in array values
       sum=sum+values[i];//adds the values of value[]
       sumsq=sumsq+(values[i]*values[i]);//adds the squares of values in value[]
   }
   double real_mean=sum/n;//real mean
   double sq=sumsq/n;
   double real_stddev=sqrt(sq-(real_mean*real_mean));//real standard deviation
   double diff_mean=abs(real_mean-Dmean);
   double diff_sdev=abs(real_stddev-Ddev);
   cout<<" Difference in the desired mean and real mean: "<<diff_mean;
   cout<<" Difference in the desired standard deviation and the real standard deviation: "<<diff_sdev;
   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