protected double trapezoid ( int n ) { double x = 0 ; double tnm = 0 ; double sum = 0 ; double del = 0 ; int it = 0 ; int j = 0 ; if ( n == 1 ) { strapezoid = 0.5f * ( upperlimit - lowerlimit ) * ( equation ( lowerlimit ) + equation ( upperlimit ) ) ; } else { /* * for (it = 1, j = 1; j < n - 1; j++) { it <<= 1; } */ it = ( int ) Math . pow ( 2.0 , n - 1 ) ; tnm = ( double ) it ; del = ( upperlimit - lowerlimit ) / tnm ; x = lowerlimit + 0.5f * del ; for ( sum = 0f , j = 1 ; j <= it ; j ++ , x += del ) { if ( x >= upperlimit ) { System . out . println ( "hoi" ) ; } sum += equation ( x ) ; } strapezoid = ( double ) ( 0.5f * ( strapezoid + ( upperlimit - lowerlimit ) * sum / tnm ) ) ; } return strapezoid ; }
Calculate the integral with the trapezoidal algorithm of the equation implemented in the method equation