
23.06.2011, 11:05
|
Прохожий
|
|
Регистрация: 22.06.2011
Сообщения: 3
Репутация: 10
|
|
Компилятор никуда не ругается вообще, а если и ругается бывает то на доступ к адресу в памяти.
Код немного немного, но все равно чушь полная получается.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, Math;
type
TForm1 = class(TForm)
Chart1: TChart;
Chart2: TChart;
Series1: TLineSeries;
Series2: TLineSeries;
Series3: TLineSeries;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
xmin=-10;
xmax=10;
n=3;
var
Form1: TForm1;
i,j: integer;
x1,x2,x3,h: real;
x,fx: array [1..3] of real;
implementation
{$R *.dfm}
function yf(x:real):real;
begin
yf:=x*x+4*x+3;
end;
Function Newton(n: integer; d:real; x,y :array of real):real;
var
l,l2:real;
j,i,k,u:integer;
p,p2: real;
y1,y2: array of real;
begin
L:=fx[1];
P:=1;
p2:=1;
for j:=1 to n do
begin
p:=p*(D-X[j-1]);
for i:=0 to (n-j) do
begin
Y[i]:=(y[i+1]-y[i])/(x[i+j]-x[i]);
end;
L:=L+P*y[i];
end;
for u:=1 to n do
begin
p2:=p2*(d-x[u-1])*(d-x[u]);
for k := 0 to (n-u) do
begin
y[k]:=(((y[k+2]-y[k+1])/(x[k+u]-x[k]))-y[i])/(x[u+2]-x[u]);
end;
L2:=L2+p2*y[k];
end;
Newton:=-l-l2;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
x1:=xmin;
while x1<=xmax do
begin
Series1.AddXY(x1,yf(x1));
x1:=x1+1;
end;
x2:=-1;
for i:=1 to n do
begin
x[i]:=x2;
fx[i]:=yf(x[i]);
x2:=x2+1;
end;
x3:=xmin;
while x3<=xmax do
begin
for i:=1 to 10 do
begin
Series2.AddXY(x3,Newton(n,x3,x,fx));
Series3.AddXY(x3, abs (yf(x3)-Newton(n,x3,x,fx)) );
x3:=x3+0.01;
end;
end;
end;
end.
Вот что строит прога:

Точки это исходный график, прямая - искомый полином
|