← All examples

Trapezoidal rule

Pascal Algorithms

numeric integration

Flowchart (ISO 5807)

StartInput a, b, nh = (b - a) / ns = (a * a + b * b) / 2i = 1, n - 1, 1x = a + i * hs = s + x * xtrapez = s * hEndFigure 1 — trapez

Source code

function trapez(a, b: real; n: integer): real;
var h, s, x: real;
    i: integer;
begin
  h := (b - a) / n;
  s := (a * a + b * b) / 2;
  for i := 1 to n - 1 do
  begin
    x := a + i * h;
    s := s + x * x;
  end;
  trapez := s * h;
end;