Finding area of regions: Trapizoid and Simpson method
3 posters
IITDU Forum :: Academics (BIT) :: Semester 3 :: MATH 304
Page 1 of 1
Finding area of regions: Trapizoid and Simpson method
Hey guys, I am giving the C code of Trapizoid rule and Simpson's 1/3 rule. By these two methods we can get the result of a definite integration, or, in other words, we can say- we can find the area of a region very easily. I hope this will be helpful to everyone.
- Code:
#include<stdio.h>
#include<stdlib.h>
#define f(x) (x)*(x)
double trapizoid(double,double,double);
double simpsons(double,double,double);
int main(void){
double a,b,n,m,I,T,h,x,diff;
int i;
double sum1,sum2=0,sum3=0;
printf("Enter a,b & m::");
scanf("%lf%lf%lf",&a,&b,&m);
sum1=f(a)+f(b);
n=2*m;
I=simpsons(a,b,n);
T=trapizoid(a,b,n);
diff=fabs(T-I);
printf("%Trapizoid=%lf\nSimpsons=%lf\n\ndifference=%18.10e",T,I,diff);
return 0;
}
double simpsons(double a, double b, double n){
int i;
double x,h,sum1,sum2=0,sum3=0;
h=(b-a)/n;
sum1=f(a)+f(b);
printf("in simps h=%lf\n",h);
for(i=1;i<=n/2-1;i++){
x=a+2*i*h;
sum2+=f(x);
}
for(i=1;i<=n/2;i++)
{
x=a+(2*i-1)*h;
sum3+=f(x);
}
return (h/3.0)*(sum1+2.0*sum2+4.0*sum3);
}
double trapizoid(double a,double b,double n){
int i;
double x,h,sum=0;
h=(b-a)/n;
printf("in trapizoid h=%lf\n",h);
for(i=1;i<=n-1;i++){
x=a+i*h;
sum+=f(x);
}
sum=(h/2.0)*(f(a)+f(b)+2*sum);
return sum;
}
bit0223-sujon- Global Moderator-RC
- Course(s) :
- BIT
Posts : 98
Points : 218
Re: Finding area of regions: Trapizoid and Simpson method
Nice work,keep sharing your resources and knowledges here in fourm
Re: Finding area of regions: Trapizoid and Simpson method
Good work kiddo
You can also check this link out
This was what we studied.
[You must be registered and logged in to see this link.]
You can also check this link out
This was what we studied.
[You must be registered and logged in to see this link.]
Similar topics
» Jaccobi Iteration Method in C
» BIT0216: Numerical Method Assignment-1
» Presentation on Template Method
» printf method in Java
» Newton-Raphson method in C
» BIT0216: Numerical Method Assignment-1
» Presentation on Template Method
» printf method in Java
» Newton-Raphson method in C
IITDU Forum :: Academics (BIT) :: Semester 3 :: MATH 304
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford