0% found this document useful (0 votes)
104 views3 pages

Experiment 7 Trapezoidal

The document describes a program to calculate numerical integration using the Trapezoidal rule. It defines the function f(x), reads in the lower and upper integration limits and number of subintervals from the user. It then calculates the step size and initializes the integration value. The program uses a for loop to calculate the function value at each subinterval midpoint, adding it to the integration value. After the loop, it calculates the final integration value and prints it out.

Uploaded by

dhruv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views3 pages

Experiment 7 Trapezoidal

The document describes a program to calculate numerical integration using the Trapezoidal rule. It defines the function f(x), reads in the lower and upper integration limits and number of subintervals from the user. It then calculates the step size and initializes the integration value. The program uses a for loop to calculate the function value at each subinterval midpoint, adding it to the integration value. After the loop, it calculates the final integration value and prints it out.

Uploaded by

dhruv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program for solving numerical integration by Trapezoidal rule

#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;
}
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


1. Start

2. Define function f(x)

3. Read lower limit of integration, upper limit of


integration and number of sub interval

4. Calcultae: 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

You might also like