33 lines
986 B
Plaintext
33 lines
986 B
Plaintext
\Calculate forward differences
|
|
|
|
\Sets elements of B to the first order forward differences of A.
|
|
\A should have bounds 1 :: N, B should have bounds 1 :: N - 1.
|
|
procedure FirstOrderFDifference ( A, B, N );
|
|
integer A, B, N, I;
|
|
for I := 2 to N do B( I - 1 ) := A( I ) - A( I - 1 );
|
|
|
|
integer V ( 1 + 10 );
|
|
integer Diff( 1 + 9 );
|
|
integer VPos, Length, List, I, Order;
|
|
begin
|
|
\construct the initial values array
|
|
VPos := 1;
|
|
List:= [90, 47, 58, 29, 22, 32, 55, 5, 55, 73];
|
|
for I := 0 to 10-1 do begin
|
|
V( VPos ) := List( I );
|
|
VPos := VPos + 1
|
|
end;
|
|
|
|
\calculate and show the differences
|
|
Format(8, 0); \set output format
|
|
Length := 10;
|
|
for Order := 1 to Length - 1 do begin
|
|
FirstOrderFDifference( V, Diff, Length );
|
|
Length := Length - 1;
|
|
IntOut(0, Order); Text(0, " : ");
|
|
for I := 1 to Length do RlOut(0, float(Diff( I ) ));
|
|
CrLf(0);
|
|
for I := 1 to Length do V( I ) := Diff( I )
|
|
end
|
|
end
|