Compute the definite integral of the curve x 2 − 3 x + 2 ​
for x ranging from 2 to
8. Compute the same by approximating it by dividing the region into many
small trapeziums. Keep increasing the number of trapeziums to get to the
accuracy of 3 decimal places.
not ​ supposed to integrate it manually and then compute
the same.
Side note: We have given a simple formula for computation however there
exist functions whose integral are not possible to compute with our usual

manual techniques e.g. ∫ s in(x 2 ) dx . In these cases, numerical techniques comes

in handy.

## All 5 Replies

Welcome to Daniweb.

We will be able to help you if you firstly show us the code you have tried so far ...

Sandeep:

You just copy/pasted your assignments without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

There are lots of people here who will freely give their time to help you become the best programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

``````#include <stdio.h>
int main()
{
float a,b,area = 0;
for(a=2;a<=8;a=a+0.001)
{
b = (a*a-3*a+2)*0.001;
area = area + b;
}
printf("Ans is %f",area);
}
``````

You also have not followed the spec's you were assigned.

• You are to repeat the task (could use calling a function in a loop) until the precision is (at least) 3 places of decimals.

• You are to take the area of a trapezium (not a rectangle as you have done) and the area of a trapezium is: ((height1 + height2) / 2.0) * base

``````const double EPSILON = 0.000001; /* change here to what you want */

/* define the function to integrate ... */
double f( const double x )
{
return x*x - 3*x  + 2;
}

/* numerical method to get area inder curve of f(x) from x = beg to x = end ... */
double areaTraps( const double beg, const double end, const double dx )
{
double x, area = 0;
for( x = beg; x < end; x += dx )
area +=  (f(x) + f(x+dx)) / 2.0 * dx;
return area;
}
``````

Then in main, you could do something like this:

``````double dx = 0.1;

/* get an initial approx. value for area_2 ... */
double area_2 =  areaTraps( 2, 8, dx ),
area_1;

do
{
area_1 = area_2; /* save copy of previous area estimate ... */
dx /= 10;
area_2 = areaTraps( 2, 8, dx ); /* get a closer estimate */
}
while( fabs( area_2 - area_1 ) > EPSILON ) ;

printf( "Area was %.6f and size of last 'dx' was %.16f ", area_2, dx );

getchar();
return 0;
``````