code help - error compiling

I'm getting an error message saying undefined reference to my function 'f' and 'pow'. Can someone tell me how to fix this?

#include <stdio.h>
#include <math.h>

double f(double x);

int main(void)
{
int i, n=100;
double a=0, b=5, h = (b-a)/n, sum=0, area=0;
double x[n], y[n];

for (i=0; i<n; i++)
{
x[i] = a+i*h;
y[i] = f(x[i]);
}
for (i=1; i<n-1; i++)
{
sum += y[i];
area = h/2 * (y[0]+y[n-1] + 2*sum);
}
printf("The definite integral approximation is = %lf \n", area);

return 0;
}

double integrate(double x)
{
double y;
{
y = pow(x,3) + 2*pow(x,2) + 3*x + 1;
}
return y;
}
Well you've said that a function `f' exists, but the definition is missing.
You've used a function `pow' but the definition isn't there. Maybe you meant to link the math library, but you didn't.
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
for ( i = 1; i < n - 1; i++ ) {
    sum += y[i];
    area = h/2 * (y[0] + y[n-1] + 2*sum);
}

should be
1
2
3
4
for ( i = 1; i < n - 1; i++ ) {
    sum += y[i];
}
area = h/2 * (y[0] + y[n-1] + 2*sum);

to avoid needless calculations.

double f(double x); double integrate(double x)
I believe the integrate function should actually be called f ?
Last edited on
Topic archived. No new replies allowed.