Well, it compiles, and runs sucessfully now, but I don't quite think I have the calls done correctly. The only warnings I'm getting are due to the scanf's. The pdf needs to call on the double asimpson(double a,double b,double approx, double epsilon), which calls on the double S(double a,double b), and that calls on the double f(double x)
If someone could tell me if I have all this coded correctly that would be great. I have until Midnight to try and get it working as best I can.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
double INV_SQRT_2PI= 0.39894228; /*1/sqrt(2*pi)*/
double a, b, u, U, O, c, left, right, d, approx, x;
double epsilon= 0.0000001; /*epsilon defined as 0.0000001*/
double f(double x); /*prototype functions*/
double S(double a, double b);
double asimpson(double a, double b, double approx, double epsilon);
int main(void)
{
printf("Enter x Value: ");
scanf("%lf", &x);
printf("Enter Mean: ");
scanf("%lf", &U);
printf("Enter Standard Deviation: ");
scanf("%lf", &O);
double pdf, u;
u=((x-U)/O);
pdf=((1/2)+INV_SQRT_2PI * asimpson(0,u,S(0,u),epsilon));
printf("pdf= %f",pdf);
return 0;
}
double f(double x){
return (exp(double(x*x*(-1))/2));
}
double S(double a,double b){
return ((b-a)/6)*(f(a)+(4*f((a+b)/2))+f(b));
}
double asimpson(double a,double b,double approx, double epsilon)
{
approx= S(a,b);
c=((a+b)/2);
left=S(a,c);
right=S(c,b);
d=((left+right-approx)/15);
if(abs(d)<=epsilon)
return (left+right+d);
return (asimpson(a,c,left,epsilon/2)+asimpson(c,b,right,epsilon/2));}