package Tutorial7; public class Integration { // Regla rectangular public static double rectangular(MathFunction f, double a, double b, int nPanels) { double answer = 0; double h = (b-a)/nPanels; double x=a; for(int i=1; i<=nPanels; i++) { answer = answer + f.func(x); x = a+i*h; } return(h*answer); } // Regla trapezoidal public static double trapezoidal(MathFunction f, double a, double b, int nPanels) { double answer = 0; double h = (b-a)/nPanels; double x=a; for(int i=1; i<=nPanels; i++) { answer += 0.5* (f.func(x)+f.func(x+h)); x= a+i*h; } return(h*answer); } // Regla de Simpson public static double simpson(MathFunction f, double a, double b, int nPanels) { double answer=0; double x=a; double h = (b-a)/nPanels; for(int i=1; i<=nPanels; i++) { answer += (f.func(x)+4*f.func(x+h/2) + f.func(x+h))/6; x = a+i*h; } return(h*answer); } }