coding UTF-8; // Specify character encoding (to prevent garbled text) import Math; // Import the math function library import tool.Graph2D; // Import the graph plotting library // Parameters for the calculation const double A = 0.0; // Lower bound of the integration interval const double B = 1.0; // Upper bound of the integration interval const int N = 10; // Number of rectangles (more = finer steps = better accuracy) // Function to integrate: f(x) = cos(x) double f(double x) { return cos(x); } // ---------------------------------------------------------------------- // Numerical integration using the rectangular method (approximation) // ---------------------------------------------------------------------- double delta = (B - A) / N; // Width of each rectangle (Delta x) double value = 0.0; // Calculated integral value (total area of interval) for(int i=0; i