public static double integral ( DoubleUnaryOperator f , double x1 , double x2 , int points ) { double delta = ( x2 - x1 ) / points ; double delta2 = delta / 2.0 ; double sum = 0 ; double y1 = f . applyAsDouble ( x1 ) ; double y2 ; for ( int ii = 1 ; ii <= points ; ii ++ ) { x1 += delta ; y2 = f . applyAsDouble ( x1 ) ; sum += ( y1 + y2 ) * delta2 ; y1 = y2 ; } return sum ; }
Returns numerical integral between x1 and x2