//PROGRAM FOR INTEGRATION USING NUMERICAL METHODS
#include
#include
#define f(x) sqrt(cos(x))
#define inv 10
#include
void main()
{
clrscr();
int choice;
float l,j=0,u,h,arr[inv+1],sum1=0,sum2=0,sum3=0,res=0;
textcolor(GREEN);
cprintf("INTEGRATION USING THE TRAPEZOIDAL RULE & SIMPSON'S 1/3rd
RULE");
cout<<"\n";
textcolor(BLUE);
cprintf("1.TRAPEZOIDAL RULE");
cout<<"\n";
cprintf("2.SIMPSON'S 1/3rd RULE");
cout<<"\nenter your choice :";
cin>>choice;
cout<<"enter the lower and upper limit respectively\n";
cin>>l>>u;
j=l;
h=(u-l)/inv;
for(int i=0;i<=inv;i++)
{
arr[i]=f(j);//cout<<"\n"<
j=j+h;
}
sum1=arr[0]+arr[inv];
switch(choice)
{
case 1:
cout<<"\n================================================================================\n";
for(i=1;i
{sum2+=arr[i];}
res=h/2*(sum1+2*sum2);
cout<<"\nthe integration is :"<
break;
case 2:
cout<<"\n================================================================================\n";
for(i=1;i
{ sum2+=arr[i];}
for(i=2;i
{sum3+=arr[i];}
res=h/3*(sum1+4*sum2+2*sum3);
cout<<"\nthe integration is :"<
break;
default:cprintf("WRONG CHOICE ");
}
cout<<"\n";
cprintf("PROGRAM DESIGNED BY:ROHIT KUMAR");
cout<<"\n";
textcolor(RED);
cprintf("BRANCH : ECE / 3rd semester / roll 249/06 ");
getch();
}
output:
INTEGRATION USING THE TRAPEZOIDAL RULE & SIMPSON'S 1/3rd RULE
1.TRAPEZOIDAL RULE
2.SIMPSON'S 1/3rd RULE
enter your choice :1
enter the lower and upper limit respectively
0
1.57
================================================================================
the integration is :1.187191
PROGRAM DESIGNED BY:ROHIT KUMAR
BRANCH : ECE / 3rd semester / roll 249/06
INTEGRATION USING THE TRAPEZOIDAL RULE & SIMPSON'S 1/3rd RULE
1.TRAPEZOIDAL RULE
2.SIMPSON'S 1/3rd RULE
enter your choice :2
enter the lower and upper limit respectively
0
1.57
================================================================================
the integration is :1.19437