var
  Form1: TForm1;  x:array[0..11] of double = (37.841,40.043,42.756,45.330,47.137,47.771,49.236,50.86,52.705,54.395,55.575,56);
  y:array[0..11] of double = (18.223,14.878,12.491,11.229,10.875,10.904,10.732,9.998,8.512,6.234,3.302,0);
  a,b,c,d:array[0..11] of real;                                                                            implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var    h,m:array[0..11] of real;
        p,gama,r:array[0..11] of real;
         i,n:integer;
       begin
n:=11;
m[0]:=0;
m[n]:=0;
r[0]:=0;
r[n]:=0;for i:=0 to n-1 do
begin
h[i]:=x[i+1]-x[i];
memo9.Lines.Add(formatfloat('0.000',h[i]));
end;
for i:=1 to n-2 do
r[i]:=6*((y[i+2]-y[i+1])/h[i+1]-(y[i+1]-y[i])/h[i]);  //M方程右边的值;
gama[0]:=0;
for i:=1 to n-1 do
gama[i]:=h[i]/(2*(h[i-1]+h[i])-h[i-1]*gama[i-1]);
p[0]:=0;
for i:=2 to n do
p[i]:=(r[i]-h[i]*p[i-1])/(2*(h[i-1]+h[i])-h[i-1]*gama[i-1]);i:=n-1;
while  i>=1  do
begin
m[i]:=p[i]-gama[i]*m[i+1];
i:=i-1;
end;for i:=0 to n-1 do
begin
a[i]:=y[i];
b[i]:=(y[i+1]-y[i])/h[i]-h[i]*m[i]/2-h[i]/6*(m[i+1]-m[i]);
c[i]:=m[i]/2;
d[i]:=(m[i+1]-m[i])/(6*h[i]);
end;//---------------输出部分---------------------------
memo1.Lines.Clear;
memo2.Lines.Clear;
for i:=0 to n do
begin
memo1.lines.add(formatfloat('0.000',r[i]));
memo2.Lines.Add(formatfloat('0.000',m[i])) ;
memo4.lines.add(formatfloat('0.000',gama[i]));
memo3.Lines.Add(formatfloat('0.000',p[i])) ;
memo5.Lines.Add(formatfloat('0.000',a[i])) ;
memo6.Lines.Add(formatfloat('0.000',b[i])) ;
memo7.Lines.Add(formatfloat('0.000',c[i])) ;
memo8.Lines.Add(formatfloat('0.000',d[i])) ;
end;for i:=0 to n-1 do
begin
memo10.Lines.Add('s'+inttostr(i)+'(x)='+formatfloat('0.000',a[i])+formatfloat('0.000',b[i])+'(x-'+formatfloat('0.000',x[i])+')+'+
                   formatfloat('0.000',c[i])+'(x-'+formatfloat('0.000',x[i])+')^2+'+formatfloat('0.000',d[i])+'(x-'+formatfloat('0.000',x[i])+')^3');
memo10.Lines.add(formatfloat('0.000',x[i])+'≤x≤'+formatfloat('0.000',x[i+1]));
end;
 end;  //计算按钮的程序终止点
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;procedure TForm1.Button3Click(Sender: TObject);
var step,yn:real;
    i,j:integer;
    xn:array[0..11] of real;
begin
form2.show;
 i:=0;
 xn[1]:=x[i];
step:=0.01; while xn[1]<=x[i+1] do
begin
    yn:=8*(50-(a[i]+b[i]*(xn[1]-x[i])+c[i]*sqr(xn[1]-x[i])+d[i]*sqr(xn[1]-x[i])*(xn[1]-x[i])));
    form2.Canvas.Pixels[round(8*xn[1]),round(yn)]:=clRed;
  xn[1]:=xn[1]+step;
  if xn[1]>x[i+1] then i:=i+1;
  if i>11 then break;
  end;
  for j:=0 to 11 do
begin
form2.Canvas.Pixels[round(8*x[j]+1),round(8*(50-y[j]))]:=clGreen;
form2.Canvas.Pixels[round(8*x[j]-1),round(8*(50-y[j]))]:=clGreen;
form2.Canvas.Pixels[round(8*x[j]),round(8*(50-y[j])+1)]:=clGreen;
form2.Canvas.Pixels[round(8*x[j]),round(8*(50-y[j])-1)]:=clGreen;
form2.Canvas.Pixels[round(8*x[j]),round(8*(50-y[j]))]:=clGreen;
  end;
end;end.