0% found this document useful (0 votes)
45 views

Coding: Simpson'S 1/3 Rule

This document discusses Simpson's 1/3rd rule, a numerical method for approximating definite integrals. It provides the steps to calculate an integral using this rule, including: 1) dividing the interval into equal parts, 2) calculating function values at each point, 3) using the Simpson's 1/3rd rule formula to calculate the integral value. An example calculates the integral of 1/(1+x^2) from 0 to 6 by dividing the interval into six parts. The solution shows the function values and integral calculation.

Uploaded by

Mithun N Gowda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Coding: Simpson'S 1/3 Rule

This document discusses Simpson's 1/3rd rule, a numerical method for approximating definite integrals. It provides the steps to calculate an integral using this rule, including: 1) dividing the interval into equal parts, 2) calculating function values at each point, 3) using the Simpson's 1/3rd rule formula to calculate the integral value. An example calculates the integral of 1/(1+x^2) from 0 to 6 by dividing the interval into six parts. The solution shows the function values and integral calculation.

Uploaded by

Mithun N Gowda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Coding

SIMPSON’S 1/3rd RULE


BY
MITHUN N
OBJECTIVE:
To determine the subordinate to calculate the integral of nth order polynomial using
Simpson’s 1/3rd rule in C++
Analytical Description
In numerical analysis, Simpson’s 1/3rd rule is a method for the numerical
approximation of definite integrals.
In order to integrate any function f(x) in the interval (a, b), follow the steps given
below:
1.Select a value for n, which is the number of parts the interval is divided into.
2.Calculate the width, h = (b-a)/n
3.Calculate the values of x0 to xn as x0 = a, x1 = x0 + h, …..xn-1 = xn-2 + h, xn = b.
Consider y = f(x). Now find the values of y(y0 to yn) for the corresponding x(x0 to
xn) values.
4.Substitute all the above found values in the Simpson’s Rule Formula to calculate
the integral value.

Example
6 1
Evaluate ∫0 𝑑𝑥 by applying Simpson’s 1/3rd rule by dividing into six equal
1+𝑥 2
parts.
𝑏−𝑎 6−0
Solution: a = 0 b=6 h= = =1
𝑛 6

x 0 1 2 3 4 5 6
y 1 0.5 0.2 0.1 0.058 0.038 0.027

I = [(𝑦0 + 𝑦6 ) + 4(𝑦1 + 𝑦3 + 𝑦5 ) + 2(𝑦2 + 𝑦4 )]
3
1
I = [(1 + 0.027) + 4(0.5 + 0.1 + 0.038) + 2(0.2 + 0.058)]
3

I = 1.365
Program Description
1. Write the function whose definite integral is to be calculated.
2. Set the precision.
3. n is for subintervals and i is for loop.
4. Get the limits of integration.
5. Get the no. of subintervals.
6. Get the width of the subintervals.
7. Write a loop to evaluate x0,…….xn and y0,……yn.
8. Store them in arrays.
9. Write a loop to evaluate 4*(y1+y2+y3+y5+………+yn-1).
10. Write a loop to evaluate 4*(y1+y2+y3+y5+………+yn-1)
+2(y2+y4+y6+…...+yn-2).
11.Apply formula of Simpson’s 1/3rd rule.

Input
Output

Formula

I = [(𝑦0 + 𝑦𝑛 ) + 4(𝑦1 + 𝑦3 + 𝑦5 + ⋯ + 𝑦𝑛−1 ) + 2(𝑦2 + 𝑦4 + ⋯ + 𝑦𝑛−2 )]
3

I= [X + 2 E + 4 O]
3

Where n= equal segments (it must be even).


h= difference between sub intervals.
X= sum of extreme ordinates.
E= sum of even ordinates.
O= sum of odd ordinates.

You might also like