user2971559
user2971559

Reputation: 23

Midpoint Rule - Numerical Method in C

I want to calculate approximate area that remains under the curve. Actually it is not about the mathematical isue. This code doesnt print anything. Where is the problem? thanks in advance

double midpointrule(double,double,int);

int main(int argc, char *argv[]) {
double x,y;
int z;
scanf("%lf %lf %d", &x, &y, &z);
double midpointrule(x,y,z);
}


double midpointrule(double uplimit,double lowlimit,int interval)
{
    int i;
    double func1=0, func2=0;
    double deltax = (uplimit - lowlimit)/interval;
    for(i=1; i<=interval; i++)
    {
        func1 = func1 + pow(M_E,pow(deltax,2));
        func2 = func2 + 2*pow(M_E,deltax) - 2*deltax;
    }
func1 = func1*deltax;
func2 = func2*deltax;


printf("midpoint result for func1 = %lf\n", func1);
printf("midpoint result for func2 = %lf\n", func2);
}

Upvotes: 0

Views: 1781

Answers (1)

Reticulated Spline
Reticulated Spline

Reputation: 2012

In your main function, on line 7, you need to call your function like this

midpointrule(x,y,z);

Instead of like this

double midpointrule(x,y,z);

Also, that function is not returning anything. If you don't want it to return anything, make it a void.

Upvotes: 2

Related Questions