invalid floating point operation
Всем привет. Пытаюсь написать лабу, но вот незадача - с одними цифрами все нормально, а с другими вылазит ошибка, указанная в названии темы. Знающие, подскажите, как можно решить проблему? P.s. Ругается на строчку a1:=-6/ln(Bo);.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls, Series;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Chart1: TChart;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Edit3: TEdit;
Label3: TLabel;
Edit4: TEdit;
Label4: TLabel;
Edit5: TEdit;
Label5: TLabel;
Series1: TLineSeries;
Series2: TLineSeries;
Series3: TLineSeries;
Button1: TButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Timer1: TTimer;
Label6: TLabel;
Edit6: TEdit;
function p1 (var a,b:array of real): real;
function p2 (var a:array of real): real;
function p3 (var a,b:array of real): real;
function p4 (var a:array of real): real;
function RoundFloat(R: Extended; Decimals: Integer): Extended;
procedure Pac4eT;
procedure Edit1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Button1Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Ao,Bo,S,a1,k:real;
i:byte;
t0 : array [0..8] of real = (0,4,8,12,16,20,24,28,32);
Y0 : array [0..8] of real = (0,12,25,10.5,12.2,12.7,13.2,13.4,13.7);
t : array [0..8] of real;
Y : array [0..8] of real;
X : array [0..8] of real;
Yr : array [0..8] of real;
Yd : array [0..8] of real;
implementation
{$R *.dfm}
procedure TForm1.Edit1Click(Sender: TObject);
begin
Edit1.Text:='';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:=' t';
StringGrid1.Cells[0,1]:=' Y';
StringGrid1.Cells[0,2]:=' Yr';
StringGrid1.Cells[0,3]:=' Yd';
for i:=0 to 9 do StringGrid1.Cells[i+1,0]:=floattostr(t0[i]);
for i:=0 to 9 do StringGrid1.Cells[i+1,1]:=floattostr(Y0[i]);
for i:=0 to 9 do Series1.AddXY(t0[i],Y0[i],'',Clred);
Button1.Enabled:=false;
CheckBox1.Checked:=true;
CheckBox2.Checked:=true;
CheckBox3.Checked:=true;
CheckBox1.Enabled:=false;
CheckBox2.Enabled:=false;
CheckBox3.Enabled:=false;
end;
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Button1.Enabled:=true;
end;
function TForm1.p1 (var a,b:array of real): real;
begin
S:=0;
i:=0;
for i:=1 to 8 do S:= S+(a[i]*b[i-1]);
p1:=s;
end;
function TForm1.p2 (var a:array of real): real;
begin
S:=0;
i:=0;
for i:=1 to 8 do S:= S+(a[i-1]*a[i-1]);
p2:=s;
end;
function TForm1.p3 (var a,b:array of real): real;
begin
S:=0;
i:=0;
for i:=1 to 8 do S:= S+(a[i-1]*b[i-1]);
p3:=s;
end;
function TForm1.p4 (var a:array of real): real;
begin
S:=0;
i:=0;
for i:=1 to 8 do S:= S+(a[i]*a[i-1]);
p4:=s;
end;
procedure TForm1.Pac4eT;
begin
Ao:=(p1(Y,X)*p2(Y)-p3(Y,X)*p4(Y))/(p2(X)*p2(Y)-p3(Y,X)*p3(y,x));
Bo:=(p2(X)*p4(Y)-p1(Y,X)*p3(Y,X))/(p2(X)*p2(Y)-p3(Y,X)*p3(Y,X));
Yr[0]:=0;
Yd[0]:=0;
i:=0;
a1:=-6/ln(Bo);
k:=Ao/(1-Bo);
for i:=1 to 8 do
begin
Yr[i]:=Ao*X[i-1]+Bo*Y[i-1];
Yd[i]:=k*X[i-1]*(1-exp(-6/a1))+ (Yd[i-1]*exp(-6/a1));
end;
end;
function TForm1.RoundFloat(R: Extended; Decimals: Integer): Extended;
var
Factor: Extended;
begin
Factor := Int(Exp(Decimals * Ln(10)));
Result := Round(Factor * R) / Factor;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sn,Sud:extended;
begin
CheckBox1.Enabled:=true;
CheckBox2.Enabled:=true;
CheckBox3.Enabled:=true;
for i:=0 to 9 do t[i]:=StrToFloat(StringGrid1.Cells[i+1,0]);
for i:=0 to 9 do Y[i]:=StrToFloat(StringGrid1.Cells[i+1,1]);
for i:=0 to 9 do X[i]:=strtofloat(Edit1.Text);
if CheckBox1.Checked=true then
for i:=0 to 9 do Series1.AddXY(t[i],Y[i],'',Clred);
Pac4eT;
for i:=0 to 9 do StringGrid1.Cells[i+1,2]:=floattostr(roundfloat(Yr[i],2));
for i:=0 to 9 do StringGrid1.Cells[i+1,3]:=floattostr(roundfloat(Yd[i],2));
Edit2.Text:=floattostr(Ao);
Edit3.Text:=floattostr(Bo);
Edit4.Text:=floattostr(k);
Edit5.Text:=floattostr(a1);
Timer1.Enabled:=true;
if CheckBox2.Checked=true then
for i:=0 to 9 do Series2.AddXY(t[i],Yr[i],'',ClBlue);
if CheckBox3.Checked=true then
for i:=0 to 9 do Series3.AddXY(t[i],Yd[i],'',ClGreen);
for i:=1 to 8 do
begin
sn:=sn+((Y[i]-Ao*X[i-1]-Bo*Y[i-1])*(Y[i]-Ao*X[i-1]-Bo*Y[i-1]))/(Y[i]*Y[i])
end;
Sud:=sqrt(sn/(8-2));
Edit6.Text:=floattostr(Sud);
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked=false then
begin
Series1.Clear;
exit;
end;
for i:=0 to 9 do Series1.AddXY(t[i],Y[i],'',Clred);
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked=false then
begin
Series2.Clear;
exit;
end;
for i:=0 to 9 do Series2.AddXY(t[i],Yr[i],'',ClBlue);
end;
procedure TForm1.CheckBox3Click(Sender: TObject);
begin
if CheckBox3.Checked=false then
begin
Series3.Clear;
exit;
end;
for i:=0 to 9 do Series3.AddXY(t[i],Yd[i],'',ClGreen);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if StringGrid1.Height<=87 then
StringGrid1.Height:=StringGrid1.Height+2
else
Timer1.Enabled:=false;
end;
end.
|