Задача: Проиллюстрировать один из численных методов вычисления определенного интеграла. (любого на выбор) 


var
Form1: TForm1;
a, b, x, s, i, n, h, t,y,rX,rY:Real;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
a := -5;
b := 5;
n := 30;
h := (b - a) / n;
x:=a;
y:=sin(x);
rX:= Image1.Width / (b -a);
rY:= Image1.Height / (b -a);
Image1.Canvas.MoveTo(0, Trunc(Image1.Height/2 - (y)*rY));
Image1.Canvas.Brush.Style:=bsClear;
x:=x+h;
While x<=b+h do Begin y:= sin(x); Image1.Canvas.Pen.Color := clBlack; Image1.Canvas.LineTo(Trunc((x - a)*rX),Trunc(Image1.Height/2 - (y)*rY)); Image1.Canvas.Pen.Color := clRed; Image1.Canvas.Rectangle(Trunc((x - h - a)*rX), Trunc(Image1.Height/2), Trunc((x - a)*rX) , Trunc(Image1.Height/2 - (y)*rY)); x:=x+h; end; Image1.Canvas.Pen.Color := clBlack; Image1.Canvas.MoveTo(0,Trunc(Image1.Height/2)); Image1.Canvas.LineTo(Image1.Width,Trunc(Image1.Height/2)); Image1.Canvas.MoveTo(Trunc(Image1.Width/2),0); Image1.Canvas.LineTo(Trunc(Image1.Width/2),(Image1.Height));
end;
Комментариев нет:
Отправить комментарий