Построить график функции - Turbo Pascal (29044)
Формулировка задачи:
Функция: y=cos(x)
Диапазон:2;4
шаг:0,2
Решение задачи: «Построить график функции»
textual
Листинг программы
uses graphABC;
function F(x:real):real;
begin
F:=cos(x);
end;
var xn,xk,x,mx,dx:real;
x0,y0,my,i:integer;
s:string;
begin
x0:=40;
y0:=windowheight div 2;
xn:=2;xk:=4;{интервал по Х}
mx:=(windowwidth-x0-30)/xk;{масштаб по Х}
my:=y0-20;{по У}
for i:=1 to 20 do
begin
line(x0+round(i*mx/5),y0-3,x0+round(i*mx/5),y0+3);
line(x0-3,y0-round(i*my/5),x0+3,y0-round(i*my/5));
line(x0-3,y0+round(i*my/5),x0+3,y0+round(i*my/5));
str(i/5:0:1,s);
textout(x0+round(i*mx/5),y0+10,s);
textout(x0-20,y0-round(i*my/5),s);
textout(x0-25,y0+round(i*my/5),s);
end;
{график}
x:=xn;
setpencolor(clBlue);
moveto(x0+round(x*mx),y0-round(F(x)*my));
dx:=0.2;
while x<=xk do
begin
x:=x+dx; {наращиваем х}
lineto(x0+round(x*mx),y0-round(F(x)*my));
end;
line(0,y0,windowwidth,y0);{оси}
line(windowwidth,y0,windowwidth-10,y0+5);
line(windowwidth,y0,windowwidth-10,y0-5);
line(x0,0,X0,windowheight);
line(x0,0,x0-5,10);
line(x0,0,x0+5,10);
textout(x0+5,y0+10,'0');
{подписи концов осей}
textout(windowwidth-10,y0-20,'X');
textout(x0+10,0, 'Y');
setfontsize(12);
textout(120,30,'F(x)=cos(x)');
textout(100,50,'интервал [2;4]');
end.