1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
{ ******************************************************************
Comparison of two vectors
****************************************************************** }
unit ucompvec;
interface
uses
utypes;
function CompVec(X, Xref : PVector;
Lb, Ub : Integer;
Tol : Float) : Boolean;
{ ------------------------------------------------------------------
Checks if each component of vector X is within a fraction Tol of
the corresponding component of the reference vector Xref. In this
case, the function returns True, otherwise it returns False
------------------------------------------------------------------ }
implementation
function CompVec(X, Xref : PVector;
Lb, Ub : Integer;
Tol : Float) : Boolean;
var
I : Integer;
Ok : Boolean;
ITol : Float;
begin
I := Lb;
Ok := True;
repeat
ITol := Tol * Abs(Xref^[I]);
if ITol < MachEp then ITol := MachEp;
Ok := Ok and (Abs(X^[I] - Xref^[I]) < ITol);
I := I + 1;
until (not Ok) or (I > Ub);
CompVec := Ok;
end;
end.
|