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

7.c-Program Simpson

Uploaded by

Mohammed Iqbal
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)
13 views3 pages

7.c-Program Simpson

Uploaded by

Mohammed Iqbal
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

7.

Numerical integration by the Simpson 1/3 rule

Aim;

Write a C program to find numerical integration by using Simpson 1/3 rule.

Algorithm

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. If i mod 2 =0 then
Integration value = Integration Value + 2* f(k)
Otherwise
Integration Value = Integration Value + 4 * f(k)
End If

10. Increment i by 1 i.e. i = i+1 and go to step 7

11. Calculate: Integration value = Integration value * step size/3

12. Display Integration value as required answer

13. Stop

Flowchart:
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x) 1/(1+x*x)
int main()
{
float lower, upper, integration=0.0, stepSize, k;
int i, subInterval;
clrscr();
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);
stepSize = (upper - lower)/subInterval;
integration = f(lower) + f(upper);
for(i=1; i<= subInterval-1; i++)
{
k = lower + i*stepSize;
if(i%2==0)
{
integration = integration + 2 * f(k);
}
else
{
integration = integration + 4 * f(k);
}
}
integration = integration * stepSize/3;
printf("\nRequired value of integration is: %.3f", integration);
getch();
return 0;
}
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.785

Result: Thus a C Program using to find numerical integration by Simpson's 1/3 Rule has been successfully verified and
executed, and the output was obtained.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy