Метод хорд
procedure TForm1.BtnHordClick(Sender: TObject);
var a0,a1,a2,n0,n1,n2,m1,m2,e,c,x1,x2,y1,y2,y3,Epsylon,ERS:real;
i:integer;
begin
Epsylon:=0;
form1.StrRezult.RowCount:=1;
a0:=strToFloat(Edta0.Text);
a1:=strToFloat(Edta1.Text);
a2:=strToFloat(Edta2.Text);
n0:=strToFloat(Edtb0.Text);
n1:=strToFloat(Edtb1.Text);
n2:=strToFloat(Edtb2.Text);
ERS:=strToFloat(EdtERS.Text);
m1:=strToFloat(Edt1.Text);
m2:=strToFloat(Edt2.Text);
e:=strToFloat(EdtMaxNevjazka.Text);
form1.StrRezult.Cells[0,0]:='№';
form1.StrRezult.Cells[1,0]:='x1';
form1.StrRezult.Cells[2,0]:='x2';
form1.StrRezult.Cells[3,0]:='Нев"язка y1' ;
form1.StrRezult.Cells[4,0]:='Нев"язка y2' ;
form1.StrRezult.Cells[5,0]:='Похибка' ;
x1:=m1; x2:=m2; c:=0;
y1:=a0*power(x1,n0)+a1*power(x1,n1)+a2*power(x1,n2)+ERS;
y2:=a0*power(x2,n0)+a1*power(x2,n1)+a2*power(x2,n2)+ERS;
y3:=a0*power(c,n0)+a1*power(c,n1)+a2*power(c,n2)+ERS;
i:=1;
Epsylon:=(abs(m1-m2))/2;
while Epsylon>=e do
begin
c:=x1-y1*(x2-x1)/(y2-y1);
y3:=a0*power(c,n0)+a1*power(c,n1)+a2*power(c,n2)+ERS;
if (y1*y3)<0 then x2:=c;
else if (y2*y3)<0 then x1:=c;
y1:=a0*power(x1,n0)+a1*power(x1,n1)+a2*power(x1,n2)+ERS;
y2:=a0*power(x2,n0)+a1*power(x2,n1)+a2*power(x2,n2)+ERS;
if abs(y1)<abs(y2) then
Epsylon:=abs(y1)
else Epsylon:=abs(y2);
form1.StrRezult.RowCount:=form1.StrRezult.RowCount+1;
form1.StrRezult.Cells[0,i]:=intToStr(i);
form1.StrRezult.Cells[1,i]:=floatToStr(x1);
form1.StrRezult.Cells[2,i]:=floatToStr(x2);
form1.StrRezult.Cells[3,i]:=floatToStr(y1);
form1.StrRezult.Cells[4,i]:=floatToStr(y2);
form1.StrRezult.Cells[5,i]:=floatToStr(Epsylon);
inc(i);
end; end;
Метод Ньютона
procedure TForm1.BtnNutonClick(Sender: TObject);
var a0,a1,a2,n0,n1,n2,m1,m2,e,c,x1,x2,y1,dy,Epsylon,ERS:real;
i:integer;
begin
form1.StrRezult.RowCount:=1;
a0:=strToFloat(Edta0.Text);
a1:=strToFloat(Edta1.Text);
a2:=strToFloat(Edta2.Text);
n0:=strToFloat(Edtb0.Text);
n1:=strToFloat(Edtb1.Text);
n2:=strToFloat(Edtb2.Text);
ERS:=strToFloat(EdtERS.Text);
m1:=strToFloat(Edt1.Text);
m2:=strToFloat(Edt2.Text);
e:=strToFloat(EdtMaxNevjazka.Text);
form1.StrRezult.Cells[0,0]:='№';
form1.StrRezult.Cells[1,0]:='x(k)';
form1.StrRezult.Cells[2,0]:='Нев"язка y(k)';
form1.StrRezult.Cells[3,0]:='x(k+1)';
form1.StrRezult.Cells[4,0]:='dx=x(k+1)-x(k)' ;
x1:=m1; x2:=0;
y1:=a0*power(x1,n0)+a1*power(x1,n1)+a2*power(x1,n2)+ERS;
dy:=a0*n0*power(x1,n0-1)+a1*n1*power(x1,n1-1)+a2*n2*power(x1,n2-1);
i:=1;
Epsylon:=(abs(m1-m2))/2;
while Epsylon>=e do
begin
y1:=a0*power(x1,n0)+a1*power(x1,n1)+a2*power(x1,n2)+ERS;
dy:=a0*n0*power(x1,n0-1)+a1*n1*power(x1,n1-1)+a2*n2*power(x1,n2-1);
x2:=x1-(y1)/(dy);
Epsylon:=abs(y1);
form1.StrRezult.ColCount:=5;
form1.StrRezult.RowCount:=form1.StrRezult.RowCount+1;
form1.StrRezult.Cells[0,i]:=intToStr(i);
form1.StrRezult.Cells[1,i]:=floatToStr(x1);
form1.StrRezult.Cells[2,i]:=floatToStr(y1);
form1.StrRezult.Cells[3,i]:=floatToStr(x2);
form1.StrRezult.Cells[4,i]:=floatToStr(Epsylon);
x1:=x2;
inc(i);
end;end;
