Composite Trapezoidal Method
Algorithm : Composite Trapezoidal Rule Composite_trapezoidal(a,b,n) { Let us consider a function f(x). We want to find the integrating value of f(x) w.r.t. x from lower limit ‘a’ to upper limit ‘b’ with subdivision n. h=(b-a)/n x=a for(i=1 to n-1) { x=a+i*h sum=sum+f(x) //f(x) is a function which } returns the value of f(x) r=h/2*[f(a)+f(b)]+h*sum at x=x print “r” } C Program For Composite Trapezoidal Method Source Code: #include<stdio.h> #include<conio.h> #include<math.h> void comp_trapezoidal(float,float,int); float f(float); void main() { int n; float a,b; clrscr(); printf("\nCALCULATE :\n"); printf("\n%c\n%c(4x-3X^3)dx using the given limits.\n",244,245); printf("\nEnter the upper limit of the function:"); scanf("%f",&b); printf("\nEnter the lower limit of the function:"); scanf("%f",&a); printf("\nENTER THE NUMBER OF SUB-DIVISIONS:"); scanf("%d",&n); comp_trapezoidal(a,b,n); getch(); } void comp_trapezoidal(float a,float b,int n) { float h,sum=0,x,R; int i; h=(b-a)/n; x=a; for(i=1;i<=n-1;i++) { x=a+i*h; sum=sum+f(x); } R=(h/2)*(f(a)+f(b))+h*sum; printf("\n\nValue=%f",R); } float f(float x) { return (4*x-3*x*x); } OUTPUT : CALCULATE : ô õ(4x-3X^3)dx using the given limits. Enter the upper limit of the function:1 Enter the lower limit of the function:0 ENTER THE NUMBE3R OF SUB-DIVISIONS:10 Value=0.995000
Tags:
Integration
0 comments