
25.05.2010, 03:09
|
Прохожий
|
|
Регистрация: 17.05.2010
Сообщения: 5
Репутация: 10
|
|
нужна маленькая поправка!
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer;
x,a:real;
b:string;
h: array [1..5] of real = (1, 0.2, 0.1, 0.01, 0.001);
p1,p2,p3: array [1..5] of real;
implementation
{$R *.dfm}
Function y(x:real):real;
begin
y:=ln((2*x*x+x-3)/(3*x*x+15*x+12));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
x:=strtoint(edit1.Text);
for i:= 1 to 5 do
begin
p1[i]:=(y(x+h[i])-y(x))/h[i];
p2[i]:=(y(x)-y(x-h[i]))/h[i];
p3[i]:=(y(x+h[i])-y(x-h[i]))/(2*h[i]);
end;
for i:=1 to 5 do
begin
a:=p1[i];
str(a:4:4,b);
StringGrid1.Cells[i,1]:=b;
a:=p2[i];
str(a:4:4,b);
StringGrid1.Cells[i,2]:=b;
a:=p3[i];
str(a:4:4,b);
StringGrid1.Cells[i,3]:=b;
begin
StringGrid1.Cells[0,0]:='h';
StringGrid1.Cells[0,1]:='p1';
StringGrid1.Cells[0,2]:='p2';
StringGrid1.Cells[0,3]:='p3';
StringGrid1.Cells[1,0]:='1';
StringGrid1.Cells[2,0]:='0.2';
StringGrid1.Cells[3,0]:='0.1';
StringGrid1.Cells[4,0]:='0.01';
StringGrid1.Cells[5,0]:='0.001';
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
end.
есть такой код, как сделать что бы h задавалось с клавиатуры(h это шаг)
|