C Program for Numerical Integration (Trapezoidal Rule, Simpson's Rule and Boole's Rule

Program /* This program is for numerical integration of numerical methods Here we are going to solve the integration of defined functio...

Program

/*
This program is for numerical integration of numerical methods
Here we are going to solve the integration of defined function f(x)
Using...
1. Trapezoidal Rule
2. Composite Trapezoidal Rule
3. Simpson's 1/3 Rule
4. Composite Simpson's 1/3 Rule
5. Simpson's 3/8 Rule
6. Boole's Rule

In this program we are going to solve for integration of square root of sin(x)
and get output when lower limit is 0 and upper limit is pie/2.

Note: You can change the integration function f(x) and also can change the lower and upper limit for solution..

For more update visit daily.
Thank You!!!
*/


#include<conio.h>
#include<stdio.h>                  // header file for standard input and output
#include<stdlib.h>                 //for exit() function
#include<math.h>                   //for mathematical operation like sqrt
#define f(x) sqrt(sin(x))          //defined the function i.e of which integration is going to calculate
void main()
{
int i,choice;
float n,a,b,h,it,ict,is1,ics1,is2,ib,sum,sum1;
clrscr();
printf("Solution for integration of sqrt(sin(x)) \n");
printf("Enter lower limit and upper limit\n");         //lower and upper value of integral
scanf("%f%f",&a,&b);
printf("Select Options\n1.Trapezoidal Rule\n2.Composite Trapezoidal Rule\n3.Simpson's 1/3 Rule\n4.Composite Simpson's 1/3 Rule\n5.Simpson's 3/8 Rule\n6.Boole's Rule\n7.Exit\n");
a:printf("\nEnter Choice : ");
scanf("%d",&choice);
switch(choice)
{

///Solution for Trapezoidal Rule i.e It
case 1:
h=b-a;
it=((f(a)+f(b))/2)*h;
printf("It = %.4f\n",it);
break;

///Solution for Composite Trapezoidal Rule i.e Ict
case 2:
printf("Enter value for n : ");
scanf("%f",&n);
h=(b-a)/n;
sum=0;
for(i=1;i<n;i++)
{
sum=sum+f(a+i*h);
}
ict=(h/2)*(f(a)+f(b)+2*sum);
printf("Ict = %.4f\n",ict);
break;

///Solution for Simpson's Rule / Simpson's 1/3 Rule i.e Is1
case 3:
h=(b-a)/2;
is1=(h/3)*(f(a)+f(b)+4*f(a+h));
printf("Is1 = %.4f\n",is1);
break;

///Solution for Composite Simpson's Rule i.e Ics1
case 4:
printf("Enter value for n : ");
scanf("%f",&n);
h=(b-a)/n;
sum=0;
sum1=0;
for(i=1;i<n;i++)
{
if(i%2==0)
sum1=sum1+f(a+i*h);
else
sum=sum+f(a+i*h);
}
ics1=(h/3)*(f(a)+f(b)+4*sum+2*sum1);
printf("Ics1 = %.4f\n",ics1);
break;

///Solution for Simpson's 3/8 Rule i.e Is2
case 5:
h=(b-a)/3;
is2=(3*h/8)*(f(a)+f(b)+3*f(a+h)+3*f(a+2*h));
printf("Is2 = %.4f\n",is2);
break;

///Solution for Boole's Rule i.e Ib
case 6:
h=(b-a)/4;
ib=(2*h/45)*(7*f(a)+7*f(b)+12*f(a+2*h)+32*(f(a+h)+f(a+3*h)));
printf("Ib = %.4f\n",ib);
break;

case 7:
exit(0);

default:
printf("\nEnter the correct choice...\n");
}
goto a;
getch();
}


Output


COMMENTS

BLOGGER: 1
Loading...
Name

Accident Alert,1,AI,2,Array,1,Aurdino,1,C,2,Computer Graphics,9,Data Science,3,Dataset,1,Decoratot,1,Django,1,ESP32,1,Fixed point/iteration method,1,Greater or smaller,1,html,1,Image Processing,1,JAVA,1,Javascript,22,Machine Learning,1,Matlab,3,Numerical Method,13,OOP,1,Other,3,PHP,1,Point operation,1,Python,11,Raspberry pi,1,Recommendation System,1,Regression,1,Reservation System,1,Robotics,1,Simulation,2,sine wave,1,String Handling Function,1,Web scrap,1,Webpage,1,
ltr
item
COMPUTER PROGRAMMING: C Program for Numerical Integration (Trapezoidal Rule, Simpson's Rule and Boole's Rule
C Program for Numerical Integration (Trapezoidal Rule, Simpson's Rule and Boole's Rule
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeMOYA9amaXfMJco_pF-JQ2k45O3CWqxAFIPJfB56cskr92b2DMQoOU42HljcoDZVzXnDSTcfhgRMiXfeHI4xQpkRDipWpe-WmqE4pBd34k8zlVweHOx7MN8m9GM7gcjCbONT7WKID_vwk/s320/Screenshot+%252872%2529.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeMOYA9amaXfMJco_pF-JQ2k45O3CWqxAFIPJfB56cskr92b2DMQoOU42HljcoDZVzXnDSTcfhgRMiXfeHI4xQpkRDipWpe-WmqE4pBd34k8zlVweHOx7MN8m9GM7gcjCbONT7WKID_vwk/s72-c/Screenshot+%252872%2529.png
COMPUTER PROGRAMMING
https://computerprogram4ru.blogspot.com/2016/08/c-program-for-numerical-integration.html
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/2016/08/c-program-for-numerical-integration.html
true
8672391763020279633
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy