составьте программу для вычисления след. функции y=x^+1 если x>1
Answers & Comments
allangarsk
Uses GraphABC; type FUN = function (x: real): real; function f(x: real): real;begin Result := x*x +1 ;end; // l (logical) - логические координаты// s (screen) - физические координатыprocedure drawGraph(x1,x2: real; f: FUN); var xl0,wl,yl0,hl: real; xs0,ws,ys0,hs: integer; function LtoSx(xl: real): integer; begin Result := round(ws/wl*(xl-xl0)+xs0); end; function LtoSy(yl: real): integer; begin Result := round(hs/hl*(yl-yl0)+ys0); end; function StoLx(xs: integer): real; begin Result := wl/ws*(xs-xs0)+xl0; end; begin // drawGraph xs0 := 0; ys0 := WindowHeight-1; ws := WindowWidth; hs := WindowHeight-1; xl0 := x1; wl := x2-x1; var min := real.MaxValue; var max := real.MinValue; var yi: array of real; SetLength(yi,ws+1); for var xi:=0 to ws do begin if xi > 320 then begin yi[xi] := f(StoLx(xi+xs0)); if yi[xi]<min then min := yi[xi]; if yi[xi]>max then max := yi[xi]; end; end; yl0 := min; hl := -(max-min); // Нарисовать оси системы координат Line(0,LtoSy(0),ws,LtoSy(0)); Line(LtoSx(0),0,LtoSx(0),hs); Pen.Color := clBlue; MoveTo(xs0,LtoSy(yi[0])); for var xi:=xs0+1 to xs0+ws do LineTo(xi,LtoSy(yi[xi-xs0]));end; procedure Resize;begin ClearWindow; drawGraph(-60,60,f); Redraw;end; begin LockDrawing; SetWindowCaption('График функции: масштабирование'); drawGraph(-60,60,f); Redraw; OnResize := Resize;end.
Answers & Comments
type FUN = function (x: real): real;
function f(x: real): real;begin Result := x*x +1 ;end;
// l (logical) - логические координаты// s (screen) - физические координатыprocedure drawGraph(x1,x2: real; f: FUN); var xl0,wl,yl0,hl: real; xs0,ws,ys0,hs: integer; function LtoSx(xl: real): integer; begin Result := round(ws/wl*(xl-xl0)+xs0); end; function LtoSy(yl: real): integer; begin Result := round(hs/hl*(yl-yl0)+ys0); end; function StoLx(xs: integer): real; begin Result := wl/ws*(xs-xs0)+xl0; end;
begin // drawGraph xs0 := 0; ys0 := WindowHeight-1; ws := WindowWidth; hs := WindowHeight-1; xl0 := x1; wl := x2-x1;
var min := real.MaxValue; var max := real.MinValue; var yi: array of real; SetLength(yi,ws+1);
for var xi:=0 to ws do begin if xi > 320 then begin yi[xi] := f(StoLx(xi+xs0)); if yi[xi]<min then min := yi[xi]; if yi[xi]>max then max := yi[xi]; end; end; yl0 := min; hl := -(max-min);
// Нарисовать оси системы координат Line(0,LtoSy(0),ws,LtoSy(0)); Line(LtoSx(0),0,LtoSx(0),hs);
Pen.Color := clBlue; MoveTo(xs0,LtoSy(yi[0])); for var xi:=xs0+1 to xs0+ws do LineTo(xi,LtoSy(yi[xi-xs0]));end;
procedure Resize;begin ClearWindow; drawGraph(-60,60,f); Redraw;end;
begin LockDrawing; SetWindowCaption('График функции: масштабирование'); drawGraph(-60,60,f); Redraw; OnResize := Resize;end.