#include //Header file for cin & cout
#include //Header file for mathematical operartions
using namespace std; //calling the standard directory
//Taking a function f(x)
float f(float(x))
{
return (pow(x,3)+pow(x,2)-(4*x)-5);
}
//Taking diffrentiation of f(x) i.e. g(x)
float g(float(x))
{
return (3*pow(x,2)+2*x-4);
}
//Taking double diffrentiation of f(x) i.e. h(x)
float h(float(x))
{
return (6*x+4);
}
int main() //Main Program
{
long double a,b,d,i,n,I=0,J=0,A,K=0,E=0;
cout<<" Given f(x)= x^3 + 2x^2 - 4x - 5 "<>a;
cout<<"Enter Upper Limit "<>b;
cout<<"Enter the number of intervals : "<>n;
d=(b-a)/n;
//Steps of solving by Trapezoidal Rule
for(i=0;i<=n;i++)
{
I=I+f(a+(i*d));
}
for(i=1;i
/*OUTPUT

Given f(x)= x^3 + 2x^2 - 4x - 5

Enter lower limit

0

Enter Upper Limit

5

Enter the number of intervals :

100

The Value of integral under the enterd limits is :

122.934

The Total Error is :

-0.0199479

*/

Note - The following programs are coded for Linux (Knoppix) Operating System. For windows do the following changes

change '#include ' to '#include ' & same to all other header files.

Delete 'using namespace std;'.

At the end of main method type return 0;.

Then save it and run it in Turbo C++ or any other software.

Ph.D. researcher at Friedrich-Schiller University Jena, Germany. I’m a physicist specializing in computational material science. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT, and Machine Learning related apps and software from time to time. Can code in most of the popular languages. I like to share my knowledge in Physics and applications using this Blog and a YouTube channel.

### Like this:

Like Loading...

*Related*

[wpedon id="7041" align="center"]

cant figure this out