相关代码 |
|
procedure MIDPNT(A, B:real;var S:real; N:integer); var TNM,DEL,DDEL,X,SUM:real; J,IT:integer; begin If N = 1 Then begin S:=(B - A) * FUNC(0.5 * (A + B)); IT:=1; end Else begin IT:=Trunc(Exp((N - 2)*Ln(3))); TNM:=IT; DEL:=(B - A) / (3 * TNM); DDEL:=DEL + DEL; X:=A + 0.5 * DEL; Sum:=0; For J:=1 To IT do begin Sum:=Sum + FUNC(X); X:=X + DDEL; Sum:=Sum + FUNC(X); X:=X + DEL; end; S:=(S + (B - A) * Sum / TNM) / 3; end; end;