Trapezoidal Rule for Integration
Hi there, here is my code so far:
Code:
#include <stdio.h>
#include <math.h>
float f(float x)
{
return(exp(-x*x));
}
float g(float x)
{
return(exp(-x));
}
float trapeze(float a, float b, float x, float h, float sum, int N, int i)
{
a = 0.0;
b = 1.0;
h = (b - a)/N;
sum = ((0.5 * h) * (f(a) + f(b)));
for (i = 1; i < N; i++) {
sum = sum + h * f(a + (i * h));
}
return (sum);
}
int main (void)
{
float c, d, e, trap;
int n;
printf("Enter the number of intervals: ");
scanf("%d", &n);
printf("integral of exp(-x*x): %f\n", trap(c(e)));
printf("integral of exp(-x): %f\n", trap(d(e)));
return(0);
}
Ok so, I know there's probably a lot wrong, so I need help as it goes. What I'm supposed to do is find the numerical integration of the functions above using my other function, trapeze. I don't know how to use functions as parameters though.
Also, I'm probably forgetting, but why is my main function not recognizing my trapeze function? Variable names?