Program for finding the Integral of a given function using Boole 's Rule | Function to return the value of f ( x ) for the given value of x ; Function to computes the integrand of y at the given intervals of x with step size h and the initial limit a and final limit b ; Number of intervals ; Computing the step size ; Substituing a = 0 , b = 4 and h = 1 ; Driver code
def y ( x ) : NEW_LINE INDENT return ( 1 / ( 1 + x ) ) NEW_LINE DEDENT def BooleRule ( a , b ) : NEW_LINE INDENT n = 4 NEW_LINE h = ( ( b - a ) / n ) NEW_LINE sum = 0 NEW_LINE bl = ( 7 * y ( a ) + 32 * y ( a + h ) + 12 * y ( a + 2 * h ) + 32 * y ( a + 3 * h ) + 7 * y ( a + 4 * h ) ) * 2 * h / 45 NEW_LINE sum = sum + bl NEW_LINE return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT lowlimit = 0 NEW_LINE upplimit = 4 NEW_LINE print ( " f ( x ) ▁ = " , round ( BooleRule ( 0 , 4 ) , 4 ) ) NEW_LINE DEDENT