Q
quickdeath
Код:
TYPE VEC=ARRAY [0..100] OF REAL;
VAR N:INTEGER; A,B,H,S:REAL; X,F,C:VEC;
FUNCTION Y(X:REAL):REAL
BEGIN Y:=SIN(X) END;
PROCEDURE TAB(N:INTEGER;A,H:REAL; FUNCTION Y:REAL;VAR X,F:VEC);
VAR I:INTEGER;
BEGIN
FOR I:=0 TO N DO BEGIN X[I]:=A+I*H; F[I]:=Y(X[I]) END
END;
PROCEDURE CS(N:INTEGER; VAR X,F,C:VEC);
VAR I,J,M:INTEGER; A,B,R:REAL; K:VEC;
BEGIN K[1]:=0.0; C[1]:=0.0;
FOR I:=2 TO N DO BEGIN J:=I-1; M:=J-1;
A:=X[I]-X[J]; B:=[J]-X[M]; R:=2*(A+B)- B*C[J]; C[I]:=A/R;
K[I]:=(3.0*((F[I]-F[J])/A-(F[J]-F[M])/B)-B*K[J])/R
END;
C[N]:=K[N];
FOR I:=N-1 DOWNTO 2 DO C[I]:=K[I]-C[I]*C[I+1]
END;
PROCEDURE SSP(N:INTEGER; H:REAL;VAR F,C:VEC; VAR S:REAL);
VAR I:INTEGER; R:REAL;
BEGIN S:=(F[0]+F[N])/2; R:=0.0;
FOR I:=1 TO N-1 DO BEGIN S:=S+F[I]; R:=R+C[I+1] END;
S:=(S-R*H*H/6.0)*H
END;
BEGIN
REPEAT WRITE('N,A,B?'); REALN(N,A,B);; H:=(B-A)/N;
TAB(N,A,H,Y,X,F); CS(H,X,F,C); SSP(N,H,F,C,S);
WRITELN('S=',S)
UNTIL FALSE
END.