ВУЗ:
Составители:
Рубрика:
22
begin
result:=true;
for i:=1 to Dim do
if not(AreEqual(self.comp[i], v.comp[i])) then result:=false;
end;
procedure RVector.Assign(v: RVector);
var i: Integer;
begin for i:=1 to Dim do self.comp[i]:=v.comp[i]; end;
function RVector.GetComp(i: Integer): Rational;
begin
if (i>=1) and (i<=Dim)
then result:=self.comp[i]
else raise Exception.Create('Index is out of bounds');
end;
procedure RVector.SetComp(i: Integer; value: Rational);
begin
if (i>=1) and (i<=Dim)
then self.comp[i]:=value
else raise Exception.Create('Index is out of bounds');
end;
function RVector.AsString: String;
var i: Integer;
begin
result:='(';
for i:=1 to Dim do begin
result:=result+UnitRational.AsString(self.comp[i]);
if i<Dim then result:=result+', ';
end;
result:=result+')';
end;
constructor RVector.Create;
var i: Integer;
begin
inherited Create;
for i:=1 to Dim do begin
self.comp[i].num:=0; self.comp[i].den:=1;
end;
end;
Отметим , что реализации методов ScalarProduct и GetLength те-
перь отличаются более существенно: при определении длины вектора
рациональное число удобнее сразу перевести в вещественную форму и
уже потом возводить в квадрат (хотя вычисления в рациональных чис -
лах с одним преобразованием в конце дают более точный результат).
Модуль UnitRational не содержит процедуры , обнуляющей рациональное
begin result:=true; for i:=1 to Dim do if not(AreEqual(self.comp[i], v.comp[i])) then result:=false; end; procedure RVector.Assign(v: RVector); var i: Integer; begin for i:=1 to Dim do self.comp[i]:=v.comp[i]; end; function RVector.GetComp(i: Integer): Rational; begin if (i>=1) and (i<=Dim) then result:=self.comp[i] else raise Exception.Create('Index is out of bounds'); end; procedure RVector.SetComp(i: Integer; value: Rational); begin if (i>=1) and (i<=Dim) then self.comp[i]:=value else raise Exception.Create('Index is out of bounds'); end; function RVector.AsString: String; var i: Integer; begin result:='('; for i:=1 to Dim do begin result:=result+UnitRational.AsString(self.comp[i]); if i
Страницы
- « первая
- ‹ предыдущая
- …
- 20
- 21
- 22
- 23
- 24
- …
- следующая ›
- последняя »