Add README.md
[pdp8.git] / sw / src / pascal / NEWTON.PS
... / ...
CommitLineData
1PROGRAM NEWTON(INPUT,OUTPUT);
2
3 CONST NMAX=25;
4
5 VAR N,I,J: INTEGER;
6 X,Y,C: ARRAY[0..NMAX] OF REAL;
7 A: ARRAY[-1..NMAX] OF REAL;
8
9BEGIN
10 READ(N); N := N-1;
11 WRITELN;
12 WRITELN("I N T E R P O L A T I O N S P O L Y N O M (NEWTON)");
13 WRITELN(" C0 + C1*X + C2*X^2 + .... + CN*X^N");
14 WRITELN;
15
16(***** EINGABE DER STUETZSTELLEN *****)
17
18 WRITELN("GEGEBENE PUNKTE:");
19 FOR I := 0 TO N DO
20 BEGIN READ(X[I],Y[I]);
21 WRITELN("P",I:1,X[I]:8:2," ,",Y[I]:8:2)
22 END;
23
24(***** BERECHNUNG DER DIVIDIERTEN DIFFERENZEN *****)
25
26 FOR I := 1 TO N DO
27 FOR J := N DOWNTO I DO Y[J] := (Y[J-1]-Y[J])/(X[J-I]-X[J]);
28
29(***** KOMPOSITION DER KOEFFIZIENTEN *****)
30
31 A[-1] := 0;
32 FOR I := 0 TO N DO
33 BEGIN
34 A[I] := 1; C[I] := Y[I];
35 FOR J := I-1 DOWNTO 0 DO
36 BEGIN
37 A[J] := A[J-1] - A[J]*X[I-1];
38 C[J] := C[ J ] + A[J]*Y[ I ]
39 END
40 END;
41
42(***** AUSGABE DER KOEFFIZIENTEN *****)
43
44 WRITELN;
45 WRITELN("DIE KOEFFIZIENTEN SIND:");
46 FOR I := 0 TO N DO WRITELN("C",I:1," =",C[I]:15:8)
47
48END.