Finding Integrand using Weedle's Rule Last Updated : 22 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Given a function f(x) and two integers a and b. The task is to find the integrand of the given function from lower limit(a) to the upper limit(b) using Weedle's Rule. The given function is: f(x) = \frac{1}{(1+x)^2} Examples: Input: a = 0, b = 6 Output: 1.373448 Input: a = 10, b = 13 Output: f(x) = 0.022897 Approach: The integration of any function f(x) using Weedle's Formula is given by: \int_{a}^{b} f(x) dx = \frac{3}{10} h (f_1 + 5f_2 + f_3 + 6f_4 + f_5 + 5f_6 + f_7) where, h = \frac{(b-a)}{6} f_i = f(x_i) and i = [0, 6] x_1 = a x_2 = x_1 + h x_3 = x_1 + 2h x_4 = x_1 + 3h x_5 = x_1 + 4h x_6 = x_1 + 5h Below are the steps: Find the value of h from the above formula i.e., h = \frac{(b-a)}{6} .Find the value from x_1 to x_7 and calculate the value from f(x_1) to f(x_7) Substitute the above values in Weedle's Formula to find the integral value. Below is the implementation of the above approach: C++ // C++ program to Implement Weedle's Rule #include <bits/stdc++.h> using namespace std; // A sample function f(x) = 1/(1+x^2) float y(float x) { float num = 1; float denom = 1.0 + x * x; return num / denom; } // Function to find the integral value // of f(x) with step size h, with // initial lower limit and upper limit // a and b float WeedleRule(float a, float b) { // Find step size h double h = (b - a) / 6; // To store the final sum float sum = 0; // Find sum using Weedle's Formula sum = sum + (((3 * h) / 10) * (y(a) + y(a + 2 * h) + 5 * y(a + h) + 6 * y(a + 3 * h) + y(a + 4 * h) + 5 * y(a + 5 * h) + y(a + 6 * h))); // Return the final sum return sum; } // Driver Code int main() { // lower limit and upper limit float a = 0, b = 6; // Function Call cout<< "f(x) = "<< fixed << WeedleRule(a, b); return 0; } // This code is contributed by shivanisinghss2110 C // C program to Implement Weedle's Rule #include <math.h> #include <stdio.h> // A sample function f(x) = 1/(1+x^2) float y(float x) { float num = 1; float denom = 1.0 + x * x; return num / denom; } // Function to find the integral value // of f(x) with step size h, with // initial lower limit and upper limit // a and b float WeedleRule(float a, float b) { // Find step size h double h = (b - a) / 6; // To store the final sum float sum = 0; // Find sum using Weedle's Formula sum = sum + (((3 * h) / 10) * (y(a) + y(a + 2 * h) + 5 * y(a + h) + 6 * y(a + 3 * h) + y(a + 4 * h) + 5 * y(a + 5 * h) + y(a + 6 * h))); // Return the final sum return sum; } // Driver Code int main() { // lower limit and upper limit float a = 0, b = 6; // Function Call printf("f(x) = %f", WeedleRule(a, b)); return 0; } Java // Java program to Implement Weedle's Rule import java.util.*; class GFG{ // A sample function f(x) = 1/(1+x^2) static float y(float x) { float num = 1; float denom = (float)1.0 + x * x; return num / denom; } // Function to find the integral value // of f(x) with step size h, with // initial lower limit and upper limit // a and b static float WeedleRule(float a, float b) { // Find step size h float h = (b - a) / 6; // To store the final sum float sum = 0; // Find sum using Weedle's Formula sum = sum + (((3 * h) / 10) * (y(a) + y(a + 2 * h) + 5 * y(a + h) + 6 * y(a + 3 * h) + y(a + 4 * h) + 5 * y(a + 5 * h) + y(a + 6 * h))); // Return the final sum return sum; } // Driver Code public static void main(String args[]) { // lower limit and upper limit float a = 0, b = 6; // Function Call float num=WeedleRule(a, b); System.out.format("f(x) = "+"%.6f", num); } } // This code is contributed by AbhiThakur Python3 # Python3 program to Implement Weedle's Rule # A sample function f(x) = 1/(1+x^2) def y(x): num = 1; denom = float(1.0 + x * x); return num / denom; # Function to find the integral value # of f(x) with step size h, with # initial lower limit and upper limit # a and b def WeedleRule(a, b): # Find step size h h = (b - a) / 6; # To store the final sum sum = 0; # Find sum using Weedle's Formula sum = sum + (((3 * h) / 10) * (y(a) + y(a + 2 * h) + 5 * y(a + h) + 6 * y(a + 3 * h) + y(a + 4 * h) + 5 * y(a + 5 * h) + y(a + 6 * h))); # Return the final sum return sum; # Driver Code if __name__ == '__main__': # lower limit and upper limit a = 0; b = 6; # Function Call num = WeedleRule(a, b); print("f(x) = {0:.6f}".format(num)); # This code is contributed by sapnasingh4991 C# // C# program to Implement Weedle's Rule using System; class GFG{ // A sample function f(x) = 1/(1+x^2) static float y(float x) { float num = 1; float denom = (float)1.0 + x * x; return num / denom; } // Function to find the integral value // of f(x) with step size h, with // initial lower limit and upper limit // a and b static float WeedleRule(float a, float b) { // Find step size h float h = (b - a) / 6; // To store the final sum float sum = 0; // Find sum using Weedle's Formula sum = sum + (((3 * h) / 10) * (y(a) + y(a + 2 * h) + 5 * y(a + h) + 6 * y(a + 3 * h) + y(a + 4 * h) + 5 * y(a + 5 * h) + y(a + 6 * h))); // Return the final sum return sum; } // Driver Code public static void Main() { // lower limit and upper limit float a = 0, b = 6; // Function Call float num=WeedleRule(a, b); Console.Write("f(x) = "+num); } } // This code is contributed by AbhiThakur JavaScript <script> // Javascript program to Implement Weedle's Rule // A sample function f(x) = 1/(1+x^2) function y(x) { let num = 1; let denom = 1.0 + x * x; return num / denom; } // Function to find the integral value // of f(x) with step size h, with // initial lower limit and upper limit // a and b function WeedleRule(a, b) { // Find step size h let h = (b - a) / 6; // To store the final sum let sum = 0; // Find sum using Weedle's Formula sum = sum + (((3 * h) / 10) * (y(a) + y(a + 2 * h) + 5 * y(a + h) + 6 * y(a + 3 * h) + y(a + 4 * h) + 5 * y(a + 5 * h) + y(a + 6 * h))); // Return the final sum return sum.toFixed(6); } // Driver code // lower limit and upper limit let a = 0, b = 6; // Function Call let num = WeedleRule(a, b); document.write("f(x) = " + num); // This code is contributed by divyeshrabadiya07 </script> Output: f(x) = 1.373448 Comment More infoAdvertise with us Next Article Finding Integrand using Weedle's Rule kartik Follow Improve Article Tags : Mathematical DSA Practice Tags : Mathematical Similar Reads Program for finding the Integral of a given function using Boole's Rule Given a function, f(x), tabulated at points x_i equally spaced by h=x_{i+1} - x_i such that f_1 = f(x_1) f_2=f(x_2) .....and so on The upper and lower limits a, b correspond to which the integral needs to be found, the task is to find the integral value of the given equation f(x).Examples: Input: a 8 min read Program to implement Simpson's 3/8 rule Write a program to implement Simpson's 3/8 rule.The Simpson's 3/8 rule was developed by Thomas Simpson. This method is used for performing numerical integrations. This method is generally used for numerical approximation of definite integrals. Here, parabolas are used to approximate each part of cur 6 min read Integration in a Polynomial for a given value Given string str which represents a polynomial and a number N, the task is to integrate this polynomial with respect to X at the given value N. Examples: Input: str = "90x4 + 24x3 + 18x2 + 18x", N = 1. Output: 39 Explanation: Given, dy/dx = 90*(X4) + 24* (X3) + 18* (X2) + 18*(X). On integrating this 7 min read Program for Simpson's 1/3 Rule In numerical analysis, Simpson's 1/3 rule is a method for numerical approximation of definite integrals. Specifically, it is the following approximation: $$\int_{a}^{b} f(x) dx \approx \frac{(b-a)}{6} \bigg(f(a) + 4f \frac{(a+b)}{2} + f(b)\bigg)$$      In Simpson's 1/3 Rule, we use parabolas to appr 7 min read Trapezoidal Rule for Approximate Value of Definite Integral In the field of numerical analysis, Trapezoidal rule is used to find the approximation of a definite integral. The basic idea in Trapezoidal rule is to assume the region under the graph of the given function to be a trapezoid and calculate its area. It follows that:{\displaystyle \int _{a}^{b}f(x)\, 6 min read Program to find the indefinite Integration of the given Polynomial Given a polynomial string str, the task is to integrate the given string and print the string after integrating it. Note: The input format is such that there is a whitespace between a term and the â+â symbol. Examples: Input: str = "4X3 + 3X1 + 2X2" Output: X4 + (3/2)X2 + (2/3)X3 + C Input: str = "5 8 min read Find Tangent at a given point on the curve Given a curve [ y = x(A â x) ], the task is to find tangent at given point (x, y) on that curve, where A, x, y are integers.Examples: Input: A = 2, x = 2, y = 0 Output: y = -2x - 4 Since y = x(2 - x) y = 2x - x^2 differentiate it with respect to x dy/dx = 2 - 2x put x = 2, y = 0 in this equation dy/ 6 min read Area of a leaf inside a square Given an integer a as the side of the square ABCD. The task is to find the area of the leaf AECFA inside the square as shown below: Examples: Input: a = 7 Output: 28 Input: a = 21 Output: 252 Approach: To calculate the area of the leaf, first find the area of the half leaf AECA, which can be given a 3 min read Class 11 RD Sharma Solutions - Chapter 30 Derivatives - Exercise 30.3 In this article, we will delve into the solutions for Exercise 30.3 from Chapter 30 of RD Sharma's Class 11 Mathematics textbook which covers "Derivatives". This chapter is pivotal for understanding how to determine the rate at which a function changes which is fundamental in calculus. The solutions 10 min read Program to calculate Double Integration Write a program to calculate double integral numerically. Example: Input: Given the following integral. \int _{3.7}^{4.3}\int _{2.3}^{2.5}\sqrt{x^4+y^5}\:dxdywheref(x, y)=\sqrt{x^4+y^5}\Output: 3.915905 Explanation and Approach: We need to decide what method we are going to use to solve the integral 11 min read Like