home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
NRPAS13
/
TRAPZD.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-04-29
|
654b
|
29 lines
PROCEDURE trapzd(a,b: real; VAR s: real; n: integer);
(* Programs calling TRAPZD must provide a function
func(x:real):real which is to be integrated. They must
also define the variable
VAR
glit: integer;
in the main routine. *)
VAR
j: integer;
x,tnm,sum,del: real;
BEGIN
IF (n = 1) THEN BEGIN
s := 0.5*(b-a)*(func(a)+func(b));
glit := 1
END
ELSE BEGIN
tnm := glit;
del := (b-a)/tnm;
x := a+0.5*del;
sum := 0.0;
FOR j := 1 TO glit DO BEGIN
sum := sum+func(x);
x := x+del
END;
s := 0.5*(s+(b-a)*sum/tnm);
glit := 2*glit
END
END;