
- Data Structures & Algorithms
- DSA - Home
- DSA - Overview
- DSA - Environment Setup
- Algorithm
- DSA - Algorithms Basics
- DSA - Asymptotic Analysis
- DSA - Greedy Algorithms
- DSA - Divide and Conquer
- DSA - Dynamic Programming
- Data Structures
- DSA - Data Structure Basics
- DSA - Data Structures and Types
- DSA - Array Data Structure
- Linked Lists
- DSA - Linked List Basics
- DSA - Doubly Linked List
- DSA - Circular Linked List
- Stack & Queue
- DSA - Stack
- DSA - Expression Parsing
- DSA - Queue
- Searching Techniques
- DSA - Linear Search
- DSA - Binary Search
- DSA - Interpolation Search
- DSA - Hash Table
- Sorting Techniques
- DSA - Sorting Algorithms
- DSA - Bubble Sort
- DSA - Insertion Sort
- DSA - Selection Sort
- DSA - Merge Sort
- DSA - Shell Sort
- DSA - Quick Sort
- Graph Data Structure
- DSA - Graph Data Structure
- DSA - Depth First Traversal
- DSA - Breadth First Traversal
- Tree Data Structure
- DSA - Tree Data Structure
- DSA - Tree Traversal
- DSA - Binary Search Tree
- DSA - AVL Tree
- DSA - Red Black Trees
- DSA - B Trees
- DSA - B+ Trees
- DSA - Splay Trees
- DSA - Spanning Tree
- DSA - Tries
- DSA - Heap
- Recursion
- DSA - Recursion Basics
- DSA - Tower of Hanoi
- DSA - Fibonacci Series
- DSA Useful Resources
- DSA - Questions and Answers
- DSA - Quick Guide
- DSA - Useful Resources
- DSA - Discussion
Simpson's 1/3 Rule for definite integral
Like the Trapezoidal Rule, Simpson’s 1/3rd rule is also used to find the integral value from the range a to b. The main difference between trapezoidal and the Simpson’s 1/3rd rule is, in the trapezoidal rule, the whole sections are divided into some trapezoids, but in this case, each trapezoid are also divided into two parts.
For this rule, we will follow this formula:
Here h is the width of the interval, and n is the number of intervals. We can find the h by using
Input and Output
Input: The function f(x): (x+(1/x). The lower and upper limit: 1, 2. The number of intervals: 20. Output: The answer is: 2.19315
Algorithm
integrateSimpson(a, b, n)
Input − The lower and upper limit of the integral and number of intervals n.
Output − The result after integration.
Begin h := (b - a)/n res := f(a) + f(b) lim := n/2 for i := 1 to lim, do oddSum := oddSum + f(a + (2i - 1)h) done oddSum := oddSum * 4 for i := 1 to lim-1, do evenSum := evenSum + f(a + 2ih) done evenSum := evenSum * 2 res := res + oddSum + evenSum res := res * (h/3) return res End
Example
#include<iostream> #include<cmath> using namespace std; float mathFunc(float x) { return (x+(1/x)); //function 1 + 1/x } float integrate(float a, float b, int n) { float h, res = 0.0, oddSum = 0.0, evenSum = 0.0, lim; int i; h = (b-a)/n; //calculate the distance between two interval res = (mathFunc(a)+mathFunc(b)); //initial sum using f(a) and f(b) lim = n/2; for(i = 1; i<=lim; i++) oddSum += mathFunc(a+(2*i-1)*h); //sum of numbers, placed at odd number oddSum *= 4; //odd sum are multiplied by 4 for(i = 1; i<lim; i++) evenSum += mathFunc(a+(2*i)*h); //sum of numbers, placed at even number evenSum *= 2; //even sum are multiplied by 2 res += oddSum+evenSum; res *= (h/3); return res; //The result of integration } main() { float result, lowLim, upLim; int interval; cout << "Enter Lower Limit, Upper Limit and interval: "; cin >>lowLim >>upLim >>interval; result = integrate(lowLim, upLim, interval); cout << "The answer is: " << result; }
Output
Enter Lower Limit, Upper Limit and interval: 1 2 20 The answer is: 2.19315
- Related Articles
- Trapezoidal Rule for definite integral
- Usage of @import Rule for CSS
- C++ program to implement Simpson’s 3/8 rule
- A quadratic equation with integral coefficient has integral roots. Justify your answer.
- Solve for $x$:$\frac{1}{x-3}-\frac{1}{x+5}=\frac{1}{6}, x≠3, -5$
- Runge-Kutta 4th order rule for differential equation
- What is the golden rule for complimentary feeding?
- Check the divisibility rule of 11 for 1.10000001.
- Solve for $x$:\( 1-(x-2)-[(x-3)-(x-1)]=0 \)
- Indefinite and Definite Articles: Definition and Examples
- Integral conversion characters in Java
- Psychotherapy and Integral Yoga Psychology
- Shorthand property for setting all the column-rule-* properties
- What is rule for perimeter of rectangle and square?
- Integrate along axis 1 using the composite trapezoidal rule in Python

Advertisements