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

Need help with the last part (Number 5) on my C++ lab Note: Please use comments

ID: 3847379 • Letter: N

Question

Need help with the last part (Number 5) on my C++ lab

Note: Please use comments to explain key parts. Also the randomx.h file needs to be called in the new code, Thanks!

5. Verify the Normal Random Number You are asked to verify the rx normal function whether it generates Gaussian random numbers. Call the rx normal(u,s) for n times where u nd s are the desired mean and standard deviation, respectively. Calculate their sum and sum of square as Ex and yx2 and compare their real mean and standard deviation to the desired mean and standard deviation. EUX] ELX2] Verify the ratio of samples within Hto,Ht2o, ut 30 ranges based on the statistics from the wikipedia (https en.wikipedia.org/wiki Normal distribution

Explanation / Answer

#include<math.h>

#include<stdlib.h>

double rx_normal(double ,double)

{

double U1,U2,mult;

static double X1,X2;

static int n = 0;

if(n == 1)

{

n=!n;

return(+*(double)X2)

}

do

{

U1 = -1+((double)rx_normal()/RAND_MAX)*2;

U2 = -1+((double)rx_normal()/RAND_MAX)*2;

W = pow(U1,2)+pow(U2,2)

}

while(W>=1||W==0);

mult=sqrt((-2*log(W))/W);

X1 = U1 * mult;

X2 = U2 * mult;

n = !n;

return(+*(double)X1);

}

int calculate(int n)

{

float x[50];

int n;

float sum, ,;

int i;

clrscr();

for(i=0;i<n;i++)

scanf("%f",&x[i]);

//mean calculation

sum=0.0;

for (i=0;i<n;i++)

sum+=x[i];

=sum/n;

//standard deviation calculation

sum=0.0;

for(i=0;i<n;i++)

sum+=(x[i]-)*(x[i]-);

=sqrt(sum/n);

printf("Mean=%6.3f ",);

printf("Standard Deviation: %6.3f ",);

getch();

}

void main()

{

int result = rx_normal(u,s);

int cal = calculate(result);

if(result==calculate)

printf("verified");

else

printf("not verified")

}

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