Skip to content

Trapezoidal rule

Pascal numeric integration

Flowchart (ISO 5807)

StartInput a, b, nh = (b − a) / ns = (a² + b²) / 2i = 1, n − 1, 1x = a + ihs = s + x²trapez = shEndFigure 1 — trapez

Source code

Pascal
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;

The editor opens with this code — change it and the chart redraws.

Language
Pascal
Constructs
numeric integration
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples