Warning: count(): Parameter must be an array or an object that implements Countable in /srv/users/serverpilot/apps/eken/public/th_main/class/Single/SinglePost.php on line 1081

### e-Governance system in Nepalese context of transition to federalism QnA

Trapezoidal rule can be applied to find the value of a limiting integer programmatically in both cases whether individual functional values are given or not. A complete algorithm follows the both process below.

/*********

Trapezoidal rule complete algorithm

1. start

2. read n= no of intervals

3. read initial and final values ie a,b

4. h=(b-a)/n;

5. set x=a; x[n]=b;

6. next element

i= 1 to n-1

x[i]=x[i-1]+h

i=0 to n

f[i]=function or input functional values as cin<

8. 1st &last terms

sum=f+f[n]

9. i= 1 to n-1

sum= sum + 2 * ( f[i] )

10. sum=h/2*sum

11. display sum

12. stop

***********/

//To calculate the value of an integer using Trapeziodal Rule (no corressponding functional values provided)

#include

#include

#include

#include

void main()

{

double n,i,a,b;

double x,f, sum;

float h;

clrscr();

cout<<<“Enter no of intervals: “;

cin>>n;

cout<<<“Enter limiting values:\t”;

cin>>a>>b;

h=(b-a)/n;

x=a;

x[n]=b;

for(i=1;i<=n-1;i++)

{

x[i]=(x[i-1]+h);

}

for(i=0;i<=n;i++)

{

f[i]=exp(x[i]*tan(x[i]));

}

sum=f+f[n];

for(i=1;i<=n-1;i++)

{

sum=sum+(2*f[i]);

}

sum=(h/2.0)*sum;

cout<<<“The required integral value = “<

getch();

}

/* To evaluate value of an integral using Trapezoidal Rule when the functional values are given */

#include

#include

#include

#include

void main()

{

double n,a,b,h,sum,x,i,f;

clrscr();

cout<<“To Calculate The Integral Value Using Trapezoidal Rule”<

cout<

cout<<“The given functional vaue is e^(x*tanx) \n”<

cout<<“Enter the Number of interval “;

cin>>n;

cout<<“There are “<<<” intervals\n”<

cout<<“Enter the initial point\t”<

cin>>a;

cout<<“Enter the final point\t”<

cin>>b;

cout<<“The limit of integration is from “<<<“to”<<<

h=(b-a)/n;

x=a;

x[n]=b;

cout<

for(i=1;i<=n-1;i++)

{

x[i]=x[i-1]+h;

}

cout<<“Enter the functional value accordingly \n”;

for(i=0;i<=n;i++)

{

cout<<“f”<<<“= “;

//    f[i]=exp(x[i]*tan(x[i]))   ;

cin>>f[i];

}

sum=f+f[n];

for(i=1;i<=n-1;i++)

{

sum=sum+2*f[i];

}

sum=(h/2)*sum;

cout<<“The required value of integration is”<

getch();

}

To calculate the value of an integer using Trapezoidal rule both when functional values are given and values NOT given in C++ Programming Language for Numerical Methods for Engineering Students

Next Post