public class IntegralOutput { // ======================================================================= // Settings for Integrations // ======================================================================= // The tntegrant function. static final double f(double x) { return x * Math.cos(x); } static final double A = 0.0; // The lower-limit of the integration interval. static final double B = 40.0; // The upper-limit of the integration interval. static final int N = 10000; // The number of tiny intervals for numerical integration. // ======================================================================= // Settings for Plottings // ======================================================================= static final int PRINT_POINTS = 1000; // Number of points to be plotted (*). static final int PRINT_INTERVAL = N / PRINT_POINTS; // Loop-intervals between points to be plotted. // *) Actually, the number of plotted points will be PRINT_POINTS + 1, // because the last one point will be output after when integration loops ended. // Also, if N is indivisible by PRINT_POINTS, the actual number of plotted points // will be larger/smaller than PRINT_POINTS in some extent. // ======================================================================= // Compute The Integral Value Numerically // ======================================================================= public static void main(String[] args) { double delta = (B - A) / N; // The width of a tiny interval. double value = 0.0; // Add approximated area of all tiny intervals to this variable. // Traverse tiny intervals from lower-limit (left) to upper-limit (right). for(int i=0; i