-use double precision -use sqrt() and exponential function exp() -use * to compute the square -do not use pow()
I am getting values they are just not anything as to what I expected. I tried making them all signed but it didn't change anything and I've tried printing out with 12 decimal places and nothing seems to be working.I have linked the math library and defined it as well.
double normal(double x, double sigma, double mu)
{
double func = 1.0/(sigma * sqrt(2.0*M_PI));
double raise = 1.0/2.0*((x-mu)/sigma);
double func1 = func * exp(raise);
double comp_func = (func1 * func1);
return comp_func;
}
int main(void)
{
// create two constant variables for μ and σ
const double sigma, mu;
//create a variable for x - only dynamic variable in equation
unsigned int x;
//create a variable for N values of x to use for loop
int no_x;
//scaniing value into mu
printf("Enter mean u: ");
scanf("%lf", &mu);
//scanning value into sigma
printf("Enter standard deviation: ");
scanf("%lf", &sigma);
//if sigma = 0 then exit
if(sigma == 0)
{
printf("error you entered: 0");
exit(0);
}
//storing number of x values in no_x
printf("Number of x values: ");
scanf("%d", &no_x);
//the for loop where i am calling function normal N times
for(int i = 1; i <= no_x; i++)
{
//printing i for the counter in prompted x values
printf("x value %d : ", i);
// scanning in x
scanf("%lf", &x);
x = normal(x,sigma,mu);
printf("f(x) = : %lf.12", x);
printf("\n");
}
return 0;
}
C:>.\a.exe Enter mean u: 3.489 Enter std dev s: 1.203 Number of x values: 3 x value 1: 3.4 f(X) = 0.330716549275 x value 2: -3.4 f(X) = 0.000000025104 x value 3: 4 f(X) = 0.303015189801
But this is what I am receiving
C:\Csource>a.exe Enter mean u: 3.489 Enter standard deviation: 1.203 Number of x values: 3 x value 1 : 3.4 f(x) = : 15086080.000000 x value 2 : -3.4 f(x) = : 15086080.000000 x value 3 : 4 f(x) = : 1610612736.000000