Finding Integreand using Weedle 's Rule | A sample function f ( x ) = 1 / ( 1 + x ^ 2 ) ; Function to find the integral value of f ( x ) with step size h , with initial lower limit and upper limit a and b ; Find step size h ; To store the final sum ; Find sum using Weedle 's Formula ; Return the final sum ; lower limit and upper limit ; Function Call
function y ( x ) { let num = 1 ; let denom = 1.0 + x * x ; return num / denom ; } function WeedleRule ( a , b ) { let h = ( b - a ) / 6 ; let sum = 0 ; 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 sum . toFixed ( 6 ) ; } let a = 0 , b = 6 ; let num = WeedleRule ( a , b ) ; document . write ( " " + num ) ;