Numerical Integration
Using Trapezoidal Method Algorithm
In numerical analysis, Trapezoidal method is a
technique for evaluating definite integral. This method is also known as
Trapezoidal rule or Trapezium rule.
This method is based on Newton's Cote Quadrature Formula and Trapezoidal rule is obtained when we put value of n = 1 in this formula. In this article, we are going to develop an algorithm for Trapezoidal method.
Trapezoidal Method
Algorithm
1.
Start
2.
Define function f(x)
3.
Read lower limit of integration, upper limit of integration and number of sub interval
4.
Calculate: step size = (upper limit - lower limit)/number of sub interval
5.
Set: integration value = f(lower limit) + f(upper limit)
6.
Set: i = 1
7. If
i > number of sub interval then goto
8.
Calculate: k = lower limit + i * h
9.
Calculate: Integration value = Integration Value + 2* f(k)
10.
Increment i by 1 i.e. i = i+1 and go to step 7
11.
Calculate: Integration value = Integration value * step size/2
12.
Display Integration value as required answer
13.
Stop
Numerical
Integration Using Trapezoidal Method C Program
C
program for Trapezoidal Rule or Method to find numerical integration. To learn
algorithm about Trapezoidal rule follow article Trapezoidal Method Algorithm.
#include<stdio.h>
#include<conio.h>
#include<math.h>
/*
Define function here */
#define
f(x) 1/(1+pow(x,2))
int
main()
{
float lower, upper, integration=0.0, stepSize,
k;
int i, subInterval;
clrscr();
/* Input */
printf("Enter lower limit of integration:
");
scanf("%f", &lower);
printf("Enter upper limit of integration:
");
scanf("%f", &upper);
printf("Enter number of sub intervals:
");
scanf("%d", &subInterval);
/* Calculation */
/* Finding step size */
stepSize = (upper - lower)/subInterval;
/* Finding Integration Value */
integration = f(lower) + f(upper);
for(i=1; i<= subInterval-1; i++)
{
k = lower + i*stepSize;
integration = integration + 2 * f(k);
}
integration = integration * stepSize/2;
printf("\nRequired value of integration
is: %.3f", integration);
getch();
return 0;
}
Trapezoidal Method
C Program Output
Enter
lower limit of integration: 0
Enter
upper limit of integration: 1
Enter
number of sub intervals: 6
Required
value of integration is: 0.784
Regression Method Algorithm Using Least Square Method
Solve the initial value problems using Modified Euler's Method.
Integratea function using numerically using trapezoidal Method.
0 Comments