//pascalabc.net uses graphabc; const w = 600; h = 600; function f(x: real): real; begin f : = 1 / x; end; var x0, y0, x, y, xleft, yleft, xright, yright, n: integer; a, b, fmin, fmax, x1, y1, mx, my, dx, dy, num: real; i: byte; s: string; begin setwindowsize(w, h); xleft : = 10; yleft : = 10; xright : = w - 10; yright : = h - 10; a : = -5; b : = 5; dx : = 1; fmin : = -5; fmax : = 5; dy : = 1; mx : = (xright - xleft) / (b - a); my : = (yright - yleft) / (fmax - fmin); x0 : = trunc(abs(a) * mx) + xleft; y0 : = h div 2; line(xleft, y0, xright + 10, y0); line(x0, yleft - 10, x0, yright); setfontsize(12); setfontcolor(clblue); textout(xright + 20, y0 - 15, 'x'); textout(x0 - 10, yleft - 30, 'y'); setfontsize(8); setfontcolor(clred); n : = round((b - a) / dx) + 1; for i : = 1 to n do begin num : = a + (i - 1) * dx; x : = xleft + trunc(mx * (num - a)); line(x, y0 - 3, x, y0 + 3); str(num: 0: 0, s); if abs(num) > 1e-15 then textout(x - textwidth(s) div 2, y0 + 10, s) end; n : = round((fmax - fmin) / dy) + 1; for i : = 1 to n do begin num : = fmin + (i - 1) * dy; y : = yright - trunc(my * (num - fmin)); line(x0 - 3, y, x0 + 3, y); str(num: 0: 0, s); if abs(num) > 1e-15 then textout(x0 + 7, y - textheight(s) div 2, s) end; textout(x0 - 10, y0 + 10, '0'); x1 : = a; while x1 < = b do begin x : = x0 + round(x1 * mx); y1 : = f(x1); if y < h then y : = y0 - round(y1 * my); if (y > = yleft) and (y < = yright) then setpixel(w - x, h - y, clgreen); if (y > = yleft) and (y < = yright) then setpixel(x, y, clgreen); x1 : = x1 + 0.001; end; end.
Спасибо
Популярные вопросы