← All examples

Rectangle rule

Java Algorithms

numeric integration

Flowchart (ISO 5807)

StartInput a, b, nh = (b - a) / ns = 0i = 0, n - 1, 1x = a + i * hs = s + x * x * hReturn sEndFigure 1 — Integral.rect

Source code

class Integral {
    static double rect(double a, double b, int n) {
        double h = (b - a) / n;
        double s = 0;
        for (int i = 0; i < n; i++) {
            double x = a + i * h;
            s = s + x * x * h;
        }
        return s;
    }
}